OpenWalnut  1.5.0dev
WMTeemGlyphs.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 WMTEEMGLYPHS_H
26 #define WMTEEMGLYPHS_H
27 
28 #include <memory>
29 #include <string>
30 
31 #include <osg/Geode>
32 
33 #include "core/common/WItemSelection.h"
34 #include "core/common/WItemSelector.h"
35 #include "core/dataHandler/WDataSetScalar.h"
36 #include "core/dataHandler/WDataSetSphericalHarmonics.h"
37 #include "core/graphicsEngine/shaders/WGEShader.h"
38 #include "core/kernel/WModule.h"
39 #include "core/kernel/WModuleInputData.h"
40 #include "core/kernel/WModuleOutputData.h"
41 
42 /**
43  * Spherical harmonics glyphs using teem (http://teem.sourceforge.net/).
44  * According to http://www.ci.uchicago.edu/~schultz/sphinx/home-glyph.htm
45  * Thanks to Thomas Schultz.
46  *
47  * \warning Not yet in useful state.
48  * \ingroup modules
49  */
50 class WMTeemGlyphs: public WModule
51 {
52 public:
53  /**
54  * Nothing special with this constructor.
55  */
56  WMTeemGlyphs();
57 
58  /**
59  * Nothing special with this constructor.
60  */
61  virtual ~WMTeemGlyphs();
62 
63  /**
64  * Gives back the name of this module.
65  * \return the module's name.
66  */
67  virtual const std::string getName() const;
68 
69  /**
70  * Gives back a description of this module.
71  * \return description to module.
72  */
73  virtual const std::string getDescription() const;
74 
75  /**
76  * Due to the prototype design pattern used to build modules, this method returns a new instance of this method. NOTE: it
77  * should never be initialized or modified in some other way. A simple new instance is required.
78  *
79  * \return the prototype used to create every module in OpenWalnut.
80  */
81  virtual std::shared_ptr< WModule > factory() const;
82 
83  /**
84  * Get the icon for this module in XPM format.
85  * \return The icon.
86  */
87  virtual const char** getXPMIcon() const;
88 
89 protected:
90  /**
91  * Entry point after loading the module. Runs in separate thread.
92  */
93  virtual void moduleMain();
94 
95  /**
96  * Initialize the connectors this module is using.
97  */
98  virtual void connectors();
99 
100  /**
101  * Initialize the properties for this module.
102  */
103  virtual void properties();
104 
105  /**
106  * Handle an exception that was thrown by the threaded function in any worker thread.
107  *
108  * \param e The exception that was thrown.
109  */
110  void handleException( WException const& e );
111 
112 private:
113  /**
114  * An input connector that accepts spherical harmonics datasets.
115  */
116  std::shared_ptr< WModuleInputData< WDataSetSphericalHarmonics > > m_input;
117 
118  /**
119  * This condition denotes whether we need to recompute the surface
120  */
121  std::shared_ptr< WCondition > m_recompute;
122 
123  /**
124  * Just a preliminary function to avoid polluting moduleMain()
125  */
126  void execute();
127 
128  /**
129  * Gets signaled from the properties object when something was changed. Now, only m_active is used. This method therefore simply
130  * activates/deactivates the glyphs.
131  */
132  void activate();
133 
134  /**
135  * Renders all glyphs for the given slice
136  * \param sliceId The number of the slice to be rendered.
137  */
138  void renderSlice( size_t sliceId );
139 
140  std::shared_ptr< WDataSetSphericalHarmonics > m_dataSet; //!< Pointer to the treated data set.
141 
142  std::shared_ptr< WModuleInputData< WDataSetScalar > > m_inputGFA; //!< The input for the GFA.
143  osg::ref_ptr< WGEShader > m_shader; //!< The shader used for the glyph surfaces
144  std::shared_ptr< WItemSelection > m_sliceOrientations; //!< A list of the selectable slice orientations, i.e x, y and z.
145  WPropSelection m_sliceOrientationSelectionProp; //!< To choose whether to x, y or z slice.
146  WPropBool m_usePolarPlotProp; //!< Property indicating whether to use polar plot instead of HOME glyph
147  WPropBool m_useNormalizationProp; //!< Indicates whether to use min max normalization.
148  WPropBool m_useRadiusNormalizationProp; //!< Indicates whether to use radius normalization.
149  WPropBool m_hideNegativeLobesProp; //!< Indicates whether to hide negativ radius lobes of glyphs
150  WPropDouble m_GFAThresholdProp; //!< Property holding the threshold of GFA above which glyphs should be drawn.
151  WPropDouble m_glyphSizeProp; //!< Property holding the size of the displayed glyphs
152  WPropInt m_sliceIdProp; //!< Property holding the slice ID
153  std::shared_ptr< WItemSelection > m_orders; //!< A list of the selectable orders
154  WPropSelection m_orderProp; //!< Property holding the order of the SH to show.
155 
156  WPropInt m_moduloProp; //!< Property holding information on how many glyphs will be omited between two glyphs (modulo-1).
157  WPropInt m_subdivisionLevelProp; //!< Property holding information on the subdivision level of the spheres (resolution).
158 
159  osg::ref_ptr< osg::Geode > m_glyphsGeode; //!< Pointer to geode containing the glyphs.
160  osg::ref_ptr< WGEGroupNode > m_moduleNode; //!< Pointer to the modules group node.
161 
162  //! The last exception thrown by any worker thread.
163  std::shared_ptr< WException > m_lastException;
164  boost::mutex m_moduleNodeLock; //!< Lock to prevent concurrent threads trying access m_moduleNode
165 
166  //! condition indicating if any exception was thrown.
167  std::shared_ptr< WCondition > m_exceptionCondition;
168 
169  /**
170  * This class actually generated the glyph geometry. This class has () operator that the work.
171  * The () operator enables it to be parallelized by WThreadedFunction.
172  */
174  {
175  public:
176  /**
177  * Constructor setting the data pointers and the properties from the module.
178  *
179  * \param dataSet Pointer to the treated data set.
180  * \param dataGFA GFA data for dataSet.
181  * \param thresholdGFA Threshold of GFA below which we will not draw the glyphs
182  * \param sliceId Rendered slice
183  * \param order Order of the rendered spherical harmonics.
184  * \param subdivisionLevel Subidivision level of spheres that are basis for glyphs (resolution)
185  * \param modulo Show only every modulo-th glyph in each direction.
186  * \param sliceType Slice direction (sagittal, coronal, axial )
187  * \param usePolar Use polar glyphs (HOME otherwise)
188  * \param scale Resize the glyphs.
189  * \param useNormalization Scale minimum and maximum radius to [0,1].
190  * \param useRadiusNormalization Scale glyphs to make them all the same size.
191  * \param hideNegativeLobes Vertices with negative radius will be set to zero.
192  */
193  GlyphGeneration( std::shared_ptr< WDataSetSphericalHarmonics > dataSet,
194  std::shared_ptr< WDataSetScalar > dataGFA,
195  double thresholdGFA,
196  const size_t& sliceId,
197  const size_t& order,
198  const size_t& subdivisionLevel,
199  const size_t& modulo,
200  const size_t& sliceType,
201  const bool& usePolar,
202  const float& scale,
203  const bool& useNormalization,
204  const bool& useRadiusNormalization,
205  const bool& hideNegativeLobes );
206 
207  /**
208  * Destructor freeing the data.
209  */
211 
212  /**
213  * Computes the glyphs.
214  *
215  * \param id Thread id.
216  * \param numThreads The number of threads accessing this function simultaneously
217  * \param b A flag allowing to check whether a an abort has been requested.
218  */
219  void operator()( size_t id, size_t numThreads, WBoolFlag& b ); //NOLINT
220 
221  /**
222  * Get the geode of the computed glyphs.
223  *
224  * \return geode
225  */
226  osg::ref_ptr< osg::Geode > getGraphics();
227  private:
228  /**
229  * Makes the radii of the glyph be distributed between [0,1]
230  * \param glyph The glyph that will be normalized given as teem's limnPolyData.
231  * \param nbVertCoords Number of coordinates per vertex for the glyph poly-data
232  */
233  void minMaxNormalization( limnPolyData *glyph, const size_t& nbVertCoords );
234 
235  size_t m_nA; //!< Internal variable holding the number of glyphs in the first direction of the slice.
236  size_t m_nB; //!< Internal variable holding the number of glyphs in the second direction of the slice.
237  size_t m_nX; //!< Number of voxels in x direction.
238  size_t m_nY; //!< Number of voxels in y direction.
239  size_t m_nZ; //!< Number of voxels in z direction.
240  std::shared_ptr< WDataSetSphericalHarmonics > m_dataSet; //!< Pointer to the treated data set.
241  std::shared_ptr< WDataSetScalar > m_dataGFA; //!< Pointer to possible GFA data set.
242  std::shared_ptr< WGridRegular3D > m_grid; //!< Pointer to the grid of the treated data set.
243  osg::ref_ptr< osg::Vec3Array > m_vertArray; //!< Vertices of the triangles of the glyphs.
244  osg::ref_ptr< osg::Vec3Array > m_normals; //!< Normals of the vertices of the glyphs.
245  osg::ref_ptr< osg::Vec4Array > m_colors; //!< Colors of the vertices of the glyphs.
246  osg::ref_ptr< osg::DrawElementsUInt > m_glyphElements; //!< Indices of the vertices of the triangles of the glyphs.
247 
248  double m_thresholdGFA; //!< Stores the GFA threshold from the property.
249  size_t m_sliceId; //!< Stores option from property.
250  size_t m_order; //!< Stores option from property.
251  size_t m_sliceType; //!< Stores option from property.
252  size_t m_subdivisionLevel; //!< Store option from property
253  size_t m_modulo; //!< Store option from property
254  bool m_usePolar; //!< Stores option from property.
255  float m_scale; //!< Stores option from property.
256  bool m_useNormalization; //!< Stores option from property.
257  bool m_useRadiusNormalization; //!< Stores option from property.
258  bool m_hideNegativeLobes; //!< Stores option from property.
259 
260  limnPolyData *m_sphere; //!< The geometry of the subdivided icosahedron
261  };
262 };
263 
264 #endif // WMTEEMGLYPHS_H
Basic exception handler.
Definition: WException.h:39
This class actually generated the glyph geometry.
Definition: WMTeemGlyphs.h:174
~GlyphGeneration()
Destructor freeing the data.
size_t m_sliceId
Stores option from property.
Definition: WMTeemGlyphs.h:249
bool m_useNormalization
Stores option from property.
Definition: WMTeemGlyphs.h:256
osg::ref_ptr< osg::Vec3Array > m_normals
Normals of the vertices of the glyphs.
Definition: WMTeemGlyphs.h:244
size_t m_sliceType
Stores option from property.
Definition: WMTeemGlyphs.h:251
size_t m_nB
Internal variable holding the number of glyphs in the second direction of the slice.
Definition: WMTeemGlyphs.h:236
size_t m_nY
Number of voxels in y direction.
Definition: WMTeemGlyphs.h:238
osg::ref_ptr< osg::DrawElementsUInt > m_glyphElements
Indices of the vertices of the triangles of the glyphs.
Definition: WMTeemGlyphs.h:246
size_t m_nZ
Number of voxels in z direction.
Definition: WMTeemGlyphs.h:239
osg::ref_ptr< osg::Geode > getGraphics()
Get the geode of the computed glyphs.
limnPolyData * m_sphere
The geometry of the subdivided icosahedron.
Definition: WMTeemGlyphs.h:260
osg::ref_ptr< osg::Vec4Array > m_colors
Colors of the vertices of the glyphs.
Definition: WMTeemGlyphs.h:245
std::shared_ptr< WDataSetSphericalHarmonics > m_dataSet
Pointer to the treated data set.
Definition: WMTeemGlyphs.h:240
bool m_usePolar
Stores option from property.
Definition: WMTeemGlyphs.h:254
size_t m_nA
Internal variable holding the number of glyphs in the first direction of the slice.
Definition: WMTeemGlyphs.h:235
std::shared_ptr< WDataSetScalar > m_dataGFA
Pointer to possible GFA data set.
Definition: WMTeemGlyphs.h:241
std::shared_ptr< WGridRegular3D > m_grid
Pointer to the grid of the treated data set.
Definition: WMTeemGlyphs.h:242
float m_scale
Stores option from property.
Definition: WMTeemGlyphs.h:255
double m_thresholdGFA
Stores the GFA threshold from the property.
Definition: WMTeemGlyphs.h:248
size_t m_subdivisionLevel
Store option from property.
Definition: WMTeemGlyphs.h:252
GlyphGeneration(std::shared_ptr< WDataSetSphericalHarmonics > dataSet, std::shared_ptr< WDataSetScalar > dataGFA, double thresholdGFA, const size_t &sliceId, const size_t &order, const size_t &subdivisionLevel, const size_t &modulo, const size_t &sliceType, const bool &usePolar, const float &scale, const bool &useNormalization, const bool &useRadiusNormalization, const bool &hideNegativeLobes)
Constructor setting the data pointers and the properties from the module.
void minMaxNormalization(limnPolyData *glyph, const size_t &nbVertCoords)
Makes the radii of the glyph be distributed between [0,1].
bool m_hideNegativeLobes
Stores option from property.
Definition: WMTeemGlyphs.h:258
size_t m_nX
Number of voxels in x direction.
Definition: WMTeemGlyphs.h:237
size_t m_modulo
Store option from property.
Definition: WMTeemGlyphs.h:253
size_t m_order
Stores option from property.
Definition: WMTeemGlyphs.h:250
void operator()(size_t id, size_t numThreads, WBoolFlag &b)
Computes the glyphs.
bool m_useRadiusNormalization
Stores option from property.
Definition: WMTeemGlyphs.h:257
osg::ref_ptr< osg::Vec3Array > m_vertArray
Vertices of the triangles of the glyphs.
Definition: WMTeemGlyphs.h:243
Spherical harmonics glyphs using teem (http://teem.sourceforge.net/).
Definition: WMTeemGlyphs.h:51
std::shared_ptr< WCondition > m_exceptionCondition
condition indicating if any exception was thrown.
Definition: WMTeemGlyphs.h:167
virtual const std::string getName() const
Gives back the name of this module.
WPropSelection m_sliceOrientationSelectionProp
To choose whether to x, y or z slice.
Definition: WMTeemGlyphs.h:145
WPropInt m_subdivisionLevelProp
Property holding information on the subdivision level of the spheres (resolution).
Definition: WMTeemGlyphs.h:157
void handleException(WException const &e)
Handle an exception that was thrown by the threaded function in any worker thread.
osg::ref_ptr< WGEGroupNode > m_moduleNode
Pointer to the modules group node.
Definition: WMTeemGlyphs.h:160
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
void execute()
Just a preliminary function to avoid polluting moduleMain()
std::shared_ptr< WException > m_lastException
The last exception thrown by any worker thread.
Definition: WMTeemGlyphs.h:163
std::shared_ptr< WItemSelection > m_orders
A list of the selectable orders.
Definition: WMTeemGlyphs.h:153
std::shared_ptr< WModuleInputData< WDataSetSphericalHarmonics > > m_input
An input connector that accepts spherical harmonics datasets.
Definition: WMTeemGlyphs.h:116
virtual void connectors()
Initialize the connectors this module is using.
WPropBool m_hideNegativeLobesProp
Indicates whether to hide negativ radius lobes of glyphs.
Definition: WMTeemGlyphs.h:149
virtual const std::string getDescription() const
Gives back a description of this module.
std::shared_ptr< WModuleInputData< WDataSetScalar > > m_inputGFA
The input for the GFA.
Definition: WMTeemGlyphs.h:142
WPropSelection m_orderProp
Property holding the order of the SH to show.
Definition: WMTeemGlyphs.h:154
std::shared_ptr< WItemSelection > m_sliceOrientations
A list of the selectable slice orientations, i.e x, y and z.
Definition: WMTeemGlyphs.h:144
virtual void properties()
Initialize the properties for this module.
std::shared_ptr< WCondition > m_recompute
This condition denotes whether we need to recompute the surface.
Definition: WMTeemGlyphs.h:121
void activate()
Gets signaled from the properties object when something was changed.
WPropInt m_moduloProp
Property holding information on how many glyphs will be omited between two glyphs (modulo-1).
Definition: WMTeemGlyphs.h:156
osg::ref_ptr< osg::Geode > m_glyphsGeode
Pointer to geode containing the glyphs.
Definition: WMTeemGlyphs.h:159
osg::ref_ptr< WGEShader > m_shader
The shader used for the glyph surfaces.
Definition: WMTeemGlyphs.h:143
WPropDouble m_GFAThresholdProp
Property holding the threshold of GFA above which glyphs should be drawn.
Definition: WMTeemGlyphs.h:150
WMTeemGlyphs()
Nothing special with this constructor.
WPropDouble m_glyphSizeProp
Property holding the size of the displayed glyphs.
Definition: WMTeemGlyphs.h:151
WPropBool m_useRadiusNormalizationProp
Indicates whether to use radius normalization.
Definition: WMTeemGlyphs.h:148
boost::mutex m_moduleNodeLock
Lock to prevent concurrent threads trying access m_moduleNode.
Definition: WMTeemGlyphs.h:164
void renderSlice(size_t sliceId)
Renders all glyphs for the given slice.
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...
WPropBool m_usePolarPlotProp
Property indicating whether to use polar plot instead of HOME glyph.
Definition: WMTeemGlyphs.h:146
WPropBool m_useNormalizationProp
Indicates whether to use min max normalization.
Definition: WMTeemGlyphs.h:147
virtual void moduleMain()
Entry point after loading the module.
virtual ~WMTeemGlyphs()
Nothing special with this constructor.
std::shared_ptr< WDataSetSphericalHarmonics > m_dataSet
Pointer to the treated data set.
Definition: WMTeemGlyphs.h:140
WPropInt m_sliceIdProp
Property holding the slice ID.
Definition: WMTeemGlyphs.h:152
Class representing a single module of OpenWalnut.
Definition: WModule.h:72