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