OpenWalnut  1.5.0dev
WMSuperquadricGlyphs.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 WMSUPERQUADRICGLYPHS_H
26 #define WMSUPERQUADRICGLYPHS_H
27 
28 #include <memory>
29 #include <string>
30 
31 #include <osg/Geode>
32 #include <osg/Node>
33 #include <osg/Uniform>
34 
35 #include "core/dataHandler/WDataSetDTI.h"
36 #include "core/graphicsEngine/WGEManagedGroupNode.h"
37 #include "core/graphicsEngine/callbacks/WGELinearTranslationCallback.h"
38 #include "core/graphicsEngine/shaders/WGEShader.h"
39 #include "core/kernel/WModule.h"
40 #include "core/kernel/WModuleInputData.h"
41 #include "core/kernel/WModuleOutputData.h"
42 
43 /**
44  * Rendering of GPU bases Superquadric Glyphs. These glyphs are completely ray-traced on the GPU.
45  *
46  * \ingroup modules
47  */
49 {
50 public:
51  /**
52  * Constructor.
53  */
55 
56  /**
57  * Destructor.
58  */
59  virtual ~WMSuperquadricGlyphs();
60 
61  /**
62  * Gives back the name of this module.
63  *
64  * \return the module's name.
65  */
66  virtual const std::string getName() const;
67 
68  /**
69  * Gives back a description of this module.
70  *
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 private:
106  /**
107  * Initializes the needed geodes, transformations and vertex arrays. This needs to be done once for each new dataset.
108  */
109  void initOSG();
110 
111  /**
112  * The Geode containing all the glyphs. In fact it only contains a quad per glyph on which the raytracing is done.
113  */
114  osg::ref_ptr< WGEManagedGroupNode > m_output;
115 
116  /**
117  * The transformation node moving the X slice through the dataset space if the sliders are used
118  */
119  osg::ref_ptr< WGEManagedGroupNode > m_xSlice;
120 
121  /**
122  * The transformation node moving the Y slice through the dataset space if the sliders are used
123  */
124  osg::ref_ptr< WGEManagedGroupNode > m_ySlice;
125 
126  /**
127  * The transformation node moving the Z slice through the dataset space if the sliders are used
128  */
129  osg::ref_ptr< WGEManagedGroupNode > m_zSlice;
130 
131  /**
132  * The input dataset. It contains the second order tensor data needed here.
133  */
134  std::shared_ptr< WModuleInputData< WDataSetDTI > > m_input;
135 
136  /**
137  * The current tensor dataset.
138  */
139  std::shared_ptr< const WDataSetDTI > m_dataSet;
140 
141  /**
142  * The current tensor dataset's grid.
143  */
144  std::shared_ptr< WGridRegular3D > m_dataSetGrid;
145 
146  /**
147  * The current tensor dataset's valueset.
148  */
149  std::shared_ptr< WValueSetBase > m_dataSetValueSet;
150 
151  /**
152  * Number of cells in X direction. Stored as a member to avoid permanent gird look ups.
153  */
154  size_t m_maxX;
155 
156  /**
157  * Number of cells in Y direction. Stored as a member to avoid permanent gird look ups.
158  */
159  size_t m_maxY;
160 
161  /**
162  * Number of cells in Z direction. Stored as a member to avoid permanent gird look ups.
163  */
164  size_t m_maxZ;
165 
166  /**
167  * Number of glyphs on X Plane.
168  */
169  size_t m_nbGlyphsX;
170 
171  /**
172  * Number of glyphs on Y Plane.
173  */
174  size_t m_nbGlyphsY;
175 
176  /**
177  * Number of glyphs on Z Plane.
178  */
179  size_t m_nbGlyphsZ;
180 
181  /**
182  * the shader actually doing the glyph raytracing
183  */
184  osg::ref_ptr< WGEShader > m_shader;
185 
186  /**
187  * A condition used to notify about changes in several properties.
188  */
189  std::shared_ptr< WCondition > m_propCondition;
190 
191  WPropInt m_xPos; //!< x position of the slice
192 
193  WPropInt m_yPos; //!< y position of the slice
194 
195  WPropInt m_zPos; //!< z position of the slice
196 
197  WPropBool m_showonX; //!< indicates whether the vector should be shown on slice X
198 
199  WPropBool m_showonY; //!< indicates whether the vector should be shown on slice Y
200 
201  WPropBool m_showonZ; //!< indicates whether the vector should be shown on slice Z
202 
203  /**
204  * The eigenvalue threshold to filter glyphs
205  */
206  WPropDouble m_evThreshold;
207 
208  /**
209  * The FA threshold to filter glyphs
210  */
211  WPropDouble m_faThreshold;
212 
213  /**
214  * Sharpness of the glyphs
215  */
216  WPropDouble m_gamma;
217 
218  /**
219  * Scaling of the glyphs
220  */
221  WPropDouble m_scaling;
222 
223  /**
224  * Color glyphs by direction?
225  */
227 
228  /**
229  * Adds a cube to the vertex array.
230  *
231  * \param position the position in world
232  * \param vertices the vertex array
233  * \param orientation the tex coord array storing the orientation
234  */
235  inline void addGlyph( osg::Vec3 position, osg::ref_ptr< osg::Vec3Array > vertices, osg::ref_ptr< osg::Vec3Array > orientation );
236 
237  /**
238  * Adds a tensor to two arrays. 6*4 times per glyph.
239  *
240  * \param idx the idx of the tensor in the valueset
241  * \param diag the diagonal array
242  * \param offdiag the off-diagonal array
243  */
244  inline void addTensor( size_t idx, osg::Vec3Array* diag, osg::Vec3Array* offdiag );
245 
246  /**
247  * Node callback to handle updates in the glyph tensor data
248  */
250  {
251  public: // NOLINT
252  /**
253  * Constructor.
254  *
255  * \param geo the geometry object to handle
256  */
257  explicit GlyphGeometryNodeCallback( osg::Geometry* geo ):
258  osg::Drawable::UpdateCallback(),
259  m_geometry( geo )
260  {
261  }
262 
263  /**
264  * This operator gets called by OSG every update cycle.
265  *
266  * \param d the osg drawable
267  * \param nv the node visitor
268  */
269  virtual void update( osg::NodeVisitor* nv, osg::Drawable* d );
270 
271  /**
272  * Updates the tensor data in the glyph slice.
273  *
274  * \param diag the diagonal elements as texture coords
275  * \param offdiag the off diagonal elements as texture coords
276  */
277  void setNewTensorData( osg::ref_ptr< osg::Vec3Array > diag, osg::ref_ptr< osg::Vec3Array > offdiag );
278 
279  /**
280  * The geometry node to handle here
281  */
282  osg::Geometry* m_geometry;
283 
284  /**
285  * Dirty flag. If true, the m_tensorDiag and m_tensorOffDiag get set
286  */
287  bool m_dirty;
288 
289  /**
290  * Diagonal tensor elements in texture coordinate array.
291  */
292  osg::ref_ptr< osg::Vec3Array > m_tensorDiag;
293 
294  /**
295  * Off-diagonal tensor elements in texture coordinate array.
296  */
297  osg::ref_ptr< osg::Vec3Array > m_tensorOffDiag;
298  };
299 
300  /**
301  * The update callback of m_xSlice glphs.
302  */
303  osg::ref_ptr< GlyphGeometryNodeCallback > m_xSliceGlyphCallback;
304 
305  /**
306  * The update callback of m_ySlice glphs.
307  */
308  osg::ref_ptr< GlyphGeometryNodeCallback > m_ySliceGlyphCallback;
309 
310  /**
311  * The update callback of m_zSlice glphs.
312  */
313  osg::ref_ptr< GlyphGeometryNodeCallback > m_zSliceGlyphCallback;
314 };
315 
316 #endif // WMSUPERQUADRICGLYPHS_H
Node callback to handle updates in the glyph tensor data.
virtual void update(osg::NodeVisitor *nv, osg::Drawable *d)
This operator gets called by OSG every update cycle.
osg::Geometry * m_geometry
The geometry node to handle here.
osg::ref_ptr< osg::Vec3Array > m_tensorOffDiag
Off-diagonal tensor elements in texture coordinate array.
osg::ref_ptr< osg::Vec3Array > m_tensorDiag
Diagonal tensor elements in texture coordinate array.
void setNewTensorData(osg::ref_ptr< osg::Vec3Array > diag, osg::ref_ptr< osg::Vec3Array > offdiag)
Updates the tensor data in the glyph slice.
GlyphGeometryNodeCallback(osg::Geometry *geo)
Constructor.
Rendering of GPU bases Superquadric Glyphs.
virtual void properties()
Initialize the properties for this module.
size_t m_nbGlyphsZ
Number of glyphs on Z Plane.
osg::ref_ptr< WGEManagedGroupNode > m_output
The Geode containing all the glyphs.
WMSuperquadricGlyphs()
Constructor.
size_t m_maxY
Number of cells in Y direction.
osg::ref_ptr< WGEManagedGroupNode > m_xSlice
The transformation node moving the X slice through the dataset space if the sliders are used.
osg::ref_ptr< GlyphGeometryNodeCallback > m_zSliceGlyphCallback
The update callback of m_zSlice glphs.
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
WPropInt m_zPos
z position of the slice
std::shared_ptr< WModuleInputData< WDataSetDTI > > m_input
The input dataset.
size_t m_maxX
Number of cells in X direction.
WPropDouble m_evThreshold
The eigenvalue threshold to filter glyphs.
WPropDouble m_faThreshold
The FA threshold to filter glyphs.
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...
osg::ref_ptr< GlyphGeometryNodeCallback > m_ySliceGlyphCallback
The update callback of m_ySlice glphs.
WPropDouble m_gamma
Sharpness of the glyphs.
virtual ~WMSuperquadricGlyphs()
Destructor.
WPropInt m_yPos
y position of the slice
WPropDouble m_scaling
Scaling of the glyphs.
void addTensor(size_t idx, osg::Vec3Array *diag, osg::Vec3Array *offdiag)
Adds a tensor to two arrays.
osg::ref_ptr< GlyphGeometryNodeCallback > m_xSliceGlyphCallback
The update callback of m_xSlice glphs.
WPropInt m_xPos
x position of the slice
virtual const std::string getDescription() const
Gives back a description of this module.
WPropBool m_showonY
indicates whether the vector should be shown on slice Y
WPropBool m_showonZ
indicates whether the vector should be shown on slice Z
size_t m_nbGlyphsX
Number of glyphs on X Plane.
std::shared_ptr< WGridRegular3D > m_dataSetGrid
The current tensor dataset's grid.
void initOSG()
Initializes the needed geodes, transformations and vertex arrays.
std::shared_ptr< WValueSetBase > m_dataSetValueSet
The current tensor dataset's valueset.
osg::ref_ptr< WGEShader > m_shader
the shader actually doing the glyph raytracing
WPropBool m_showonX
indicates whether the vector should be shown on slice X
osg::ref_ptr< WGEManagedGroupNode > m_zSlice
The transformation node moving the Z slice through the dataset space if the sliders are used.
osg::ref_ptr< WGEManagedGroupNode > m_ySlice
The transformation node moving the Y slice through the dataset space if the sliders are used.
std::shared_ptr< const WDataSetDTI > m_dataSet
The current tensor dataset.
virtual void connectors()
Initialize the connectors this module is using.
size_t m_maxZ
Number of cells in Z direction.
virtual const std::string getName() const
Gives back the name of 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.
size_t m_nbGlyphsY
Number of glyphs on Y Plane.
WPropBool m_directionalColoring
Color glyphs by direction?
void addGlyph(osg::Vec3 position, osg::ref_ptr< osg::Vec3Array > vertices, osg::ref_ptr< osg::Vec3Array > orientation)
Adds a cube to the vertex array.
Class representing a single module of OpenWalnut.
Definition: WModule.h:72