Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
VolumeMeshNode.hh
1 /*===========================================================================*\
2 * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40  \*===========================================================================*/
41 
42 /*===========================================================================*\
43 * *
44  * $Revision$ *
45  * $LastChangedBy$ *
46  * $Date$ *
47  * *
48  \*===========================================================================*/
49 
50 #ifndef VOLUMEMESHNODE_HH
51 #define VOLUMEMESHNODE_HH
52 
53 //== INCLUDES =================================================================
54 
55 #include <ACG/GL/gl.hh>
56 #include <ACG/Scenegraph/BaseNode.hh>
57 #include <ACG/Scenegraph/MaterialNode.hh>
58 #include <ACG/Scenegraph/DrawModes.hh>
59 #include <OpenVolumeMesh/Core/OpenVolumeMeshHandle.hh>
60 #include <OpenVolumeMesh/Core/BaseEntities.hh>
61 #include <OpenVolumeMesh/Attribs/StatusAttrib.hh>
62 #include <OpenVolumeMesh/Attribs/ColorAttrib.hh>
63 #include <OpenVolumeMesh/Attribs/NormalAttrib.hh>
64 #include <OpenVolumeMesh/Attribs/TexCoordAttrib.hh>
65 
66 #include "VolumeMeshBufferManager.hh"
67 #include "VolumeMeshDrawModesContainer.hh"
68 
69 
70 #include <ACG/GL/RenderObject.hh>
71 #include <ACG/GL/VertexDeclaration.hh>
72 #include <ACG/GL/IRenderer.hh>
73 
74 //== FORWARDDECLARATIONS ======================================================
75 
76 //== NAMESPACES ===============================================================
77 
78 namespace ACG {
79 namespace SceneGraph {
80 
81 //== CLASS DEFINITION =========================================================
82 
86 template<class VolumeMeshT>
87 class VolumeMeshNodeT: public BaseNode {
88 public:
89 
90  // typedefs for easy access
91  typedef VolumeMeshT VolumeMesh;
98 
99  typedef typename VolumeMeshT::PointT Vertex;
103 
105 
106 
108  VolumeMeshNodeT(const VolumeMesh& _mesh,
109  OpenVolumeMesh::StatusAttrib& _statusAttrib,
112  OpenVolumeMesh::TexCoordAttrib<Vec2f> &_texcoordAttrib,
113  const MaterialNode* _matNode, BaseNode* _parent = 0,
114  std::string _name = "<VolumeMeshNode>");
115 
118 
120  ACG_CLASSNAME(VolumeMeshNodeT)
121 
122 
124 
126  void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
127 
129  void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
130 
134  void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat);
135 
137  void pick(GLState& _state, PickTarget _target);
138 
139  // clear all cutplanes
140  void clear_cut_planes();
141 
142  // add a new cutplane
143  void add_cut_plane(const Plane& _p);
144  void add_cut_plane(const Vec3d& _p, const Vec3d& _n, const Vec3d& _xsize, const Vec3d& _ysize);
145 
146  // set shrinkage of cells
147  void set_scaling(double _scale);
148 
149  // Get scaling
150  double scaling() const { return scale_; }
151 
152  // Choose whether to visualize the boundary only
153  void set_boundary_only(bool _boundary);
154  bool boundary_only() const { return boundary_only_; }
155 
156  // Set translucency factor
157  void set_translucency_factor(float _factor) { translucency_factor_ = _factor; }
158  float translucency_factor() const { return translucency_factor_; }
159 
160  // Set whether to update the topology in next render pass
161  void set_topology_changed(bool _topology_changed);
162 
163  // Set whether to update the geometry in next render pass
164  void set_geometry_changed(bool _geom_changed);
165 
166  // Set whether to update the color in next render pass
167  void set_color_changed(bool _color_changed);
168 
169  // Set whether to update the texture in next render pass
170  void set_texture_changed(bool _texture_changed);
171 
172  // Set whether to update the selectopm in next render pass
173  void set_selection_changed(bool _selection_changed);
174 
175 private:
176 
178  void drawCells(GLState& _state, const DrawModes::DrawMode& _drawMode);
180  void drawFaces(GLState& _state, const DrawModes::DrawMode& _drawMode);
182  void drawEdges(GLState& _state, const DrawModes::DrawMode& _drawMode);
184  void drawVertices(GLState& _state, const DrawModes::DrawMode& _drawMode);
186  void drawSelection(GLState& _state, const DrawModes::DrawMode& _drawMode);
187 
189  void getCellRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat);
191  void getFaceRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat);
193  void getEdgeRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat);
195  void getVertexRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat);
196 
198  void getSelectionRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat);
199 
201  void invalidateAllBuffers();
208 
210  void pickVertices(GLState& _state);
212  void pickEdges(GLState& _state, unsigned int _offset);
214  void pickFaces(GLState& _state, unsigned int _offset);
216  void pickCells(GLState& _state, unsigned int _offset);
217 
219  void update_face_normals();
221  void update_vertex_normals();
222 
224  VolumeMeshNodeT(const VolumeMeshNodeT& _rhs);
225 
228 
229 private:
230 
231  const VolumeMesh& mesh_;
232 
233  double scale_;
234 
235  // Flag that indicates whether to render the boundary faces only
236  bool boundary_only_;
237 
238  // Translucency factor in [0, 1]
239  GLfloat translucency_factor_;
240 
241  // Hold color of selection
242  ACG::Vec4f selection_color_;
243 
244  OpenVolumeMesh::StatusAttrib& statusAttrib_;
247  OpenVolumeMesh::TexCoordAttrib<Vec2f>& texcoordAttrib_;
248 
249  const MaterialNode* materialNode_;
250 
251  VolumeMeshBufferManager<VolumeMeshT> cellsBufferManager_;
252  VolumeMeshBufferManager<VolumeMeshT> facesBufferManager_;
253  VolumeMeshBufferManager<VolumeMeshT> edgesBufferManager_;
254  VolumeMeshBufferManager<VolumeMeshT> verticesBufferManager_;
255 
256  VolumeMeshBufferManager<VolumeMeshT> cellSelectionBufferManager_;
257  VolumeMeshBufferManager<VolumeMeshT> faceSelectionBufferManager_;
258  VolumeMeshBufferManager<VolumeMeshT> edgeSelectionBufferManager_;
259  VolumeMeshBufferManager<VolumeMeshT> vertexSelectionBufferManager_;
260 
261  VolumeMeshBufferManager<VolumeMeshT> cellPickBufferManager_;
262  VolumeMeshBufferManager<VolumeMeshT> facePickBufferManager_;
263  VolumeMeshBufferManager<VolumeMeshT> edgePickBufferManager_;
264  VolumeMeshBufferManager<VolumeMeshT> vertexPickBufferManager_;
265 
266  VolumeMeshDrawModesContainer drawModes_;
267 
268  DrawModes::DrawMode lastDrawMode_;
269  DrawModes::DrawMode lastCellDrawMode_;
270  DrawModes::DrawMode lastFaceDrawMode_;
271  DrawModes::DrawMode lastEdgeDrawMode_;
272  DrawModes::DrawMode lastVertexDrawMode_;
273 
274  PickTarget lastPickTarget_;
275 
276  bool face_normals_calculated_;
277  bool vertex_normals_calculated_;
278 
279 };
280 
281 //=============================================================================
282 } // namespace SceneGraph
283 } // namespace ACG
284 //=============================================================================
285 #if defined(INCLUDE_TEMPLATES) && !defined(VOLUMEMESHNODET_CC)
286 #include "VolumeMeshNodeT.cc"
287 #endif
288 //=============================================================================
289 #endif // VOLUMEMESHNODE_HH
290 //=============================================================================
291 
VolumeMeshNodeT & operator=(const VolumeMeshNodeT &_rhs)
Assignment operator (not used)
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
void invalidateAllDrawBuffers()
invalidates all buffers used for normal rendering
PickTarget
What target to use for picking.
Definition: BaseNode.hh:99
void invalidateAllPickingBuffers()
invalidates all buffers used for picking
void pickEdges(GLState &_state, unsigned int _offset)
pick edges
void update_face_normals()
updates face normals
void drawEdges(GLState &_state, const DrawModes::DrawMode &_drawMode)
renders the edges or halfedges of the mesh
void drawSelection(GLState &_state, const DrawModes::DrawMode &_drawMode)
draw selected primitves
VolumeMeshNodeT(const VolumeMesh &_mesh, OpenVolumeMesh::StatusAttrib &_statusAttrib, OpenVolumeMesh::ColorAttrib< Vec4f > &_colorAttrib, OpenVolumeMesh::NormalAttrib< VolumeMesh > &_normalAttrib, OpenVolumeMesh::TexCoordAttrib< Vec2f > &_texcoordAttrib, const MaterialNode *_matNode, BaseNode *_parent=0, std::string _name="<VolumeMeshNode>")
Constructor.
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax)
update bounding box
void getVertexRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat)
adds render objects for drawing vertices to the given renderer
This class creates buffers that can be used to render open volume meshs.
DrawModes::DrawMode availableDrawModes() const
static name of this class
void drawCells(GLState &_state, const DrawModes::DrawMode &_drawMode)
renders the cells of the mesh
void invalidateAllBuffers()
invalidates all buffers
void getEdgeRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat)
adds render objects for drawing edges or halfedges to the given renderer
void update_vertex_normals()
updates vertex normals
void getFaceRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat)
adds render objects for drawing faces or halffaces to the given renderer
void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat)
Draws the object deferred.
void drawFaces(GLState &_state, const DrawModes::DrawMode &_drawMode)
renders the faces or halffaces of the mesh
void drawVertices(GLState &_state, const DrawModes::DrawMode &_drawMode)
renders the vertices of the mesh
void pick(GLState &_state, PickTarget _target)
picking
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode)
draw lines and normals
void pickVertices(GLState &_state)
pick vertices
void pickFaces(GLState &_state, unsigned int _offset)
pick faces
void pickCells(GLState &_state, unsigned int _offset)
pick cells
void getSelectionRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat)
adds render objects for drawing selected primitves to the given renderer
void invalidateAllSelectionBuffers()
invalidates all buffers used for rendering selected primitives
This class provides easy access to DrawModes supported by OpenVolumeMesh.
void getCellRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat)
adds render objects for drawing cells to the given renderer