Developer Documentation
Loading...
Searching...
No Matches
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
64namespace ACG {
65namespace SceneGraph {
66
67
68//== CLASS DEFINITION =========================================================
69
70
73class 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
103template <class Mesh>
105{
106public:
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
152private:
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
170public:
171
174 const Mesh& mesh() const { return mesh_; }
175
176private:
179
182//===========================================================================
185//===========================================================================
186private:
187 DrawMeshT<Mesh>* drawMesh_;
188
193//===========================================================================
196//===========================================================================
197
198public:
199
204 void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax) override;
205
206private:
207
210
213
216//===========================================================================
219//===========================================================================
220
221public:
223 bool normalsEnabled() { return enableNormals_; };
224
226 void enableNormals(bool _enable) { enableNormals_ = _enable; };
227
228private:
229
232
235//===========================================================================
238//===========================================================================
239public:
241 bool colorsEnabled() { return enableColors_; };
242
244 void enableColors(bool _enable) { enableColors_ = _enable; };
245
246private:
247
249
252//===========================================================================
255//===========================================================================
256
257public:
258
264 void enable_arrays(unsigned int _arrays);
265
266private:
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
287public:
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
302
303
310
311private:
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
338private:
339
343//===========================================================================
346//===========================================================================
347public:
351 void pick(GLState& _state, PickTarget _target) override;
352
355//===========================================================================
358//===========================================================================
359
360private:
361
365 void pick_vertices(GLState& _state, bool _front = false);
366
369
372
376//===========================================================================
379//===========================================================================
380
381
382private:
386 void pick_edges(GLState& _state, bool _front = false);
387
390
393
394
397//===========================================================================
400//===========================================================================
401
402
403private:
407 void pick_faces(GLState& _state);
408
411
414
415
418//===========================================================================
421//===========================================================================
422
423private:
424
428 void pick_any(GLState& _state);
429
432
435
439//===========================================================================
442//===========================================================================
443public:
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
480private:
481
484
486 std::map< int, GLuint>* textureMap_;
487
491
492public:
493 void set_property_map( std::map< int, std::string>* _map){ };
494
495
498 unsigned int getMemoryUsage();
499
500private:
501 bool draw_with_offset_;
502
503public:
504 void set_offset(bool enable) { draw_with_offset_ = enable; }
505};
506
507// defined in MeshNode2T_impl.cc:
508extern template class MeshNodeT<::OpenMesh::TriMesh>;
509extern template class MeshNodeT<::OpenMesh::PolyMesh>;
510
511//=============================================================================
512} // namespace SceneGraph
513} // namespace ACG
514//=============================================================================
Mesh Drawing Class.
Definition DrawMesh.hh:172
bool normalsEnabled()
Returns if the normal array is currently activated.
void setHalfedgeTextcoordPropertyName(std::string _halfedgeTextcoordPropertyName)
Set the name of the per face texture coordinate property.
void update_color()
the colors of the mesh have changed
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...
virtual ~MeshNodeT()
Destructor.
void pick(GLState &_state, PickTarget _target) override
Draws the object in picking mode.
ArrayType
Enum controlling which array should be used for rendering.
void enableColors(bool _enable)
Enable or disable the use of color array.
void draw_halfedges()
draws all halfedges of the mesh
unsigned int enabled_arrays_
which arrays are currently enabled?
void add_face_RenderObjects(IRenderer *_renderer, const RenderObject *_baseObj, bool _nonindexed=false)
Draws the object.
size_t anyPickingBaseIndex_
Index of the first face in anypicking.
Mesh & mesh_
The mesh this node works on.
const std::string & indexPropertyName() const
Get current texture index property name.
void set_property_map(std::map< int, std::string > *_map)
size_t facePickingBaseIndex_
Index of the first face in facepicking.
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode) override
Draws the object.
void pick_faces(GLState &_state)
Renders picking for faces _front: Only render front faces (not occluded by geometry)
DrawMeshT< Mesh > * getDrawMesh()
Get DrawMesh instance.
bool enableNormals_
Flag if normals should be used.
void enable_arrays(unsigned int _arrays)
enable/disable vertex arrays according to the bits in _arrays
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax) override
Current bounding box.
Vec3d bbMax_
bounding box upper right corner
void update_geometry()
the geometry of the mesh has changed
bool perFaceTextureIndexAvailable_
This flag indicates if we have a per Face texture index property.
const Mesh & mesh() const
get the internal mesh
void pick_any(GLState &_state)
Renders picking for all primitives.
unsigned int getMemoryUsage()
measures the size in bytes of allocated memory
ACG::SceneGraph::DrawModes::DrawMode availableDrawModes() const override
return available draw modes
void pick_edges(GLState &_state, bool _front=false)
Renders picking for edges _front: Only render front edges (not occluded by geometry)
bool updateEdgePicking_
Flag indicating if the edge picking has to be updated.
std::map< int, GLuint > * textureMap_
Mapping of mesh face texture indices to gltexture id ( has to be provided externally )
void pick_vertices(GLState &_state, bool _front=false)
Renders picking for vertices _front: Only render front vertices (not occluded by geometry)
void setIndexPropertyName(std::string _indexPropertyName)
set the name of the property used for texture index specification
bool updateVertexPicking_
Flag indicating if the vertex picking has to be updated.
bool updateFacePicking_
Flag indicating if the edge picking has to be updated.
size_t vertexPickingBaseIndex_
Index of the first vertex in vertexpicking.
size_t edgePickingBaseIndex_
Index of the first edge in edgepicking.
void update_topology()
the topology of the mesh has changed
void draw_lines()
draws all edges of the mesh
VertexDeclaration halfedgeDecl
Draws the object.
void enableNormals(bool _enable)
Enable or disable the use of the normal array.
Vec3d bbMin_
bounding box lower left corner
void update_textures()
force an texture update
bool updateAnyPicking_
Flag indicating if the any picking has to be updated.
void draw_faces()
draws all faces of the mesh
void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat) override
Draws the object deferred.
bool enableColors_
Returns if the color array is currently activated.
bool colorsEnabled()
Returns if the color array is currently activated.
void add_point_RenderObjects(IRenderer *_renderer, const RenderObject *_baseObj)
Draws the object.
void draw_vertices()
draws all vertices of the mesh
Class to define the vertex input layout.
Kernel::Normal Normal
Normal type.
Definition PolyMeshT.hh:114
Kernel::Point Point
Coordinate type.
Definition PolyMeshT.hh:112
Kernel::Color Color
Color type.
Definition PolyMeshT.hh:116
PickTarget
What target to use for picking.
Definition PickTarget.hh:74
Namespace providing different geometric functions concerning angles.
Interface class between scenegraph and renderer.