30 #include "WMDeterministicFTMori.h"
31 #include "WMDeterministicFTMori.xpm"
32 #include "core/common/WAssert.h"
33 #include "core/common/math/WLinearAlgebraFunctions.h"
34 #include "core/common/math/WTensorFunctions.h"
35 #include "core/common/math/WTensorSym.h"
36 #include "core/dataHandler/WDataSetFiberVector.h"
37 #include "core/dataHandler/WDataSetSingle.h"
38 #include "core/dataHandler/WGridRegular3D.h"
39 #include "core/dataHandler/WValueSet.h"
40 #include "core/dataHandler/io/WWriterFiberVTK.h"
41 #include "core/kernel/WModuleInputData.h"
42 #include "core/kernel/WModuleOutputData.h"
52 m_eigenOperationFloat(),
53 m_eigenOperationDouble(),
69 return moriTracking_xpm;
74 return "Mori Det. Tracking";
79 return "Implements the simple deterministic fibertracking algorithm by Mori et al.";
110 std::shared_ptr< WDataSetSingle > inData =
m_input->getData();
111 bool dataChanged = (
m_dataSet != inData );
129 debugLog() <<
"Running computation of eigenvectors.";
138 if(
m_dataSet->getValueSet()->getDataType() == W_DT_DOUBLE )
147 m_eigenPool = std::shared_ptr< WThreadedFunctionBase >();
148 debugLog() <<
"Eigenvectors computed.";
158 debugLog() <<
"Running tracking function.";
169 std::shared_ptr< WGridRegular3D > g( std::dynamic_pointer_cast< WGridRegular3D >(
m_eigenField->getGrid() ) );
170 std::size_t todo = ( g->getNbCoordsX() - 2 ) * ( g->getNbCoordsY() - 2 ) * ( g->getNbCoordsZ() - 2 );
173 debugLog() <<
"Running tracking function.";
178 debugLog() <<
"Shutting down module.";
185 debugLog() <<
"Aborting computation of eigenvalues because the module was ordered to shut down.";
194 debugLog() <<
"Aborting fiber tracking because the module was ordered to shut down.";
202 "det FT Mori output fibers",
"A set of fibers extracted from the input set." )
206 "det FT Mori input tensor field",
"An input set of 2nd-order tensors on a regular 3d-grid." )
219 m_minFA =
m_properties->addProperty(
"Min. FA",
"The fractional anisotropy threshold value needed by "
246 debugLog() <<
"Stopping eigencomputation.";
248 if( s != W_THREADS_FINISHED && s != W_THREADS_ABORTED )
253 WAssert( s == W_THREADS_FINISHED || s == W_THREADS_ABORTED,
"" );
263 if(
m_dataSet->getValueSet()->getDataType() == W_DT_DOUBLE )
270 else if(
m_dataSet->getValueSet()->getDataType() == W_DT_FLOAT )
279 errorLog() <<
"Input data does not contain floating point values, skipping.";
280 m_eigenPool = std::shared_ptr< WThreadedFunctionBase >();
291 if( s != W_THREADS_FINISHED && s != W_THREADS_ABORTED )
296 WAssert( s == W_THREADS_FINISHED || s == W_THREADS_ABORTED,
"" );
308 boost::placeholders::_1,
309 boost::placeholders::_2,
310 boost::placeholders::_3 ),
312 boost::bind( &
This::pointVis,
this, boost::placeholders::_1 ) ) );
321 WAssert( ds->getGrid(),
"" );
322 WAssert( ds->getValueSet(),
"" );
323 std::shared_ptr< WGridRegular3D > g = std::dynamic_pointer_cast< WGridRegular3D >( ds->getGrid() );
324 int i = g->getVoxelNum( j.first );
325 WAssert( i != -1,
"" );
326 std::shared_ptr< WValueSet< double > > vs = std::dynamic_pointer_cast< WValueSet< double > >( ds->getValueSet() );
335 v[ 0 ] = vs->rawData()[ 4 * i + 0 ];
336 v[ 1 ] = vs->rawData()[ 4 * i + 1 ];
337 v[ 2 ] = vs->rawData()[ 4 * i + 2 ];
339 if( length( j.second ) == 0 )
373 boost::array< double, 4 > a;
375 RealEigenSystem eigenSys;
376 std::vector< double > ev( 3 );
377 std::vector< WVector3d > t( 3 );
380 jacobiEigenvector3D( m, &eigenSys );
385 for(
int n = 0; n < 3; ++n )
387 if( fabs( eigenSys[ n ].first ) > h )
389 h = fabs( eigenSys[ n ].first );
395 a[ 0 ] = eigenSys[ u ].second[ 0 ];
396 a[ 1 ] = eigenSys[ u ].second[ 1 ];
397 a[ 2 ] = eigenSys[ u ].second[ 2 ];
400 double d = eigenSys[ 0 ].first * eigenSys[ 0 ].first + eigenSys[ 1 ].first * eigenSys[ 1 ].first + eigenSys[ 2 ].first * eigenSys[ 2 ].first;
401 if( fabs( d ) == 0.0 )
407 double trace = ( eigenSys[ 0 ].first + eigenSys[ 1 ].first + eigenSys[ 2 ].first ) / 3;
408 a[ 3 ] = sqrt( 1.5 * ( ( eigenSys[ 0 ].first - trace ) * ( eigenSys[ 0 ].first - trace )
409 + ( eigenSys[ 1 ].first - trace ) * ( eigenSys[ 1 ].first - trace )
410 + ( eigenSys[ 2 ].first - trace ) * ( eigenSys[ 2 ].first - trace ) ) / d );
419 m( 0, 0 ) =
static_cast< double >( input[ 0 ] );
420 m( 0, 1 ) =
static_cast< double >( input[ 1 ] );
421 m( 0, 2 ) =
static_cast< double >( input[ 2 ] );
422 m( 1, 1 ) =
static_cast< double >( input[ 3 ] );
423 m( 1, 2 ) =
static_cast< double >( input[ 4 ] );
424 m( 2, 2 ) =
static_cast< double >( input[ 5 ] );
434 m( 0, 0 ) =
static_cast< double >( input[ 0 ] );
435 m( 0, 1 ) =
static_cast< double >( input[ 1 ] );
436 m( 0, 2 ) =
static_cast< double >( input[ 2 ] );
437 m( 1, 1 ) =
static_cast< double >( input[ 3 ] );
438 m( 1, 2 ) =
static_cast< double >( input[ 4 ] );
439 m( 2, 2 ) =
static_cast< double >( input[ 5 ] );
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.
void add(std::vector< WVector3d > const &in)
Add a fiber to the dataset.
std::shared_ptr< WDataSetFibers > buildDataSet()
Return the dataset that has been accumulated to this point and start a new dataset.
void clear()
Clears all data.
This module implements the simple fiber tracking algorithm by Mori et al.
wtracking::WThreadedTrackingFunction Tracking
the threaded tracking functor
WThreadedFunction< TPVOFloat > EigenFunctionTypeFloat
the thread pool type for the eigencomputation (float input)
std::shared_ptr< WThreadedFunctionBase > m_eigenPool
The threadpool for the eigenvector and fa computations.
std::shared_ptr< WDataSetSingle > m_dataSet
A pointer to the input tensor dataset.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
WPropDouble m_minCos
The minimum cosine property.
WVector3d getEigenDirection(std::shared_ptr< WDataSetSingle const > ds, wtracking::WTrackingUtility::JobType const &j)
Calculate the direction of the eigenvector with largest magnitude.
boost::array< double, 4 > const computeFaAndEigenVec(WTensorSym< 2, 3, double > const &m) const
The function that does the actual fa and eigenvector computations.
virtual void moduleMain()
The worker function, runs in its own thread.
std::shared_ptr< TPVODouble > m_eigenOperationDouble
the functor used for the calculation of the eigenvectors
WMDeterministicFTMori()
Standard Constructor.
WThreadedPerVoxelOperation< float, 6, double, 4 > TPVOFloat
the threaded per-voxel function for the eigenvector computation (float input)
WThreadedPerVoxelOperation< double, 6, double, 4 > TPVODouble
the threaded per-voxel function for the eigenvector computation (double input)
virtual void properties()
Initialize the module's properties.
TPVODouble::OutTransmitType const eigenFuncDouble(TPVODouble::TransmitType const &input)
The function that computes the eigenvectors from the input tensor field.
virtual const std::string getName() const
Return the name of this module.
WFiberAccumulator m_fiberAccu
The fiber accumulator.
virtual ~WMDeterministicFTMori()
Destructor.
virtual void activate()
Callback.
void resetTracking()
Reset the tracking function and abort the current one, if there is a current one.
double m_currentMinFA
The current minimum FA property.
void pointVis(WVector3d const &)
The point visitor.
WPropDouble m_minFA
The minimum FA property.
double m_currentMinCos
The current minimum cosine property.
std::vector< WVector3d > FiberType
the fiber type
virtual void connectors()
Initialize the module's connectors.
std::size_t m_currentMinPoints
The current minimum number of points property.
std::shared_ptr< TrackingFuncType > m_trackingPool
The threadpool for the tracking.
virtual std::shared_ptr< WModule > factory() const
Returns a new instance of this module.
std::shared_ptr< WModuleOutputData< WDataSetFibers > > m_output
The output Connector.
std::shared_ptr< WCondition > m_propCondition
A condition for property changes.
std::shared_ptr< WProgress > m_currentProgress
the object that keeps track of the current progress
WPropInt m_minPoints
The minimum number of points property.
TPVOFloat::OutTransmitType const eigenFuncFloat(TPVOFloat::TransmitType const &input)
The function that computes the eigenvectors from the input tensor field.
void fiberVis(FiberType const &f)
The fiber visitor.
std::shared_ptr< WDataSetFibers > m_fiberSet
The output dataset. Stores all fibers extracted from the input tensor field.
std::shared_ptr< TPVOFloat > m_eigenOperationFloat
the functor used for the calculation of the eigenvectors
void resetProgress(std::size_t todo)
Resets the current progress to 0.
std::shared_ptr< WModuleInputData< WDataSetSingle > > m_input
The input Connector.
WThreadedFunction< TPVODouble > EigenFunctionTypeDouble
the thread pool type for the eigencomputation (double input)
virtual const std::string getDescription() const
Return the description of this module.
std::shared_ptr< WDataSetSingle > m_eigenField
Stores eigenvectors and fractional anisotropy of the input dataset.
WThreadedFunction< Tracking > TrackingFuncType
the tracking threadpool
void resetEigenFunction()
Resets the threaded function/threadpool.
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.
std::shared_ptr< WProperties > m_properties
The property object for the module.
void ready()
Call this whenever your module is ready and can react on property changes.
WConditionSet m_moduleState
The internal state of the module.
wlog::WStreamedLogger errorLog() const
Logger instance for comfortable error logging.
virtual void activate()
Callback for m_active.
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.
Implements a symmetric tensor that has the same number of components in every direction.
boost::array< Output_T, numOutputs > OutTransmitType
the output type for the per-voxel operation
ValueSetType::SubArray const TransmitType
the input type for the per-voxel operation
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
std::pair< WVector3d, WVector3d > JobType
define a job type for tracking algorithms
static bool followToNextVoxel(DataSetPtr dataset, JobType &job, DirFunc const &dirFunc)
A function that follows a direction until leaving the current voxel.