25 #ifndef WMHARDITOSPHERICALHARMONICS_H
26 #define WMHARDITOSPHERICALHARMONICS_H
34 #include "WSphericalHarmonicsCoefficientsThread.h"
35 #include "core/common/WThreadedRunner.h"
36 #include "core/common/math/WMatrix.h"
37 #include "core/dataHandler/WDataSetRawHARDI.h"
38 #include "core/dataHandler/WDataSetSphericalHarmonics.h"
39 #include "core/dataHandler/WGridRegular3D.h"
40 #include "core/kernel/WModule.h"
41 #include "core/kernel/WModuleInputData.h"
42 #include "core/kernel/WModuleOutputData.h"
45 template<
typename T >
74 virtual const std::string
getName()
const;
88 virtual std::shared_ptr< WModule >
factory()
const;
156 std::shared_ptr< WModuleInputData< WDataSetRawHARDI > >
m_input;
161 std::shared_ptr< WModuleOutputData< WDataSetSphericalHarmonics > >
m_output;
193 virtual std::shared_ptr< WPropertyVariable< WPVBaseTypes::PV_INT >::PropertyConstraint >
clone();
208 std::shared_ptr< WDataSetRawHARDI > > >
220 std::shared_ptr< WGrid > grid, std::vector< WVector3d >
const& gradients );
234 template<
typename T >
251 template<
typename T >
252 WMHARDIToSphericalHarmonics::HARDICalculation::result_type
257 size_t voxelCount =
m_parameter.m_valueSet->size();
262 parameter.m_data = std::shared_ptr< std::vector< double > >(
new std::vector< double >( voxelCount * dimension ) );
265 ( boost::thread::hardware_concurrency() == 0 ? 1 : boost::thread::hardware_concurrency() ) : 1;
268 if( parameter.m_doResidualCalculation )
270 parameter.m_dataResiduals = std::shared_ptr< std::vector< double > >(
271 new std::vector< double >( parameter.m_valueSet->size() * parameter.m_validIndices.size() ) );
274 std::pair< size_t, size_t > range;
276 typename std::vector< WSphericalHarmonicsCoefficientsThread< T >* > threads;
279 for(
unsigned int i = 0; i < threadCount; i++ )
281 range.first = ( voxelCount / threadCount ) * i;
282 range.second = ( i == ( threadCount - 1 ) ) ? voxelCount : ( voxelCount / threadCount ) * ( i + 1 );
284 threads.back()->
run();
287 for(
unsigned int i = 0; i < threads.size(); i++ )
289 threads[ i ]->wait();
295 parameter.m_progress->finish();
300 std::shared_ptr< WValueSet< double > > sphericalHarmonicsData
301 = std::shared_ptr< WValueSet< double > >(
new WValueSet< double >( 1, dimension, parameter.m_data, W_DT_DOUBLE ) );
303 result.first = std::shared_ptr< WDataSetSphericalHarmonics >(
306 if( parameter.m_doResidualCalculation )
308 std::shared_ptr< WValueSet< double > > residualsData = std::shared_ptr< WValueSet< double > >(
309 new WValueSet< double >( 1, parameter.m_validIndices.size(), parameter.m_dataResiduals, W_DT_DOUBLE ) );
312 std::shared_ptr< std::vector< WVector3d > >(
This data set type contains raw HARDI and its gradients.
This data set type contains spherical harmonic coefficients as values.
Functor that does multithreaded spherical harmonic fitting.
std::vector< WVector3d > const & m_gradients
The gradients of the hardi data.
WSphericalHarmonicsCoefficientsThread ::ThreadParameter m_parameter
The parameters that will be forwarded to the threads.
result_type operator()(WValueSet< T > const *) const
Allocate shared memory and construct and run threads, construct output datasets.
std::shared_ptr< WGrid > m_grid
The grid of the data.
~HARDICalculation()
Destructor.
bool m_multiThreaded
If more than 1 thread should be used.
HARDICalculation(WSphericalHarmonicsCoefficientsThread<>::ThreadParameter threadParams, bool multiThreaded, std::shared_ptr< WGrid > grid, std::vector< WVector3d > const &gradients)
Constructor.
This class is derived from PropertyConstraint and ensures that only even values are valid.
virtual bool accept(std::shared_ptr< WPropertyVariable< WPVBaseTypes::PV_INT > > property, const WPVBaseTypes::PV_INT &value)
You need to overwrite this method.
virtual std::shared_ptr< WPropertyVariable< WPVBaseTypes::PV_INT >::PropertyConstraint > clone()
Method to clone the constraint and create a new one with the correct dynamic type.
Module for the creation of a spherical harmonic data set from raw HARDI data.
virtual std::shared_ptr< WModule > factory() const
Due to the prototype design pattern used to build modules, this method returns a new instance of this...
virtual const std::string getName() const
Gives back the name of this module.
WPropInt m_order
Property holding the order of the spherical harmonics.
std::shared_ptr< WModuleOutputData< WDataSetSphericalHarmonics > > m_output
Output connector provided by this module.
WPropBool m_doNormalisation
Property indicating whether the measurements are normalized from 0 to 1 for each voxel.
WPropSelection m_reconstructionTypeProp
To choose the reconstruction type.
std::shared_ptr< WDataSetRawHARDI > m_dataSet
This is a pointer to the dataset the module is currently working on.
std::shared_ptr< WModuleInputData< WDataSetRawHARDI > > m_input
Input connector required by this module.
~WMHARDIToSphericalHarmonics()
Destructor.
virtual void properties()
Initialize the properties for this module.
WPropBool m_doResidualCalculation
Property indicating whether the reprojection error (measurement relative to spherical harmonic calcul...
WMHARDIToSphericalHarmonics()
Standard constructor.
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
virtual const std::string getDescription() const
Gives back a description of this module.
WPropBool m_doFunkRadonTransformation
Property indicating whether to do the Funk-Radon-transformation with calculated spherical harmonics.
virtual void moduleMain()
Entry point after loading the module.
WPropDouble m_CSADelta1
Delta1 value for the constant solid angle reconstruction.
friend class WMHARDIToSphericalHarmonicsTest
Only UnitTests may be friends.
WPropBool m_doErrorCalculation
Property indicating whether a reprojection error of the spherical harmonics is calculated.
std::shared_ptr< WModuleOutputData< WDataSetRawHARDI > > m_outputResiduals
The reprojection error for each measurement.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
WPropBool m_multiThreaded
Property indicating whether the spherical harmonics calculation is done multithreaded.
std::shared_ptr< WItemSelection > m_reconstructionTypes
A list of the selectable reconstruction types.
WPropDouble m_regularisationFactorLambda
Property holding the regularisation factor lambda.
virtual void connectors()
Initialize the connectors this module is using.
WPropDouble m_CSADelta2
Delta2 value for the constant solid angle reconstruction.
void stopThreads()
Stop the threads.
Class representing a single module of OpenWalnut.
A named property class with a concrete type.
Module for the creation of a spherical harmonic data set from raw HARDI data.
virtual void run()
Run thread.
Base Class for all value set types.
int32_t PV_INT
base type used for every WPVInt