25 #ifndef WTHREADEDTRACKINGFUNCTION_TEST_H
26 #define WTHREADEDTRACKINGFUNCTION_TEST_H
30 #include <cxxtest/TestSuite.h>
32 #include "../../common/WLogger.h"
33 #include "../WThreadedTrackingFunction.h"
69 boost::shared_ptr< WGridRegular3D > g = boost::dynamic_pointer_cast<
WGridRegular3D >( ds->getGrid() );
74 v[ 0 ] += 0.5 * TRACKING_EPS;
76 v[ 2 ] -= 2.0 * TRACKING_EPS;
77 v[ 1 ] += 1.6 * TRACKING_EPS;
82 v[ 0 ] -= 0.6 * TRACKING_EPS;
84 v[ 2 ] += 1.5 * TRACKING_EPS;
85 v[ 1 ] += 2.6 * TRACKING_EPS;
88 v =
WVector3d( 1.0, 0.0, 0.0 ) + y * 1.77 + z * 0.65;
91 v =
WVector3d( 1.0, 0.0, 0.0 ) + y * 1.0 + z * 0.65;
94 v =
WVector3d( 1.0, 0.0, 0.0 ) + x * 3.5 + y * 1.77 + z * 0.65;
97 v =
WVector3d( 1.0, 0.0, 0.0 ) + x * 1.5 + y * 1.77 + z * 0.65;
100 v =
WVector3d( 1.0, 0.0, 0.0 ) + x * 3.9 + y * 5.0 + z * 0.65;
103 v =
WVector3d( 1.0, 0.0, 0.0 ) + x * 2.3 + y * 7.73 + z * 3.75;
106 v =
WVector3d( 1.0, 0.0, 0.0 ) + x * 3.4 + y * 1.77 + z * 6.75;
109 v =
WVector3d( 1.0, 0.0, 0.0 ) + x * 3.5 + y * 5.0 + z * 0.65;
111 v[ 1 ] -= 0.7 * TRACKING_EPS;
113 v[ 0 ] += 3.5 * TRACKING_EPS;
114 v[ 1 ] += 0.7 * TRACKING_EPS;
117 v =
WVector3d( 1.0, 0.0, 0.0 ) + x * 1.2 + y * 7.9 + z * 5.3;
135 boost::shared_ptr< WGridRegular3D > g = boost::dynamic_pointer_cast<
WGridRegular3D >( ds->getGrid() );
141 v =
WVector3d( 1.0, 0.0, 0.0 ) + x * 0.5;
144 v -= x * 2.0 * TRACKING_EPS;
149 dir = normalize( dir );
154 v =
WVector3d( 1.0, 0.0, 0.0 ) + x * 3.75 + y * 6.65 + z * 5.59;
172 boost::shared_ptr< WGridRegular3D > g = boost::dynamic_pointer_cast<
WGridRegular3D >( ds->getGrid() );
178 TS_ASSERT( g->encloses( j.first ) );
184 TS_ASSERT( g->encloses( j.first ) );
186 TS_ASSERT_DELTA( length( j.first - v ), 0.0, 2.0 * TRACKING_EPS );
224 mat( 0, 0 ) = x[ 0 ];
225 mat( 1, 0 ) = x[ 1 ];
226 mat( 2, 0 ) = x[ 2 ];
227 mat( 0, 1 ) = y[ 0 ];
228 mat( 1, 1 ) = y[ 1 ];
229 mat( 2, 1 ) = y[ 2 ];
230 mat( 0, 2 ) = z[ 0 ];
231 mat( 1, 2 ) = z[ 1 ];
232 mat( 2, 2 ) = z[ 2 ];
238 data = normalize( data );
240 boost::shared_ptr< std::vector< double > > v(
new std::vector< double > ( 5 * 5 * 5 * 3 ) );
241 for( std::size_t k = 0; k < 5 * 5 * 5; ++k )
243 v->at( 3 * k + 0 ) = data[ 0 ];
244 v->
at( 3 * k + 1 ) = data[ 1 ];
245 v->
at( 3 * k + 2 ) = data[ 2 ];
249 return boost::shared_ptr< WDataSetSingle >(
new WDataSetSingle( vs, g ) );
269 std::vector< int > v0;
270 std::vector< int > v1;
271 std::size_t numSeeds = 1;
272 std::size_t seedsPerPosition = 1;
275 boost::shared_ptr< WGridRegular3D > g = boost::dynamic_pointer_cast<
WGridRegular3D >( ds->getGrid() );
283 TS_ASSERT_EQUALS( i.
m_done,
false );
284 TS_ASSERT_EQUALS( i.
m_offset, 1.0 );
285 TS_ASSERT_EQUALS( i.
m_pos[ 0 ], 1 );
286 TS_ASSERT_EQUALS( i.
m_pos[ 1 ], 1 );
287 TS_ASSERT_EQUALS( i.
m_pos[ 2 ], 1 );
288 TS_ASSERT_EQUALS( i.
m_pos[ 3 ], 0 );
289 TS_ASSERT_EQUALS( i.
m_min[ 0 ], 1 );
290 TS_ASSERT_EQUALS( i.
m_min[ 1 ], 1 );
291 TS_ASSERT_EQUALS( i.
m_min[ 2 ], 1 );
292 TS_ASSERT_EQUALS( i.
m_min[ 3 ], 0 );
293 TS_ASSERT_EQUALS( i.
m_max[ 0 ], 4 );
294 TS_ASSERT_EQUALS( i.
m_max[ 1 ], 4 );
295 TS_ASSERT_EQUALS( i.
m_max[ 2 ], 4 );
296 TS_ASSERT_EQUALS( i.
m_max[ 3 ], 1 );
308 seedsPerPosition = 3;
314 TS_ASSERT_EQUALS( i.
m_done,
false );
315 TS_ASSERT_EQUALS( i.
m_offset, 0.25 );
316 TS_ASSERT_EQUALS( i.
m_pos[ 0 ], 4 );
317 TS_ASSERT_EQUALS( i.
m_pos[ 1 ], 8 );
318 TS_ASSERT_EQUALS( i.
m_pos[ 2 ], 4 );
319 TS_ASSERT_EQUALS( i.
m_pos[ 3 ], 0 );
320 TS_ASSERT_EQUALS( i.
m_min[ 0 ], 4 );
321 TS_ASSERT_EQUALS( i.
m_min[ 1 ], 8 );
322 TS_ASSERT_EQUALS( i.
m_min[ 2 ], 4 );
323 TS_ASSERT_EQUALS( i.
m_min[ 3 ], 0 );
324 TS_ASSERT_EQUALS( i.
m_max[ 0 ], 12 );
325 TS_ASSERT_EQUALS( i.
m_max[ 1 ], 12 );
326 TS_ASSERT_EQUALS( i.
m_max[ 2 ], 16 );
327 TS_ASSERT_EQUALS( i.
m_max[ 3 ], 3 );
345 std::vector< int > v0;
346 std::vector< int > v1;
347 std::size_t numSeeds = 1;
348 std::size_t seedsPerPosition = 1;
351 boost::shared_ptr< WGridRegular3D > g = boost::dynamic_pointer_cast<
WGridRegular3D >( ds->getGrid() );
358 for(
int j = 0; j < 27; ++j )
360 TS_ASSERT( !i.
done() );
363 TS_ASSERT( i.
done() );
370 for(
int j = 0; j < 27 * 64; ++j )
372 TS_ASSERT( !i.
done() );
375 TS_ASSERT( i.
done() );
378 seedsPerPosition = 3;
382 for(
int j = 0; j < 27 * 64 * 3; ++j )
384 TS_ASSERT( !i.
done() );
387 TS_ASSERT( i.
done() );
398 for(
int j = 0; j < 18 * 64 * 3; ++j )
400 TS_ASSERT( !i.
done() );
403 TS_ASSERT( i.
done() );
420 std::vector< int > v0;
421 std::vector< int > v1;
422 std::size_t numSeeds = 2;
423 std::size_t seedsPerPosition = 1;
426 boost::shared_ptr< WGridRegular3D > g = boost::dynamic_pointer_cast<
WGridRegular3D >( ds->getGrid() );
434 WVector3d v = g->getOrigin() + 0.75 * x + 0.75 * y + 0.75 * z;
436 std::cout << g->getOrigin() << std::endl;
438 TS_ASSERT_DELTA( v[ 0 ], job.first[ 0 ], TRACKING_EPS );
439 TS_ASSERT_DELTA( v[ 1 ], job.first[ 1 ], TRACKING_EPS );
440 TS_ASSERT_DELTA( v[ 2 ], job.first[ 2 ], TRACKING_EPS );
445 TS_ASSERT_DELTA( v[ 0 ], job.first[ 0 ], TRACKING_EPS );
446 TS_ASSERT_DELTA( v[ 1 ], job.first[ 1 ], TRACKING_EPS );
447 TS_ASSERT_DELTA( v[ 2 ], job.first[ 2 ], TRACKING_EPS );
449 for(
int k = 0; k < 6; ++k )
455 TS_ASSERT_DELTA( v[ 0 ], job.first[ 0 ], TRACKING_EPS );
456 TS_ASSERT_DELTA( v[ 1 ], job.first[ 1 ], TRACKING_EPS );
457 TS_ASSERT_DELTA( v[ 2 ], job.first[ 2 ], TRACKING_EPS );
459 for(
int k = 0; k < 36; ++k )
465 TS_ASSERT_DELTA( v[ 0 ], job.first[ 0 ], TRACKING_EPS );
466 TS_ASSERT_DELTA( v[ 1 ], job.first[ 1 ], TRACKING_EPS );
467 TS_ASSERT_DELTA( v[ 2 ], job.first[ 2 ], TRACKING_EPS );
469 TS_ASSERT_EQUALS( job.second[ 0 ], 0.0 );
470 TS_ASSERT_EQUALS( job.second[ 1 ], 0.0 );
471 TS_ASSERT_EQUALS( job.second[ 2 ], 0.0 );
475 seedsPerPosition = 11;
480 WVector3d v = g->getOrigin() + 0.625 * x + 0.625 * y + 0.625 * z;
481 for(
int k = 0; k < 11; ++k )
484 TS_ASSERT_DELTA( v[ 0 ], job.first[ 0 ], TRACKING_EPS );
485 TS_ASSERT_DELTA( v[ 1 ], job.first[ 1 ], TRACKING_EPS );
486 TS_ASSERT_DELTA( v[ 2 ], job.first[ 2 ], TRACKING_EPS );
498 boost::shared_ptr< WGridRegular3D > g = boost::dynamic_pointer_cast<
WGridRegular3D >( ds->getGrid() );
501 TS_ASSERT_THROWS_NOTHING(
515 boost::shared_ptr< WGridRegular3D > g = boost::dynamic_pointer_cast<
WGridRegular3D >( ds->getGrid() );
523 for(
int i = 0; i < 125; ++i )
525 TS_ASSERT( w.
getJob( job ) );
527 TS_ASSERT( !w.
getJob( job ) );
542 boost::shared_ptr< WGridRegular3D > g = boost::dynamic_pointer_cast<
WGridRegular3D >( ds->getGrid() );
589 mat( 0, 0 ) = x[ 0 ];
590 mat( 1, 0 ) = x[ 1 ];
591 mat( 2, 0 ) = x[ 2 ];
592 mat( 0, 1 ) = y[ 0 ];
593 mat( 1, 1 ) = y[ 1 ];
594 mat( 2, 1 ) = y[ 2 ];
595 mat( 0, 2 ) = z[ 0 ];
596 mat( 1, 2 ) = z[ 1 ];
597 mat( 2, 2 ) = z[ 2 ];
603 data = normalize( data );
605 boost::shared_ptr< std::vector< double > > v(
new std::vector< double >( n * n * n * 3 ) );
606 for( std::size_t k = 0; k < static_cast< std::size_t >( n * n * n ); ++k )
608 v->at( 3 * k + 0 ) = data[ 0 ];
609 v->
at( 3 * k + 1 ) = data[ 1 ];
610 v->
at( 3 * k + 2 ) = data[ 2 ];
614 return boost::shared_ptr< WDataSetSingle >(
new WDataSetSingle( vs, g ) );
629 if( dot( j.second, d ) > 0.0 )
642 void fibVis( std::vector< WVector3d >
const& )
658 #endif // WTHREADEDTRACKINGFUNCTION_TEST_H
Test the utility functions for tracking.
WThreadedTrackingFunctionTest This
a handy abbreviation
WTrackingUtility::DataSetPtr DataSetPtr
a pointer to a dataset
A grid that has parallelepiped cells which all have the same proportion.
WTrackingUtilityTest This
an abbreviation
void testFollowToNextVoxel()
Test if followToNextVoxel() returns a valid (inside the grid) position in the next voxel (and not on ...
WMatrix & makeIdentity()
Makes the matrix contain the identity matrix, i.e.
void testIndexToJob()
Test if the right jobs get created from seeds.
boost::shared_ptr< WDataSetSingle > buildTestData(WVector3d data)
Build a test dataset.
void testIndexInitialization()
Test if everything gets initialized correctly.
void testGetDistanceToBoundary()
Check if getDistanceToBoundary() returns the correct distance.
std::pair< WVector3d, WVector3d > JobType
define a job type for tracking algorithms
bool m_done
true, iff there are no more seeds
bool done()
Check if there aren't any more seed positions.
boost::shared_ptr< DataSetType const > DataSetPtr
a pointer to a dataset
void pntVis(WVector3d const &)
The point visitor.
boost::array< std::size_t, 4 > m_pos
the position in the seed space
virtual bool getJob(JobType &job)
The job generator.
double m_offset
the relative (to the size of a voxel) distance between seeds
ReadTicket getReadTicket() const
Returns a ticket to get read access to the contained data.
virtual void compute(DataSetPtr input, JobType const &job)
The calculation per job.
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.
WriteTicket getWriteTicket(bool suppressNotify=false) const
Returns a ticket to get write access to the contained data.
const float FLT_EPS
Smallest float such: 1.0 + FLT_EPS == 1.0 is still true.
void testInstantiation()
Test if everything gets initialized correctly.
void testIndexIncrement()
Test if indices (seed positions) iteration works.
boost::array< std::size_t, 4 > m_max
the maximum position in the seed space
WVector3d simpleDirFunc(wtracking::WTrackingUtility::DataSetPtr, wtracking::WTrackingUtility::JobType const &)
A simple direction calculation function.
boost::array< std::size_t, 4 > m_min
the minimum position in the seed space
static bool followToNextVoxel(DataSetPtr dataset, JobType &job, DirFunc const &dirFunc)
A function that follows a direction until leaving the current voxel.
A data set consisting of a set of values based on a grid.
WSharedObject< std::size_t > m_points
the number of points found
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...
void setUp()
Setup logger and other stuff for each test.
Implements a generalized multithreaded tracking algorithm.
void fibVis(std::vector< WVector3d > const &)
The fiber visitor.
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...
Base Class for all value set types.
void testBoundary()
Test if positions with a distance less then TRACKING_EPS from a boundary are determined correctly by ...
void testGetJob()
Test if the correct amount of jobs gets created.
WVector3d dirFunc(wtracking::WThreadedTrackingFunction::DataSetPtr, wtracking::WThreadedTrackingFunction::JobType const &j, WVector3d d)
The direction computation function.
JobType job()
Create a job from this index.
An index for seed positions.
void testCompute()
Test if fibers with the right number of points get created.
boost::shared_ptr< WDataSetSingle > buildTestData(WVector3d data, int n)
Build a test dataset.
Test the WThreadedTrackingFunction class.
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...
WTrackingUtility::JobType JobType
the job type