OpenWalnut  1.5.0dev
WMSurfaceParameterAnimator.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 WMSURFACEPARAMETERANIMATOR_H
26 #define WMSURFACEPARAMETERANIMATOR_H
27 
28 #include <memory>
29 #include <string>
30 #include <utility>
31 
32 #include <osg/Node>
33 #include <osg/Uniform>
34 #include <osgDB/WriteFile>
35 
36 #include "core/common/WBoundingBox.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  * Forward declaration of the WGEGroupNode.
44  */
45 class WGEGroupNode;
46 
47 /**
48  * This module is a ray-tracing based isosurface using special methods for animating particle flow on its surface. The modules needs a scalar
49  * dataset as input and renders an isosurface on it. This isosurface is furthermore used to show an animation of moving bars on it. The module
50  * needs a corresponding scalar dataset which contains the parameterization of the track on which the bars should move.
51  * \ingroup modules
52  */
54 {
55 public:
56  /**
57  * Default constructor.
58  */
60 
61  /**
62  * Destructor.
63  */
65 
66  /**
67  * Gives back the name of this module.
68  * \return the module's name.
69  */
70  virtual const std::string getName() const;
71 
72  /**
73  * Gives back a description of this module.
74  * \return description to module.
75  */
76  virtual const std::string getDescription() const;
77 
78  /**
79  * Due to the prototype design pattern used to build modules, this method returns a new instance of this method. NOTE: it
80  * should never be initialized or modified in some other way. A simple new instance is required.
81  *
82  * \return the prototype used to create every module in OpenWalnut.
83  */
84  virtual std::shared_ptr< WModule > factory() const;
85 
86  /**
87  * Get the icon for this module in XPM format.
88  * \return the icon.
89  */
90  virtual const char** getXPMIcon() const;
91 
92 protected:
93  /**
94  * Entry point after loading the module. Runs in separate thread.
95  */
96  virtual void moduleMain();
97 
98  /**
99  * Initialize the connectors this module is using.
100  */
101  virtual void connectors();
102 
103  /**
104  * Initialize the properties for this module.
105  */
106  virtual void properties();
107 
108  /**
109  * Callback for m_active. Overwrite this in your modules to handle m_active changes separately.
110  */
111  virtual void activate();
112 
113 private:
114  /**
115  * An input connector used to get datasets from other modules. The connection management between connectors must not be handled by the module.
116  */
117  std::shared_ptr< WModuleInputData< WDataSetSingle > > m_input;
118 
119  /**
120  * The input for the volumized fiber traces. Mostly, this is some kind of integrated length data.
121  */
122  std::shared_ptr< WModuleInputData< WDataSetSingle > > m_tracesInput;
123 
124  /**
125  * This is a pointer to the dataset the module is currently working on.
126  */
127  std::shared_ptr< WDataSetSingle > m_dataSet;
128 
129  /**
130  * The dataset containing the fiber traces in each voxel in m_dataSet.
131  */
132  std::shared_ptr< WDataSetSingle > m_tracesDataSet;
133 
134  /////////////////////////////////////////////////////////////////////
135  // The Properties
136  /////////////////////////////////////////////////////////////////////
137 
138  /**
139  * The Isovalue used in the case m_isoSurface is true.
140  */
141  WPropInt m_isoValue;
142 
143  /**
144  * The number of steps to walk along the ray.
145  */
146  WPropInt m_stepCount;
147 
148  /**
149  * The alpha transparency used for the rendering
150  */
151  WPropInt m_alpha;
152 
153  /**
154  * The size of beam 1. A value of 0 denotes the smallest size and a value of 100 the largest, which typically is one third of the length of
155  * the fiber cluster.
156  */
157  WPropInt m_size1;
158 
159  /**
160  * The size of beam 1. A value of 0 denotes the smallest size and a value of 100 the largest, which typically is one third of the length of
161  * the fiber cluster.
162  */
163  WPropInt m_size2;
164 
165  /**
166  * The speed of beam 1 on the surface. This is relative to the clock which ticks 25 times per second.
167  */
168  WPropInt m_speed1;
169 
170  /**
171  * The speed of beam 2 on the surface. This is relative to the clock which ticks 25 times per second.
172  */
173  WPropInt m_speed2;
174 
175  /**
176  * Saturation of final rendering.
177  */
178  WPropInt m_saturation;
179 
180  /**
181  * Scaling the parameter space ensures consistent sizes and speeds along multiple WMSurfaceParameterAnimator instances.
182  */
183  WPropDouble m_parameterScale;
184 
185  /**
186  * The color used when in isosurface mode for blending.
187  */
188  WPropColor m_isoColor;
189 
190  /**
191  * A condition used to notify about changes in several properties.
192  */
193  std::shared_ptr< WCondition > m_propCondition;
194 
195  /////////////////////////////////////////////////////////////////////
196  // OSG Stuff
197  /////////////////////////////////////////////////////////////////////
198 
199  /**
200  * Renders the surface to an FBO.
201  *
202  * \param bbox the bounding box that should be used
203  *
204  * \return the node which contains the cube with the surface rendering
205  */
206  osg::ref_ptr< osg::Node > renderSurface( const WBoundingBox& bbox );
207 
208  /**
209  * The root node used for this modules graphics. For OSG nodes, always use osg::ref_ptr to ensure proper resource management.
210  */
211  osg::ref_ptr< WGEGroupNode > m_rootNode;
212 
213  /**
214  * the DVR shader.
215  */
216  osg::ref_ptr< WGEShader > m_shader;
217 
218  /**
219  * Node callback to change the color of the shapes inside the root node. For more details on this class, refer to the documentation in
220  * moduleMain().
221  */
222  class SafeUpdateCallback : public osg::NodeCallback
223  {
224  public: // NOLINT
225  /**
226  * Constructor.
227  *
228  * \param module just set the creating module as pointer for later reference.
229  */
231  {
232  };
233 
234  /**
235  * operator () - called during the update traversal.
236  *
237  * \param node the osg node
238  * \param nv the node visitor
239  */
240  virtual void operator()( osg::Node* node, osg::NodeVisitor* nv );
241 
242  /**
243  * Pointer used to access members of the module to modify the node.
244  */
246 
247  /**
248  * Denotes whether the update callback is called the first time.
249  */
251  };
252 
253  /**
254  * Class handling uniform update during render traversal
255  */
257  {
258  public:
259  /**
260  * Constructor.
261  *
262  * \param module just set the creating module as pointer for later reference.
263  */
265  {
266  };
267 
268  /**
269  * The callback. Called every render traversal for the uniform.
270  *
271  * \param uniform the uniform for which this callback is.
272  * \param nv the visitor.
273  */
274  virtual void operator() ( osg::Uniform* uniform, osg::NodeVisitor* nv );
275 
276  /**
277  * Pointer used to access members of the module to modify the node.
278  */
280  };
281 };
282 
283 #endif // WMSURFACEPARAMETERANIMATOR_H
284 
Class to wrap around the osg Group node and providing a thread safe add/removal mechanism.
Definition: WGEGroupNode.h:48
Class handling uniform update during render traversal.
WMSurfaceParameterAnimator * m_module
Pointer used to access members of the module to modify the node.
virtual void operator()(osg::Uniform *uniform, osg::NodeVisitor *nv)
The callback.
SafeUniformCallback(WMSurfaceParameterAnimator *module)
Constructor.
Node callback to change the color of the shapes inside the root node.
bool m_initialUpdate
Denotes whether the update callback is called the first time.
virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
operator () - called during the update traversal.
SafeUpdateCallback(WMSurfaceParameterAnimator *module)
Constructor.
WMSurfaceParameterAnimator * m_module
Pointer used to access members of the module to modify the node.
This module is a ray-tracing based isosurface using special methods for animating particle flow on it...
WPropInt m_isoValue
The Isovalue used in the case m_isoSurface is true.
virtual const std::string getDescription() const
Gives back a description of this module.
WPropInt m_speed2
The speed of beam 2 on the surface.
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
std::shared_ptr< WDataSetSingle > m_tracesDataSet
The dataset containing the fiber traces in each voxel in m_dataSet.
virtual ~WMSurfaceParameterAnimator()
Destructor.
WPropInt m_saturation
Saturation of final rendering.
std::shared_ptr< WModuleInputData< WDataSetSingle > > m_input
An input connector used to get datasets from other modules.
std::shared_ptr< WDataSetSingle > m_dataSet
This is a pointer to the dataset the module is currently working on.
WPropInt m_speed1
The speed of beam 1 on the surface.
WPropDouble m_parameterScale
Scaling the parameter space ensures consistent sizes and speeds along multiple WMSurfaceParameterAnim...
virtual const std::string getName() const
Gives back the name of this module.
WPropInt m_alpha
The alpha transparency used for the rendering.
WPropColor m_isoColor
The color used when in isosurface mode for blending.
osg::ref_ptr< osg::Node > renderSurface(const WBoundingBox &bbox)
Renders the surface to an FBO.
WPropInt m_size1
The size of beam 1.
WPropInt m_stepCount
The number of steps to walk along the ray.
WMSurfaceParameterAnimator()
Default constructor.
virtual void moduleMain()
Entry point after loading the module.
virtual void connectors()
Initialize the connectors this module is using.
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< WGEShader > m_shader
the DVR shader.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
osg::ref_ptr< WGEGroupNode > m_rootNode
The root node used for this modules graphics.
WPropInt m_size2
The size of beam 1.
std::shared_ptr< WModuleInputData< WDataSetSingle > > m_tracesInput
The input for the volumized fiber traces.
virtual void properties()
Initialize the properties for this module.
virtual void activate()
Callback for m_active.
Class representing a single module of OpenWalnut.
Definition: WModule.h:72