MeshNode2T.hh 17.1 KB
Newer Older
1
2
3
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
Jan Möbius's avatar
Jan Möbius committed
4
 *      Copyright (C) 2001-2010 by Computer Graphics Group, RWTH Aachen      *
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 *                           www.openflipper.org                             *
 *                                                                           *
 *---------------------------------------------------------------------------*
 *  This file is part of OpenFlipper.                                        *
 *                                                                           *
 *  OpenFlipper is free software: you can redistribute it and/or modify      *
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
 *                                                                           *
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
 *                                                                           *
 *  OpenFlipper is distributed in the hope that it will be useful,           *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
 *                                                                           *
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenFlipper. If not,                                  *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
Jan Möbius's avatar
Jan Möbius committed
37
38
39
 *   $Revision$                                                       *
 *   $Author$                                                      *
 *   $Date$                   *
40
41
42
43
44
45
46
47
 *                                                                           *
\*===========================================================================*/




//=============================================================================
//
Jan Möbius's avatar
Jan Möbius committed
48
//  CLASS MeshNodeT
49
50
51
52
53
54
55
56
57
58
59
60
61
//
//=============================================================================


#ifndef ACG_MESHNODE_HH
#define ACG_MESHNODE_HH


//== INCLUDES =================================================================



#include "BaseNode.hh"
62
#include <vector>
63
#include <ACG/Scenegraph/StripProcessorT.hh>
64
65
66
67
68
69
70
71
72
73
74
75

//== NAMESPACES ===============================================================


namespace ACG {
namespace SceneGraph {


//== CLASS DEFINITION =========================================================



Jan Möbius's avatar
Jan Möbius committed
76
/** \class MeshNodeT MeshNodeT.hh <ACG/Scenegraph/MeshNodeT.hh>
77
78
79
80
81

    This node draws a mesh using triangle strips.
*/

template <class Mesh>
Jan Möbius's avatar
Jan Möbius committed
82
class MeshNodeT  : public BaseNode
83
84
85
86
87
88
89
90
{
public:
  ACG_CLASSNAME(MeshNode);

  /** \brief Default constructor
  *     
  * The constructor needs a mesh on which this node will work.
  */
Jan Möbius's avatar
Jan Möbius committed
91
92
93
  MeshNodeT(Mesh&        _mesh,
            BaseNode*    _parent=0,
            std::string  _name="<MeshNode>" );
94
95

  /// Destructor
Jan Möbius's avatar
Jan Möbius committed
96
  virtual ~MeshNodeT();
97
98
99
100
101
102
103
104
105
106
107
108
109
  
  
  /** \brief the geometry of the mesh has changed
  *
  * call this function if you changed the geometry of the mesh.
  * All buffers related to the geometry will be updated.
  */
  void update_geometry();
  
  /** \brief the topology of the mesh has changed
  *
  * call this function if you changed the topology of the mesh.
  * All buffers related to the topology will be updated.
110
111
  *
  * this also triggers an update for the colors
112
113
114
  */
  void update_topology();  

115
116
117
118
119
120
121
122
123
  /** \brief the colors of the mesh have changed
  *
  * call this function if you changed the colors of the mesh.
  * All buffers related to the color will be updated.
  *
  * if you also updated the topology, the color is updated automatically
  */
  void update_color();
  
124
125
126
127
128
129
130
131
132
133
private:

  /** Typedefs of the mesh representation
  * 
  * These typedefs are used to specifiy and convert all input to float for rendering
  */
  typedef typename Mesh::Point         Point;
  typedef typename Point::value_type   PointScalar;
  typedef typename Mesh::Normal        Normal;
  typedef typename Normal::value_type  NormalScalar;
Jan Möbius's avatar
Jan Möbius committed
134
135
  typedef typename Mesh::Color         Color;
  typedef typename Color::value_type   ColorScalar;
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
  
//===========================================================================
/** @name Mesh Handling
* @{ */
//===========================================================================  
  
public:
  
  /** \brief get the internal mesh
  */
  const Mesh& mesh() const { return mesh_; }  
  
private:  
  /// The mesh this node works on
  Mesh& mesh_;  
  
152
153
154
155
156
157
158
159
160
161
162
163
164
/** @} */  
  
//===========================================================================
/** @name Strip generation and handling
* @{ */
//===========================================================================  
public:
//   void update_strips();

private:
  StripProcessorT<Mesh> stripProcessor_;

/** @} */  
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196

//===========================================================================
/** @name Bounding Box
* @{ */
//===========================================================================  

public:  
  
  /** \brief Current bounding box
  *
  * This function returns the bounding box of the node.
  */
  void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);  
  
private:
  
  /// bounding box lower left corner
  Vec3d bbMin_;
  
  /// bounding box upper right corner
  Vec3d bbMax_;
  
/** @} */
  
//===========================================================================
/** @name Vertex Buffer
* @{ */
//===========================================================================
  
private:
  
  /// Vertex buffer
197
  GLuint vertexBuffer_;
198
199
200
201
202
203
204
205
206
  
  /// Vertex buffer initialization flag
  bool   vertexBufferInitialized_;  
  
  /// Internal buffer used when rendering non float vertex coordinates
  std::vector< ACG::Vec3f > vertices_;
  
/** @} */

207
208
209
210
211
//===========================================================================
/** @name Normal Buffer
* @{ */
//===========================================================================

212
213
214
215
216
217
218
public:
  /// Returns if the normal array is currently activated
  bool normalsEnabled() { return enableNormals_; };
  
  /// Enable or disable the use of the normal array
  void enableNormals(bool _enable) { enableNormals_ = _enable; };

219
220
private:
  
221
222
223
  /// Flag if normals should be used
  bool enableNormals_;
  
224
  /// Normal buffer
225
  GLuint normalVertexBuffer_;
226
227
  
  /// normal buffer initialization flag
228
  bool normalVertexBufferInitialized_;
229
230
231
232
  
  /// Internal buffer used when rendering non float normals
  std::vector< ACG::Vec3f > normals_;

233
234
235
236
237
238
/** @} */
  
//===========================================================================
/** @name Color buffer
* @{ */
//===========================================================================  
239
240
241
242
243
244
public:
  /// Returns if the color array is currently activated
  bool colorsEnabled() { return enableColors_; };
  
  /// Enable or disable the use of color array
  void enableColors(bool _enable) { enableColors_ = _enable; };
245
246
247

private:
  
248
249
  bool enableColors_;
  
Jan Möbius's avatar
Jan Möbius committed
250
  /// color buffer
251
  GLuint colorVertexbuffer_;
252
  
Jan Möbius's avatar
Jan Möbius committed
253
  /// normal buffer initialization flag
254
  bool colorVertexBufferInitialized_;
Jan Möbius's avatar
Jan Möbius committed
255
  
256
257
258
  /// Internal buffer used when rendering non Vec4f colors
  std::vector< ACG::Vec4f > colors_;
  
Jan Möbius's avatar
Jan Möbius committed
259
  /** @} */
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
  
//===========================================================================
/** @name Texcoord buffer
* @{ */
//===========================================================================  
public:
  /// Returns if the per vertex Texture coordinates array is currently activated
  bool texCoordEnabled() { return enableTexCoords_; };
  
  /// Enable or disable the use of the  per vertex Texture coordinates array
  void enableTexCoords(bool _enable) { enableTexCoords_ = _enable; };
  
private:
  
  bool enableTexCoords_;
  
  /** @} */  
277
    
278
279
280
281
282
283
284
285
286
//===========================================================================
/** @name Line buffer
* @{ */
//===========================================================================    
private:
  /// Vector storing vertices for rendering all edges in the mesh
  std::vector< unsigned int > lineIndices_;
  
  /// Index buffer for lines
287
  GLuint lineIndexBuffer_;
288
289
  
  /// lineIndexBuffer initialization flag
290
  bool lineIndexBufferInitialized_;
291
  
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
//===========================================================================
/** @name Array control functions
* @{ */
//===========================================================================

public:
  
  /** \brief enable/disable vertex arrays according to the bits in _arrays
  *
  * Use this function to enable or disable the appropriate array for rendering. Currently
  * the arrays in ArrayType are supported
  */
  void enable_arrays(unsigned int _arrays);    

private:
  
  /// Enum controlling which array should be used for rendering
  enum ArrayType
  {
311
312
313
314
315
316
317
318
319
320
321
322
    NONE                             = 0,
    VERTEX_ARRAY                     = 1,
    NORMAL_VERTEX_ARRAY              = 2,
    COLOR_VERTEX_ARRAY               = 4,
    TEXCOORD_VERTEX_ARRAY            = 8,
    LINE_INDEX_ARRAY                 = 16,
    PER_EDGE_VERTEX_ARRAY            = 32,
    PER_EDGE_COLOR_ARRAY             = 64,
    PER_FACE_VERTEX_ARRAY            = 128,
    PER_FACE_NORMAL_ARRAY            = 256,
    PER_FACE_PER_VERTEX_NORMAL_ARRAY = 512,
    PER_FACE_COLOR_ARRAY             = 1024,
323
324
325
    PER_FACE_TEXCOORD_ARRAY          = 2048,
    PER_HALFEDGE_VERTEX_ARRAY        = 4096,
    PER_HALFEDGE_COLOR_ARRAY         = 8192
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
  };
  
  /// which arrays are currently enabled?
  unsigned int enabled_arrays_;
  

//===========================================================================
/** @name Rendering functions
* @{ */
//===========================================================================
  
public:
  /** \brief Draws the object
  *
  */
Jan Möbius's avatar
Jan Möbius committed
341
  void draw(GLState& _state, DrawModes::DrawMode _drawMode);
342
  
343
344
345
346
347
348
349
  /** \brief return available draw modes 
  *
  * The drawmodes are constructed based on the mesh properties and the hardware capabilities
  * of the system.
  */
  ACG::SceneGraph::DrawModes::DrawMode  availableDrawModes() const;
  
350
351
private:
  // types
352
  enum FaceMode {  PER_VERTEX, PER_FACE };
353
  
354
355
356
  /** \brief draws all vertices of the mesh
  *
  */
357
  inline void draw_vertices();
358
  
359
360
361
  /** \brief draws all edges of the mesh
  *
  */
362
  inline void draw_lines();
363
364
365
366
367
368

  /** \brief draws all halfedges of the mesh
  *
  */
  inline void draw_halfedges();

369
370
371
372
373
  
  /** \brief draws all faces of the mesh 
  *
  */
  void draw_faces(FaceMode _mode);
374
  
375
  
376
377
378
379
380
private:
  

/** @} */

381
//===========================================================================
Jan Möbius's avatar
Jan Möbius committed
382
/** @name general picking functions
383
384
385
386
387
388
389
* @{ */
//===========================================================================
public:
  /** \brief Draws the object in picking mode
  *
  */
  void pick(GLState& _state, PickTarget _target);
Jan Möbius's avatar
Jan Möbius committed
390
391
392
393
394
395
396
397

/** @} */

//===========================================================================
/** @name vertex picking functions
* @{ */
//===========================================================================  
  
398
private:
399

400
  /** \brief Renders picking for vertices
401
  * _front: Only render front vertices (not occluded by geometry)
402
403
404
  */
  void pick_vertices(GLState& _state, bool _front = false);
  
Jan Möbius's avatar
Jan Möbius committed
405
  /// Flag indicating if the vertex picking display list has to be updates
Jan Möbius's avatar
Jan Möbius committed
406
  bool updateVertexPickingList_;  
Jan Möbius's avatar
Jan Möbius committed
407
408

  /// Index of the first vertex in vertexpicking
Jan Möbius's avatar
Jan Möbius committed
409
410
  unsigned int vertexPickingBaseIndex_;
  
Jan Möbius's avatar
Jan Möbius committed
411
412
  /// Dispplay list for rendering vertex picking
  GLuint vertexPickingList_;
Jan Möbius's avatar
Jan Möbius committed
413
414
415
  
/** @} */
  
Jan Möbius's avatar
Jan Möbius committed
416
417
418
419
420
421
422
423
424

//===========================================================================
/** @name edge picking functions
* @{ */
//=========================================================================== 


private:
  /** \brief Renders picking for edges
425
  * _front: Only render front edges (not occluded by geometry)
Jan Möbius's avatar
Jan Möbius committed
426
427
428
429
430
431
  */
  void pick_edges(GLState& _state, bool _front = false);  
  
  /// Flag indicating if the edge picking display list has to be updates
  bool updateEdgePickingList_;
  
Jan Möbius's avatar
Jan Möbius committed
432
  /// Index of the first edge in edgepicking
Jan Möbius's avatar
Jan Möbius committed
433
434
435
436
437
438
439
440
441
442
443
444
445
  unsigned int edgePickingBaseIndex_;
  
  /// Dispplay list for rendering edge picking
  GLuint edgePickingList_;

/** @} */

//===========================================================================
/** @name face picking functions
* @{ */
//=========================================================================== 


Jan Möbius's avatar
Jan Möbius committed
446
private:  
447
  /** \brief Renders picking for faces
448
  * _front: Only render front faces (not occluded by geometry)
449
450
451
  */
  void pick_faces(GLState& _state);
  
Jan Möbius's avatar
Jan Möbius committed
452
453
454
455
456
457
458
459
  /// Flag indicating if the edge picking display list has to be updates
  bool updateFacePickingList_;
  
  /// Index of the first face in facepicking
  unsigned int facePickingBaseIndex_;  
  
  /// Dispplay list for rendering edge picking
  GLuint facePickingList_;
Jan Möbius's avatar
Jan Möbius committed
460
461

/** @} */
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484

//===========================================================================
/** @name anything picking functions
* @{ */
//=========================================================================== 
  
private:  
  
  /** \brief Renders picking for all primitives
  *
  */
  void pick_any(GLState& _state);  
  
  /// Flag indicating if the any picking display list has to be updates
  bool updateAnyPickingList_;
  
  /// Index of the first face in anypicking
  unsigned int anyPickingBaseIndex_;    
  
  /// Dispplay list for rendering general picking
  GLuint anyPickingList_;  
  
/** @} */
485
  
486

487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
//===========================================================================
/** @name Texture handling
* @{ */
//=========================================================================== 
public:
  /** \brief set the name of the property used for texture index specification
  *
  * The given property name will define a texture index. This index is used to make
  * a lookup in the texture correspondence map containing for each index the gluint
  * for the texture to be used. A zero in the property means, that no texture will be bound for the 
  * face.
  * If you define a non existing name here, texture switching will be disabled and it
  * is assumed that a texture is bound already.
  *
  *\todo Remove the external texture loading and do it here.
  *
  */
  
505
  void setIndexPropertyName( std::string _indexPropertyName );
506
507
  
  
508
509
510
511
512
513
514
  /** \brief Set the name of the per face texture coordinate property
  *
  * Set this property for per face per vertex texture coordinates. Additionally you have to set
  * the IndexPropertyName to make texturing with multiple textures work.
  */
  void setHalfedgeTextcoordPropertyName( std::string _halfedgeTextcoordPropertyName );
  
515
516
517
518
519
520
521
522
523
524
525
  public:
    
    /** \brief Setup a mapping between internal texture ids on the mesh and the ids for the loaded textures in opengl
    *
    * @param _map maps between an int index stored in the Mesh describing which texture to use for a face,
    *             and the GluInt name of the texture bound by the TextureNode. \n
    *             If such a map is not available ( =0 ), assume TextureNode has already bound a texture
    *             And render without switching textures
    */
    void setTextureMap( std::map< int, GLuint>* _map){ textureMap_ = _map; };
  
526
private:
527
  
528
529
530
  /// This flag indicates if we have a per Face texture index property
  bool perFaceTextureIndexAvailable_;
  
531
532
533
  /// This flag indicates if we have a per Face texture coordinate property
  bool perFaceTextureCoordsAvailable_;
  
534
535
  /// Mapping of mesh face texture indices to gltexture id ( has to be provided externally )
  std::map< int, GLuint>* textureMap_;
536
537

/** @} */
538
  
539
540
  /// \todo Remove all these functions afterwards!
  
541
542
public:  
  void set_property_map( std::map< int, std::string>* _map){ };  
543
    
544
    
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
    

};


//=============================================================================
} // namespace SceneGraph
} // namespace ACG
//=============================================================================
#if defined(INCLUDE_TEMPLATES) && !defined(ACG_MESHNODE_C)
#define ACG_MESHNODE_TEMPLATES
#include "MeshNode2T.cc"
#endif
//=============================================================================
#endif // ACG_MESHNODE_HH defined
//=============================================================================