25 #ifndef WTHREADEDTRACKINGFUNCTION_TEST_H
26 #define WTHREADEDTRACKINGFUNCTION_TEST_H
31 #include <cxxtest/TestSuite.h>
33 #include "../../common/WLogger.h"
34 #include "../WThreadedTrackingFunction.h"
70 std::shared_ptr< WGridRegular3D > g = std::dynamic_pointer_cast< WGridRegular3D >( ds->getGrid() );
75 v[ 0 ] += 0.5 * TRACKING_EPS;
77 v[ 2 ] -= 2.0 * TRACKING_EPS;
78 v[ 1 ] += 1.6 * TRACKING_EPS;
83 v[ 0 ] -= 0.6 * TRACKING_EPS;
85 v[ 2 ] += 1.5 * TRACKING_EPS;
86 v[ 1 ] += 2.6 * TRACKING_EPS;
89 v =
WVector3d( 1.0, 0.0, 0.0 ) + y * 1.77 + z * 0.65;
92 v =
WVector3d( 1.0, 0.0, 0.0 ) + y * 1.0 + z * 0.65;
95 v =
WVector3d( 1.0, 0.0, 0.0 ) + x * 3.5 + y * 1.77 + z * 0.65;
98 v =
WVector3d( 1.0, 0.0, 0.0 ) + x * 1.5 + y * 1.77 + z * 0.65;
101 v =
WVector3d( 1.0, 0.0, 0.0 ) + x * 3.9 + y * 5.0 + z * 0.65;
104 v =
WVector3d( 1.0, 0.0, 0.0 ) + x * 2.3 + y * 7.73 + z * 3.75;
107 v =
WVector3d( 1.0, 0.0, 0.0 ) + x * 3.4 + y * 1.77 + z * 6.75;
110 v =
WVector3d( 1.0, 0.0, 0.0 ) + x * 3.5 + y * 5.0 + z * 0.65;
112 v[ 1 ] -= 0.7 * TRACKING_EPS;
114 v[ 0 ] += 3.5 * TRACKING_EPS;
115 v[ 1 ] += 0.7 * TRACKING_EPS;
118 v =
WVector3d( 1.0, 0.0, 0.0 ) + x * 1.2 + y * 7.9 + z * 5.3;
136 std::shared_ptr< WGridRegular3D > g = std::dynamic_pointer_cast< WGridRegular3D >( ds->getGrid() );
142 v =
WVector3d( 1.0, 0.0, 0.0 ) + x * 0.5;
145 v -= x * 2.0 * TRACKING_EPS;
150 dir = normalize( dir );
155 v =
WVector3d( 1.0, 0.0, 0.0 ) + x * 3.75 + y * 6.65 + z * 5.59;
173 std::shared_ptr< WGridRegular3D > g = std::dynamic_pointer_cast< WGridRegular3D >( ds->getGrid() );
179 TS_ASSERT( g->encloses( j.first ) );
185 boost::placeholders::_1,
186 boost::placeholders::_2 ) ) );
188 TS_ASSERT( g->encloses( j.first ) );
190 TS_ASSERT_DELTA( length( j.first - v ), 0.0, 2.0 * TRACKING_EPS );
228 mat( 0, 0 ) = x[ 0 ];
229 mat( 1, 0 ) = x[ 1 ];
230 mat( 2, 0 ) = x[ 2 ];
231 mat( 0, 1 ) = y[ 0 ];
232 mat( 1, 1 ) = y[ 1 ];
233 mat( 2, 1 ) = y[ 2 ];
234 mat( 0, 2 ) = z[ 0 ];
235 mat( 1, 2 ) = z[ 1 ];
236 mat( 2, 2 ) = z[ 2 ];
242 data = normalize( data );
244 std::shared_ptr< std::vector< double > > v(
new std::vector< double > ( 5 * 5 * 5 * 3 ) );
245 for( std::size_t k = 0; k < 5 * 5 * 5; ++k )
247 v->at( 3 * k + 0 ) = data[ 0 ];
248 v->
at( 3 * k + 1 ) = data[ 1 ];
249 v->
at( 3 * k + 2 ) = data[ 2 ];
253 return std::shared_ptr< WDataSetSingle >(
new WDataSetSingle( vs, g ) );
273 std::vector< int > v0;
274 std::vector< int > v1;
275 std::size_t numSeeds = 1;
276 std::size_t seedsPerPosition = 1;
279 std::shared_ptr< WGridRegular3D > g = std::dynamic_pointer_cast< WGridRegular3D >( ds->getGrid() );
287 TS_ASSERT_EQUALS( i.
m_done,
false );
288 TS_ASSERT_EQUALS( i.
m_offset, 1.0 );
289 TS_ASSERT_EQUALS( i.
m_pos[ 0 ], 1 );
290 TS_ASSERT_EQUALS( i.
m_pos[ 1 ], 1 );
291 TS_ASSERT_EQUALS( i.
m_pos[ 2 ], 1 );
292 TS_ASSERT_EQUALS( i.
m_pos[ 3 ], 0 );
293 TS_ASSERT_EQUALS( i.
m_min[ 0 ], 1 );
294 TS_ASSERT_EQUALS( i.
m_min[ 1 ], 1 );
295 TS_ASSERT_EQUALS( i.
m_min[ 2 ], 1 );
296 TS_ASSERT_EQUALS( i.
m_min[ 3 ], 0 );
297 TS_ASSERT_EQUALS( i.
m_max[ 0 ], 4 );
298 TS_ASSERT_EQUALS( i.
m_max[ 1 ], 4 );
299 TS_ASSERT_EQUALS( i.
m_max[ 2 ], 4 );
300 TS_ASSERT_EQUALS( i.
m_max[ 3 ], 1 );
312 seedsPerPosition = 3;
318 TS_ASSERT_EQUALS( i.
m_done,
false );
319 TS_ASSERT_EQUALS( i.
m_offset, 0.25 );
320 TS_ASSERT_EQUALS( i.
m_pos[ 0 ], 4 );
321 TS_ASSERT_EQUALS( i.
m_pos[ 1 ], 8 );
322 TS_ASSERT_EQUALS( i.
m_pos[ 2 ], 4 );
323 TS_ASSERT_EQUALS( i.
m_pos[ 3 ], 0 );
324 TS_ASSERT_EQUALS( i.
m_min[ 0 ], 4 );
325 TS_ASSERT_EQUALS( i.
m_min[ 1 ], 8 );
326 TS_ASSERT_EQUALS( i.
m_min[ 2 ], 4 );
327 TS_ASSERT_EQUALS( i.
m_min[ 3 ], 0 );
328 TS_ASSERT_EQUALS( i.
m_max[ 0 ], 12 );
329 TS_ASSERT_EQUALS( i.
m_max[ 1 ], 12 );
330 TS_ASSERT_EQUALS( i.
m_max[ 2 ], 16 );
331 TS_ASSERT_EQUALS( i.
m_max[ 3 ], 3 );
349 std::vector< int > v0;
350 std::vector< int > v1;
351 std::size_t numSeeds = 1;
352 std::size_t seedsPerPosition = 1;
355 std::shared_ptr< WGridRegular3D > g = std::dynamic_pointer_cast< WGridRegular3D >( ds->getGrid() );
362 for(
int j = 0; j < 27; ++j )
364 TS_ASSERT( !i.
done() );
367 TS_ASSERT( i.
done() );
374 for(
int j = 0; j < 27 * 64; ++j )
376 TS_ASSERT( !i.
done() );
379 TS_ASSERT( i.
done() );
382 seedsPerPosition = 3;
386 for(
int j = 0; j < 27 * 64 * 3; ++j )
388 TS_ASSERT( !i.
done() );
391 TS_ASSERT( i.
done() );
402 for(
int j = 0; j < 18 * 64 * 3; ++j )
404 TS_ASSERT( !i.
done() );
407 TS_ASSERT( i.
done() );
424 std::vector< int > v0;
425 std::vector< int > v1;
426 std::size_t numSeeds = 2;
427 std::size_t seedsPerPosition = 1;
430 std::shared_ptr< WGridRegular3D > g = std::dynamic_pointer_cast< WGridRegular3D >( ds->getGrid() );
438 WVector3d v = g->getOrigin() + 0.75 * x + 0.75 * y + 0.75 * z;
440 std::cout << g->getOrigin() << std::endl;
442 TS_ASSERT_DELTA( v[ 0 ], job.first[ 0 ], TRACKING_EPS );
443 TS_ASSERT_DELTA( v[ 1 ], job.first[ 1 ], TRACKING_EPS );
444 TS_ASSERT_DELTA( v[ 2 ], job.first[ 2 ], TRACKING_EPS );
449 TS_ASSERT_DELTA( v[ 0 ], job.first[ 0 ], TRACKING_EPS );
450 TS_ASSERT_DELTA( v[ 1 ], job.first[ 1 ], TRACKING_EPS );
451 TS_ASSERT_DELTA( v[ 2 ], job.first[ 2 ], TRACKING_EPS );
453 for(
int k = 0; k < 6; ++k )
459 TS_ASSERT_DELTA( v[ 0 ], job.first[ 0 ], TRACKING_EPS );
460 TS_ASSERT_DELTA( v[ 1 ], job.first[ 1 ], TRACKING_EPS );
461 TS_ASSERT_DELTA( v[ 2 ], job.first[ 2 ], TRACKING_EPS );
463 for(
int k = 0; k < 36; ++k )
469 TS_ASSERT_DELTA( v[ 0 ], job.first[ 0 ], TRACKING_EPS );
470 TS_ASSERT_DELTA( v[ 1 ], job.first[ 1 ], TRACKING_EPS );
471 TS_ASSERT_DELTA( v[ 2 ], job.first[ 2 ], TRACKING_EPS );
473 TS_ASSERT_EQUALS( job.second[ 0 ], 0.0 );
474 TS_ASSERT_EQUALS( job.second[ 1 ], 0.0 );
475 TS_ASSERT_EQUALS( job.second[ 2 ], 0.0 );
479 seedsPerPosition = 11;
484 WVector3d v = g->getOrigin() + 0.625 * x + 0.625 * y + 0.625 * z;
485 for(
int k = 0; k < 11; ++k )
488 TS_ASSERT_DELTA( v[ 0 ], job.first[ 0 ], TRACKING_EPS );
489 TS_ASSERT_DELTA( v[ 1 ], job.first[ 1 ], TRACKING_EPS );
490 TS_ASSERT_DELTA( v[ 2 ], job.first[ 2 ], TRACKING_EPS );
502 std::shared_ptr< WGridRegular3D > g = std::dynamic_pointer_cast< WGridRegular3D >( ds->getGrid() );
505 TS_ASSERT_THROWS_NOTHING(
509 boost::placeholders::_1,
510 boost::placeholders::_2,
513 boost::placeholders::_1,
514 boost::placeholders::_2,
515 boost::placeholders::_3 ),
516 boost::bind( &
This::fibVis,
this, boost::placeholders::_1 ),
517 boost::bind( &
This::pntVis,
this, boost::placeholders::_1 ) ) );
526 std::shared_ptr< WGridRegular3D > g = std::dynamic_pointer_cast< WGridRegular3D >( ds->getGrid() );
531 boost::placeholders::_1,
532 boost::placeholders::_2,
535 boost::placeholders::_1,
536 boost::placeholders::_2,
537 boost::placeholders::_3 ),
538 boost::bind( &
This::fibVis,
this, boost::placeholders::_1 ),
539 boost::bind( &
This::pntVis,
this, boost::placeholders::_1 ) );
541 for(
int i = 0; i < 125; ++i )
543 TS_ASSERT( w.
getJob( job ) );
545 TS_ASSERT( !w.
getJob( job ) );
560 std::shared_ptr< WGridRegular3D > g = std::dynamic_pointer_cast< WGridRegular3D >( ds->getGrid() );
565 boost::placeholders::_1,
566 boost::placeholders::_2,
567 boost::placeholders::_3 ),
568 boost::bind( &
This::fibVis,
this, boost::placeholders::_1 ),
569 boost::bind( &
This::pntVis,
this, boost::placeholders::_1 ) );
579 boost::placeholders::_1,
580 boost::placeholders::_2,
581 boost::placeholders::_3 ),
582 boost::bind( &
This::fibVis,
this, boost::placeholders::_1 ),
583 boost::bind( &
This::pntVis,
this, boost::placeholders::_1 ) );
613 mat( 0, 0 ) = x[ 0 ];
614 mat( 1, 0 ) = x[ 1 ];
615 mat( 2, 0 ) = x[ 2 ];
616 mat( 0, 1 ) = y[ 0 ];
617 mat( 1, 1 ) = y[ 1 ];
618 mat( 2, 1 ) = y[ 2 ];
619 mat( 0, 2 ) = z[ 0 ];
620 mat( 1, 2 ) = z[ 1 ];
621 mat( 2, 2 ) = z[ 2 ];
627 data = normalize( data );
629 std::shared_ptr< std::vector< double > > v(
new std::vector< double >( n * n * n * 3 ) );
630 for( std::size_t k = 0; k < static_cast< std::size_t >( n * n * n ); ++k )
632 v->at( 3 * k + 0 ) = data[ 0 ];
633 v->
at( 3 * k + 1 ) = data[ 1 ];
634 v->
at( 3 * k + 2 ) = data[ 2 ];
638 return std::shared_ptr< WDataSetSingle >(
new WDataSetSingle( vs, g ) );
653 if( dot( j.second, d ) > 0.0 )
666 void fibVis( std::vector< WVector3d >
const& )
A data set consisting of a set of values based on a grid.
A grid that has parallelepiped cells which all have the same proportion.
static void startup(std::ostream &output=std::cout, LogLevel level=LL_DEBUG)
Create the first and only instance of the logger as it is a singleton.
ValueT & at(size_t row, size_t col)
Returns a reference to the component of an row and column in order to provide access to the component...
WMatrix & makeIdentity()
Makes the matrix contain the identity matrix, i.e.
ReadTicket getReadTicket() const
Returns a ticket to get read access to the contained data.
WriteTicket getWriteTicket(bool suppressNotify=false) const
Returns a ticket to get write access to the contained data.
Test the WThreadedTrackingFunction class.
WSharedObject< std::size_t > m_points
the number of points found
std::shared_ptr< WDataSetSingle > buildTestData(WVector3d data, int n)
Build a test dataset.
void testCompute()
Test if fibers with the right number of points get created.
void testIndexInitialization()
Test if everything gets initialized correctly.
void testInstantiation()
Test if everything gets initialized correctly.
WThreadedTrackingFunctionTest This
a handy abbreviation
WVector3d dirFunc(wtracking::WThreadedTrackingFunction::DataSetPtr, wtracking::WThreadedTrackingFunction::JobType const &j, WVector3d d)
The direction computation function.
void testIndexIncrement()
Test if indices (seed positions) iteration works.
void pntVis(WVector3d const &)
The point visitor.
void testIndexToJob()
Test if the right jobs get created from seeds.
void testGetJob()
Test if the correct amount of jobs gets created.
void fibVis(std::vector< WVector3d > const &)
The fiber visitor.
Test the utility functions for tracking.
WTrackingUtilityTest This
an abbreviation
std::shared_ptr< WDataSetSingle > buildTestData(WVector3d data)
Build a test dataset.
void testBoundary()
Test if positions with a distance less then TRACKING_EPS from a boundary are determined correctly by ...
void testFollowToNextVoxel()
Test if followToNextVoxel() returns a valid (inside the grid) position in the next voxel (and not on ...
WVector3d simpleDirFunc(wtracking::WTrackingUtility::DataSetPtr, wtracking::WTrackingUtility::JobType const &)
A simple direction calculation function.
void testGetDistanceToBoundary()
Check if getDistanceToBoundary() returns the correct distance.
void setUp()
Setup logger and other stuff for each test.
Base Class for all value set types.
An index for seed positions.
boost::array< std::size_t, 4 > m_max
the maximum position in the seed space
boost::array< std::size_t, 4 > m_min
the minimum position in the seed space
bool m_done
true, iff there are no more seeds
bool done()
Check if there aren't any more seed positions.
double m_offset
the relative (to the size of a voxel) distance between seeds
JobType job()
Create a job from this index.
boost::array< std::size_t, 4 > m_pos
the position in the seed space
Implements a generalized multithreaded tracking algorithm.
WTrackingUtility::JobType JobType
the job type
WTrackingUtility::DataSetPtr DataSetPtr
a pointer to a dataset
virtual void compute(DataSetPtr input, JobType const &job)
The calculation per job.
virtual bool getJob(JobType &job)
The job generator.
static bool onBoundary(Grid3DPtr grid, WVector3d const &pos)
Check if a point is on the boundary of the given grid, where boundary means a distance less then TRAC...
std::pair< WVector3d, WVector3d > JobType
define a job type for tracking algorithms
static bool followToNextVoxel(DataSetPtr dataset, JobType &job, DirFunc const &dirFunc)
A function that follows a direction until leaving the current voxel.
std::shared_ptr< DataSetType const > DataSetPtr
a pointer to a dataset
static double getDistanceToBoundary(Grid3DPtr grid, WVector3d const &pos, WVector3d const &dir)
Calculate the distance from a given position to the nearest voxel boundary on the ray from the positi...
const float FLT_EPS
Smallest float such: 1.0 + FLT_EPS == 1.0 is still true.