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