OpenWalnut  1.5.0dev
WMSurfaceIllustrator.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 WMSURFACEILLUSTRATOR_H
26 #define WMSURFACEILLUSTRATOR_H
27 
28 #include <memory>
29 #include <string>
30 
31 #include <osg/Uniform>
32 
33 #include "core/common/datastructures/WColoredVertices.h"
34 #include "core/common/math/linearAlgebra/WVectorFixed.h"
35 #include "core/graphicsEngine/WGEManagedGroupNode.h"
36 #include "core/kernel/WModule.h"
37 #include "core/kernel/WModuleInputData.h"
38 #include "core/kernel/WModuleOutputData.h"
39 
40 
41 class WTriangleMesh;
42 class WGEShader;
43 
44 /**
45  * This module renders the triangle mesh given at its input connector
46  * as a surface.
47  *
48  * \ingroup modules
49  */
51 {
52 public:
53  /**
54  * Constructor. Creates the module skeleton.
55  */
57 
58  /**
59  * Destructor.
60  */
61  virtual ~WMSurfaceIllustrator();
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 private:
106  /**
107  * Calculates the bounding box of a vector and increases the specified one if needed.
108  *
109  * \param minX old maximum X and gets overwritten by new one
110  * \param maxX old maximum Y and gets overwritten by new one
111  * \param minY old minimum Z and gets overwritten by new one
112  * \param maxY old maximum X and gets overwritten by new one
113  * \param minZ old maximum Y and gets overwritten by new one
114  * \param maxZ old maximum Z and gets overwritten by new one
115  * \param vector the new vector to include in bbox calculation.
116  */
117  void updateMinMax( double& minX, double& maxX, double& minY, double& maxY, double& minZ, double& maxZ, const osg::Vec3d& vector ) const;
118 
119  /**
120  * Gets the median of three values.
121  *
122  * \param x first value
123  * \param y second value
124  * \param z third value
125  *
126  * \return the median of x,y,z
127  */
128  double getMedian( double x, double y, double z ) const;
129 
130  /**
131  * Center of the mesh. Needed for applying transformation with the mesh in (0,0,0).
132  */
134 
135  /**
136  * Group for all color and colormapping options.
137  */
138  WPropGroup m_coloringGroup;
139 
140  /**
141  * Turn Colormapping on/off
142  */
143  WPropBool m_colormap;
144 
145  /**
146  * Set center of selected surface parameter
147  */
148  WPropDouble m_parameterCenter;
149 
150  /**
151  * Set width of selected surface parameter interval
152  */
153  WPropDouble m_parameterWidth;
154 
155  /**
156  * Select the type of illustration applied in the shader
157  */
158  WPropSelection m_illustrationMode;
159 
160  /**
161  * A condition used to notify about changes in several properties.
162  */
163  std::shared_ptr< WCondition > m_propCondition;
164 
165  /**
166  * An input connector used to get meshes from other modules. The connection management between connectors must not be handled by the module.
167  */
168  std::shared_ptr< WModuleInputData< WTriangleMesh > > m_meshInput;
169 
170  /**
171  * A map for mapping each vertex to a color.
172  */
173  std::shared_ptr< WModuleInputData< WColoredVertices > > m_colorMapInput;
174 
175  /**
176  * A group wich contains all transformation tools.
177  */
179 
180  /**
181  * Set the transformation tool to default
182  */
183  WPropTrigger m_setDefault;
184 
185  /**
186  * Render the mesh
187  *
188  * \param mesh The mesh to be rendered.
189  */
190  void renderMesh( std::shared_ptr< WTriangleMesh > mesh );
191  /**
192  * OSG Uniform for the transformation matrix which transforms the mesh. Needed for the colormapper
193  */
194  osg::ref_ptr< osg::Uniform > m_colorMapTransformation;
195 
196  /**
197  * The mesh's opacity value.
198  */
199  WPropDouble m_opacity;
200 
201  /**
202  * Toggle showing outline instead fo surface.
203  */
204  WPropBool m_showOutline;
205 
206  /**
207  * The color of the mesh to be rendered.
208  */
209  WPropColor m_color;
210 
211  /**
212  * Which colormode should be used?
213  */
214  WPropSelection m_colorMode;
215 
216  WPropInt m_nbTriangles; //!< Info-property showing the number of triangles in the mesh.
217  WPropInt m_nbVertices; //!< Info-property showing the number of vertices in the mesh.
218 
219  /**
220  * The node containing all geometry nodes.
221  */
223 
224  /**
225  * The shader for the mesh
226  */
227  osg::ref_ptr< WGEShader > m_shader;
228 };
229 
230 #endif // WMSURFACEILLUSTRATOR_H
osg::ref_ptr< WGEManagedGroupNode > SPtr
Shared pointer.
Class encapsulating the OSG Program class for a more convenient way of adding and modifying shader.
Definition: WGEShader.h:48
This module renders the triangle mesh given at its input connector as a surface.
WPropBool m_colormap
Turn Colormapping on/off.
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
WPropBool m_showOutline
Toggle showing outline instead fo surface.
WPropInt m_nbTriangles
Info-property showing the number of triangles in the mesh.
WPropTrigger m_setDefault
Set the transformation tool to default.
WPropSelection m_colorMode
Which colormode should be used?
osg::ref_ptr< osg::Uniform > m_colorMapTransformation
OSG Uniform for the transformation matrix which transforms the mesh.
std::shared_ptr< WModuleInputData< WColoredVertices > > m_colorMapInput
A map for mapping each vertex to a color.
WGEManagedGroupNode::SPtr m_moduleNode
The node containing all geometry nodes.
WPropInt m_nbVertices
Info-property showing the number of vertices in the mesh.
virtual void properties()
Initialize the properties for this module.
virtual const std::string getDescription() const
Gives back a description of this module.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
void renderMesh(std::shared_ptr< WTriangleMesh > mesh)
Render the mesh.
void updateMinMax(double &minX, double &maxX, double &minY, double &maxY, double &minZ, double &maxZ, const osg::Vec3d &vector) const
Calculates the bounding box of a vector and increases the specified one if needed.
WPropGroup m_groupTransformation
A group wich contains all transformation tools.
WPropColor m_color
The color of the mesh to be rendered.
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...
virtual void connectors()
Initialize the connectors this module is using.
WMSurfaceIllustrator()
Constructor.
WPropDouble m_parameterWidth
Set width of selected surface parameter interval.
WPropDouble m_parameterCenter
Set center of selected surface parameter.
virtual void moduleMain()
Entry point after loading the module.
WPropDouble m_opacity
The mesh's opacity value.
osg::ref_ptr< WGEShader > m_shader
The shader for the mesh.
std::shared_ptr< WModuleInputData< WTriangleMesh > > m_meshInput
An input connector used to get meshes from other modules.
double getMedian(double x, double y, double z) const
Gets the median of three values.
WPropSelection m_illustrationMode
Select the type of illustration applied in the shader.
virtual ~WMSurfaceIllustrator()
Destructor.
WVector3d m_meshCenter
Center of the mesh.
WPropGroup m_coloringGroup
Group for all color and colormapping options.
virtual const std::string getName() const
Gives back the name of this module.
Class representing a single module of OpenWalnut.
Definition: WModule.h:72
Triangle mesh data structure allowing for convenient access of the elements.
Definition: WTriangleMesh.h:46