OpenWalnut  1.4.0
WGridRegular3D_test.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WGRIDREGULAR3D_TEST_H
26 #define WGRIDREGULAR3D_TEST_H
27 
28 #include <cstdio>
29 #include <sstream>
30 #include <string>
31 #include <vector>
32 
33 #ifndef Q_MOC_RUN
34 #include <boost/shared_ptr.hpp>
35 #endif
36 
37 #include <cxxtest/TestSuite.h>
38 
39 #include "../../common/exceptions/WOutOfBounds.h"
40 #include "../../common/math/test/WVector3dTraits.h"
41 #include "../../common/WLimits.h"
42 #include "../WGridRegular3D.h"
43 
44 
45 /**
46  * Tests the WGridRegular3D class.
47  */
48 class WGridRegular3DTest : public CxxTest::TestSuite
49 {
50 public:
51  /**
52  * Called before every test.
53  */
54  void setUp( void )
55  {
56  m_delta = 1e-14;
57  }
58 
59  /**
60  * Ensure that nothing is thrown when an instance is created.
61  */
62  void testInstantiation( void )
63  {
64  TS_ASSERT_THROWS_NOTHING( WGridRegular3D grid( 3, 3, 3 ) );
65  }
66 
67  /**
68  * After instantiation there should be the requested number of positions.
69  */
70  void testSize( void )
71  {
72  WGridTransformOrtho t( WMatrix< double >( 4, 4 ).makeIdentity() );
73  WGridRegular3D grid( 3, 3, 3, t );
74  TS_ASSERT_EQUALS( grid.size(), 27 );
75  }
76 
77  /**
78  * Each convinience function just assembles the three values into an boost array.
79  */
81  {
82  boost::shared_ptr< WGridRegular3D > grid( new WGridRegular3D( 3, 3, 3 ) );
83  boost::array< unsigned int, 3 > expectedNbCoords = { { 3, 3, 3 } }; // NOLINT curly braces
84  TS_ASSERT_EQUALS( expectedNbCoords, getNbCoords< double >( grid ) );
85  boost::array< double, 3 > expectedOffsets = { { 1.0, 1.0, 1.0 } }; // NOLINT curly braces
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 ) } }; // NOLINT curly braces line length
88  TS_ASSERT_EQUALS( expectedDirections, getDirections< double >( grid ) );
89  TS_ASSERT_EQUALS( expectedDirections, getUnitDirections< double >( grid ) );
90  }
91 
92  /**
93  * After instantiation there should be the right vectors, matrix and origin.
94  */
95  void testOrientation( void )
96  {
97  WMatrix< double > mat( 4, 4 );
98  mat.makeIdentity();
99  mat( 0, 0 ) = 2.2;
100  mat( 1, 1 ) = 3.3;
101  mat( 2, 2 ) = 4.4;
102 
103  WGridTransformOrtho t( mat );
104  WGridRegular3D grid( 3, 3, 3, t );
105  TS_ASSERT_EQUALS( grid.size(), 27 );
106  TS_ASSERT_EQUALS( grid.getOrigin(), WPosition( 0., 0., 0. ) );
107  TS_ASSERT_EQUALS( grid.getDirectionX(), WVector3d( 2.2, 0., 0. ) );
108  TS_ASSERT_EQUALS( grid.getDirectionY(), WVector3d( 0., 3.3, 0. ) );
109  TS_ASSERT_EQUALS( grid.getDirectionZ(), WVector3d( 0., 0., 4.4 ) );
110  }
111 
112  /**
113  * getNbCoords should return the samples prescribed by the use of the constructor
114  */
115  void testGetNbCoords( void )
116  {
117  size_t x = 3;
118  size_t y = 4;
119  size_t z = 5;
120  WGridRegular3D grid( x, y, z );
121  TS_ASSERT_EQUALS( grid.getNbCoordsX(), x );
122  TS_ASSERT_EQUALS( grid.getNbCoordsY(), y );
123  TS_ASSERT_EQUALS( grid.getNbCoordsZ(), z );
124  }
125 
126  /**
127  * getOffset should return the vector offsets prescribed by the use of the
128  * constructor
129  */
130  void testGetVectorOffset( void )
131  {
132  WVector3d x( 3., 1., 2. );
133  WVector3d y( 2., -6., 0. );
134  WVector3d z( 12., 4., -20 );
135 
136  WMatrix< double > mat( 4, 4 );
137  mat.makeIdentity();
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 ];
147 
148  WGridTransformOrtho t( mat );
149  WGridRegular3D grid( 3, 3, 3, t );
150 
151  TS_ASSERT_DELTA( grid.getOffsetX(), length( x ), m_delta );
152  TS_ASSERT_DELTA( grid.getOffsetY(), length( y ), m_delta );
153  TS_ASSERT_DELTA( grid.getOffsetZ(), length( z ), m_delta );
154  }
155 
156  /**
157  * getPosition should return the correct position for scalar offsets
158  */
160  {
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;
164 
165  double orX = 1.2;
166  double orY = 3.4;
167  double orZ = 5.6;
168 
169  double ofX = 1.1;
170  double ofY = 2.2;
171  double ofZ = 3.3;
172 
173  double x = orX + iX * ofX;
174  double y = orY + iY * ofY;
175  double z = orZ + iZ * ofZ;
176 
177  WMatrix< double > mat( 4, 4 );
178  mat.makeIdentity();
179  mat( 0, 0 ) = ofX;
180  mat( 1, 1 ) = ofY;
181  mat( 2, 2 ) = ofZ;
182  mat( 0, 3 ) = orX;
183  mat( 1, 3 ) = orY;
184  mat( 2, 3 ) = orZ;
185 
186  WPosition expected( x, y, z );
187  WGridTransformOrtho t( mat );
188  WGridRegular3D grid( nX, nY, nZ, t );
189 
190  TS_ASSERT_DELTA( grid.getPosition( iX, iY, iZ )[0], expected[0], m_delta );
191  TS_ASSERT_DELTA( grid.getPosition( iX, iY, iZ )[1], expected[1], m_delta );
192  TS_ASSERT_DELTA( grid.getPosition( iX, iY, iZ )[2], expected[2], m_delta );
193  TS_ASSERT_DELTA( grid.getPosition( i )[0], expected[0], m_delta );
194  TS_ASSERT_DELTA( grid.getPosition( i )[1], expected[1], m_delta );
195  TS_ASSERT_DELTA( grid.getPosition( i )[2], expected[2], m_delta );
196  }
197 
198  /**
199  * The cell number of a Position is defined as follows:
200  *
201  \verbatim
202  y-axis
203  |_____ _____ ___ _
204  3 | | | |
205  | | | ... + dy
206  |_____|_____|___ _|
207  2 | | . Line
208  | |/ | ...
209  |_____/___ _|___
210  1 | /| |
211  | ' | | ...
212  |_____|_____|______ x-axis
213  /0 1 2
214  / `--.--´
215  / dx
216  origin e.g. ( 3.1, 3.2, -6 ) and dx == dy == 1.0 ( the z-axis is ignored in this example )
217  \endverbatim
218  *
219  * Hence the line starts at approx. ( 3.85, 3.7, -6 ) and ends at
220  * approx. ( 4.35, 5.0 , -6 ). The Cell number e.g. of the start point
221  * is then: 4 and of the end point: 7.
222  */
224  {
225  using boost::shared_ptr;
226 
227  WMatrix< double > mat( 4, 4 );
228  mat.makeIdentity();
229  mat( 0, 3 ) = 3.1;
230  mat( 1, 3 ) = 3.2;
231  mat( 2, 3 ) = -6.;
232 
233  WGridTransformOrtho t( mat );
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 );
236  }
237 
238  /**
239  * If a grid point is outside of the grid then -1 should be returned.
240  */
242  {
243  using boost::shared_ptr;
244 
245  shared_ptr< WGridRegular3D > g = shared_ptr< WGridRegular3D >( new WGridRegular3D( 3, 3, 3 ) );
246  TS_ASSERT_EQUALS( g->getVoxelNum( WPosition( 0 - m_delta, 0, 0 ) ), -1 );
247  TS_ASSERT_EQUALS( g->getVoxelNum( WPosition( 0, 2 + m_delta, 0 ) ), -1 );
248  }
249 
250  /**
251  * All points of the surfaces belonging to the lower,left,front corner of a
252  * voxel belong to this voxel. Instead all points located on the three
253  * surfaces belonging to the upper right back corner are considered not to
254  * belong to this voxel.
255  */
257  {
258  // A voxel is defined as this ( a cuboid with a center which is a grid point ):
259  // ______________ ____ (0.5, 0.5, 0.5)
260  // /: /|
261  // / : / |
262  // / : / |
263  // / : / |
264  // _/____:_ ___ __/ |
265  // | : | |
266  // | : *<--|--------- grid point (0, 0, 0)
267  // | :........|....|__
268  // dz == 1| ´ | /
269  // | ´ | / dy == 1
270  // | ´ | /
271  // _|´____________|/__
272  // |<- dx == 1 ->|
273  // -0.5,-0.5,-0.5
274  //
275  // the grid is as follows
276  // ______________ ____ 2,2,2
277  // /: / /|
278  // / : /: / |
279  // /------+------/| |
280  // / :……/……:………/…|…|
281  // /____:_/___:__/ | |---- 2,2,1
282  // | : | : | |/|
283  // | : | : | | |
284  // | :.|...:..| /| |____ 2,2,0
285  // +------+------+´ |/
286  // | ' | | /---- 2,1,0
287  // | ' | | /
288  // |'_____|______|/____
289  // | | |
290  // 0,0,0 1,0,0 2,0,0
291 
292  WGridRegular3D g( 3, 3, 3 );
293 
294  // center point of the grid
295  TS_ASSERT_EQUALS( g.getVoxelNum( WPosition( 1, 1, 1 ) ), 13 );
296 
297  // front lower left corner of the last cell
298  TS_ASSERT_EQUALS( g.getVoxelNum( WPosition( 1.5, 1.5, 1.5 ) ), 26 );
299 
300  TS_ASSERT_EQUALS( g.getVoxelNum( WPosition( 1, 1, 0.5 ) ), 13 );
301  TS_ASSERT_EQUALS( g.getVoxelNum( WPosition( 0 , 1.5 , 1 ) ), 15 );
302  TS_ASSERT_EQUALS( g.getVoxelNum( WPosition( 0.5, 1, 0 ) ), 4 );
303 
304  // origin
305  TS_ASSERT_EQUALS( g.getVoxelNum( WPosition( 0, 0, 0 ) ), 0 );
306  }
307 
308  /**
309  * A voxel inside a grid (not located on a border) has 6 neighbours.
310  */
312  {
313  WGridRegular3D g( 3, 3, 3 );
314  size_t data[] = { 12, 14, 10, 16, 4, 22 };
315  std::vector< size_t > expected( data, data + 6 );
316  TS_ASSERT_EQUALS( expected, g.getNeighbours( 13 ) );
317  }
318 
319  /**
320  * The correct voxel numbers should be returned in a rotated grid.
321  */
323  {
324  WVector3d x( 0.707, 0.707, 0.0 );
325  WVector3d y( -0.707, 0.707, 0.0 );
326  WVector3d z( 0.0, 0.0, 1.0 );
327  x = normalize( x );
328  y = normalize( y );
329  y *= 2.0;
330  z *= 1.5;
331 
332  WMatrix< double > mat( 4, 4 );
333  mat.makeIdentity();
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 ];
343  mat( 0, 3 ) = 1.0;
344 
345  WGridTransformOrtho t( mat );
346  WGridRegular3D g( 5, 5, 5, t );
347 
348  WVector3d v = WVector3d( 1.0, 0.0, 0.0 ) + 0.3 * z + 2.4 * y + 2.9 * x;
349 
350  TS_ASSERT_EQUALS( g.getXVoxelCoord( v ), 3 );
351  TS_ASSERT_EQUALS( g.getYVoxelCoord( v ), 2 );
352  TS_ASSERT_EQUALS( g.getZVoxelCoord( v ), 0 );
353  }
354 
355  /**
356  * Positions outside of a rotated grid should return voxel positions of -1.
357  */
359  {
360  WVector3d x( 0.707, 0.707, 0.0 );
361  WVector3d y( -0.707, 0.707, 0.0 );
362  WVector3d z( 0.0, 0.0, 1.0 );
363  x = normalize( x );
364  y = normalize( y );
365  y *= 2.0;
366  z *= 1.5;
367 
368  WMatrix< double > mat( 4, 4 );
369  mat.makeIdentity();
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 ];
379  mat( 0, 3 ) = 1.0;
380 
381  WGridTransformOrtho t( mat );
382  WGridRegular3D g( 5, 5, 5, t );
383 
384  WVector3d v( 1.0, 0.0, 0.0 );
385  v -= wlimits::FLT_EPS * x;
386 
387  TS_ASSERT_EQUALS( g.getXVoxelCoord( v ), -1 );
388  TS_ASSERT_DIFFERS( g.getYVoxelCoord( v ), -1 );
389  TS_ASSERT_DIFFERS( g.getZVoxelCoord( v ), -1 );
390 
391  v -= wlimits::FLT_EPS * z;
392 
393  TS_ASSERT_EQUALS( g.getXVoxelCoord( v ), -1 );
394  TS_ASSERT_DIFFERS( g.getYVoxelCoord( v ), -1 );
395  TS_ASSERT_EQUALS( g.getZVoxelCoord( v ), -1 );
396 
397  v = WVector3d( 1.0, 0.0, 0.0 ) + ( 4.0 + wlimits::FLT_EPS ) * y;
398 
399  TS_ASSERT_DIFFERS( g.getXVoxelCoord( v ), -1 );
400  TS_ASSERT_EQUALS( g.getYVoxelCoord( v ), -1 );
401  TS_ASSERT_DIFFERS( g.getZVoxelCoord( v ), -1 );
402  }
403 
404  /**
405  * A voxel with voxel-coordinates 0,0,0 has only three neighbours: 1,0,0; 0,1,0 and 0,0,1.
406  */
408  {
409  WGridRegular3D g( 3, 3, 3 );
410  size_t data[] = { 1, 3, 9 };
411  std::vector< size_t > expected( data, data + 3 );
412  TS_ASSERT_EQUALS( expected, g.getNeighbours( 0 ) );
413  }
414 
415  /**
416  * A voxel in the back upper right corner should also have only 3 neighbours.
417  */
419  {
420  WGridRegular3D g( 3, 3, 3 );
421  size_t data[] = { 25, 23, 17 };
422  std::vector< size_t > expected( data, data + 3 );
423  TS_ASSERT_EQUALS( expected, g.getNeighbours( 26 ) );
424  }
425 
426  /**
427  * A Voxel on a border plane should have neighbours on the plane but not
428  * out side the grid.
429  */
431  {
432  WGridRegular3D g( 3, 3, 3 );
433  size_t data[] = { 13, 9, 15, 3, 21 };
434  std::vector< size_t > expected( data, data + 5 );
435  TS_ASSERT_EQUALS( expected, g.getNeighbours( 12 ) );
436  }
437 
438  /**
439  * If the neighbours of a voxel not inside this grid are requested an Exception
440  * WOutOfBounds should be thrown.
441  */
443  {
444  WGridRegular3D g( 3, 3, 3 );
445  TS_ASSERT_THROWS_EQUALS( g.getNeighbours( 27 ), const WOutOfBounds &e, std::string( e.what() ),
446  "This point: 27 is not part of this grid: nbPosX: 3 nbPosY: 3 nbPosZ: 3" );
447  }
448 
449  /**
450  * Check whether we get the right Ids.
451  */
452  void testGetCellVertexIds( void )
453  {
454  WGridRegular3D g( 5, 3, 3 );
455  WGridRegular3D::CellVertexArray expected = { { 23, 24, 28, 29, 38, 39, 43, 44 } };
456  TS_ASSERT_EQUALS( g.getCellVertexIds( 15 ), expected );
457  }
458 
459  /**
460  * Check whether we get the right cellId.
461  */
462  void testGetCellId( void )
463  {
464  WGridRegular3D g( 5, 3, 3 );
465  bool isInside = true;
466 
467  // Test some value
468  size_t cellId = g.getCellId( WPosition( 3.3, 1.75, 0.78 ), &isInside );
469  TS_ASSERT_EQUALS( cellId, 7 );
470  TS_ASSERT_EQUALS( isInside, true );
471 
472  // Test bounds for X direction
473  cellId = g.getCellId( WPosition( 4.0, 1.75, 0.3 ), &isInside );
474  TS_ASSERT_EQUALS( isInside, false );
475 
476  cellId = g.getCellId( WPosition( 4.0 - wlimits::FLT_EPS, 1.75, 0.3 ), &isInside );
477  TS_ASSERT_EQUALS( isInside, true );
478 
479  cellId = g.getCellId( WPosition( 0.0, 1.75, 0.3 ), &isInside );
480  TS_ASSERT_EQUALS( isInside, true );
481 
482  cellId = g.getCellId( WPosition( 0.0 - wlimits::FLT_EPS, 1.75, 0.3 ), &isInside );
483  TS_ASSERT_EQUALS( isInside, false );
484 
485  // Test bounds for Y direction
486  cellId = g.getCellId( WPosition( 3.3, 2.0, 0.3 ), &isInside );
487  TS_ASSERT_EQUALS( isInside, false );
488 
489  cellId = g.getCellId( WPosition( 3.3, 2.0 - wlimits::FLT_EPS, 0.3 ), &isInside );
490  TS_ASSERT_EQUALS( isInside, true );
491 
492  cellId = g.getCellId( WPosition( 3.3, 0.0, 0.3 ), &isInside );
493  TS_ASSERT_EQUALS( isInside, true );
494 
495  cellId = g.getCellId( WPosition( 3.3, 0.0 - wlimits::FLT_EPS, 0.3 ), &isInside );
496  TS_ASSERT_EQUALS( isInside, false );
497 
498  // Test bounds for Z direction
499  cellId = g.getCellId( WPosition( 3.3, 1.75, 2.0 ), &isInside );
500  TS_ASSERT_EQUALS( isInside, false );
501 
502  cellId = g.getCellId( WPosition( 3.3, 1.75, 2.0 - wlimits::FLT_EPS ), &isInside );
503  TS_ASSERT_EQUALS( isInside, true );
504 
505  cellId = g.getCellId( WPosition( 3.3, 1.75, 0.0 ), &isInside );
506  TS_ASSERT_EQUALS( isInside, true );
507 
508  cellId = g.getCellId( WPosition( 3.3, 1.75, 0.0 - wlimits::FLT_EPS ), &isInside );
509  TS_ASSERT_EQUALS( isInside, false );
510  }
511 
512  /**
513  * If a point is inside of the boundary of a grid encloses should return true, otherwise false.
514  */
515  void testEnclosesQuery( void )
516  {
517  WGridRegular3D g( 2, 2, 2 );
518 
519  // Test bounds for X direction
520  TS_ASSERT( !g.encloses( WPosition( 0 - wlimits::FLT_EPS, 0, 0 ) ) );
521  TS_ASSERT( g.encloses( WPosition( 0, 0, 0 ) ) );
522  TS_ASSERT( g.encloses( WPosition( 1.0 - wlimits::FLT_EPS, 0.5, 0.5 ) ) );
523  TS_ASSERT( !g.encloses( WPosition( 1, 0.5, 0.5 ) ) );
524 
525  // Test bounds for Y direction
526  TS_ASSERT( !g.encloses( WPosition( 0, 0 - wlimits::FLT_EPS, 0 ) ) );
527  TS_ASSERT( g.encloses( WPosition( 0, 0, 0 ) ) );
528  TS_ASSERT( g.encloses( WPosition( 0.5, 1.0 - wlimits::FLT_EPS, 0.5 ) ) );
529  TS_ASSERT( !g.encloses( WPosition( 0.5, 1.0, 0.5 ) ) );
530 
531  // Test bounds for Z direction
532  TS_ASSERT( !g.encloses( WPosition( 0, 0, 0 - wlimits::FLT_EPS ) ) );
533  TS_ASSERT( g.encloses( WPosition( 0, 0, 0 ) ) );
534  TS_ASSERT( g.encloses( WPosition( 0.5, 0.5, 1.0 - wlimits::FLT_EPS ) ) );
535  TS_ASSERT( !g.encloses( WPosition( 0.5, 0.5, 1 ) ) );
536  }
537 
538  /**
539  * If a point is inside of the boundary of a grid encloses should return true, otherwise false.
540  */
542  {
543  WVector3d x( 0.707, 0.707, 0.0 );
544  WVector3d y( -0.707, 0.707, 0.0 );
545  WVector3d z( 0.0, 0.0, 1.0 );
546  x = normalize( x );
547  y = normalize( y );
548  y *= 2.0;
549  z *= 1.5;
550 
551  WMatrix< double > mat( 4, 4 );
552  mat.makeIdentity();
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 ];
562  mat( 0, 3 ) = 1.0;
563 
564  WGridTransformOrtho t( mat );
565  WGridRegular3D g( 5, 5, 5, t );
566 
567  WVector3d o = WVector3d( 1.0, 0.0, 0.0 ) + ( x + y + z ) * 2.0 * wlimits::FLT_EPS;
568  WVector3d v = o - 4.0 * wlimits::FLT_EPS * x;
569  TS_ASSERT( !g.encloses( v ) );
570  v = o;
571  TS_ASSERT( g.encloses( v ) );
572  v = o + ( 4.0 - 4.0 * wlimits::FLT_EPS ) * x;
573  TS_ASSERT( g.encloses( v ) );
574  v += 4.0 * wlimits::FLT_EPS * x;
575  TS_ASSERT( !g.encloses( v ) );
576 
577  v = o - 4.0 * wlimits::FLT_EPS * y;
578  TS_ASSERT( !g.encloses( v ) );
579  v = o + ( 4.0 - 4.0 * wlimits::FLT_EPS ) * y;
580  TS_ASSERT( g.encloses( v ) );
581  v += 4.0 * wlimits::FLT_EPS * y;
582  TS_ASSERT( !g.encloses( v ) );
583 
584  v = o - 4.0 * wlimits::FLT_EPS * z;
585  TS_ASSERT( !g.encloses( v ) );
586  v = o + ( 4.0 - 4.0 * wlimits::FLT_EPS ) * z;
587  TS_ASSERT( g.encloses( v ) );
588  v += 4.0 * wlimits::FLT_EPS * z;
589  TS_ASSERT( !g.encloses( v ) );
590  }
591 
592 private:
593  double m_delta; //!< Maximum amount to values are allowed to differ.
594 };
595 
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.
Definition: WMatrix.h:352
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.
Definition: WOutOfBounds.h:36
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.
Definition: WLimits.cpp:37
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.
Definition: WException.cpp:90
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.
Definition: WGrid.cpp:45
Implements an orthogonal grid transformation.
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...