OpenWalnut  1.5.0dev
WMCalculateGFA.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 WMCALCULATEGFA_H
26 #define WMCALCULATEGFA_H
27 
28 #include <memory>
29 #include <string>
30 #include <vector>
31 
32 #include "core/common/WThreadedFunction.h"
33 #include "core/common/math/WMatrix.h"
34 #include "core/dataHandler/WDataSetScalar.h"
35 #include "core/dataHandler/WDataSetSphericalHarmonics.h"
36 #include "core/dataHandler/WThreadedPerVoxelOperation.h"
37 #include "core/kernel/WModule.h"
38 #include "core/kernel/WModuleInputData.h"
39 #include "core/kernel/WModuleOutputData.h"
40 
41 /**
42  * \class WMCalculateGFA
43  *
44  * A module that calculates the generalized fractional anisotropy for every voxel of the input dataset.
45  *
46  * \ingroup modules
47  */
48 class WMCalculateGFA: public WModule
49 {
50  //! a conveniance typedef
52 
53 public:
54  /**
55  * Standard constructor.
56  */
58 
59  /**
60  * Destructor.
61  */
62  virtual ~WMCalculateGFA();
63 
64  /**
65  * Gives back the name of this module.
66  * \return the module's name.
67  */
68  virtual const std::string getName() const;
69 
70  /**
71  * Gives back a description of this module.
72  * \return description to module.
73  */
74  virtual const std::string getDescription() const;
75 
76  /**
77  * Due to the prototype design pattern used to build modules, this method returns a new instance of this method. NOTE: it
78  * should never be initialized or modified in some other way. A simple new instance is required.
79  *
80  * \return the prototype used to create every module in OpenWalnut.
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 protected:
91  /**
92  * Entry point after loading the module. Runs in separate thread.
93  */
94  virtual void moduleMain();
95 
96  /**
97  * Initialize the connectors this module is using.
98  */
99  virtual void connectors();
100 
101  /**
102  * Initialize the properties for this module.
103  */
104  virtual void properties();
105 
106 private:
107  //! the threaded function type for gfa computation
109 
110  //! the threadpool
112 
113  /**
114  * A function that gets called for every voxel in the input SH-dataset. Calculates a
115  * fractional anisotropy measure.
116  *
117  * \param s An array of SH-coefficients.
118  * \return A boost::array of size 1 that contains the result for the given voxel.
119  */
120  boost::array< double, 1 > perVoxelGFAFunc( WValueSet< double >::SubArray const& s );
121 
122  /**
123  * Reset the threaded functions.
124  */
125  void resetGFAPool();
126 
127  /**
128  * Handle an exception thrown by a worker thread.
129  *
130  * \param e The exception that was thrown during multithreaded computation.
131  */
132  void handleException( WException const& e );
133 
134  /**
135  * Reset the progress indicator in the ui.
136  *
137  * \param todo The number of steps needed to complete the job.
138  */
139  void resetProgress( std::size_t todo );
140 
141  //! A pointer to the input dataset.
142  std::shared_ptr< WDataSetSphericalHarmonics > m_dataSet;
143 
144  //! The output dataset.
145  std::shared_ptr< WDataSetScalar > m_result;
146 
147  //! The output Connector.
148  std::shared_ptr< WModuleOutputData< WDataSetScalar > > m_output;
149 
150  //! The input Connector for the SH data.
151  std::shared_ptr< WModuleInputData< WDataSetSphericalHarmonics > > m_input;
152 
153  //! The object that keeps track of the current progress.
154  std::shared_ptr< WProgress > m_currentProgress;
155 
156  //! The last exception thrown by any worker thread.
157  std::shared_ptr< WException > m_lastException;
158 
159  //! Condition indicating if any exception was thrown.
160  std::shared_ptr< WCondition > m_exceptionCondition;
161 
162  //! The threaded function object.
163  std::shared_ptr< GFAFuncType > m_gfaFunc;
164 
165  //! The threadpool.
166  std::shared_ptr< GFAPoolType > m_gfaPool;
167 
168  //! A matrix of SH base function values for various gradients.
170 };
171 
172 #endif // WMCALCULATEGFA_H
Basic exception handler.
Definition: WException.h:39
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.
WMCalculateGFA This
a conveniance typedef
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 representing a single module of OpenWalnut.
Definition: WModule.h:72
Creates threads that computes a function in a multithreaded fashion.
A template that performs an operation on a per voxel basis.
A helper class granting safe access to a certain part of the valueset.
Definition: WValueSet.h:65