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