OpenWalnut  1.5.0dev
WMIsosurface.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 WMISOSURFACE_H
26 #define WMISOSURFACE_H
27 
28 #include <memory>
29 #include <shared_mutex>
30 #include <string>
31 
32 #include <osg/Geode>
33 #include <osg/Node>
34 #include <osg/Uniform>
35 
36 #include "core/dataHandler/WDataSetScalar.h"
37 #include "core/dataHandler/WGridRegular3D.h"
38 #include "core/graphicsEngine/WGEManagedGroupNode.h"
39 #include "core/graphicsEngine/WTriangleMesh.h"
40 #include "core/graphicsEngine/shaders/WGEShader.h"
41 #include "core/kernel/WModule.h"
42 #include "core/kernel/WModuleInputData.h"
43 #include "core/kernel/WModuleOutputData.h"
44 
45 /**
46  * Module implementing the marching cubes algorithm with consistent triangulation for data
47  * given on regular grids with axis-aligned cells.
48  * \ingroup modules
49  */
50 class WMIsosurface : public WModule
51 {
52 /**
53  * Only UnitTests may be friends.
54  */
55 friend class WMIsosurfaceTest;
56 
57 public:
58  /**
59  * Standard constructor.
60  */
61  WMIsosurface();
62 
63  /**
64  * Destructor.
65  */
66  ~WMIsosurface();
67 
68  /**
69  * Gives back the name of this module.
70  * \return the module's name.
71  */
72  virtual const std::string getName() const;
73 
74  /**
75  * Gives back a description of this module.
76  * \return description of module.
77  */
78  virtual const std::string getDescription() const;
79 
80  /**
81  * Due to the prototype design pattern used to build modules, this method returns a new instance of this method. NOTE: it
82  * should never be initialized or modified in some other way. A simple new instance is required.
83  *
84  * \return the prototype used to create every module in OpenWalnut.
85  */
86  virtual std::shared_ptr< WModule > factory() const;
87 
88  /**
89  * Get the icon for this module in XPM format.
90  * \return the icon.
91  */
92  virtual const char** getXPMIcon() const;
93 
94  /**
95  * updates textures and shader parameters when called (usually from the callback)
96  */
98 
99 protected:
100  /**
101  * Entry point after loading the module. Runs in separate thread.
102  */
103  virtual void moduleMain();
104 
105  /**
106  * Initialize the connectors this module is using.
107  */
108  virtual void connectors();
109 
110  /**
111  * Initialize the properties for this module.
112  */
113  virtual void properties();
114 
115 private:
116  /**
117  * Prepares and commits everything for rendering with the OSG
118  */
119  void renderMesh();
120 
121  /**
122  * Kind of a convenience function for generate surface.
123  * It performs the conversions of the value sets of different data types.
124  * \param isoValue The surface will represent this value.
125  */
126  void generateSurfacePre( double isoValue );
127 
128  std::shared_mutex m_updateLock; //!< Lock to prevent concurrent threads trying to update the osg node
129 
130  WPropInt m_nbTriangles; //!< Info-property showing the number of triangles in the mesh.
131  WPropInt m_nbVertices; //!< Info-property showing the number of vertices in the mesh.
132 
133  WPropDouble m_isoValueProp; //!< Property holding the iso value
134  WPropInt m_opacityProp; //!< Property holding the opacity valueassigned to the surface
135  WPropBool m_useTextureProp; //!< Property indicating whether to use texturing with scalar data sets.
136  WPropColor m_surfaceColor; //!< Property determining the color for the surface if no textures are displayed
137 
138  WPropBool m_useMarchingLego; //!< Property indicating whether to use interpolated or non interpolated triangulation
139 
140  /**
141  * This condition denotes whether we need to recompute the surface
142  */
143  std::shared_ptr< WCondition > m_recompute;
144 
145 
146  std::shared_ptr< WModuleInputData< WDataSetScalar > > m_input; //!< Input connector required by this module.
147  std::shared_ptr< WModuleOutputData< WTriangleMesh > > m_output; //!< Input connector required by this module.
148 
149  std::shared_ptr< WTriangleMesh > m_triMesh; //!< This triangle mesh is provided as output through the connector.
150 
151  static const unsigned int m_edgeTable[256]; //!< Lookup table for edges used in the construction of the isosurface.
152  static const int m_triTable[256][16]; //!< Lookup table for triangles used in the construction of the isosurface.
153 
154  std::shared_ptr< const WDataSetScalar > m_dataSet; //!< pointer to dataSet to be able to access it throughout the whole module.
155  std::shared_ptr< WGridRegular3D > m_grid; //!< pointer to grid, because we need to access the grid for the dimensions of the texture.
156 
157  bool m_firstDataProcessed; //!< Indicates if we already processed the first arrived data. This helps us to reset the isovalue only the first time.
158 
159  osg::ref_ptr< WGEManagedGroupNode > m_moduleNode; //!< Pointer to the module's group node. We need it to be able to update it for callback.
160  bool m_moduleNodeInserted; //!< ensures that the above module node gets inserted once the first triangle mesh has been calculated.
161 
162  osg::ref_ptr< osg::Geode > m_surfaceGeode; //!< Pointer to geode containing the surface.
163 
164  /**
165  * The shader
166  */
167  osg::ref_ptr< WGEShader > m_shader;
168 };
169 
170 #endif // WMISOSURFACE_H
Module implementing the marching cubes algorithm with consistent triangulation for data given on regu...
Definition: WMIsosurface.h:51
void updateGraphicsCallback()
updates textures and shader parameters when called (usually from the callback)
WPropInt m_nbVertices
Info-property showing the number of vertices in the mesh.
Definition: WMIsosurface.h:131
bool m_moduleNodeInserted
ensures that the above module node gets inserted once the first triangle mesh has been calculated.
Definition: WMIsosurface.h:160
virtual void moduleMain()
Entry point after loading the module.
osg::ref_ptr< osg::Geode > m_surfaceGeode
Pointer to geode containing the surface.
Definition: WMIsosurface.h:162
std::shared_ptr< WModuleInputData< WDataSetScalar > > m_input
Input connector required by this module.
Definition: WMIsosurface.h:146
virtual const std::string getName() const
Gives back the name of this module.
std::shared_mutex m_updateLock
Lock to prevent concurrent threads trying to update the osg node.
Definition: WMIsosurface.h:128
osg::ref_ptr< WGEManagedGroupNode > m_moduleNode
Pointer to the module's group node. We need it to be able to update it for callback.
Definition: WMIsosurface.h:159
void renderMesh()
Prepares and commits everything for rendering with the OSG.
std::shared_ptr< WCondition > m_recompute
This condition denotes whether we need to recompute the surface.
Definition: WMIsosurface.h:143
WPropBool m_useMarchingLego
Property indicating whether to use interpolated or non interpolated triangulation.
Definition: WMIsosurface.h:138
std::shared_ptr< const WDataSetScalar > m_dataSet
pointer to dataSet to be able to access it throughout the whole module.
Definition: WMIsosurface.h:154
virtual void properties()
Initialize the properties for this module.
WMIsosurface()
Standard constructor.
bool m_firstDataProcessed
Indicates if we already processed the first arrived data. This helps us to reset the isovalue only th...
Definition: WMIsosurface.h:157
virtual const std::string getDescription() const
Gives back a description of this module.
virtual void connectors()
Initialize the connectors this module is using.
std::shared_ptr< WTriangleMesh > m_triMesh
This triangle mesh is provided as output through the connector.
Definition: WMIsosurface.h:149
friend class WMIsosurfaceTest
Only UnitTests may be friends.
Definition: WMIsosurface.h:55
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
std::shared_ptr< WModuleOutputData< WTriangleMesh > > m_output
Input connector required by this module.
Definition: WMIsosurface.h:147
std::shared_ptr< WGridRegular3D > m_grid
pointer to grid, because we need to access the grid for the dimensions of the texture.
Definition: WMIsosurface.h:155
osg::ref_ptr< WGEShader > m_shader
The shader.
Definition: WMIsosurface.h:167
WPropInt m_nbTriangles
Info-property showing the number of triangles in the mesh.
Definition: WMIsosurface.h:130
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...
static const int m_triTable[256][16]
Lookup table for triangles used in the construction of the isosurface.
Definition: WMIsosurface.h:152
void generateSurfacePre(double isoValue)
Kind of a convenience function for generate surface.
WPropColor m_surfaceColor
Property determining the color for the surface if no textures are displayed.
Definition: WMIsosurface.h:136
WPropBool m_useTextureProp
Property indicating whether to use texturing with scalar data sets.
Definition: WMIsosurface.h:135
~WMIsosurface()
Destructor.
WPropInt m_opacityProp
Property holding the opacity valueassigned to the surface.
Definition: WMIsosurface.h:134
static const unsigned int m_edgeTable[256]
Lookup table for edges used in the construction of the isosurface.
Definition: WMIsosurface.h:151
WPropDouble m_isoValueProp
Property holding the iso value.
Definition: WMIsosurface.h:133
Class representing a single module of OpenWalnut.
Definition: WModule.h:72