MeshNode2T.hh 16.2 KB
Newer Older
1
2
3
4
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
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
 *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
 *                           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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
 *                                                                           *
\*===========================================================================*/




//=============================================================================
//
//  CLASS TriStripNodeT
//
//=============================================================================


#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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122

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


namespace ACG {
namespace SceneGraph {


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



/** \class TriStripNodeT TriStripNodeT.hh <ACG/Scenegraph/TriStripNodeT.hh>

    This node draws a mesh using triangle strips.
*/

template <class Mesh>
class TriStripNodeT  : public BaseNode
{
public:
  ACG_CLASSNAME(MeshNode);

  /** \brief Default constructor
  *     
  * The constructor needs a mesh on which this node will work.
  */
  TriStripNodeT(Mesh&        _mesh,
             BaseNode*    _parent=0,
             std::string  _name="<MeshNode>" );

  /// Destructor
  virtual ~TriStripNodeT();
  
  
  /** \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.
  */
  void update_topology();  

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
123
124
  typedef typename Mesh::Color         Color;
  typedef typename Color::value_type   ColorScalar;
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
  
//===========================================================================
/** @name Mesh Handling
* @{ */
//===========================================================================  
  
public:
  
  /** \brief get the internal mesh
  */
  const Mesh& mesh() const { return mesh_; }  
  
private:  
  /// The mesh this node works on
  Mesh& mesh_;  
  
141
142
143
144
145
146
147
148
149
150
151
152
153
/** @} */  
  
//===========================================================================
/** @name Strip generation and handling
* @{ */
//===========================================================================  
public:
//   void update_strips();

private:
  StripProcessorT<Mesh> stripProcessor_;

/** @} */  
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185

//===========================================================================
/** @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
186
  GLuint vertexBuffer_;
187
188
189
190
191
192
193
194
195
  
  /// Vertex buffer initialization flag
  bool   vertexBufferInitialized_;  
  
  /// Internal buffer used when rendering non float vertex coordinates
  std::vector< ACG::Vec3f > vertices_;
  
/** @} */

196
197
198
199
200
//===========================================================================
/** @name Normal Buffer
* @{ */
//===========================================================================

201
202
203
204
205
206
207
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; };

208
209
private:
  
210
211
212
  /// Flag if normals should be used
  bool enableNormals_;
  
213
  /// Normal buffer
214
  GLuint normalVertexBuffer_;
215
216
  
  /// normal buffer initialization flag
217
  bool normalVertexBufferInitialized_;
218
219
220
221
  
  /// Internal buffer used when rendering non float normals
  std::vector< ACG::Vec3f > normals_;

222
223
224
225
226
227
/** @} */
  
//===========================================================================
/** @name Color buffer
* @{ */
//===========================================================================  
228
229
230
231
232
233
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; };
234
235
236

private:
  
237
238
  bool enableColors_;
  
Jan Möbius's avatar
Jan Möbius committed
239
  /// color buffer
240
  GLuint colorVertexbuffer_;
241
  
Jan Möbius's avatar
Jan Möbius committed
242
  /// normal buffer initialization flag
243
  bool colorVertexBufferInitialized_;
Jan Möbius's avatar
Jan Möbius committed
244
  
245
246
247
  /// Internal buffer used when rendering non Vec4f colors
  std::vector< ACG::Vec4f > colors_;
  
Jan Möbius's avatar
Jan Möbius committed
248
  /** @} */
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
  
//===========================================================================
/** @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_;
  
  /** @} */  
266
    
267
268
269
270
271
272
273
274
275
//===========================================================================
/** @name Line buffer
* @{ */
//===========================================================================    
private:
  /// Vector storing vertices for rendering all edges in the mesh
  std::vector< unsigned int > lineIndices_;
  
  /// Index buffer for lines
276
  GLuint lineIndexBuffer_;
277
278
  
  /// lineIndexBuffer initialization flag
279
  bool lineIndexBufferInitialized_;
280
  
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
//===========================================================================
/** @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
  {
300
301
302
303
304
305
306
307
308
309
310
311
    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_COLOR_ARRAY      = 512,
    PER_FACE_TEXCOORD_ARRAY   = 1024
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
  };
  
  /// which arrays are currently enabled?
  unsigned int enabled_arrays_;
  

//===========================================================================
/** @name Rendering functions
* @{ */
//===========================================================================
  
public:
  /** \brief Draws the object
  *
  */
  void draw(GLState& _state, unsigned int _drawMode);
  
329
330
private:
  // types
331
  enum FaceMode {  PER_VERTEX, PER_FACE };
332
  
333
334
335
  /** \brief draws all vertices of the mesh
  *
  */
336
  inline void draw_vertices();
337
  
338
339
340
  /** \brief draws all edges of the mesh
  *
  */
341
342
343
344
345
346
  inline void draw_lines();
  
  /** \brief draws all faces of the mesh 
  *
  */
  void draw_faces(FaceMode _mode);
347
  
348
349
350
351
352
353
  /** \brief return available draw modes 
  *
  * The drawmodes are constructed based on the mesh properties and the hardware capabilities
  * of the system.
  */
  unsigned int availableDrawModes() const;
354
355
356
357
358
359

private:
  

/** @} */

360
//===========================================================================
Jan Möbius's avatar
Jan Möbius committed
361
/** @name general picking functions
362
363
364
365
366
367
368
* @{ */
//===========================================================================
public:
  /** \brief Draws the object in picking mode
  *
  */
  void pick(GLState& _state, PickTarget _target);
Jan Möbius's avatar
Jan Möbius committed
369
370
371
372
373
374
375
376

/** @} */

//===========================================================================
/** @name vertex picking functions
* @{ */
//===========================================================================  
  
377
private:
378

379
380
381
382
383
  /** \brief Renders picking for vertices
  *
  */
  void pick_vertices(GLState& _state, bool _front = false);
  
Jan Möbius's avatar
Jan Möbius committed
384
  /// Flag indicating if the vertex picking display list has to be updates
Jan Möbius's avatar
Jan Möbius committed
385
  bool updateVertexPickingList_;  
Jan Möbius's avatar
Jan Möbius committed
386
387

  /// Index of the first vertex in vertexpicking
Jan Möbius's avatar
Jan Möbius committed
388
389
  unsigned int vertexPickingBaseIndex_;
  
Jan Möbius's avatar
Jan Möbius committed
390
391
  /// Dispplay list for rendering vertex picking
  GLuint vertexPickingList_;
Jan Möbius's avatar
Jan Möbius committed
392
393
394
  
/** @} */
  
Jan Möbius's avatar
Jan Möbius committed
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410

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


private:
  /** \brief Renders picking for edges
  *
  */
  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
411
  /// Index of the first edge in edgepicking
Jan Möbius's avatar
Jan Möbius committed
412
413
414
415
416
417
418
419
420
421
422
423
424
  unsigned int edgePickingBaseIndex_;
  
  /// Dispplay list for rendering edge picking
  GLuint edgePickingList_;

/** @} */

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


Jan Möbius's avatar
Jan Möbius committed
425
private:  
426
427
428
429
430
  /** \brief Renders picking for faces
  *
  */
  void pick_faces(GLState& _state);
  
Jan Möbius's avatar
Jan Möbius committed
431
432
433
434
435
436
437
438
  /// 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
439
440

/** @} */
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463

//===========================================================================
/** @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_;  
  
/** @} */
464
  
465

466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
//===========================================================================
/** @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.
  *
  */
  
484
  void setIndexPropertyName( std::string _indexPropertyName );
485
486
  
  
487
488
489
490
491
492
493
  /** \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 );
  
494
495
496
497
498
499
500
501
502
503
504
  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; };
  
505
private:
506
  
507
508
509
510
511
  /// This flag indicates if we have a per Face texture index property
  bool perFaceTextureIndexAvailable_;
  
  /// Mapping of mesh face texture indices to gltexture id ( has to be provided externally )
  std::map< int, GLuint>* textureMap_;
512
513

/** @} */
514
  
515
516
  /// \todo Remove all these functions afterwards!
  
517
518
public:  
  void set_property_map( std::map< int, std::string>* _map){ };  
519
    
520
    
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
    

};


//=============================================================================
} // 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
//=============================================================================