Commit ac3db61c authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[ADD] matrix representation of transformation of grid. Now Ralph can get the

matrix directly.
parent 55832a1a
......@@ -38,14 +38,31 @@ WGridRegular3D::WGridRegular3D( double originX, double originY, double originZ,
m_nbPosX( nbPosX ), m_nbPosY( nbPosY ), m_nbPosZ( nbPosZ ),
m_directionX( directionX ),
m_directionY( directionY ),
m_directionZ( directionZ )
m_directionZ( directionZ ),
m_matrix( 4, 4 )
{
m_matrix( 0, 0 ) = directionX[0];
m_matrix( 0, 1 ) = directionY[0];
m_matrix( 0, 2 ) = directionZ[0];
m_matrix( 1, 0 ) = directionX[1];
m_matrix( 1, 1 ) = directionY[1];
m_matrix( 1, 2 ) = directionZ[1];
m_matrix( 2, 0 ) = directionX[2];
m_matrix( 2, 1 ) = directionY[2];
m_matrix( 2, 2 ) = directionZ[2];
m_matrix( 0, 3 ) = originX;
m_matrix( 1, 3 ) = originY;
m_matrix( 2, 3 ) = originZ;
m_matrix( 3, 3 ) = 1.;
}
WGridRegular3D::WGridRegular3D( unsigned int nbPosX, unsigned int nbPosY, unsigned int nbPosZ,
const WMatrix< double >& mat )
: WGrid( nbPosX * nbPosY * nbPosZ ),
m_nbPosX( nbPosX ), m_nbPosY( nbPosY ), m_nbPosZ( nbPosZ )
m_nbPosX( nbPosX ),
m_nbPosY( nbPosY ), m_nbPosZ( nbPosZ ),
m_matrix( wmath::WMatrix<double>( mat ) )
{
assert( mat.getNbRows() == 4 && mat.getNbCols() == 4 );
// only affine transformations are allowed
......@@ -56,6 +73,8 @@ WGridRegular3D::WGridRegular3D( unsigned int nbPosX, unsigned int nbPosY, unsign
m_directionX = WVector3D( mat( 0, 0 ) / mat( 3, 3 ), mat( 1, 0 ) / mat( 3, 3 ), mat( 2, 0 ) / mat( 3, 3 ) );
m_directionY = WVector3D( mat( 0, 1 ) / mat( 3, 3 ), mat( 1, 1 ) / mat( 3, 3 ), mat( 2, 1 ) / mat( 3, 3 ) );
m_directionZ = WVector3D( mat( 0, 2 ) / mat( 3, 3 ), mat( 1, 2 ) / mat( 3, 3 ), mat( 2, 2 ) / mat( 3, 3 ) );
m_matrix = mat;
}
......@@ -64,22 +83,41 @@ WGridRegular3D::WGridRegular3D( double originX, double originY, double originZ,
double offsetX, double offsetY, double offsetZ )
: WGrid( nbPosX * nbPosY * nbPosZ ),
m_origin( WPosition( originX, originY, originZ ) ),
m_nbPosX( nbPosX ), m_nbPosY( nbPosY ), m_nbPosZ( nbPosZ ),
m_nbPosX( nbPosX ),
m_nbPosY( nbPosY ),
m_nbPosZ( nbPosZ ),
m_directionX( WVector3D( offsetX, 0., 0. ) ),
m_directionY( WVector3D( 0., offsetY, 0. ) ),
m_directionZ( WVector3D( 0., 0., offsetZ ) )
m_directionZ( WVector3D( 0., 0., offsetZ ) ),
m_matrix( 4, 4 )
{
m_matrix( 0, 0 ) = offsetX;
m_matrix( 1, 1 ) = offsetY;
m_matrix( 2, 2 ) = offsetZ;
m_matrix( 0, 3 ) = originX;
m_matrix( 1, 3 ) = originY;
m_matrix( 2, 3 ) = originZ;
m_matrix( 3, 3 ) = 1.;
}
WGridRegular3D::WGridRegular3D( unsigned int nbPosX, unsigned int nbPosY, unsigned int nbPosZ,
double offsetX, double offsetY, double offsetZ )
: WGrid( nbPosX * nbPosY * nbPosZ ),
m_origin( WPosition( 0., 0., 0. ) ),
m_nbPosX( nbPosX ), m_nbPosY( nbPosY ), m_nbPosZ( nbPosZ ),
m_nbPosX( nbPosX ),
m_nbPosY( nbPosY ),
m_nbPosZ( nbPosZ ),
m_directionX( WVector3D( offsetX, 0., 0. ) ),
m_directionY( WVector3D( 0., offsetY, 0. ) ),
m_directionZ( WVector3D( 0., 0., offsetZ ) )
m_directionZ( WVector3D( 0., 0., offsetZ ) ),
m_matrix( 4, 4 )
{
m_matrix( 0, 0 ) = offsetX;
m_matrix( 1, 1 ) = offsetY;
m_matrix( 2, 2 ) = offsetZ;
m_matrix( 3, 3 ) = 1.;
}
WPosition WGridRegular3D::getPosition( unsigned int i ) const
......@@ -91,3 +129,7 @@ WPosition WGridRegular3D::getPosition( unsigned int iX, unsigned int iY, unsigne
{
return m_origin + iX * m_directionX + iY * m_directionY + iZ * m_directionZ;
}
wmath::WMatrix<double> WGridRegular3D::getTransformationMatrix() const
{
return m_matrix;
}
......@@ -39,6 +39,10 @@
*/
class WGridRegular3D : public WGrid
{
/**
* Only test are allowed as friends.
*/
friend class WGridRegular3DTest;
public:
/**
* Defines the position of the origin of the grid, the number of
......@@ -166,6 +170,13 @@ public:
*/
wmath::WPosition getPosition( unsigned int iX, unsigned int iY, unsigned int iZ ) const;
/**
* Return the matrix storing the transformation of the grid. This information is redundant.
* Please use m_origin and m_direction? for all normal computations.
* Use matrix only where you really need a matrix for multiplication.
*/
wmath::WMatrix<double> getTransformationMatrix() const;
protected:
private:
wmath::WPosition m_origin;
......@@ -177,6 +188,13 @@ private:
wmath::WVector3D m_directionX;
wmath::WVector3D m_directionY;
wmath::WVector3D m_directionZ;
/**
* Matrix storing the transformation of the grid. This is redundant.
* Please use m_origin and m_direction? for all normal computations.
* Use matrix only where you really need a matrix for multiplication.
*/
wmath::WMatrix<double> m_matrix;
};
#endif // WGRIDREGULAR3D_H
......@@ -104,6 +104,113 @@ public:
TS_ASSERT_EQUALS( grid4.size(), 27 );
}
/**
* After instantiation there should be the right vectors, matrix and origin.
*/
void testOrientation( void )
{
WGridRegular3D grid( 3, 3, 3, 2.2, 3.3, 4.4 );
TS_ASSERT_EQUALS( grid.size(), 27 );
TS_ASSERT_EQUALS( grid.m_origin, WPosition( 0., 0., 0. ) );
TS_ASSERT_EQUALS( grid.m_directionX, WVector3D( 2.2, 0., 0. ) );
TS_ASSERT_EQUALS( grid.m_directionY, WVector3D( 0., 3.3, 0. ) );
TS_ASSERT_EQUALS( grid.m_directionZ, WVector3D( 0., 0., 4.4 ) );
TS_ASSERT_EQUALS( grid.m_matrix( 0, 0 ), 2.2 );
TS_ASSERT_EQUALS( grid.m_matrix( 0, 1 ), 0.0 );
TS_ASSERT_EQUALS( grid.m_matrix( 0, 2 ), 0.0 );
TS_ASSERT_EQUALS( grid.m_matrix( 0, 3 ), 0.0 );
TS_ASSERT_EQUALS( grid.m_matrix( 1, 0 ), 0.0 );
TS_ASSERT_EQUALS( grid.m_matrix( 1, 1 ), 3.3 );
TS_ASSERT_EQUALS( grid.m_matrix( 1, 2 ), 0.0 );
TS_ASSERT_EQUALS( grid.m_matrix( 1, 3 ), 0.0 );
TS_ASSERT_EQUALS( grid.m_matrix( 2, 0 ), 0.0 );
TS_ASSERT_EQUALS( grid.m_matrix( 2, 1 ), 0.0 );
TS_ASSERT_EQUALS( grid.m_matrix( 2, 2 ), 4.4 );
TS_ASSERT_EQUALS( grid.m_matrix( 2, 3 ), 0.0 );
TS_ASSERT_EQUALS( grid.m_matrix( 3, 0 ), 0. );
TS_ASSERT_EQUALS( grid.m_matrix( 3, 1 ), 0. );
TS_ASSERT_EQUALS( grid.m_matrix( 3, 2 ), 0. );
TS_ASSERT_EQUALS( grid.m_matrix( 3, 3 ), 1. );
WGridRegular3D grid2( 1.1, 2.2, 3.3, 3, 3, 3, 1.11, 2.22, 3.33 );
TS_ASSERT_EQUALS( grid2.size(), 27 );
TS_ASSERT_EQUALS( grid2.m_origin, WPosition( 1.1, 2.2, 3.3 ) );
TS_ASSERT_EQUALS( grid2.m_directionX, WVector3D( 1.11, 0., 0. ) );
TS_ASSERT_EQUALS( grid2.m_directionY, WVector3D( 0., 2.22, 0. ) );
TS_ASSERT_EQUALS( grid2.m_directionZ, WVector3D( 0., 0., 3.33 ) );
TS_ASSERT_EQUALS( grid2.m_matrix( 0, 0 ), 1.11 );
TS_ASSERT_EQUALS( grid2.m_matrix( 0, 1 ), 0. );
TS_ASSERT_EQUALS( grid2.m_matrix( 0, 2 ), 0. );
TS_ASSERT_EQUALS( grid2.m_matrix( 0, 3 ), 1.1 );
TS_ASSERT_EQUALS( grid2.m_matrix( 1, 0 ), 0. );
TS_ASSERT_EQUALS( grid2.m_matrix( 1, 1 ), 2.22 );
TS_ASSERT_EQUALS( grid2.m_matrix( 1, 2 ), 0. );
TS_ASSERT_EQUALS( grid2.m_matrix( 1, 3 ), 2.2 );
TS_ASSERT_EQUALS( grid2.m_matrix( 2, 0 ), 0. );
TS_ASSERT_EQUALS( grid2.m_matrix( 2, 1 ), 0. );
TS_ASSERT_EQUALS( grid2.m_matrix( 2, 2 ), 3.33 );
TS_ASSERT_EQUALS( grid2.m_matrix( 2, 3 ), 3.3 );
TS_ASSERT_EQUALS( grid2.m_matrix( 3, 0 ), 0. );
TS_ASSERT_EQUALS( grid2.m_matrix( 3, 1 ), 0. );
TS_ASSERT_EQUALS( grid2.m_matrix( 3, 2 ), 0. );
TS_ASSERT_EQUALS( grid2.m_matrix( 3, 3 ), 1. );
WGridRegular3D grid3( 2.22, 3.33, 4.44, 3, 3, 3,
WVector3D( 3.1, 1.1, 2.1 ), WVector3D( 1.2, 3.2, 2.2 ), WVector3D( 1.3, 2.3, 3.3 ) );
TS_ASSERT_EQUALS( grid3.size(), 27 );
TS_ASSERT_EQUALS( grid3.m_origin, WPosition( 2.22, 3.33, 4.44 ) );
TS_ASSERT_EQUALS( grid3.m_directionX, WVector3D( 3.1, 1.1, 2.1 ) );
TS_ASSERT_EQUALS( grid3.m_directionY, WVector3D( 1.2, 3.2, 2.2 ) );
TS_ASSERT_EQUALS( grid3.m_directionZ, WVector3D( 1.3, 2.3, 3.3 ) );
TS_ASSERT_EQUALS( grid3.m_matrix( 0, 0 ), 3.1 );
TS_ASSERT_EQUALS( grid3.m_matrix( 0, 1 ), 1.2 );
TS_ASSERT_EQUALS( grid3.m_matrix( 0, 2 ), 1.3 );
TS_ASSERT_EQUALS( grid3.m_matrix( 0, 3 ), 2.22 );
TS_ASSERT_EQUALS( grid3.m_matrix( 1, 0 ), 1.1 );
TS_ASSERT_EQUALS( grid3.m_matrix( 1, 1 ), 3.2 );
TS_ASSERT_EQUALS( grid3.m_matrix( 1, 2 ), 2.3 );
TS_ASSERT_EQUALS( grid3.m_matrix( 1, 3 ), 3.33 );
TS_ASSERT_EQUALS( grid3.m_matrix( 2, 0 ), 2.1 );
TS_ASSERT_EQUALS( grid3.m_matrix( 2, 1 ), 2.2 );
TS_ASSERT_EQUALS( grid3.m_matrix( 2, 2 ), 3.3 );
TS_ASSERT_EQUALS( grid3.m_matrix( 2, 3 ), 4.44 );
TS_ASSERT_EQUALS( grid3.m_matrix( 3, 0 ), 0. );
TS_ASSERT_EQUALS( grid3.m_matrix( 3, 1 ), 0. );
TS_ASSERT_EQUALS( grid3.m_matrix( 3, 2 ), 0. );
TS_ASSERT_EQUALS( grid3.m_matrix( 3, 3 ), 1. );
// constructor taking matrix
WMatrix<double> mat( 4, 4 );
for( unsigned int i = 0; i < 4; ++i )
{
for( unsigned int j = 0; j < 4; ++j )
{
mat( i, j ) = 1.1 + i + 0.1 * j; // This make entries like (1,2)=2.3, (0,0)=1.1
}
}
mat( 3, 0 ) = 0;
mat( 3, 1 ) = 0;
mat( 3, 2 ) = 0;
mat( 3, 3 ) = 1;
double delta = 1e-8;
WGridRegular3D grid4( 3, 3, 3, mat );
TS_ASSERT_EQUALS( grid4.size(), 27 );
TS_ASSERT_DELTA( grid4.m_origin[0], 1.4, delta );
TS_ASSERT_DELTA( grid4.m_origin[1], 2.4, delta );
TS_ASSERT_DELTA( grid4.m_origin[2], 3.4, delta );
TS_ASSERT_DELTA( grid4.m_directionX[0], 1.1, delta );
TS_ASSERT_DELTA( grid4.m_directionX[1], 2.1, delta );
TS_ASSERT_DELTA( grid4.m_directionX[2], 3.1, delta );
TS_ASSERT_DELTA( grid4.m_directionY[0], 1.2, delta );
TS_ASSERT_DELTA( grid4.m_directionY[1], 2.2, delta );
TS_ASSERT_DELTA( grid4.m_directionY[2], 3.2, delta );
TS_ASSERT_DELTA( grid4.m_directionZ[0], 1.3, delta );
TS_ASSERT_DELTA( grid4.m_directionZ[1], 2.3, delta );
TS_ASSERT_DELTA( grid4.m_directionZ[2], 3.3, delta );
TS_ASSERT_EQUALS( grid4.m_matrix, mat );
}
/**
* getNbCoords should return the samples prescribed by the use of the constructor
*/
......
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