Developer Documentation
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 #pragma once
43 
44 //== INCLUDES =================================================================
45 
46 #include <ACG/GL/gl.hh>
47 #include <ACG/Scenegraph/BaseNode.hh>
48 #include <ACG/Scenegraph/MaterialNode.hh>
49 #include <ACG/Scenegraph/DrawModes.hh>
50 #include <ACG/Geometry/Types/PlaneType.hh>
51 #include <OpenVolumeMesh/Core/OpenVolumeMeshHandle.hh>
52 #include <OpenVolumeMesh/Core/BaseEntities.hh>
53 #include <OpenVolumeMesh/Attribs/StatusAttrib.hh>
54 #include <OpenVolumeMesh/Attribs/ColorAttrib.hh>
55 #include <OpenVolumeMesh/Attribs/NormalAttrib.hh>
56 #include <OpenVolumeMesh/Attribs/TexCoordAttrib.hh>
57 
58 #include "VolumeMeshBufferManager.hh"
59 #include "VolumeMeshDrawModesContainer.hh"
60 
61 
62 #include <ACG/GL/RenderObject.hh>
63 #include <ACG/GL/VertexDeclaration.hh>
64 #include <ACG/GL/IRenderer.hh>
65 
66 //== FORWARDDECLARATIONS ======================================================
67 
68 //== NAMESPACES ===============================================================
69 
70 namespace ACG {
71 namespace SceneGraph {
72 
73 //== CLASS DEFINITION =========================================================
74 
78 template<class VolumeMeshT>
79 class VolumeMeshNodeT: public BaseNode {
80 public:
81 
82  // typedefs for easy access
83  typedef VolumeMeshT VolumeMesh;
90 
91  typedef typename VolumeMeshT::PointT Vertex;
95 
97 
98 
100  VolumeMeshNodeT(const VolumeMesh& _mesh,
101  OpenVolumeMesh::StatusAttrib& _statusAttrib,
104  OpenVolumeMesh::TexCoordAttrib<Vec2f> &_texcoordAttrib,
105  const MaterialNode* _matNode, BaseNode* _parent = 0,
106  std::string _name = "<VolumeMeshNode>");
107 
110 
112  ACG_CLASSNAME(VolumeMeshNodeT)
113 
114 
115  DrawModes::DrawMode availableDrawModes() const override;
116 
118  void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax) override;
119 
121  void draw(GLState& _state, const DrawModes::DrawMode& _drawMode) override;
122 
126  void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat) override;
127 
129  void pick(GLState& _state, PickTarget _target) override;
130 
131  // clear all cutplanes
132  void clear_cut_planes();
133 
134  // add a new cutplane
135  void add_cut_plane(const Plane& _p);
136  void add_cut_plane(const Vec3d& _p, const Vec3d& _n, const Vec3d& _xsize, const Vec3d& _ysize);
137 
138  // set shrinkage of cells
139  void set_scaling(double _scale);
140 
141  // Get scaling
142  double scaling() const { return scale_; }
143 
144  // Choose whether to visualize the boundary only
145  void set_boundary_only(bool _boundary);
146  bool boundary_only() const { return boundary_only_; }
147 
148  // Set translucency factor
149  void set_translucency_factor(float _factor) { translucency_factor_ = _factor; }
150  float translucency_factor() const { return translucency_factor_; }
151 
152  // Set whether to update the topology in next render pass
153  void set_topology_changed(bool _topology_changed);
154 
155  // Set whether to update the geometry in next render pass
156  void set_geometry_changed(bool _geom_changed);
157 
158  // Set whether to update the color in next render pass
159  void set_color_changed(bool _color_changed);
160 
161  // Set whether to update the texture in next render pass
162  void set_texture_changed(bool _texture_changed);
163 
164  // Set whether to update the selectopm in next render pass
165  void set_selection_changed(bool _selection_changed);
166 
167 private:
168 
170  void drawCells(GLState& _state, const DrawModes::DrawMode& _drawMode);
172  void drawFaces(GLState& _state, const DrawModes::DrawMode& _drawMode);
174  void drawEdges(GLState& _state, const DrawModes::DrawMode& _drawMode);
176  void drawVertices(GLState& _state, const DrawModes::DrawMode& _drawMode);
178  void drawSelection(GLState& _state, const DrawModes::DrawMode& _drawMode);
179 
181  void getCellRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat);
183  void getFaceRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat);
185  void getEdgeRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat);
187  void getVertexRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat);
188 
190  void getSelectionRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat);
191 
193  void invalidateAllBuffers();
200 
202  void pickVertices(GLState& _state);
204  void pickEdges(GLState& _state, unsigned int _offset);
206  void pickFaces(GLState& _state, unsigned int _offset);
208  void pickCells(GLState& _state, unsigned int _offset);
210  void pickVerticesCompat(GLState& _state);
212  void pickEdgesCompat(GLState& _state, unsigned int _offset);
214  void pickFacesCompat(GLState& _state, unsigned int _offset);
216  void pickCellsCompat(GLState& _state, unsigned int _offset);
218  void pickCompat(GLState& _state, PickTarget _target);
219 
221  void update_face_normals();
223  void update_vertex_normals();
224 
226  VolumeMeshNodeT(const VolumeMeshNodeT& _rhs);
227 
230 
231 private:
232 
233  const VolumeMesh& mesh_;
234 
235  double scale_;
236 
237  // Flag that indicates whether to render the boundary faces only
238  bool boundary_only_;
239 
240  // Translucency factor in [0, 1]
241  GLfloat translucency_factor_;
242 
243  // Hold color of selection
244  ACG::Vec4f selection_color_;
245 
246  OpenVolumeMesh::StatusAttrib& statusAttrib_;
249  OpenVolumeMesh::TexCoordAttrib<Vec2f>& texcoordAttrib_;
250 
251  const MaterialNode* materialNode_;
252 
253  VolumeMeshBufferManager<VolumeMeshT> cellsBufferManager_;
254  VolumeMeshBufferManager<VolumeMeshT> facesBufferManager_;
255  VolumeMeshBufferManager<VolumeMeshT> edgesBufferManager_;
256  VolumeMeshBufferManager<VolumeMeshT> verticesBufferManager_;
257 
258  VolumeMeshBufferManager<VolumeMeshT> cellSelectionBufferManager_;
259  VolumeMeshBufferManager<VolumeMeshT> faceSelectionBufferManager_;
260  VolumeMeshBufferManager<VolumeMeshT> edgeSelectionBufferManager_;
261  VolumeMeshBufferManager<VolumeMeshT> vertexSelectionBufferManager_;
262 
263  VolumeMeshBufferManager<VolumeMeshT> cellPickBufferManager_;
264  VolumeMeshBufferManager<VolumeMeshT> facePickBufferManager_;
265  VolumeMeshBufferManager<VolumeMeshT> edgePickBufferManager_;
266  VolumeMeshBufferManager<VolumeMeshT> vertexPickBufferManager_;
267 
268  VolumeMeshDrawModesContainer drawModes_;
269 
270  DrawModes::DrawMode lastDrawMode_;
271  DrawModes::DrawMode lastCellDrawMode_;
272  DrawModes::DrawMode lastFaceDrawMode_;
273  DrawModes::DrawMode lastEdgeDrawMode_;
274  DrawModes::DrawMode lastVertexDrawMode_;
275 
276  PickTarget lastPickTarget_;
277 
278  bool face_normals_calculated_;
279  bool vertex_normals_calculated_;
280 
281 };
282 
283 //=============================================================================
284 } // namespace SceneGraph
285 } // namespace ACG
286 //=============================================================================
287 
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode) override
draw lines and normals
void pickEdges(GLState &_state, unsigned int _offset)
pick edges
void pickVerticesCompat(GLState &_state)
pick vertices using opengl compatibility profile
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 drawFaces(GLState &_state, const DrawModes::DrawMode &_drawMode)
renders the faces or halffaces of the mesh
void pickCompat(GLState &_state, PickTarget _target)
picking using opengl compatibility profile
void pickCellsCompat(GLState &_state, unsigned int _offset)
pick cells using opengl compatibility profile
Namespace providing different geometric functions concerning angles.
void pick(GLState &_state, PickTarget _target) override
picking
void pickCells(GLState &_state, unsigned int _offset)
pick cells
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.
This class provides easy access to DrawModes supported by OpenVolumeMesh.
VolumeMeshNodeT & operator=(const VolumeMeshNodeT &_rhs)
Assignment operator (not used)
void getCellRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat)
adds render objects for drawing cells to the given renderer
void pickFacesCompat(GLState &_state, unsigned int _offset)
pick faces using opengl compatibility profile
void getVertexRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat)
adds render objects for drawing vertices to the given renderer
void invalidateAllSelectionBuffers()
invalidates all buffers used for rendering selected primitives
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
void drawCells(GLState &_state, const DrawModes::DrawMode &_drawMode)
renders the cells of the mesh
void pickFaces(GLState &_state, unsigned int _offset)
pick faces
void update_vertex_normals()
updates vertex normals
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 pickEdgesCompat(GLState &_state, unsigned int _offset)
pick edges using opengl compatibility profile
void pickVertices(GLState &_state)
pick vertices
void invalidateAllDrawBuffers()
invalidates all buffers used for normal rendering
void drawSelection(GLState &_state, const DrawModes::DrawMode &_drawMode)
draw selected primitves
DrawModes::DrawMode availableDrawModes() const override
static name of this class
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax) override
update bounding box
void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat) override
Draws the object deferred.
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 invalidateAllPickingBuffers()
invalidates all buffers used for picking
void drawEdges(GLState &_state, const DrawModes::DrawMode &_drawMode)
renders the edges or halfedges of the mesh
void invalidateAllBuffers()
invalidates all buffers
void drawVertices(GLState &_state, const DrawModes::DrawMode &_drawMode)
renders the vertices of the mesh
void update_face_normals()
updates face normals