OpenWalnut  1.5.0dev
WMSplineSurface.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 WMSPLINESURFACE_H
26 #define WMSPLINESURFACE_H
27 
28 #include <map>
29 #include <memory>
30 #include <string>
31 #include <vector>
32 
33 #include <osg/Geode>
34 #include <osg/Node>
35 #include <osg/Uniform>
36 
37 #include "core/dataHandler/WDataSetScalar.h"
38 #include "core/dataHandler/WGridRegular3D.h"
39 #include "core/dataHandler/datastructures/WFiberCluster.h"
40 #include "core/graphicsEngine/WGEGroupNode.h"
41 #include "core/graphicsEngine/WTriangleMesh.h"
42 #include "core/graphicsEngine/shaders/WGEShader.h"
43 #include "core/kernel/WModule.h"
44 #include "core/kernel/WModuleInputData.h"
45 #include "core/kernel/WModuleOutputData.h"
46 
47 /**
48  * Module implementing the marching cubes algorithm with consistent triangulation for data
49  * given on regular grids with axis-aligned cells.
50  * \ingroup modules
51  */
52 class WMSplineSurface: public WModule
53 {
54 public:
55  /**
56  * Standard constructor.
57  */
59 
60  /**
61  * Destructor.
62  */
64 
65  /**
66  * Gives back the name of this module.
67  * \return the module's name.
68  */
69  virtual const std::string getName() const;
70 
71  /**
72  * Gives back a description of this module.
73  * \return description of module.
74  */
75  virtual const std::string getDescription() const;
76 
77  /**
78  * Due to the prototype design pattern used to build modules, this method returns a new instance of this method. NOTE: it
79  * should never be initialized or modified in some other way. A simple new instance is required.
80  *
81  * \return the prototype used to create every module in OpenWalnut.
82  */
83  virtual std::shared_ptr< WModule > factory() const;
84 
85  /**
86  * Get the icon for this module in XPM format.
87  * \return The icon
88  */
89  virtual const char** getXPMIcon() const;
90 
91  /**
92  * updates textures and shader parameters
93  */
94  void updateGraphics();
95 
96 protected:
97  /**
98  * Entry point after loading the module. Runs in separate thread.
99  */
100  virtual void moduleMain();
101 
102  /**
103  * Initialize the connectors this module is using.
104  */
105  virtual void connectors();
106 
107  /**
108  * Initialize the properties for this module.
109  */
110  virtual void properties();
111 
112 private:
113  /**
114  * Prepares and commits everything for rendering with the OSG
115  */
116  void renderMesh();
117 
118  /**
119  * Store the mesh in legacy vtk file format.
120  * \return Did the save succeed?
121  */
122  bool save() const;
123 
124  WPropInt m_opacityProp; //!< Property holding the opacity valueassigned to the surface
125  WPropBool m_useTextureProp; //!< Property indicating whether to use texturing with scalar data sets.
126  WPropColor m_surfaceColor; //!< Property determining the color for the surface if no textures are displayed
127 
128  WPropGroup m_savePropGroup; //!< Property group containing properties needed for saving the mesh.
129  WPropTrigger m_saveTriggerProp; //!< This property triggers the actual writing,
130  WPropFilename m_meshFile; //!< The mesh will be written to this file.
131 
132  /**
133  * This condition denotes whether we need to recompute the surface
134  */
135  std::shared_ptr< WCondition > m_recompute;
136 
137  std::shared_ptr< WModuleInputData< const WFiberCluster > > m_input; //!< Input connector for a fiber cluster
138  std::shared_ptr< WModuleOutputData< WTriangleMesh > > m_output; //!< Input connector required by this module.
139 
140  std::shared_ptr< WTriangleMesh > m_triMesh; //!< This triangle mesh is provided as output through the connector.
141 
142  osg::ref_ptr< WGEGroupNode > m_moduleNode; //!< Pointer to the modules group node. We need it to be able to update it when callback is invoked.
143 
144  osg::ref_ptr< osg::Geode > m_surfaceGeode; //!< Pointer to geode containing the surface.
145 };
146 
147 /**
148  * Adapter object for realizing callbacks of the node representing the isosurface in the osg
149  */
150 class SplineSurfaceNodeCallback: public osg::NodeCallback
151 {
152 public:
153  /**
154  * Constructor of the callback adapter.
155  * \param module A function of this module will be called
156  */
157  explicit SplineSurfaceNodeCallback( WMSplineSurface* module );
158 
159  /**
160  * Function that is called by the osg and that call the function in the module.
161  * \param node The node we are called.
162  * \param nv the visitor calling us.
163  */
164  virtual void operator()( osg::Node* node, osg::NodeVisitor* nv );
165 
166 private:
167  WMSplineSurface* m_module; //!< Pointer to the module to which the function that is called belongs to.
168 };
169 
171  m_module( module )
172 {
173 }
174 
175 inline void SplineSurfaceNodeCallback::operator()( osg::Node* node, osg::NodeVisitor* nv )
176 {
177  if( m_module )
178  {
180  }
181  traverse( node, nv );
182 }
183 
184 #endif // WMSPLINESURFACE_H
Adapter object for realizing callbacks of the node representing the isosurface in the osg.
WMSplineSurface * m_module
Pointer to the module to which the function that is called belongs to.
virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
Function that is called by the osg and that call the function in the module.
SplineSurfaceNodeCallback(WMSplineSurface *module)
Constructor of the callback adapter.
Module implementing the marching cubes algorithm with consistent triangulation for data given on regu...
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
WPropBool m_useTextureProp
Property indicating whether to use texturing with scalar data sets.
osg::ref_ptr< osg::Geode > m_surfaceGeode
Pointer to geode containing the surface.
WPropColor m_surfaceColor
Property determining the color for the surface if no textures are displayed.
virtual const std::string getName() const
Gives back the name of this module.
void updateGraphics()
updates textures and shader parameters
virtual void moduleMain()
Entry point after loading the module.
bool save() const
Store the mesh in legacy vtk file format.
osg::ref_ptr< WGEGroupNode > m_moduleNode
Pointer to the modules group node. We need it to be able to update it when callback is invoked.
virtual void properties()
Initialize the properties for this module.
virtual const std::string getDescription() const
Gives back a description of this module.
~WMSplineSurface()
Destructor.
WMSplineSurface()
Standard constructor.
WPropInt m_opacityProp
Property holding the opacity valueassigned to the surface.
std::shared_ptr< WTriangleMesh > m_triMesh
This triangle mesh is provided as output through the connector.
virtual void connectors()
Initialize the connectors this module is using.
std::shared_ptr< WModuleOutputData< WTriangleMesh > > m_output
Input connector required by this module.
WPropGroup m_savePropGroup
Property group containing properties needed for saving the mesh.
void renderMesh()
Prepares and commits everything for rendering with the OSG.
WPropFilename m_meshFile
The mesh will be written to this file.
std::shared_ptr< WModuleInputData< const WFiberCluster > > m_input
Input connector for a fiber cluster.
WPropTrigger m_saveTriggerProp
This property triggers the actual writing,.
std::shared_ptr< WCondition > m_recompute
This condition denotes whether we need to recompute the surface.
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...
Class representing a single module of OpenWalnut.
Definition: WModule.h:72