OpenWalnut  1.5.0dev
WMEigenSystem.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 WMEIGENSYSTEM_H
26 #define WMEIGENSYSTEM_H
27 
28 #include <memory>
29 #include <string>
30 #include <utility>
31 #include <vector>
32 
33 #include <Eigen/Eigen>
34 #include <osg/Geode>
35 
36 #include "core/common/WThreadedFunction.h"
37 #include "core/common/math/WTensorFunctions.h"
38 #include "core/dataHandler/WThreadedPerVoxelOperation.h"
39 #include "core/dataHandler/WThreadedTrackingFunction.h"
40 #include "core/kernel/WModule.h"
41 
42 // forward declaration
43 class WDataSetDTI;
44 class WDataSetVector;
45 template< class T > class WModuleInputData;
46 template< class T > class WModuleOutputData;
47 
48 /**
49  * Computes the eigensystem of a second order tensor field. For each eigen vector and eigen value an output connector field is
50  * available. If you need all you may connect to a special output carrying all eigenvalues.
51  *
52  * \ingroup modules
53  */
54 class WMEigenSystem: public WModule
55 {
56 public:
57  /**
58  * Constructs a new module for eigensystem computation.
59  */
60  WMEigenSystem();
61 
62  /**
63  * Destructs this module.
64  */
65  virtual ~WMEigenSystem();
66 
67  /**
68  * Gives back the name of this module.
69  * \return the module's name.
70  */
71  virtual const std::string getName() const;
72 
73  /**
74  * Gives back a description of this module.
75  * \return description to module.
76  */
77  virtual const std::string getDescription() const;
78 
79  /**
80  * Due to the prototype design pattern used to build modules, this method returns a new instance of this method. NOTE: it
81  * should never be initialized or modified in some other way. A simple new instance is required.
82  *
83  * \return the prototype used to create every module in OpenWalnut.
84  */
85  virtual std::shared_ptr< WModule > factory() const;
86 
87  /**
88  * Get the icon for this module in XPM format.
89  * \return The icon.
90  */
91  virtual const char** getXPMIcon() const;
92 
93 protected:
94  /**
95  * Entry point after loading the module. Runs in separate thread.
96  */
97  virtual void moduleMain();
98 
99  /**
100  * Initialize the connectors this module is using.
101  */
102  virtual void connectors();
103 
104  /**
105  * Initialize the properties for this module.
106  */
107  virtual void properties();
108 
109  /**
110  * Initialize requirements for this module.
111  */
112  virtual void requirements();
113 
114 private:
115  //! the threaded per-voxel function for the eigenvector computation (float input)
117 
118  //! the threaded per-voxel function for the eigenvector computation (double input)
120 
121  //! the thread pool type for the eigencomputation (float input)
123 
124  //! the thread pool type for the eigencomputation (double input)
126 
127  //! the valueset type
129 
130  //! the threaded tracking functor
132 
133  //! the tracking threadpool
135 
136  /**
137  * Resets the current progress to 0.
138  *
139  * \param todo The number of operations of the new progress.
140  * \param name Identifying what kind of work this progress is indicating.
141  */
142  void resetProgress( std::size_t todo, std::string name );
143 
144  /**
145  * Resets the threaded function/threadpool.
146  *
147  * \param tensors The field of computed eigen systems, where each eigensystem is in the form: ev, evc, ev, evec, ev, evec.
148  */
149  void resetEigenFunction( std::shared_ptr< WDataSetDTI > tensors );
150 
151  /**
152  * Update the output connectors out of the computed eigensystem field.
153  *
154  * \param es Dataset carrying all eigen systems.
155  */
156  void updateOCs( std::shared_ptr< const WDataSetSingle > es );
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 complete eigen system as double array with 12 components.
163  */
165 
166  /**
167  * The function that computes the eigenvectors from the input tensor field.
168  *
169  * \param input A subarray of a valueset that consists of the 6 floats that make up the tensor.
170  * \return The complete eigen system as double array with 12 components.
171  */
173 
174  /**
175  * Computes the eigen system for double input parameters via using applyEigenSolver.
176  *
177  * \param input A subarray of a valueset that consists of the 6 floats that make up the tensor.
178  *
179  * \return The complete eigen system as double array with 12 components.
180  */
182 
183  /**
184  * Computes the eigen system for double input parameters via using applyEigenSolver.
185  *
186  * \param input A subarray of a valueset that consists of the 6 floats that make up the tensor.
187  *
188  * \return The complete eigen system as double array with 12 components.
189  */
191 
192  /**
193  * Copies the eigenvalues and eigenvectors from the libEigen output format into the double array.
194  *
195  * \param m The symmetric input matrix where only the lower triangular part is considered.
196  *
197  * \return The 12 components of the eigen system.
198  */
199  boost::array< double, 12 > applyEigenSolver( const Eigen::Matrix3d& m ) const;
200 
201  /**
202  * Is used by every thread to compute the eigensystem for the given tensor.
203  *
204  * \param m Tensor to compute the eigensystem for
205  *
206  * \return Eigen system of the given tensor.
207  */
208  boost::array< double, 12 > computeEigenSystem( WTensorSym< 2, 3, double > const& m ) const;
209 
210  /**
211  * Input tensor field.
212  */
213  std::shared_ptr< WModuleInputData< WDataSetDTI > > m_tensorIC;
214 
215  /**
216  * Shortcut for the vector field output connectors.
217  */
218  typedef std::shared_ptr< WModuleOutputData< WDataSetVector > > EigenOutputConnector;
219 
220  /**
221  * Ouput vector field for principal eigenvectors as well as one for all eigenvalues at once.
222  */
223  std::vector< EigenOutputConnector > m_evecOutputs;
224 
225  /**
226  * Output scalar field , each for an eigenvalue field.
227  */
228  std::vector< std::shared_ptr< WModuleOutputData< WDataSetScalar > > > m_evalOutputs;
229 
230  //! The threadpool for the eigenvector computation
231  std::shared_ptr< WThreadedFunctionBase > m_eigenPool;
232 
233  //! the functor used for the calculation of the eigenvectors
234  std::shared_ptr< TPVOFloat > m_eigenOperationFloat;
235 
236  //! the functor used for the calculation of the eigenvectors
237  std::shared_ptr< TPVODouble > m_eigenOperationDouble;
238 
239  /**
240  * Indicating current work progress.
241  */
242  std::shared_ptr< WProgress > m_currentProgress;
243 
244  /**
245  * List for selecting the strategy.
246  */
247  WPropSelection m_strategySelector;
248 };
249 
250 #endif // WMEIGENSYSTEM_H
Represents a Diffusion-Tensor-Image dataset.
Definition: WDataSetDTI.h:40
This data set type contains vectors as values.
Computes the eigensystem of a second order tensor field.
Definition: WMEigenSystem.h:55
void resetProgress(std::size_t todo, std::string name)
Resets the current progress to 0.
std::shared_ptr< WModuleOutputData< WDataSetVector > > EigenOutputConnector
Shortcut for the vector field output connectors.
std::vector< std::shared_ptr< WModuleOutputData< WDataSetScalar > > > m_evalOutputs
Output scalar field , each for an eigenvalue field.
virtual void moduleMain()
Entry point after loading the module.
std::shared_ptr< TPVOFloat > m_eigenOperationFloat
the functor used for the calculation of the eigenvectors
virtual void requirements()
Initialize requirements 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...
WThreadedFunction< TPVOFloat > EigenFunctionTypeFloat
the thread pool type for the eigencomputation (float input)
std::shared_ptr< WProgress > m_currentProgress
Indicating current work progress.
WThreadedPerVoxelOperation< double, 6, double, 12 > TPVODouble
the threaded per-voxel function for the eigenvector computation (double input)
virtual const std::string getDescription() const
Gives back a description of this module.
WValueSet< double > FloatValueSetType
the valueset type
TPVOFloat::OutTransmitType const eigenSolverFloat(TPVOFloat::TransmitType const &input)
Computes the eigen system for double input parameters via using applyEigenSolver.
boost::array< double, 12 > computeEigenSystem(WTensorSym< 2, 3, double > const &m) const
Is used by every thread to compute the eigensystem for the given tensor.
boost::array< double, 12 > applyEigenSolver(const Eigen::Matrix3d &m) const
Copies the eigenvalues and eigenvectors from the libEigen output format into the double array.
virtual void connectors()
Initialize the connectors this module is using.
TPVOFloat::OutTransmitType const eigenFuncFloat(TPVOFloat::TransmitType const &input)
The function that computes the eigenvectors from the input tensor field.
TPVODouble::OutTransmitType const eigenSolverDouble(TPVODouble::TransmitType const &input)
Computes the eigen system for double input parameters via using applyEigenSolver.
virtual ~WMEigenSystem()
Destructs this module.
std::shared_ptr< WModuleInputData< WDataSetDTI > > m_tensorIC
Input tensor field.
std::shared_ptr< WThreadedFunctionBase > m_eigenPool
The threadpool for the eigenvector computation.
WPropSelection m_strategySelector
List for selecting the strategy.
std::vector< EigenOutputConnector > m_evecOutputs
Ouput vector field for principal eigenvectors as well as one for all eigenvalues at once.
WThreadedPerVoxelOperation< float, 6, double, 12 > TPVOFloat
the threaded per-voxel function for the eigenvector computation (float input)
WThreadedFunction< Tracking > TrackingFuncType
the tracking threadpool
virtual const std::string getName() const
Gives back the name of this module.
void resetEigenFunction(std::shared_ptr< WDataSetDTI > tensors)
Resets the threaded function/threadpool.
virtual void properties()
Initialize the properties for this module.
void updateOCs(std::shared_ptr< const WDataSetSingle > es)
Update the output connectors out of the computed eigensystem field.
WMEigenSystem()
Constructs a new module for eigensystem computation.
std::shared_ptr< TPVODouble > m_eigenOperationDouble
the functor used for the calculation of the eigenvectors
wtracking::WThreadedTrackingFunction Tracking
the threaded tracking functor
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
TPVODouble::OutTransmitType const eigenFuncDouble(TPVODouble::TransmitType const &input)
The function that computes the eigenvectors from the input tensor field.
WThreadedFunction< TPVODouble > EigenFunctionTypeDouble
the thread pool type for the eigencomputation (double input)
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.