25 #ifndef WGRIDREGULAR3D_TEST_H
26 #define WGRIDREGULAR3D_TEST_H
34 #include <boost/shared_ptr.hpp>
37 #include <cxxtest/TestSuite.h>
39 #include "../../common/exceptions/WOutOfBounds.h"
40 #include "../../common/math/test/WVector3dTraits.h"
41 #include "../../common/WLimits.h"
42 #include "../WGridRegular3D.h"
74 TS_ASSERT_EQUALS( grid.
size(), 27 );
82 boost::shared_ptr< WGridRegular3D > grid(
new WGridRegular3D( 3, 3, 3 ) );
83 boost::array< unsigned int, 3 > expectedNbCoords = { { 3, 3, 3 } };
84 TS_ASSERT_EQUALS( expectedNbCoords, getNbCoords< double >( grid ) );
85 boost::array< double, 3 > expectedOffsets = { { 1.0, 1.0, 1.0 } };
86 TS_ASSERT_EQUALS( expectedOffsets, getOffsets< double >( grid ) );
87 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 ) } };
88 TS_ASSERT_EQUALS( expectedDirections, getDirections< double >( grid ) );
89 TS_ASSERT_EQUALS( expectedDirections, getUnitDirections< double >( grid ) );
105 TS_ASSERT_EQUALS( grid.
size(), 27 );
138 mat( 0, 0 ) = x[ 0 ];
139 mat( 1, 0 ) = x[ 1 ];
140 mat( 2, 0 ) = x[ 2 ];
141 mat( 0, 1 ) = y[ 0 ];
142 mat( 1, 1 ) = y[ 1 ];
143 mat( 2, 1 ) = y[ 2 ];
144 mat( 0, 2 ) = z[ 0 ];
145 mat( 1, 2 ) = z[ 1 ];
146 mat( 2, 2 ) = z[ 2 ];
161 unsigned int nX = 10, nY = 11, nZ = 12;
162 unsigned int iX = 8, iY = 9, iZ = 5;
163 unsigned int i = iX + iY * nX + iZ * nX * nY;
173 double x = orX + iX * ofX;
174 double y = orY + iY * ofY;
175 double z = orZ + iZ * ofZ;
225 using boost::shared_ptr;
234 shared_ptr< WGridRegular3D > g = shared_ptr< WGridRegular3D >(
new WGridRegular3D( 3, 3, 3, t ) );
235 TS_ASSERT_EQUALS( g->getVoxelNum(
WPosition( 4.35, 5.0, -6 ) ), 7 );
243 using boost::shared_ptr;
245 shared_ptr< WGridRegular3D > g = shared_ptr< WGridRegular3D >(
new WGridRegular3D( 3, 3, 3 ) );
314 size_t data[] = { 12, 14, 10, 16, 4, 22 };
315 std::vector< size_t > expected( data, data + 6 );
334 mat( 0, 0 ) = x[ 0 ];
335 mat( 1, 0 ) = x[ 1 ];
336 mat( 2, 0 ) = x[ 2 ];
337 mat( 0, 1 ) = y[ 0 ];
338 mat( 1, 1 ) = y[ 1 ];
339 mat( 2, 1 ) = y[ 2 ];
340 mat( 0, 2 ) = z[ 0 ];
341 mat( 1, 2 ) = z[ 1 ];
342 mat( 2, 2 ) = z[ 2 ];
370 mat( 0, 0 ) = x[ 0 ];
371 mat( 1, 0 ) = x[ 1 ];
372 mat( 2, 0 ) = x[ 2 ];
373 mat( 0, 1 ) = y[ 0 ];
374 mat( 1, 1 ) = y[ 1 ];
375 mat( 2, 1 ) = y[ 2 ];
376 mat( 0, 2 ) = z[ 0 ];
377 mat( 1, 2 ) = z[ 1 ];
378 mat( 2, 2 ) = z[ 2 ];
410 size_t data[] = { 1, 3, 9 };
411 std::vector< size_t > expected( data, data + 3 );
421 size_t data[] = { 25, 23, 17 };
422 std::vector< size_t > expected( data, data + 3 );
433 size_t data[] = { 13, 9, 15, 3, 21 };
434 std::vector< size_t > expected( data, data + 5 );
446 "This point: 27 is not part of this grid: nbPosX: 3 nbPosY: 3 nbPosZ: 3" );
465 bool isInside =
true;
469 TS_ASSERT_EQUALS( cellId, 7 );
470 TS_ASSERT_EQUALS( isInside,
true );
474 TS_ASSERT_EQUALS( isInside,
false );
477 TS_ASSERT_EQUALS( isInside,
true );
480 TS_ASSERT_EQUALS( isInside,
true );
483 TS_ASSERT_EQUALS( isInside,
false );
487 TS_ASSERT_EQUALS( isInside,
false );
490 TS_ASSERT_EQUALS( isInside,
true );
493 TS_ASSERT_EQUALS( isInside,
true );
496 TS_ASSERT_EQUALS( isInside,
false );
500 TS_ASSERT_EQUALS( isInside,
false );
503 TS_ASSERT_EQUALS( isInside,
true );
506 TS_ASSERT_EQUALS( isInside,
true );
509 TS_ASSERT_EQUALS( isInside,
false );
553 mat( 0, 0 ) = x[ 0 ];
554 mat( 1, 0 ) = x[ 1 ];
555 mat( 2, 0 ) = x[ 2 ];
556 mat( 0, 1 ) = y[ 0 ];
557 mat( 1, 1 ) = y[ 1 ];
558 mat( 2, 1 ) = y[ 2 ];
559 mat( 0, 2 ) = z[ 0 ];
560 mat( 1, 2 ) = z[ 1 ];
561 mat( 2, 2 ) = z[ 2 ];
596 #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...