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