29 #include "WMCalculateGFA.h"
30 #include "WMCalculateGFA.xpm"
31 #include "core/common/WLimits.h"
32 #include "core/common/math/WGeometryFunctions.h"
33 #include "core/common/math/WSymmetricSphericalHarmonic.h"
34 #include "core/common/math/linearAlgebra/WVectorFixed.h"
35 #include "core/kernel/WKernel.h"
57 return WMCalculateGFA_xpm;
61 return "Calculate GFA";
66 return "Calculates the generalized fractional anisotropy as defined in \"Q-Ball Imaging\" by S.Tuch in 2004";
71 m_input = std::shared_ptr< WModuleInputData< WDataSetSphericalHarmonics > >(
73 "inSH",
"A spherical harmonics dataset." )
77 "outGFA",
"The generalized fractional anisotropy map." )
100 std::vector< unsigned int > temp;
101 std::vector< WVector3d > grad;
103 tesselateIcosahedron( &grad, &temp, 2 );
107 std::vector< WUnitSphereCoordinates< double > > ori;
108 for( std::size_t k = 0; k < grad.size(); ++k )
110 if( grad[ k ][ 0 ] >= 0.0 )
127 std::shared_ptr< WDataSetSphericalHarmonics > inData =
m_input->getData();
128 bool dataChanged = (
m_dataSet != inData );
130 if( dataChanged && inData )
137 debugLog() <<
"Running computation.";
141 debugLog() <<
"Computation finished.";
143 m_result = std::dynamic_pointer_cast< WDataSetScalar >(
m_gfaFunc->getResult() );
144 m_gfaPool = std::shared_ptr< GFAPoolType >();
145 m_gfaFunc = std::shared_ptr< GFAFuncType >();
157 debugLog() <<
"Shutting down module.";
160 if(
m_gfaPool->status() == W_THREADS_RUNNING ||
m_gfaPool->status() == W_THREADS_STOP_REQUESTED )
172 WThreadedFunctionStatus s =
m_gfaPool->status();
173 if( s != W_THREADS_FINISHED && s != W_THREADS_ABORTED )
178 WAssert( s == W_THREADS_FINISHED || s == W_THREADS_ABORTED,
"" );
184 std::shared_ptr< WGridRegular3D > g = std::dynamic_pointer_cast< WGridRegular3D >(
m_dataSet->getGrid() );
186 resetProgress( g->getNbCoordsX() * g->getNbCoordsY() * g->getNbCoordsZ() );
191 boost::placeholders::_1 ) ) );
216 boost::array< double, 1 > a;
218 for(
int i = 0; i < 15; ++i )
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.
A module that calculates the generalized fractional anisotropy for every voxel of the input dataset.
virtual ~WMCalculateGFA()
Destructor.
std::shared_ptr< WCondition > m_exceptionCondition
Condition indicating if any exception was thrown.
void resetProgress(std::size_t todo)
Reset the progress indicator in the ui.
std::shared_ptr< WException > m_lastException
The last exception thrown by any worker thread.
std::shared_ptr< WModuleInputData< WDataSetSphericalHarmonics > > m_input
The input Connector for the SH data.
std::shared_ptr< WProgress > m_currentProgress
The object that keeps track of the current progress.
WThreadedFunction< GFAFuncType > GFAPoolType
the threadpool
virtual void connectors()
Initialize the connectors this module is using.
virtual const std::string getDescription() const
Gives back a description of this module.
WMatrix< double > m_BMat
A matrix of SH base function values for various gradients.
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 void properties()
Initialize the properties for this module.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
virtual void moduleMain()
Entry point after loading the module.
void resetGFAPool()
Reset the threaded functions.
WMCalculateGFA()
Standard constructor.
boost::array< double, 1 > perVoxelGFAFunc(WValueSet< double >::SubArray const &s)
A function that gets called for every voxel in the input SH-dataset.
std::shared_ptr< GFAFuncType > m_gfaFunc
The threaded function object.
std::shared_ptr< WDataSetScalar > m_result
The output dataset.
std::shared_ptr< WModuleOutputData< WDataSetScalar > > m_output
The output Connector.
WThreadedPerVoxelOperation< double, 15, double, 1 > GFAFuncType
the threaded function type for gfa computation
std::shared_ptr< WDataSetSphericalHarmonics > m_dataSet
A pointer to the input dataset.
std::shared_ptr< GFAPoolType > m_gfaPool
The threadpool.
virtual const std::string getName() const
Gives back the name of this module.
void handleException(WException const &e)
Handle an exception thrown by a worker thread.
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.
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.
Class for symmetric spherical harmonics The index scheme of the coefficients/basis values is like in ...
static WMatrix< T > calcBaseMatrix(const std::vector< WUnitSphereCoordinates< T > > &orientations, int order)
Calculates the base matrix B like in the dissertation of Descoteaux.
T calcGFA(std::vector< WUnitSphereCoordinates< T > > const &orientations) const
Calculate the generalized fractional anisotropy for this ODF.
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.