29 #include "WMCalculateTensors.h"
30 #include "core/common/WLimits.h"
31 #include "core/common/math/WMatrix.h"
32 #include "core/common/math/WSymmetricSphericalHarmonic.h"
33 #include "core/common/math/linearAlgebra/WVectorFixed.h"
34 #include "core/kernel/WKernel.h"
41 m_SHToTensorMat( 1, 1 )
60 return "Calculate Tensors";
65 return "Calculates diffusion tensors from an input sh dataset.";
70 m_input = std::shared_ptr< WModuleInputData< WDataSetSphericalHarmonics > >(
72 "shInput",
"A spherical harmonics dataset." )
76 "dtiOutput",
"The diffusion tensor image." )
100 std::vector< WUnitSphereCoordinates< double > > orientations;
117 std::shared_ptr< WDataSetSphericalHarmonics > inData =
m_input->getData();
118 bool dataChanged = (
m_dataSet != inData );
120 if( dataChanged && inData )
130 debugLog() <<
"Running computation.";
134 debugLog() <<
"Computation finished.";
136 std::shared_ptr< WDataSetSingle > temp =
m_tensorFunc->getResult();
137 m_result = std::shared_ptr< WDataSetDTI >(
new WDataSetDTI( temp->getValueSet(), temp->getGrid() ) );
151 debugLog() <<
"Shutting down module.";
167 if( s != W_THREADS_FINISHED && s != W_THREADS_ABORTED )
172 WAssert( s == W_THREADS_FINISHED || s == W_THREADS_ABORTED,
"" );
178 if(
m_dataSet->getSphericalHarmonicAt( 0 ).getOrder() == 2 )
180 std::shared_ptr< WGridRegular3D > g = std::dynamic_pointer_cast< WGridRegular3D >(
m_dataSet->getGrid() );
182 resetProgress( g->getNbCoordsX() * g->getNbCoordsY() * g->getNbCoordsZ() );
187 boost::placeholders::_1 ) ) );
194 warnLog() <<
"SH dataset has order > 2";
217 boost::array< double, 6 > a;
221 for( std::size_t k = 0; k < 6; ++k )
228 for( std::size_t k = 0; k < 6; ++k )
virtual void wait() const
Wait for the condition.
void setResetable(bool resetable=true, bool autoReset=true)
Sets the resetable flag.
virtual void remove(std::shared_ptr< WCondition > condition)
Removes the specified condition.
virtual void add(std::shared_ptr< WCondition > condition)
Adds another condition to the set of conditions to wait for.
Class to encapsulate boost::condition_variable_any.
Represents a Diffusion-Tensor-Image dataset.
A module that calculates tensors from the input SH dataset.
boost::array< double, 6 > perVoxelTensorFunc(WValueSet< double >::SubArray const &s)
A function that gets called for every voxel in the input SH-dataset.
std::shared_ptr< WException > m_lastException
The last exception thrown by any worker thread.
std::shared_ptr< WCondition > m_exceptionCondition
Condition indicating if any exception was thrown.
std::shared_ptr< WDataSetSphericalHarmonics > m_dataSet
A pointer to the input dataset.
virtual const std::string getName() const
Gives back the name of this module.
void resetTensorPool()
Reset the threaded functions.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
virtual void moduleMain()
Entry point after loading the module.
WThreadedPerVoxelOperation< double, 6, double, 6 > TensorFuncType
the threaded function type for tensor computation, order 4 to 2
std::shared_ptr< WModuleOutputData< WDataSetDTI > > m_output
The output Connector.
std::shared_ptr< WModuleInputData< WDataSetSphericalHarmonics > > m_input
The input Connector for the SH data.
WMCalculateTensors()
Standard constructor.
WThreadedFunction< TensorFuncType > TensorPoolType
the threadpool
std::shared_ptr< TensorPoolType > m_tensorPool
The threadpool.
virtual ~WMCalculateTensors()
Destructor.
std::shared_ptr< WProgress > m_currentProgress
The object that keeps track of the current progress.
WMatrix< double > m_SHToTensorMat
The sh->tensor conversion.
virtual void properties()
Initialize the properties for this module.
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...
std::shared_ptr< TensorFuncType > m_tensorFunc
The threaded function object.
void handleException(WException const &e)
Handle an exception thrown by a worker thread.
std::shared_ptr< WDataSetDTI > m_result
The output dataset.
void resetProgress(std::size_t todo)
Reset the progress indicator in the ui.
virtual void connectors()
Initialize the connectors this module is using.
virtual const std::string getDescription() const
Gives back a description of this module.
Class offering an instantiate-able data connection between modules.
Class representing a single module of OpenWalnut.
virtual void properties()
Initialize properties in this function.
wlog::WStreamedLogger debugLog() const
Logger instance for comfortable debug logging.
void addConnector(std::shared_ptr< WModuleInputConnector > con)
Adds the specified connector to the list of inputs.
wlog::WStreamedLogger warnLog() const
Logger instance for comfortable warning- logs.
void ready()
Call this whenever your module is ready and can react on property changes.
WConditionSet m_moduleState
The internal state of the module.
std::shared_ptr< WProgressCombiner > m_progress
Progress indicator used as parent for all progress' of this module.
virtual void connectors()
Initialize connectors in this function.
Class managing progress inside of modules.
static WMatrix< T > calcSHToTensorSymMatrix(std::size_t order)
Calculates a matrix that converts spherical harmonics to symmetric tensors of equal or lower order.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
This class stores coordinates on the unit sphere.
A helper class granting safe access to a certain part of the valueset.
Base class for all higher level values like tensors, vectors, matrices and so on.