Commit 4ded3ded authored by wiebel's avatar wiebel
Browse files

[ADD #9] more functionality and tests for WGridRegular3D

parent aea53440
......@@ -4,7 +4,7 @@ ADD_SUBDIRECTORY( exceptions )
FILE( GLOB DATAHANDLER_SRC "*.cpp" "*.hpp" )
FILE( GLOB DATAHANDLER_EXCEPTIONS_SRC "exceptions/*.cpp" )
ADD_LIBRARY( dataHandler SHARED ${DATAHANDLER_SRC} ${DATAHANDLER_EXCEPTIONS_SRC} )
TARGET_LINK_LIBRARIES( dataHandler niftiio common ${Boost_LIBRARIES} )
TARGET_LINK_LIBRARIES( dataHandler niftiio common math ${Boost_LIBRARIES} )
# Unit tests
IF( CXXTEST_FOUND )
......
......@@ -21,24 +21,27 @@
//
//---------------------------------------------------------------------------
#include "../math/WPosition.h"
#include "../math/WVector3D.h"
#include "WGridRegular3D.h"
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_originX( originX ), m_originY( originY ), m_originZ( originZ ),
m_origin( WPosition( originX, originY, originZ ) ),
m_nbPosX( nbPosX ), m_nbPosY( nbPosY ), m_nbPosZ( nbPosZ ),
m_offsetX( offsetX ) , m_offsetY( offsetY ) , m_offsetZ( offsetZ )
m_offset( WVector3D( offsetX, offsetY, offsetZ ) )
{
}
WGridRegular3D::WGridRegular3D( unsigned int nbPosX, unsigned int nbPosY, unsigned int nbPosZ,
double offsetX, double offsetY, double offsetZ )
: WGrid( nbPosX * nbPosY * nbPosZ ),
m_originX( 0. ), m_originY( 0. ), m_originZ( 0. ),
m_origin( WPosition( 0., 0., 0. ) ),
m_nbPosX( nbPosX ), m_nbPosY( nbPosY ), m_nbPosZ( nbPosZ ),
m_offsetX( offsetX ) , m_offsetY( offsetY ) , m_offsetZ( offsetZ )
m_offset( WVector3D( offsetX, offsetY, offsetZ ) )
{
}
......
......@@ -24,6 +24,9 @@
#ifndef WGRIDREGULAR3D_H
#define WGRIDREGULAR3D_H
#include "../math/WPosition.h"
#include "../math/WVector3D.h"
#include "WGrid.h"
/**
......@@ -51,17 +54,68 @@ public:
WGridRegular3D(
unsigned int nbPosX, unsigned int nbPosY, unsigned int nbPosZ,
double offsetX, double offsetY, double offsetZ );
/**
* Returns the number of samples in x direction.
*/
unsigned int getNbCoordsX() const
{
return m_nbPosX;
}
/**
* Returns the number of samples in y direction.
*/
unsigned int getNbCoordsY() const
{
return m_nbPosY;
}
/**
* Returns the number of samples in z direction.
*/
unsigned int getNbCoordsZ() const
{
return m_nbPosZ;
}
/**
* Returns the distance between samples in x direction.
*/
double getOffsetX() const
{
return m_offset[0];
}
/**
* Returns the distance between samples in y direction.
*/
double getOffsetY() const
{
return m_offset[1];
}
/**
* Returns the distance between samples in z direction.
*/
double getOffsetZ() const
{
return m_offset[2];
}
/**
* Returns the position of the origin of the grid.
*/
WPosition getOrigin() const
{
return m_origin;
}
protected:
private:
double m_originX;
double m_originY;
double m_originZ;
WPosition m_origin;
unsigned int m_nbPosX;
unsigned int m_nbPosY;
unsigned int m_nbPosZ;
double m_offsetX;
double m_offsetY;
double m_offsetZ;
WVector3D m_offset;
};
#endif // WGRIDREGULAR3D_H
......@@ -27,6 +27,7 @@
#include <cxxtest/TestSuite.h>
#include "../WGridRegular3D.h"
#include "../../math/WVector3D.h"
/**
* Tests the WGridRegular3D class.
......@@ -44,7 +45,7 @@ public:
}
/**
* After instantiation there should be no positions.
* After instantiation there should be the requested number of positions.
*/
void testSize( void )
{
......@@ -54,6 +55,49 @@ public:
WGridRegular3D grid2( 0., 0., 0., 3, 3, 3, 1., 1., 1. );
TS_ASSERT_EQUALS( grid2.size(), 27 );
}
/**
* getNbCoords should return the samples prescribed by the use of the constructor
*/
void testGetNbCoords( void )
{
size_t x = 3;
size_t y = 4;
size_t z = 5;
WGridRegular3D grid( x, y, z, 1., 1., 1. );
TS_ASSERT_EQUALS( grid.getNbCoordsX(), x );
TS_ASSERT_EQUALS( grid.getNbCoordsY(), y );
TS_ASSERT_EQUALS( grid.getNbCoordsZ(), z );
}
/**
* getOffset should return the offsets prescribed by the use of the constructor
*/
void testGetOffset( void )
{
double x = 1.2;
double y = 3.4;
double z = 5.6;
WGridRegular3D grid( 10., 10., 10., x, y, z );
TS_ASSERT_EQUALS( grid.getOffsetX(), x );
TS_ASSERT_EQUALS( grid.getOffsetY(), y );
TS_ASSERT_EQUALS( grid.getOffsetZ(), z );
}
/**
* getOrigin should return the origin prescribed by the use of the constructor
* or (0,0,0) when using the second constructor.
*/
void testGetOrigin( void )
{
WVector3D zeroOrigin( 0., 0., 0. );
WGridRegular3D grid( 10., 10., 10., 1., 1., 1. );
TS_ASSERT_EQUALS( grid.getOrigin(), zeroOrigin );
WVector3D origin( 1.2, 3.4, 5.6 );
WGridRegular3D grid2( origin[0], origin[1], origin[2], 10., 10., 10., 1., 1., 1. );
TS_ASSERT_EQUALS( grid2.getOrigin(), origin );
}
};
#endif // WGRIDREGULAR3D_TEST_H
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