25 #ifndef WGRIDREGULAR3D_TEST_H
26 #define WGRIDREGULAR3D_TEST_H
33 #include <boost/shared_ptr.hpp>
35 #include <cxxtest/TestSuite.h>
37 #include "../../common/exceptions/WOutOfBounds.h"
38 #include "../../common/math/test/WVector3dTraits.h"
39 #include "../../common/WLimits.h"
40 #include "../WGridRegular3D.h"
72 TS_ASSERT_EQUALS( grid.
size(), 27 );
80 boost::shared_ptr< WGridRegular3D > grid(
new WGridRegular3D( 3, 3, 3 ) );
81 boost::array< unsigned int, 3 > expectedNbCoords = { { 3, 3, 3 } };
82 TS_ASSERT_EQUALS( expectedNbCoords, getNbCoords< double >( grid ) );
83 boost::array< double, 3 > expectedOffsets = { { 1.0, 1.0, 1.0 } };
84 TS_ASSERT_EQUALS( expectedOffsets, getOffsets< double >( grid ) );
85 boost::array< WVector3d, 3 > expectedDirections = { {
WVector3d( 1.0, 0.0, 0.0 ),
WVector3d( 0.0, 1.0, 0.0 ),
WVector3d( 0.0, 0.0, 1.0 ) } };
86 TS_ASSERT_EQUALS( expectedDirections, getDirections< double >( grid ) );
87 TS_ASSERT_EQUALS( expectedDirections, getUnitDirections< double >( grid ) );
103 TS_ASSERT_EQUALS( grid.
size(), 27 );
136 mat( 0, 0 ) = x[ 0 ];
137 mat( 1, 0 ) = x[ 1 ];
138 mat( 2, 0 ) = x[ 2 ];
139 mat( 0, 1 ) = y[ 0 ];
140 mat( 1, 1 ) = y[ 1 ];
141 mat( 2, 1 ) = y[ 2 ];
142 mat( 0, 2 ) = z[ 0 ];
143 mat( 1, 2 ) = z[ 1 ];
144 mat( 2, 2 ) = z[ 2 ];
159 unsigned int nX = 10, nY = 11, nZ = 12;
160 unsigned int iX = 8, iY = 9, iZ = 5;
161 unsigned int i = iX + iY * nX + iZ * nX * nY;
171 double x = orX + iX * ofX;
172 double y = orY + iY * ofY;
173 double z = orZ + iZ * ofZ;
223 using boost::shared_ptr;
232 shared_ptr< WGridRegular3D > g = shared_ptr< WGridRegular3D >(
new WGridRegular3D( 3, 3, 3, t ) );
233 TS_ASSERT_EQUALS( g->getVoxelNum(
WPosition( 4.35, 5.0, -6 ) ), 7 );
241 using boost::shared_ptr;
243 shared_ptr< WGridRegular3D > g = shared_ptr< WGridRegular3D >(
new WGridRegular3D( 3, 3, 3 ) );
312 size_t data[] = { 12, 14, 10, 16, 4, 22 };
313 std::vector< size_t > expected( data, data + 6 );
332 mat( 0, 0 ) = x[ 0 ];
333 mat( 1, 0 ) = x[ 1 ];
334 mat( 2, 0 ) = x[ 2 ];
335 mat( 0, 1 ) = y[ 0 ];
336 mat( 1, 1 ) = y[ 1 ];
337 mat( 2, 1 ) = y[ 2 ];
338 mat( 0, 2 ) = z[ 0 ];
339 mat( 1, 2 ) = z[ 1 ];
340 mat( 2, 2 ) = z[ 2 ];
368 mat( 0, 0 ) = x[ 0 ];
369 mat( 1, 0 ) = x[ 1 ];
370 mat( 2, 0 ) = x[ 2 ];
371 mat( 0, 1 ) = y[ 0 ];
372 mat( 1, 1 ) = y[ 1 ];
373 mat( 2, 1 ) = y[ 2 ];
374 mat( 0, 2 ) = z[ 0 ];
375 mat( 1, 2 ) = z[ 1 ];
376 mat( 2, 2 ) = z[ 2 ];
408 size_t data[] = { 1, 3, 9 };
409 std::vector< size_t > expected( data, data + 3 );
419 size_t data[] = { 25, 23, 17 };
420 std::vector< size_t > expected( data, data + 3 );
431 size_t data[] = { 13, 9, 15, 3, 21 };
432 std::vector< size_t > expected( data, data + 5 );
444 "This point: 27 is not part of this grid: nbPosX: 3 nbPosY: 3 nbPosZ: 3" );
463 bool isInside =
true;
467 TS_ASSERT_EQUALS( cellId, 7 );
468 TS_ASSERT_EQUALS( isInside,
true );
472 TS_ASSERT_EQUALS( isInside,
false );
475 TS_ASSERT_EQUALS( isInside,
true );
478 TS_ASSERT_EQUALS( isInside,
true );
481 TS_ASSERT_EQUALS( isInside,
false );
485 TS_ASSERT_EQUALS( isInside,
false );
488 TS_ASSERT_EQUALS( isInside,
true );
491 TS_ASSERT_EQUALS( isInside,
true );
494 TS_ASSERT_EQUALS( isInside,
false );
498 TS_ASSERT_EQUALS( isInside,
false );
501 TS_ASSERT_EQUALS( isInside,
true );
504 TS_ASSERT_EQUALS( isInside,
true );
507 TS_ASSERT_EQUALS( isInside,
false );
551 mat( 0, 0 ) = x[ 0 ];
552 mat( 1, 0 ) = x[ 1 ];
553 mat( 2, 0 ) = x[ 2 ];
554 mat( 0, 1 ) = y[ 0 ];
555 mat( 1, 1 ) = y[ 1 ];
556 mat( 2, 1 ) = y[ 2 ];
557 mat( 0, 2 ) = z[ 0 ];
558 mat( 1, 2 ) = z[ 1 ];
559 mat( 2, 2 ) = z[ 2 ];
594 #endif // WGRIDREGULAR3D_TEST_H
Vector3Type getDirectionX() const
Returns the vector determining the direction of samples in x direction.
unsigned int getNbCoordsY() const
Returns the number of samples in y direction.
A grid that has parallelepiped cells which all have the same proportion.
WMatrix & makeIdentity()
Makes the matrix contain the identity matrix, i.e.
boost::array< size_t, 8 > CellVertexArray
Convenience typedef for a boost::array< size_t, 8 >.
void testSize(void)
After instantiation there should be the requested number of positions.
int getVoxelNum(const Vector3Type &pos) const
Returns the i'th voxel where the given position belongs too.
void setUp(void)
Called before every test.
void testEnclosesRotated()
If a point is inside of the boundary of a grid encloses should return true, otherwise false...
void testGetCellId(void)
Check whether we get the right cellId.
void testGetVoxelNumberOfGeneralPosition(void)
The cell number of a Position is defined as follows:
void testGetCellVertexIds(void)
Check whether we get the right Ids.
Indicates invalid element access of a container.
This only is a 3d double vector.
void testGetVoxelNumberOfPositionOutsideOfGrid(void)
If a grid point is outside of the grid then -1 should be returned.
void testNeighboursInsideAGrid(void)
A voxel inside a grid (not located on a border) has 6 neighbours.
void testNeighbourOnBackUpperRight(void)
A voxel in the back upper right corner should also have only 3 neighbours.
unsigned int getNbCoordsZ() const
Returns the number of samples in z direction.
Vector3Type getPosition(unsigned int i) const
Returns the i-th position on the grid.
T getOffsetZ() const
Returns the distance between samples in z direction.
void testGetNbCoords(void)
getNbCoords should return the samples prescribed by the use of the constructor
CellVertexArray getCellVertexIds(size_t cellId) const
Computes the ids of the vertices of a cell given by its id.
double m_delta
Maximum amount to values are allowed to differ.
T getOffsetY() const
Returns the distance between samples in y direction.
void testGetPositionScalarOffset(void)
getPosition should return the correct position for scalar offsets
const float FLT_EPS
Smallest float such: 1.0 + FLT_EPS == 1.0 is still true.
void testOrientation(void)
After instantiation there should be the right vectors, matrix and origin.
size_t getCellId(const Vector3Type &pos, bool *success) const
Computes the id of the cell containing the position pos.
void testGetVectorOffset(void)
getOffset should return the vector offsets prescribed by the use of the constructor ...
void testRotatedVoxelOutOfGrid()
Positions outside of a rotated grid should return voxel positions of -1.
void testNeighbourOfVoxelNotInsideThisGrid(void)
If the neighbours of a voxel not inside this grid are requested an Exception WOutOfBounds should be t...
void testNeighbourOnLeftBorderPlane(void)
A Voxel on a border plane should have neighbours on the plane but not out side the grid...
virtual const char * what() const
Returns the message string set on throw.
bool encloses(const Vector3Type &pos) const
Decides whether a certain position is inside this grid or not.
int getYVoxelCoord(const Vector3Type &pos) const
Computes the Y coordinate of that voxel that contains the position pos.
T getOffsetX() const
Returns the distance between samples in x direction.
void testRotatedVoxelNum()
The correct voxel numbers should be returned in a rotated grid.
int getZVoxelCoord(const Vector3Type &pos) const
Computes the Z coordinate of that voxel that contains the position pos.
Vector3Type getDirectionZ() const
Returns the vector determining the direction of samples in z direction.
void testInstantiation(void)
Ensure that nothing is thrown when an instance is created.
Vector3Type getOrigin() const
Returns the position of the origin of the grid.
Vector3Type getDirectionY() const
Returns the vector determining the direction of samples in y direction.
unsigned int getNbCoordsX() const
Returns the number of samples in x direction.
int getXVoxelCoord(const Vector3Type &pos) const
Computes the X coordinate of that voxel that contains the position pos.
void testEnclosesQuery(void)
If a point is inside of the boundary of a grid encloses should return true, otherwise false...
size_t size() const
The number of positions in this grid.
std::vector< size_t > getNeighbours(size_t id) const
Return the list of neighbour voxels.
Tests the WGridRegular3D class.
void testConvinienceFunctions(void)
Each convinience function just assembles the three values into an boost array.
void testNeighboursOnFrontLowerLeft(void)
A voxel with voxel-coordinates 0,0,0 has only three neighbours: 1,0,0; 0,1,0 and 0,0,1.
void testGetVoxelNumberOfPositionExactlyBetweenVoxels(void)
All points of the surfaces belonging to the lower,left,front corner of a voxel belong to this voxel...