25 #ifndef WTHREADEDPERVOXELOPERATION_TEST_H
26 #define WTHREADEDPERVOXELOPERATION_TEST_H
30 #include <cxxtest/TestSuite.h>
32 #include "../../common/WThreadedFunction.h"
33 #include "../../common/WLogger.h"
34 #include "../WDataHandlerEnums.h"
35 #include "../WDataSetSingle.h"
36 #include "../WThreadedPerVoxelOperation.h"
74 TS_ASSERT_THROWS( TPVO t( boost::shared_ptr< WDataSetSingle >(),
77 TS_ASSERT_THROWS( TPVO t( boost::shared_ptr< WDataSetSingle >(
new WDataSetSingle( ds->getValueSet(),
78 boost::shared_ptr< WGrid >() ) ),
80 TS_ASSERT_THROWS( TPVO t( boost::shared_ptr< WDataSetSingle >(
new WDataSetSingle( boost::shared_ptr< WValueSetBase >(),
88 TS_ASSERT_EQUALS( ds->getGrid(), t.
m_grid );
106 TS_ASSERT_THROWS_NOTHING( f.
run() );
107 TS_ASSERT_THROWS_NOTHING( f.
wait() );
111 boost::shared_ptr< WDataSetSingle > res = t->getResult();
118 -28.0f, 13.0f, -44.0f,
125 TS_ASSERT( res->getValueSet() );
126 TS_ASSERT_EQUALS( res->getGrid(), ds->getGrid() );
127 TS_ASSERT_EQUALS( res->getValueSet()->dimension(), 3 );
128 TS_ASSERT_EQUALS( res->getValueSet()->order(), 1 );
129 TS_ASSERT_EQUALS( res->getValueSet()->size(), 8 );
131 boost::shared_ptr< WValueSet< float > > vs = boost::dynamic_pointer_cast<
WValueSet< float > >( res->getValueSet() );
134 TS_ASSERT( vs->rawData() );
135 TS_ASSERT_EQUALS( vs->rawDataVectorPointer()->size(), 24 );
136 TS_ASSERT_SAME_DATA( vs->rawData(), shouldBe, 8 * 3 *
sizeof( float ) );
146 OutArrayType
const func( ArrayType
const& a )
const
149 o[ 0 ] =
static_cast< float >( a[ 1 ] );
150 o[ 1 ] =
static_cast< float >( a[ 0 ] + 1 );
151 o[ 2 ] =
static_cast< float >( a[ 0 ] + 2 * a[ 1 ] );
162 int a[] = { 1, 2, 3, -5, 7, 8, 2, -4, 12, -28, 3, 3, 4, -4, -5, 2 };
163 boost::shared_ptr< std::vector< int > > v(
new std::vector< int >( a, a + 16 ) );
165 boost::shared_ptr< ValueSetType > vs(
new ValueSetType( 1, 2, v, r ) );
166 boost::shared_ptr< WGridRegular3D > g(
new WGridRegular3D( 2, 2, 2 ) );
167 return boost::shared_ptr< WDataSetSingle >(
new WDataSetSingle( vs, g ) );
193 #endif // WTHREADEDPERVOXELOPERATION_TEST_H
void setUp()
Setup logger and other stuff for each test.
TPVO::OutTransmitType OutArrayType
the output type of the test function
Creates threads that computes a function in a multithreaded fashion.
A grid that has parallelepiped cells which all have the same proportion.
void testInstantiation()
Test if everything gets instantiated correctly or if incorrect values properly lead to exceptions...
void handleThreadsDone()
This function gets called when all threads are done.
void handleException(WException const &)
Handle an exception.
virtual void run()
Starts the threads.
ValueSetType::SubArray const TransmitType
the input type for the per-voxel operation
OutArrayType const func(ArrayType const &a) const
The test operation.
boost::function< OutTransmitType const (TransmitType const &) > FunctionType
the function type
boost::shared_ptr< WDataSetSingle > buildTestData()
Build a test dataset.
bool m_exception
a flag that is used to check if any exceptions were thrown
WThreadedPerVoxelOperation< int, 2, float, 3 > TPVO
the test instance of the template
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.
A template that performs an operation on a per voxel basis.
An object that knows an appropriate dataType flag for the typename T.
boost::shared_ptr< WCondition > getThreadsDoneCondition()
Returns a condition that gets fired when all threads have finished.
TPVO::ValueSetType ValueSetType
the type of valueset used in the test
dataType
Data types and number values taken from the nifti1.h, at this point it's unknown if it makes sense to...
A data set consisting of a set of values based on a grid.
bool m_threadsDone
a flag indicating if all threads are done
Base Class for all value set types.
TPVO::TransmitType ArrayType
the input type of the test function
boost::shared_ptr< WGrid > m_grid
store the grid
void testMultithreadedFunction()
Now test the whole class as a multithreaded function.
boost::array< Output_T, numOutputs > OutTransmitType
the output type for the per-voxel operation
void subscribeExceptionSignal(ExceptionFunction func)
Subscribe a function to an exception signal.
virtual void wait()
Wait for all threads to stop.
Test the WThreadedPerVoxelOperation template.