OpenWalnut  1.5.0dev
WMDeterministicFTMori.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WMDETERMINISTICFTMORI_H
26 #define WMDETERMINISTICFTMORI_H
27 
28 #include <memory>
29 #include <string>
30 #include <vector>
31 
32 #include <boost/thread.hpp>
33 
34 #include "core/common/WThreadedFunction.h"
35 #include "core/common/math/linearAlgebra/WVectorFixed.h"
36 #include "core/common/math/WTensorSym.h"
37 #include "core/dataHandler/WFiberAccumulator.h"
38 #include "core/dataHandler/WThreadedPerVoxelOperation.h"
39 #include "core/dataHandler/WThreadedTrackingFunction.h"
40 #include "core/kernel/WModule.h"
41 
42 // forward delcarations
44 class WDataSetSingle;
45 template< class T > class WModuleInputData;
46 template< class T > class WModuleOutputData;
47 
48 #define WM_MORI_NUM_CORES W_AUTOMATIC_NB_THREADS
49 
50 /**
51  * \class WMDeterministicFTMori
52  *
53  * This module implements the simple fiber tracking algorithm by Mori et al.
54  *
55  * S. Mori, B. Crain, V. Chacko, and P. van Zijl,
56  * "Three-dimensional tracking of axonal projections in the brain by magnetic resonance imaging",
57  * Annals of Neurology 45, pp. 265-269, 1999
58  *
59  * \ingroup modules
60  */
62 {
63  //! the class itself
65 
66 public:
67  /**
68  * Standard Constructor.
69  */
71 
72  /**
73  * Destructor.
74  */
75  virtual ~WMDeterministicFTMori();
76 
77  /**
78  * Returns a new instance of this module.
79  *
80  * \return A new instance of this module.
81  */
82  virtual std::shared_ptr< WModule > factory() const;
83 
84  /**
85  * Get the icon for this module in XPM format.
86  * \return The icon.
87  */
88  virtual const char** getXPMIcon() const;
89 
90  /**
91  * Return the name of this module.
92  *
93  * \return The name of this module.
94  */
95  virtual const std::string getName() const;
96 
97  /**
98  * Return the description of this module.
99  *
100  * \return This module's description.
101  */
102  virtual const std::string getDescription() const;
103 
104 protected:
105  /**
106  * The worker function, runs in its own thread.
107  */
108  virtual void moduleMain();
109 
110  /**
111  * Initialize the module's connectors.
112  */
113  virtual void connectors();
114 
115  /**
116  * Initialize the module's properties.
117  */
118  virtual void properties();
119 
120  /**
121  * Callback. This function gets called whenever the modules "active" state changes.
122  */
123  virtual void activate();
124 
125 private:
126  //! the threaded per-voxel function for the eigenvector computation (float input)
128 
129  //! the threaded per-voxel function for the eigenvector computation (double input)
131 
132  //! the thread pool type for the eigencomputation (float input)
134 
135  //! the thread pool type for the eigencomputation (double input)
137 
138  //! the valueset type
140 
141  //! the fiber type
142  typedef std::vector< WVector3d > FiberType;
143 
144  //! the threaded tracking functor
146 
147  //! the tracking threadpool
149 
150  /**
151  * The function that computes the eigenvectors from the input tensor field.
152  *
153  * \param input A subarray of a valueset that consists of the 6 floats that make up the tensor.
154  * \return The components of the largest eigenvector and the fa value in a 4-double array.
155  */
157 
158  /**
159  * The function that computes the eigenvectors from the input tensor field.
160  *
161  * \param input A subarray of a valueset that consists of the 6 floats that make up the tensor.
162  * \return The components of the largest eigenvector and the fa value in a 4-double array.
163  */
165 
166  /**
167  * The function that does the actual fa and eigenvector computations.
168  *
169  * \param m The tensor to calculate the fa and largest eigenvector from.
170  * \return The largest eigenvector and fa (in this order).
171  */
172  boost::array< double, 4 > const computeFaAndEigenVec( WTensorSym< 2, 3, double > const& m ) const;
173 
174  /**
175  * Calculate the direction of the eigenvector with largest magnitude.
176  *
177  * \param ds The dataset.
178  * \param j The job, that means the current position and direction of the last fiber segment.
179  *
180  * \return The direction to follow.
181  */
182  WVector3d getEigenDirection( std::shared_ptr< WDataSetSingle const > ds,
184 
185  /**
186  * The fiber visitor. Adds a fiber to the result data and increment the progress.
187  *
188  * \param f The fiber.
189  */
190  void fiberVis( FiberType const& f );
191 
192  /**
193  * The point visitor. Does nothing.
194  */
195  void pointVis( WVector3d const& );
196 
197  /**
198  * Reset the tracking function and abort the current one, if there is a current one.
199  */
200  void resetTracking();
201 
202  /**
203  * Resets the threaded function/threadpool.
204  */
205  void resetEigenFunction();
206 
207  /**
208  * Resets the current progress to 0.
209  *
210  * \param todo The number of operations of the new progress.
211  */
212  void resetProgress( std::size_t todo );
213 
214  //! A condition for property changes.
215  std::shared_ptr< WCondition > m_propCondition;
216 
217  //! A pointer to the input tensor dataset.
218  std::shared_ptr< WDataSetSingle > m_dataSet;
219 
220  //! The output dataset. Stores all fibers extracted from the input tensor field.
221  std::shared_ptr< WDataSetFibers > m_fiberSet;
222 
223  //! The output Connector.
224  std::shared_ptr< WModuleOutputData< WDataSetFibers > > m_output;
225 
226  //! The input Connector.
227  std::shared_ptr< WModuleInputData< WDataSetSingle > > m_input;
228 
229  //! Stores eigenvectors and fractional anisotropy of the input dataset.
230  std::shared_ptr< WDataSetSingle > m_eigenField;
231 
232  //! the functor used for the calculation of the eigenvectors
233  std::shared_ptr< TPVOFloat > m_eigenOperationFloat;
234 
235  //! the functor used for the calculation of the eigenvectors
236  std::shared_ptr< TPVODouble > m_eigenOperationDouble;
237 
238  //! the object that keeps track of the current progress
239  std::shared_ptr< WProgress > m_currentProgress;
240 
241  //! The threadpool for the eigenvector and fa computations.
242  std::shared_ptr< WThreadedFunctionBase > m_eigenPool;
243 
244  //! The threadpool for the tracking
245  std::shared_ptr< TrackingFuncType > m_trackingPool;
246 
247  //! The fiber accumulator
249 
250  //! The minimum FA property.
251  WPropDouble m_minFA;
252 
253  //! The minimum number of points property.
254  WPropInt m_minPoints;
255 
256  //! The minimum cosine property.
257  WPropDouble m_minCos;
258 
259  //! The current minimum FA property.
261 
262  //! The current minimum number of points property.
263  std::size_t m_currentMinPoints;
264 
265  //! The current minimum cosine property.
267 };
268 
269 #endif // WMDETERMINISTICFTMORI_H
Represents a simple set of WFibers.
A data set consisting of a set of values based on a grid.
A class that encapsulates the data needed to construct a WDataSetFibers.
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.
WValueSet< double > FloatValueSetType
the valueset type
WMDeterministicFTMori This
the class itself
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 offering an instantiate-able data connection between modules.
Class representing a single module of OpenWalnut.
Definition: WModule.h:72
Implements a symmetric tensor that has the same number of components in every direction.
Definition: WTensorSym.h:73
Creates threads that computes a function in a multithreaded fashion.
A template that performs an operation on a per voxel basis.
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
Base Class for all value set types.
Definition: WValueSet.h:47
Implements a generalized multithreaded tracking algorithm.
std::pair< WVector3d, WVector3d > JobType
define a job type for tracking algorithms