OpenWalnut  1.5.0dev
WMTriangleMeshRenderer.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 WMTRIANGLEMESHRENDERER_H
26 #define WMTRIANGLEMESHRENDERER_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 ~WMTriangleMeshRenderer();
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  * Calculates the center point of a given interval. This simply is \f$x_{min} + \frac{x_{max} - x_{min}}{2}\f$.
132  *
133  * \param min interval min
134  * \param max interval max
135  *
136  * \return interval center
137  */
138  double getIntervallCenterMiddle( double min, double max ) const;
139 
140  /**
141  * Center of the mesh. Needed for applying transformation with the mesh in (0,0,0).
142  */
144 
145  /**
146  * Enables mesh's coordinate system.
147  */
149 
150  /**
151  * Group for all color and colormapping options.
152  */
153  WPropGroup m_coloringGroup;
154 
155  /**
156  * Turn Colormapping on/off
157  */
158  WPropBool m_colormap;
159 
160  /**
161  * Set Colormap Ratio
162  */
163  WPropDouble m_colormapRatio;
164 
165  /**
166  * A condition used to notify about changes in several properties.
167  */
168  std::shared_ptr< WCondition > m_propCondition;
169 
170  /**
171  * An input connector used to get meshes from other modules. The connection management between connectors must not be handled by the module.
172  */
173  std::shared_ptr< WModuleInputData< WTriangleMesh > > m_meshInput;
174 
175  /**
176  * A map for mapping each vertex to a color.
177  */
178  std::shared_ptr< WModuleInputData< WColoredVertices > > m_colorMapInput;
179 
180  /**
181  * A group wich contains all transformation tools.
182  */
184 
185  /**
186  * Set the transformation tool to default
187  */
188  WPropTrigger m_setDefault;
189 
190  /**
191  * Render the mesh
192  *
193  * \param mesh The mesh to be rendered.
194  */
195  void renderMesh( std::shared_ptr< WTriangleMesh > mesh );
196 
197  /**
198  * Set the transformation tool to default
199  */
200  void setToDefault();
201 
202  /**
203  * OSG Uniform for the transformation matrix which transforms the mesh. Needed for the colormapper
204  */
205  osg::ref_ptr< osg::Uniform > m_colorMapTransformation;
206 
207  /**
208  * The mesh's opacity value.
209  */
210  WPropDouble m_opacity;
211 
212  /**
213  * If true, the mesh scale properties are linked.
214  */
215  WPropBool m_scale;
216 
217  /**
218  * The mesh's scale value in X direction.
219  */
220  WPropDouble m_scaleX;
221 
222  /**
223  * The mesh's scale value in Y direction.
224  */
225  WPropDouble m_scaleY;
226 
227  /**
228  * The mesh's scale value in Z direction.
229  */
230  WPropDouble m_scaleZ;
231 
232  /**
233  * The mesh's rotate value around X.
234  */
235  WPropDouble m_rotateX;
236 
237  /**
238  * The mesh's rotate value around Y.
239  */
240  WPropDouble m_rotateY;
241 
242  /**
243  * The mesh's rotate value around Z.
244  */
245  WPropDouble m_rotateZ;
246 
247  /**
248  * The mesh's translate value along X.
249  */
250  WPropDouble m_translateX;
251 
252  /**
253  * The mesh's translate value along X.
254  */
255  WPropDouble m_translateY;
256 
257  /**
258  * The mesh's translate value along X.
259  */
260  WPropDouble m_translateZ;
261 
262  /**
263  * Which rendering mode should be used?
264  */
265  WPropSelection m_renderingMode;
266 
267  /**
268  * Toggle showing outline instead fo surface.
269  */
270  WPropBool m_showOutline;
271 
272  /**
273  * En/Disable display of only the main component (biggest vertices number)
274  */
276 
277  /**
278  * The color of the mesh to be rendered.
279  */
280  WPropColor m_color;
281 
282  /**
283  * Which color mode should be used?
284  */
285  WPropSelection m_colorMode;
286 
287  WPropInt m_nbTriangles; //!< Info-property showing the number of triangles in the mesh.
288  WPropInt m_nbVertices; //!< Info-property showing the number of vertices in the mesh.
289 
290  /**
291  * Updates the transformation matrix of the main node. Called every frame.
292  */
293  void updateTransformation();
294 
295  /**
296  * The node containing all geometry nodes.
297  */
299 
300  /**
301  * The shader for the mesh
302  */
303  osg::ref_ptr< WGEShader > m_shader;
304 };
305 
306 #endif // WMTRIANGLEMESHRENDERER_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_mainComponentOnly
En/Disable display of only the main component (biggest vertices number)
void renderMesh(std::shared_ptr< WTriangleMesh > mesh)
Render the mesh.
WPropInt m_nbTriangles
Info-property showing the number of triangles in the mesh.
osg::ref_ptr< osg::Uniform > m_colorMapTransformation
OSG Uniform for the transformation matrix which transforms the mesh.
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.
virtual const std::string getDescription() const
Gives back a description of this module.
double getIntervallCenterMiddle(double min, double max) const
Calculates the center point of a given interval.
WPropBool m_showCoordinateSystem
Enables mesh's coordinate system.
WPropDouble m_scaleY
The mesh's scale value in Y direction.
WPropGroup m_groupTransformation
A group wich contains all transformation tools.
void setToDefault()
Set the transformation tool to default.
WPropGroup m_coloringGroup
Group for all color and colormapping options.
WPropDouble m_scaleZ
The mesh's scale value in Z direction.
virtual void connectors()
Initialize the connectors this module is using.
WPropDouble m_rotateY
The mesh's rotate value around Y.
void updateTransformation()
Updates the transformation matrix of the main node.
virtual const std::string getName() const
Gives back the name of this module.
WPropDouble m_translateY
The mesh's translate value along X.
WPropDouble m_opacity
The mesh's opacity value.
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.
WPropDouble m_translateX
The mesh's translate value along X.
WPropDouble m_scaleX
The mesh's scale value in X direction.
WPropDouble m_colormapRatio
Set Colormap Ratio.
WGEManagedGroupNode::SPtr m_moduleNode
The node containing all geometry nodes.
WPropBool m_colormap
Turn Colormapping on/off.
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.
std::shared_ptr< WModuleInputData< WColoredVertices > > m_colorMapInput
A map for mapping each vertex to a color.
virtual ~WMTriangleMeshRenderer()
Destructor.
WPropDouble m_translateZ
The mesh's translate value along X.
WPropInt m_nbVertices
Info-property showing the number of vertices in the mesh.
WVector3d m_meshCenter
Center of the mesh.
WPropColor m_color
The color of the mesh to be rendered.
virtual void properties()
Initialize the properties for this module.
double getMedian(double x, double y, double z) const
Gets the median of three values.
WPropSelection m_renderingMode
Which rendering mode should be used?
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...
WPropSelection m_colorMode
Which color mode should be used?
WPropBool m_scale
If true, the mesh scale properties are linked.
WPropTrigger m_setDefault
Set the transformation tool to default.
WPropDouble m_rotateX
The mesh's rotate value around X.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
virtual void moduleMain()
Entry point after loading the module.
WPropDouble m_rotateZ
The mesh's rotate value around Z.
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