Commit 22819a65 authored by cornimueller's avatar cornimueller
Browse files

[ADD #97 #141]

 * #97: expanded WGridRegular3D to allow affine transformed grids (as defined in the NIfTI-format)
 * #141: added cast-constructor to WVector3D to cast from WValue< double >
 * increased required Boost version in CMakeLists.txt to 1.39.0 (for signals2)
 * changed directory of "make cleantest" from binary dir to source dir to allow non standard build dirs
parent 2e70a768
......@@ -33,7 +33,7 @@ ENDIF( CMAKE_BUILD_TYPE STREQUAL "Static" )
# in the trunk/src directory on a linux box to make some investigations:
# grep -i include `find . -type f` | grep boost | awk '{print $2}' | sort | uniq
FIND_PACKAGE( Boost REQUIRED program_options thread filesystem date_time system signals )
ASSERT_GE_VERSION( "Boost" "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}" 1.36.0 )
ASSERT_GE_VERSION( "Boost" "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}" 1.39.0 )
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )
### OpenGL ###
......@@ -202,7 +202,7 @@ ADD_CUSTOM_TARGET( vtest
#-------------------------------------------------------------------------------------------------------------
# Removes all tests thus forcing them to be recompiled during the next "make"
ADD_CUSTOM_TARGET( cleantest
COMMAND ${CMAKE_COMMAND} -P ${PROJECT_BINARY_DIR}/../tools/CMakeModules/RemoveGeneratedTests.cmake
COMMAND ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/../tools/CMakeModules/RemoveGeneratedTests.cmake
COMMENT "Remove all tests to force them to be recompiled"
)
......
......@@ -30,13 +30,29 @@
using wmath::WVector3D;
using wmath::WPosition;
WGridRegular3D::WGridRegular3D( double originX, double originY, double originZ,
unsigned int nbPosX, unsigned int nbPosY, unsigned int nbPosZ,
const WVector3D& directionX,
const WVector3D& directionY,
const WVector3D& directionZ )
: WGrid( nbPosX * nbPosY * nbPosZ ),
m_origin( WPosition( originX, originY, originZ ) ),
m_nbPosX( nbPosX ), m_nbPosY( nbPosY ), m_nbPosZ( nbPosZ ),
m_directionX( directionX ),
m_directionY( directionY ),
m_directionZ( directionZ )
{
}
WGridRegular3D::WGridRegular3D( double originX, double originY, double originZ,
unsigned int nbPosX, unsigned int nbPosY, unsigned int nbPosZ,
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_offset( WVector3D( offsetX, offsetY, offsetZ ) )
m_directionX( WVector3D( offsetX, 0., 0. ) ),
m_directionY( WVector3D( 0., offsetY, 0. ) ),
m_directionZ( WVector3D( 0., 0., offsetZ ) )
{
}
......@@ -45,24 +61,18 @@ WGridRegular3D::WGridRegular3D( unsigned int nbPosX, unsigned int nbPosY, unsign
: WGrid( nbPosX * nbPosY * nbPosZ ),
m_origin( WPosition( 0., 0., 0. ) ),
m_nbPosX( nbPosX ), m_nbPosY( nbPosY ), m_nbPosZ( nbPosZ ),
m_offset( WVector3D( offsetX, offsetY, offsetZ ) )
m_directionX( WVector3D( offsetX, 0., 0. ) ),
m_directionY( WVector3D( 0., offsetY, 0. ) ),
m_directionZ( WVector3D( 0., 0., offsetZ ) )
{
}
WPosition WGridRegular3D::getPosition( unsigned int i ) const
{
double x = m_origin[0] + ( i % m_nbPosX ) * m_offset[0];
double y = m_origin[1] + ( ( i / m_nbPosX ) % m_nbPosY ) * m_offset[1];
double z = m_origin[2] + ( i / ( m_nbPosX * m_nbPosY ) ) * m_offset[2];
WPosition pos( x, y, z );
return pos;
return getPosition(i % m_nbPosX, ( i / m_nbPosX ) % m_nbPosY, i / ( m_nbPosX * m_nbPosY ) );
}
WPosition WGridRegular3D::getPosition( unsigned int iX, unsigned int iY, unsigned int iZ ) const
{
WPosition pos( m_origin[0] + iX * m_offset[0],
m_origin[1] + iY * m_offset[1],
m_origin[2] + iZ * m_offset[2] );
return pos;
return m_origin + iX * m_directionX + iY * m_directionY + iZ * m_directionZ;
}
......@@ -31,9 +31,9 @@
#include "WGrid.h"
/**
* A grid that has axis aligned cuboid cells which all have the same width,
* the same height and the same depth. I.e. the samples along a single axis
* are equidistant. The distance of samples may vary between axes.
* A grid that has parallelepiped cells which all have the same proportion. I.e.
* the samples along a single axis are equidistant. The distance of samples may
* vary between axes.
* \ingroup dataHandler
*/
class WGridRegular3D : public WGrid
......@@ -42,7 +42,19 @@ public:
/**
* Defines the position of the origin of the grid, the number of
* samples in each coordinate direction and the offset between the
* samples in the different coordinate directions.
* samples in the different coordinate directions as vector.
*/
WGridRegular3D(
double originX, double originY, double originZ,
unsigned int nbPosX, unsigned int nbPosY, unsigned int nbPosZ,
const wmath::WVector3D& directionX,
const wmath::WVector3D& directionY,
const wmath::WVector3D& directionZ );
/**
* Defines the position of the origin of the grid, the number of
* samples in each coordinate direction and the offset between the
* samples in the different coordinate directions as scalar.
*/
WGridRegular3D(
double originX, double originY, double originZ,
......@@ -84,21 +96,21 @@ public:
*/
double getOffsetX() const
{
return m_offset[0];
return m_directionX.norm();
}
/**
* Returns the distance between samples in y direction.
*/
double getOffsetY() const
{
return m_offset[1];
return m_directionY.norm();
}
/**
* Returns the distance between samples in z direction.
*/
double getOffsetZ() const
{
return m_offset[2];
return m_directionZ.norm();
}
/**
......@@ -128,7 +140,9 @@ private:
unsigned int m_nbPosY;
unsigned int m_nbPosZ;
wmath::WVector3D m_offset;
wmath::WVector3D m_directionX;
wmath::WVector3D m_directionY;
wmath::WVector3D m_directionZ;
};
#endif // WGRIDREGULAR3D_H
......@@ -58,6 +58,14 @@ public:
class WGridRegular3DTest : public CxxTest::TestSuite
{
public:
/**
* Called before every test.
*/
void setUp( void )
{
m_delta = 1e-14;
}
/**
* Ensure that nothing is thrown when an instance is created.
*/
......@@ -65,6 +73,8 @@ public:
{
TS_ASSERT_THROWS_NOTHING( WGridRegular3D grid( 3, 3, 3, 1., 1., 1. ) );
TS_ASSERT_THROWS_NOTHING( WGridRegular3D grid( 0., 0., 0., 3, 3, 3, 1., 1., 1. ) );
TS_ASSERT_THROWS_NOTHING( WGridRegular3D grid( 0., 0., 0., 3, 3, 3,
WVector3D( 3., 1., 2. ), WVector3D( 1., 3., 2. ), WVector3D( 1., 2., 3. ) ) );
}
/**
......@@ -77,6 +87,10 @@ public:
WGridRegular3D grid2( 0., 0., 0., 3, 3, 3, 1., 1., 1. );
TS_ASSERT_EQUALS( grid2.size(), 27 );
WGridRegular3D grid3( 0., 0., 0., 3, 3, 3,
WVector3D( 3., 1., 2. ), WVector3D( 1., 3., 2. ), WVector3D( 1., 2., 3. ) );
TS_ASSERT_EQUALS( grid3.size(), 27 );
}
/**
......@@ -94,9 +108,10 @@ public:
}
/**
* getOffset should return the offsets prescribed by the use of the constructor
* getOffset should return the scalar offsets prescribed by the use of the
* constructor
*/
void testGetOffset( void )
void testGetScalarOffset( void )
{
double x = 1.2;
double y = 3.4;
......@@ -107,6 +122,21 @@ public:
TS_ASSERT_EQUALS( grid.getOffsetZ(), z );
}
/**
* getOffset should return the vector offsets prescribed by the use of the
* constructor
*/
void testGetVectorOffset( void )
{
WVector3D x( 3., 1., 2. );
WVector3D y( 2., 6., 4. );
WVector3D z( 3., 6., 9. );
WGridRegular3D grid( 0., 0., 0., 10, 10, 10, x, y, z );
TS_ASSERT_DELTA( grid.getOffsetX(), x.norm(), m_delta );
TS_ASSERT_DELTA( grid.getOffsetY(), y.norm(), m_delta );
TS_ASSERT_DELTA( grid.getOffsetZ(), z.norm(), m_delta );
}
/**
* getOrigin should return the origin prescribed by the use of the constructor
* or (0,0,0) when using the second constructor.
......@@ -123,9 +153,9 @@ public:
}
/**
* getPosition should return the correct position
* getPosition should return the correct position for scalar offsets
*/
void testGetPositionOneParam( void )
void testGetPositionScalarOffset( void )
{
unsigned int nX = 10, nY = 11, nZ = 12;
unsigned int iX = 8, iY = 9, iZ = 5;
......@@ -146,15 +176,44 @@ public:
WPosition expected( x, y, z );
WGridRegular3D grid( orX, orY, orZ, nX, nY, nZ, ofX, ofY, ofZ );
double delta = 1e-14;
TS_ASSERT_DELTA( grid.getPosition( iX, iY, iZ )[0], expected[0], m_delta );
TS_ASSERT_DELTA( grid.getPosition( iX, iY, iZ )[1], expected[1], m_delta );
TS_ASSERT_DELTA( grid.getPosition( iX, iY, iZ )[2], expected[2], m_delta );
TS_ASSERT_DELTA( grid.getPosition( i )[0], expected[0], m_delta );
TS_ASSERT_DELTA( grid.getPosition( i )[1], expected[1], m_delta );
TS_ASSERT_DELTA( grid.getPosition( i )[2], expected[2], m_delta );
}
TS_ASSERT_DELTA( grid.getPosition( iX, iY, iZ )[0], expected[0], delta );
TS_ASSERT_DELTA( grid.getPosition( iX, iY, iZ )[1], expected[1], delta );
TS_ASSERT_DELTA( grid.getPosition( iX, iY, iZ )[2], expected[2], delta );
TS_ASSERT_DELTA( grid.getPosition( i )[0], expected[0], delta );
TS_ASSERT_DELTA( grid.getPosition( i )[1], expected[1], delta );
TS_ASSERT_DELTA( grid.getPosition( i )[2], expected[2], delta );
/**
* getPosition should return the correct position for vector offsets
*/
void testGetPositionVectorOffset( void )
{
unsigned int nX = 10, nY = 11, nZ = 12;
unsigned int iX = 8, iY = 9, iZ = 5;
unsigned int i = iX + iY * nX + iZ * nX * nY;
double orX = 1.2;
double orY = 3.4;
double orZ = 5.6;
WVector3D ofX( 3., 1., 2. );
WVector3D ofY( 1., 3., 2. );
WVector3D ofZ( 1., 2., 3. );
WPosition expected = WPosition( orX, orY, orZ ) + iX * ofX + iY * ofY + iZ * ofZ;
WGridRegular3D grid( orX, orY, orZ, nX, nY, nZ, ofX, ofY, ofZ );
TS_ASSERT_DELTA( grid.getPosition( iX, iY, iZ )[0], expected[0], m_delta );
TS_ASSERT_DELTA( grid.getPosition( iX, iY, iZ )[1], expected[1], m_delta );
TS_ASSERT_DELTA( grid.getPosition( iX, iY, iZ )[2], expected[2], m_delta );
TS_ASSERT_DELTA( grid.getPosition( i )[0], expected[0], m_delta );
TS_ASSERT_DELTA( grid.getPosition( i )[1], expected[1], m_delta );
TS_ASSERT_DELTA( grid.getPosition( i )[2], expected[2], m_delta );
}
private:
double m_delta;
};
#endif // WGRIDREGULAR3D_TEST_H
......@@ -59,7 +59,7 @@ public:
/**
* Get number of components the value consists of.
*/
size_t size()
size_t size() const
{
return m_components.size();
}
......
......@@ -23,8 +23,6 @@
//---------------------------------------------------------------------------
#include "WVector3D.h"
#include "WValue.hpp"
#include "../common/WStringUtils.hpp"
using wmath::WVector3D;
......@@ -41,8 +39,13 @@ WVector3D::WVector3D( double x, double y, double z )
(*this)[2] = z;
}
WVector3D::WVector3D( const WVector3D & newVector )
WVector3D::WVector3D( const WVector3D& newVector )
: WValue< double >( newVector )
{
}
WVector3D::WVector3D( const WValue< double >& newVector )
: WValue< double >( newVector )
{
assert( this->size() == 3 );
}
......@@ -54,6 +54,12 @@ public:
*/
WVector3D( const WVector3D& newVector );
/**
* TODO(wiebel): Ticket #141 (How to use WValue-operators in child classes)
* Copies the values of the given WValue< double >. Used for casting.
*/
WVector3D( const WValue< double >& newVector ); // NOLINT
/**
* Compute the cross product of the current WValue with the parameter.
*/
......
......@@ -49,7 +49,7 @@ public:
public:
/**
* Instatiation should throw nothing.
* Instantiation should throw nothing.
*/
void testInstantiationStandard( void )
{
......@@ -57,7 +57,7 @@ public:
}
/**
* Instatiation should throw nothing.
* Instantiation should throw nothing.
*/
void testInstantiationWithDoubles( void )
{
......@@ -65,7 +65,7 @@ public:
}
/**
* Instatiation should throw nothing.
* Instantiation should throw nothing.
*/
void testInstantiationWithCopyConstructor( void )
{
......@@ -73,6 +73,15 @@ public:
TS_ASSERT_THROWS_NOTHING( WVector3D vec( vecToCopy ) );
}
/**
* Instantiation with right sized WValue should throw nothing.
*/
void testInstantiationWithCastConstructor( void )
{
wmath::WValue< double > arrayToCopy( 3 );
TS_ASSERT_THROWS_NOTHING( WVector3D vec( arrayToCopy ) );
}
/**
* Standard constructor should set values to zero
*/
......@@ -110,6 +119,22 @@ public:
TS_ASSERT_EQUALS( vec[2], vecToCopy[2] );
}
/**
* Cast constructor should copy values
*/
void testInitializationWithCastConstructor( void )
{
wmath::WValue< double > arrayToCopy( 3 );
arrayToCopy[0] = 32.32;
arrayToCopy[1] = 42.42;
arrayToCopy[2] = 23.23;
WVector3D vec( arrayToCopy );
TS_ASSERT_EQUALS( vec[0], arrayToCopy[0] );
TS_ASSERT_EQUALS( vec[1], arrayToCopy[1] );
TS_ASSERT_EQUALS( vec[2], arrayToCopy[2] );
}
/**
* Element access operator should return the right values
*/
......
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