Developer Documentation
MeshNode2T.hh
1 #pragma once
2 /*===========================================================================*\
3  * *
4  * OpenFlipper *
5  * Copyright (c) 2001-2015, RWTH-Aachen University *
6  * Department of Computer Graphics and Multimedia *
7  * All rights reserved. *
8  * www.openflipper.org *
9  * *
10  *---------------------------------------------------------------------------*
11  * This file is part of OpenFlipper. *
12  *---------------------------------------------------------------------------*
13  * *
14  * Redistribution and use in source and binary forms, with or without *
15  * modification, are permitted provided that the following conditions *
16  * are met: *
17  * *
18  * 1. Redistributions of source code must retain the above copyright notice, *
19  * this list of conditions and the following disclaimer. *
20  * *
21  * 2. Redistributions in binary form must reproduce the above copyright *
22  * notice, this list of conditions and the following disclaimer in the *
23  * documentation and/or other materials provided with the distribution. *
24  * *
25  * 3. Neither the name of the copyright holder nor the names of its *
26  * contributors may be used to endorse or promote products derived from *
27  * this software without specific prior written permission. *
28  * *
29  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
30  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
31  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
32  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
33  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
34  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
35  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
36  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
37  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
38  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
39  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
40  * *
41 \*===========================================================================*/
42 
43 
44 //=============================================================================
45 //
46 // CLASS MeshNodeT
47 //
48 //=============================================================================
49 
50 //== INCLUDES =================================================================
51 
52 
53 
54 #include "BaseNode.hh"
55 #include <vector>
56 #include <ACG/GL/DrawMesh.hh>
57 #include <ACG/ShaderUtils/GLSLShader.hh>
58 #include <OpenMesh/Core/Mesh/DefaultTriMesh.hh>
59 #include <OpenMesh/Core/Mesh/DefaultPolyMesh.hh>
60 
61 //== NAMESPACES ===============================================================
62 
63 
64 namespace ACG {
65 namespace SceneGraph {
66 
67 
68 //== CLASS DEFINITION =========================================================
69 
70 
73 class ACGDLLEXPORT MeshNodeBase : public BaseNode {
74  protected:
75  MeshNodeBase(BaseNode* _parent, std::string _name);
76 
77  void supplyDrawMesh(DrawMeshBase *drawMeshBase);
78 
79  public:
80  void updatePolyEdgeBuf();
81 
82  protected:
83 
84  DrawMeshBase *drawMeshBase_;
85 
86  // poly edge buffer used for wireframe/hiddenline rendering with barycentric interpolation in geometry shader
87  GLuint polyEdgeBuf_;
88 
89  // size in bytes of the poly edge buffer
90  int polyEdgeBufSize_;
91 
92  // texture object for polyEdgeBuf
93  GLuint polyEdgeBufTex_;
94 };
95 
96 
97 
103 template <class Mesh>
104 class MeshNodeT : public MeshNodeBase
105 {
106 public:
107  ACG_CLASSNAME(MeshNode);
108 
113  MeshNodeT( Mesh& _mesh,
114  BaseNode* _parent=0,
115  const std::string& _name="<MeshNode>" );
116 
118  virtual ~MeshNodeT();
119 
120 
126  void update_geometry();
127 
135  void update_topology();
136 
144  void update_color();
145 
150  void update_textures();
151 
152 private:
153 
158  typedef typename Mesh::Point Point;
159  typedef typename Point::value_type PointScalar;
160  typedef typename Mesh::Normal Normal;
161  typedef typename Normal::value_type NormalScalar;
162  typedef typename Mesh::Color Color;
163  typedef typename Color::value_type ColorScalar;
164 
165 //===========================================================================
168 //===========================================================================
169 
170 public:
171 
174  const Mesh& mesh() const { return mesh_; }
175 
176 private:
179 
182 //===========================================================================
185 //===========================================================================
186 private:
187  DrawMeshT<Mesh>* drawMesh_;
188 
193 //===========================================================================
196 //===========================================================================
197 
198 public:
199 
204  void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax) override;
205 
206 private:
207 
210 
213 
216 //===========================================================================
219 //===========================================================================
220 
221 public:
223  bool normalsEnabled() { return enableNormals_; };
224 
226  void enableNormals(bool _enable) { enableNormals_ = _enable; };
227 
228 private:
229 
231  bool enableNormals_;
232 
235 //===========================================================================
238 //===========================================================================
239 public:
241  bool colorsEnabled() { return enableColors_; };
242 
244  void enableColors(bool _enable) { enableColors_ = _enable; };
245 
246 private:
247 
248  bool enableColors_;
249 
252 //===========================================================================
255 //===========================================================================
256 
257 public:
258 
264  void enable_arrays(unsigned int _arrays);
265 
266 private:
267 
270  {
271  NONE = 0,
272  PER_EDGE_VERTEX_ARRAY = 1,
273  PER_EDGE_COLOR_ARRAY = 2,
274  PER_HALFEDGE_VERTEX_ARRAY = 4,
275  PER_HALFEDGE_COLOR_ARRAY = 8
276  };
277 
279  unsigned int enabled_arrays_;
280 
281 
282 //===========================================================================
285 //===========================================================================
286 
287 public:
291  void draw(GLState& _state, const DrawModes::DrawMode& _drawMode) override;
292 
296  void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat) override;
297 
298 
301  DrawMeshT<Mesh>* getDrawMesh();
302 
303 
309  ACG::SceneGraph::DrawModes::DrawMode availableDrawModes() const override;
310 
311 private:
312 
316  inline void draw_vertices();
317 
318  inline void add_point_RenderObjects(IRenderer* _renderer, const RenderObject* _baseObj);
319 
323  inline void draw_lines();
324 
328  inline void draw_halfedges();
329 
330 
334  void draw_faces();
335 
336  void add_face_RenderObjects(IRenderer* _renderer, const RenderObject* _baseObj, bool _nonindexed = false);
337 
338 private:
339 
343 //===========================================================================
346 //===========================================================================
347 public:
351  void pick(GLState& _state, PickTarget _target) override;
352 
355 //===========================================================================
358 //===========================================================================
359 
360 private:
361 
365  void pick_vertices(GLState& _state, bool _front = false);
366 
369 
372 
376 //===========================================================================
379 //===========================================================================
380 
381 
382 private:
386  void pick_edges(GLState& _state, bool _front = false);
387 
390 
393 
394 
397 //===========================================================================
400 //===========================================================================
401 
402 
403 private:
407  void pick_faces(GLState& _state);
408 
411 
414 
415 
418 //===========================================================================
421 //===========================================================================
422 
423 private:
424 
428  void pick_any(GLState& _state);
429 
432 
435 
439 //===========================================================================
442 //===========================================================================
443 public:
456  void setIndexPropertyName( std::string _indexPropertyName );
457 
459  const std::string& indexPropertyName() const;
460 
461 
467  void setHalfedgeTextcoordPropertyName( std::string _halfedgeTextcoordPropertyName );
468 
469  public:
470 
478  void setTextureMap( std::map< int, GLuint>* _map){ textureMap_ = _map; };
479 
480 private:
481 
483  bool perFaceTextureIndexAvailable_;
484 
486  std::map< int, GLuint>* textureMap_;
487 
490 
492 public:
493  void set_property_map( std::map< int, std::string>* _map){ };
494 
495 
498  unsigned int getMemoryUsage();
499 
500 private:
501  bool draw_with_offset_;
502 
503 public:
504  void set_offset(bool enable) { draw_with_offset_ = enable; }
505 };
506 
507 // defined in MeshNode2T_impl.cc:
508 extern template class MeshNodeT<::OpenMesh::TriMesh>;
509 extern template class MeshNodeT<::OpenMesh::PolyMesh>;
510 
511 //=============================================================================
512 } // namespace SceneGraph
513 } // namespace ACG
514 //=============================================================================
Kernel::Color Color
Color type.
Definition: PolyMeshT.hh:116
bool updateVertexPicking_
Flag indicating if the vertex picking has to be updated.
Definition: MeshNode2T.hh:368
Kernel::Normal Normal
Normal type.
Definition: PolyMeshT.hh:114
Namespace providing different geometric functions concerning angles.
void set_property_map(std::map< int, std::string > *_map)
Definition: MeshNode2T.hh:493
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:112
bool updateEdgePicking_
Flag indicating if the edge picking has to be updated.
Definition: MeshNode2T.hh:389
Class to define the vertex input layout.
bool updateFacePicking_
Flag indicating if the edge picking has to be updated.
Definition: MeshNode2T.hh:410
unsigned int enabled_arrays_
which arrays are currently enabled?
Definition: MeshNode2T.hh:279
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
Vec3d bbMin_
bounding box lower left corner
Definition: MeshNode2T.hh:209
Add colors to mesh item (vertices/faces/edges)
Definition: Attributes.hh:83
size_t facePickingBaseIndex_
Index of the first face in facepicking.
Definition: MeshNode2T.hh:413
size_t vertexPickingBaseIndex_
Index of the first vertex in vertexpicking.
Definition: MeshNode2T.hh:371
size_t edgePickingBaseIndex_
Index of the first edge in edgepicking.
Definition: MeshNode2T.hh:392
Vec3d bbMax_
bounding box upper right corner
Definition: MeshNode2T.hh:212
bool colorsEnabled()
Returns if the color array is currently activated.
Definition: MeshNode2T.hh:241
std::map< int, GLuint > * textureMap_
Mapping of mesh face texture indices to gltexture id ( has to be provided externally ) ...
Definition: MeshNode2T.hh:486
ArrayType
Enum controlling which array should be used for rendering.
Definition: MeshNode2T.hh:269
Mesh Drawing Class.
Definition: DrawMesh.hh:171
const Mesh & mesh() const
get the internal mesh
Definition: MeshNode2T.hh:174
void setTextureMap(std::map< int, GLuint > *_map)
Setup a mapping between internal texture ids on the mesh and the ids for the loaded textures in openg...
Definition: MeshNode2T.hh:478
bool enableColors_
Returns if the color array is currently activated.
Definition: MeshNode2T.hh:244
bool normalsEnabled()
Returns if the normal array is currently activated.
Definition: MeshNode2T.hh:223
bool updateAnyPicking_
Flag indicating if the any picking has to be updated.
Definition: MeshNode2T.hh:431
VertexDeclaration halfedgeDecl
Draws the object.
Definition: MeshNode2T.hh:340
bool enableNormals_
Flag if normals should be used.
Definition: MeshNode2T.hh:226
Interface class between scenegraph and renderer.
Definition: RenderObject.hh:98
size_t anyPickingBaseIndex_
Index of the first face in anypicking.
Definition: MeshNode2T.hh:434
Mesh & mesh_
The mesh this node works on.
Definition: MeshNode2T.hh:178