25 #ifndef WTHREADEDPERVOXELOPERATION_H
26 #define WTHREADEDPERVOXELOPERATION_H
32 #include <boost/array.hpp>
35 #include <boost/shared_ptr.hpp>
38 #include <boost/function.hpp>
41 #include "../common/WException.h"
42 #include "../common/WThreadedJobs.h"
43 #include "../common/WSharedObject.h"
44 #include "../common/WSharedSequenceContainer.h"
45 #include "WDataSetSingle.h"
46 #include "WDataSetScalar.h"
47 #include "WValueSet.h"
48 #include "WDataHandlerEnums.h"
74 template<
typename Value_T, std::
size_t numValues,
typename Output_T, std::
size_t numOutputs >
97 typedef boost::function< OutTransmitType const ( TransmitType const& ) >
FunctionType;
118 virtual void compute( boost::shared_ptr< ValueSetType const > input, std::size_t voxelNum );
125 boost::shared_ptr< WDataSetSingle >
getResult();
144 template<
typename Value_T, std::
size_t numValues,
typename Output_T, std::
size_t numOutputs >
146 boost::shared_ptr< WDataSetSingle const > dataset,
153 throw WException( std::string(
"No input dataset." ) );
155 if( !dataset->getValueSet() )
157 throw WException( std::string(
"The input dataset has no valueset." ) );
159 if( !dataset->getGrid() )
161 throw WException( std::string(
"The input dataset has no grid." ) );
163 if( dataset->getValueSet()->order() > 1 )
165 throw WException( std::string(
"An order of 2 or more is currently not supported." ) );
167 if( dataset->getValueSet()->dimension() != numValues )
169 throw WException( std::string(
"Invalid valueset dimension." ) );
173 throw WException( std::string(
"No valid function provided." ) );
181 catch( std::exception
const& e )
186 m_grid = dataset->getGrid();
189 template<
typename Value_T, std::
size_t numValues,
typename Output_T, std::
size_t numOutputs >
194 template<
typename Value_T, std::
size_t numValues,
typename Output_T, std::
size_t numOutputs >
196 std::size_t voxelNum )
198 TransmitType t = input->getSubArray( voxelNum * numValues, numValues );
200 for( std::size_t k = 0; k < numOutputs; ++k )
202 ( *m_output )[ voxelNum * numOutputs + k ] = o[ k ];
206 template<
typename Value_T, std::
size_t numValues,
typename Output_T, std::
size_t numOutputs >
209 boost::shared_ptr< OutValueSetType > values;
213 values = boost::shared_ptr< OutValueSetType >(
new OutValueSetType( 0, 1, m_output,
215 return boost::shared_ptr< WDataSetScalar >(
new WDataSetScalar( values, m_grid ) );
217 values = boost::shared_ptr< OutValueSetType >(
new OutValueSetType( 1, numOutputs, m_output,
219 return boost::shared_ptr< WDataSetSingle >(
new WDataSetSingle( values, m_grid ) );
223 #endif // WTHREADEDPERVOXELOPERATION_H
FunctionType m_func
the function applied to every voxel
WThreadedStripingJobs< WValueSet< Value_T >, std::size_t > BaseType
the base class
ValueSetType::SubArray const TransmitType
the input type for the per-voxel operation
boost::shared_ptr< std::vector< Output_T > > OutputVectorType
a threadsafe vector (container)
OutArrayType const func(ArrayType const &a) const
The test operation.
boost::function< OutTransmitType const (TransmitType const &) > FunctionType
the function type
boost::shared_ptr< WDataSetSingle > getResult()
Get the output dataset.
WValueSet< Value_T > ValueSetType
the input valueset's type
A helper class granting safe access to a certain part of the valueset.
OutputVectorType m_output
stores the output of the per-voxel-operation
A template that performs an operation on a per voxel basis.
An object that knows an appropriate dataType flag for the typename T.
virtual ~WThreadedPerVoxelOperation()
Destructor.
boost::shared_ptr< InputType const > m_input
the input
A data set consisting of a set of values based on a grid.
Nearly the same class as WThreadedJobs, but this class is intended to be used for multithreaded opera...
WThreadedPerVoxelOperation(boost::shared_ptr< WDataSetSingle const > dataset, FunctionType func)
Construct a per-voxel operation.
Base Class for all value set types.
WValueSet< Output_T > OutValueSetType
the output valueset's type
boost::shared_ptr< WGrid > m_grid
store the grid
This data set type contains scalars as values.
virtual void compute(boost::shared_ptr< ValueSetType const > input, std::size_t voxelNum)
Perform the computation for a specific voxel.
boost::array< Output_T, numOutputs > OutTransmitType
the output type for the per-voxel operation
Test the WThreadedPerVoxelOperation template.