Commit 1e8451f9 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[FIX] - fixed several tests

parent e0a1948b
......@@ -155,7 +155,7 @@ void WLine::resampleBySegmentLength( double newSegmentLength )
{
if( length( newLine.back() - ( *this )[i] ) > newSegmentLength )
{
const WVector3d_2& pred = ( *this )[i - 1];
const WPosition_2& pred = ( *this )[i - 1];
if( pred == newLine.back() )
{
// Then there is no triangle and the old Segment Length is bigger as the new segment
......@@ -239,7 +239,7 @@ double maxSegmentLength( const WLine& line )
}
for( size_t i = 0; i < line.size() - 1; ++i )
{
result = std::max( result, length( line[i] - line[i+1] ) );
result = std::max( result, static_cast< double >( length( line[i] - line[i+1] ) ) );
}
return result;
}
......
......@@ -67,7 +67,7 @@ WPosition_2 transformPosition3DWithMatrix4D( WMatrix<double> mat, WPosition_2 ve
resultVec4D[2] = mat( 2, 0 ) * vec[0] + mat( 2, 1 ) * vec[1] + mat( 2, 2 ) * vec[2] + mat( 2, 3 ) * 1;
resultVec4D[3] = mat( 3, 0 ) * vec[0] + mat( 3, 1 ) * vec[1] + mat( 3, 2 ) * vec[2] + mat( 3, 3 ) * 1;
WVector3d_2 result;
WPosition_2 result;
result[0] = resultVec4D[0] / resultVec4D[3];
result[1] = resultVec4D[1] / resultVec4D[3];
result[2] = resultVec4D[2] / resultVec4D[3];
......
......@@ -55,7 +55,7 @@ WVector3d_2 OWCOMMON_EXPORT transformVector3DWithMatrix4D( WMatrix<double> mat,
* \param mat 4x4 matrix
* \param vec vector
*/
WVector3d_2 OWCOMMON_EXPORT transformPosition3DWithMatrix4D( WMatrix<double> mat, WPosition_2 vec );
WPosition_2 OWCOMMON_EXPORT transformPosition3DWithMatrix4D( WMatrix<double> mat, WPosition_2 vec );
/**
* helper routine to invert a 3x3 matrix
......
......@@ -149,7 +149,11 @@ boost::shared_ptr< std::set< WPosition_2 > > WPlane::samplePoints( double stepWi
WPosition_2 WPlane::getPointInPlane( double x, double y ) const
{
return m_pos + x * m_first + y * m_second;
WVector3d_2 sd= m_pos +
x * m_first
+
y * m_second;
return sd;
}
void WPlane::setPlaneVectors( const WVector3d_2& first, const WVector3d_2& second )
......
......@@ -195,12 +195,19 @@ public:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Default constructor. The values are un-initialized! Use the static methods \ref zero(), \ref identity() or any of the predefined
* Default constructor. The values are initialized with 0. Use the static methods \ref zero(), \ref identity() or any of the predefined
* transformations if an initialized matrix is wished.
*/
WMatrixFixed()
{
// No initialization needed. Matrix values are initialized by ValueStoreT.
// initialize to zero
for ( size_t row = 0; row < Rows; ++row )
{
for ( size_t col = 0; col < Cols; ++col )
{
operator()( row, col ) = ValueT( 0 );
}
}
}
/**
......@@ -237,6 +244,19 @@ public:
operator[]( 3 ) = w;
}
/**
* Copy construction casting the given value type. This is useful to create matrices with matrices using another value type.
*
* \tparam RHSValueT Value type of the given matrix to copy
* \tparam RHSValueStoreT Valuestore type of the given matrix to copy
* \param m the matrix to copy
*/
template< typename RHSValueT, ValueStoreTemplate RHSValueStoreT >
explicit WMatrixFixed( const WMatrixFixed< RHSValueT, Rows, Cols, RHSValueStoreT >& m ) // NOLINT - we do not want it explicit
{
setValues( m.m_values );
}
/**
* Returns an identity matrix.
*
......@@ -479,6 +499,22 @@ public:
return m2;
}
/**
* Cast to matrix of same size with different value type.
*
* \tparam ResultValueType resulting value type
* \tparam ResultValueStore resulting value store
*
* \return the converted matrix.
*/
template < typename ResultValueType, ValueStoreTemplate ResultValueStore >
operator WMatrixFixed< ResultValueType, Rows, Cols, ResultValueStore >() const
{
WMatrixFixed< ResultValueType, Rows, Cols, ResultValueStore > result;
result.setValues( m_values );
return result;
}
/**
* Creates a WMatrix from a given Eigen3 Matrix
*
......@@ -994,10 +1030,7 @@ public:
// For compatibility to the old vec/matrix types. They are ALL deprecated and will be removed
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double normalize() // 28 files use this
{
return 0.0;
}
double normalize();
private:
/**
......@@ -1051,9 +1084,9 @@ typedef WMatrixFixed< float, 4, 4 > WMatrix4f_2;
* \return scaled matrix.
*/
template < typename ScalarT,
typename MatrixValueT, size_t MatrixRows, size_t MatrixCols, ValueStoreTemplate MatrixValueStoreT >
WMatrixFixed< MatrixValueT, MatrixRows, MatrixCols, MatrixValueStoreT >
operator*( const ScalarT n, const WMatrixFixed< MatrixValueT, MatrixRows, MatrixCols, MatrixValueStoreT >& mat )
typename RHSValueT, size_t RHSRows, size_t RHSCols, ValueStoreTemplate RHSValueStoreT >
WMatrixFixed< typename WTypeTraits::TypePromotion< ScalarT, RHSValueT >::Result, RHSRows, RHSCols, RHSValueStoreT >
operator*( const ScalarT n, const WMatrixFixed< RHSValueT, RHSRows, RHSCols, RHSValueStoreT >& mat )
{
return mat * n;
}
......@@ -1197,15 +1230,27 @@ ValueT length( const WMatrixFixed< ValueT, 1, Cols, ValueStoreT >& a )
/**
* Normalizes the given vector.
*
* \tparam MatrixType type of matrix. This type needs to be supported by length().
* \tparam RHSValueT given matrix value type
* \tparam Rows given row number
* \tparam Cols given col number
* \tparam RHSValueStoreT given matrix' valuestore
* \param m the vector
*
* \return normalized vector
*/
template< typename MatrixType >
MatrixType normalize( const MatrixType& m )
template< typename RHSValueT, size_t Rows, size_t Cols, ValueStoreTemplate RHSValueStoreT >
WMatrixFixed< RHSValueT, Rows, Cols, RHSValueStoreT > normalize( const WMatrixFixed< RHSValueT, Rows, Cols, RHSValueStoreT >& m )
{
// NOTE: the static cast ensures that the returned matrix value type is the same as the input one.
return m * static_cast< RHSValueT >( 1.0 / length( m ) );
}
template< typename ValueT, size_t Rows, size_t Cols, ValueStoreTemplate ValueStoreT >
double WMatrixFixed< ValueT, Rows, Cols, ValueStoreT >::normalize()
{
return m * ( 1.0 / length( m ) );
ValueT l = length( *this );
operator/=( l );
return l;
}
/**
......
......@@ -34,6 +34,7 @@
* WPosition_2 such is just another name for WVector3d_2 to indicate the specific use
* for positions in some places.
*/
typedef WVector3d_2 WPosition_2;
#endif // WPOSITION_H
......@@ -37,7 +37,6 @@ typedef WMatrixFixed< double, 4, 1 > WVector4d_2;
typedef WMatrixFixed< double, 1, 2 > WVector2dRow_2;
typedef WMatrixFixed< double, 1, 3 > WVector3dRow_2;
typedef WMatrixFixed< double, 1, 4 > WVector4dRow_2;
typedef WMatrixFixed< double, 3, 1 > WPosition_2;
// Float vectors
typedef WMatrixFixed< float, 2, 1 > WVector2f_2;
......
......@@ -100,9 +100,9 @@ public:
l.push_back( WPosition_2( 1.0, 1.0, 3.1415 ) );
l.push_back( WPosition_2( 0.0, 0.0, 0.44 ) );
l.push_back( WPosition_2( 1.0, 1.0, 1.0 ) );
std::string expected( "[[1.0000000000000000e+00, 1.0000000000000000e+00, 3.1415000000000002e+00], "
"[0.0000000000000000e+00, 0.0000000000000000e+00, 4.4000000000000000e-01], "
"[1.0000000000000000e+00, 1.0000000000000000e+00, 1.0000000000000000e+00]]" );
std::string expected( "[1.0000000000000000e+00;1.0000000000000000e+00;3.1415000000000002e+00;, "
"0.0000000000000000e+00;0.0000000000000000e+00;4.4000000000000000e-01;, "
"1.0000000000000000e+00;1.0000000000000000e+00;1.0000000000000000e+00;]" );
std::stringstream ss;
ss << l;
TS_ASSERT_EQUALS( expected, ss.str() );
......
......@@ -128,27 +128,30 @@ int WGridRegular3D::getXVoxelCoord( const WPosition_2& pos ) const
WPosition_2 v = m_transform.positionToGridSpace( pos );
// this part could be refactored into an inline function
v[ 2 ] = modf( v[ 0 ] + 0.5, &v[ 1 ] );
double d;
v[ 2 ] = modf( v[ 0 ] + 0.5, &d );
int i = static_cast< int >( v[ 0 ] >= 0.0 && v[ 0 ] < m_nbPosX - 1.0 );
return -1 + i * static_cast< int >( 1.0 + v[ 1 ] );
return -1 + i * static_cast< int >( 1.0 + d );
}
int WGridRegular3D::getYVoxelCoord( const WPosition_2& pos ) const
{
WPosition_2 v = m_transform.positionToGridSpace( pos );
v[ 0 ] = modf( v[ 1 ] + 0.5, &v[ 2 ] );
double d;
v[ 0 ] = modf( v[ 1 ] + 0.5, &d );
int i = static_cast< int >( v[ 1 ] >= 0.0 && v[ 1 ] < m_nbPosY - 1.0 );
return -1 + i * static_cast< int >( 1.0 + v[ 2 ] );
return -1 + i * static_cast< int >( 1.0 + d );
}
int WGridRegular3D::getZVoxelCoord( const WPosition_2& pos ) const
{
WPosition_2 v = m_transform.positionToGridSpace( pos );
v[ 0 ] = modf( v[ 2 ] + 0.5, &v[ 1 ] );
double d;
v[ 0 ] = modf( v[ 2 ] + 0.5, &d );
int i = static_cast< int >( v[ 2 ] >= 0.0 && v[ 2 ] < m_nbPosZ - 1.0 );
return -1 + i * static_cast< int >( 1.0 + v[ 1 ] );
return -1 + i * static_cast< int >( 1.0 + d );
}
WValue< int > WGridRegular3D::getVoxelCoord( const WPosition_2& pos ) const
......
......@@ -64,7 +64,7 @@ public:
bool success = false;
TS_ASSERT_EQUALS( ds.interpolate( WPosition_2(), &success ), ( *data )[0] );
TS_ASSERT_EQUALS( ds.interpolate( WPosition_2::zero(), &success ), ( *data )[0] );
TS_ASSERT( success );
TS_ASSERT_DELTA( ds.interpolate( WPosition_2( 1, 0, 0 ), &success ), ( *data )[1], 1e-9 );
TS_ASSERT( success );
......
......@@ -63,9 +63,9 @@ public:
bool success = false;
TS_ASSERT_EQUALS( ds.interpolate( WPosition_2(), &success )[0], ( *data )[0] );
TS_ASSERT_EQUALS( ds.interpolate( WPosition_2(), &success )[1], ( *data )[1] );
TS_ASSERT_EQUALS( ds.interpolate( WPosition_2(), &success )[2], ( *data )[2] );
TS_ASSERT_EQUALS( ds.interpolate( WPosition_2( 0, 0, 0 ), &success )[0], ( *data )[0] );
TS_ASSERT_EQUALS( ds.interpolate( WPosition_2( 0, 0, 0 ), &success )[1], ( *data )[1] );
TS_ASSERT_EQUALS( ds.interpolate( WPosition_2( 0, 0, 0 ), &success )[2], ( *data )[2] );
TS_ASSERT( success );
TS_ASSERT_DELTA( ds.interpolate( WPosition_2( 1, 0, 0 ), &success )[0], ( *data )[3], 1e-9 );
TS_ASSERT_DELTA( ds.interpolate( WPosition_2( 1, 0, 0 ), &success )[1], ( *data )[4], 1e-9 );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment