VolumeMeshNodeT_impl.hh 56.3 KB
Newer Older
1
/*===========================================================================*\
2
3
 *                                                                           *
 *                              OpenFlipper                                  *
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
37
38
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
39
40
 *                                                                           *
\*===========================================================================*/
41
42
43
44
45
46
47
48
49
50
51


#define VOLUMEMESHNODET_CC

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

#include "VolumeMeshNode.hh"

#include <ACG/GL/gl.hh>
#include <ACG/Utils/VSToolsT.hh>
#include <vector>
52
#include <type_traits>
53
54
55
56

#include <ACG/GL/RenderObject.hh>
#include <ACG/GL/VertexDeclaration.hh>
#include <ACG/GL/IRenderer.hh>
57
58
#include <ACG/ShaderUtils/GLSLShader.hh>
#include <ACG/GL/ShaderCache.hh>
59
#include <ACG/Geometry/Types/PlaneType.hh>
60
61
62
63
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177

#include <OpenVolumeMesh/Mesh/HexahedralMesh.hh>

typedef OpenVolumeMesh::HexahedralMeshTopologyKernel HexahedralMeshTopologyKernel;


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

namespace ACG {
namespace SceneGraph {

//== IMPLEMENTATION ==========================================================


template<class VolumeMeshT>
VolumeMeshNodeT<VolumeMeshT>::VolumeMeshNodeT(const VolumeMesh& _mesh,
                                              OpenVolumeMesh::StatusAttrib& _statusAttrib,
                                              OpenVolumeMesh::ColorAttrib<Vec4f>& _colorAttrib,
                                              OpenVolumeMesh::NormalAttrib<VolumeMesh>& _normalAttrib,
                                              OpenVolumeMesh::TexCoordAttrib<Vec2f>& _texcoordAttrib,
                                              const MaterialNode* _matNode, BaseNode* _parent,
                                              std::string _name) :
  BaseNode(_parent, _name),
  mesh_(_mesh),
  scale_(1.0),
  boundary_only_(false),
  translucency_factor_(0.1f),
  selection_color_(ACG::Vec4f(1.0f, 0.0f, 0.0f, 1.0f)),
  statusAttrib_(_statusAttrib),
  colorAttrib_(_colorAttrib),
  normalAttrib_(_normalAttrib),
  texcoordAttrib_(_texcoordAttrib),
  materialNode_(_matNode),

  cellsBufferManager_   (_mesh, _statusAttrib, _colorAttrib, _normalAttrib, _texcoordAttrib),
  facesBufferManager_   (_mesh, _statusAttrib, _colorAttrib, _normalAttrib, _texcoordAttrib),
  edgesBufferManager_   (_mesh, _statusAttrib, _colorAttrib, _normalAttrib, _texcoordAttrib),
  verticesBufferManager_(_mesh, _statusAttrib, _colorAttrib, _normalAttrib, _texcoordAttrib),

  cellSelectionBufferManager_  (_mesh, _statusAttrib, _colorAttrib, _normalAttrib, _texcoordAttrib),
  faceSelectionBufferManager_  (_mesh, _statusAttrib, _colorAttrib, _normalAttrib, _texcoordAttrib),
  edgeSelectionBufferManager_  (_mesh, _statusAttrib, _colorAttrib, _normalAttrib, _texcoordAttrib),
  vertexSelectionBufferManager_(_mesh, _statusAttrib, _colorAttrib, _normalAttrib, _texcoordAttrib),

  cellPickBufferManager_  (_mesh, _statusAttrib, _colorAttrib, _normalAttrib, _texcoordAttrib),
  facePickBufferManager_  (_mesh, _statusAttrib, _colorAttrib, _normalAttrib, _texcoordAttrib),
  edgePickBufferManager_  (_mesh, _statusAttrib, _colorAttrib, _normalAttrib, _texcoordAttrib),
  vertexPickBufferManager_(_mesh, _statusAttrib, _colorAttrib, _normalAttrib, _texcoordAttrib),

  drawModes_(),
  lastDrawMode_      (DrawModes::NONE),
  lastCellDrawMode_  (DrawModes::NONE),
  lastFaceDrawMode_  (DrawModes::NONE),
  lastEdgeDrawMode_  (DrawModes::NONE),
  lastVertexDrawMode_(DrawModes::NONE),
  lastPickTarget_(PICK_ANYTHING),
  face_normals_calculated_(false),
  vertex_normals_calculated_(false)
{
    vertexSelectionBufferManager_.setSelectionOnly(true);
    edgeSelectionBufferManager_.setSelectionOnly(true);
    faceSelectionBufferManager_.setSelectionOnly(true);
    cellSelectionBufferManager_.setSelectionOnly(true);
}


//----------------------------------------------------------------------------

template<class VolumeMeshT>
VolumeMeshNodeT<VolumeMeshT>::~VolumeMeshNodeT() {

}

//----------------------------------------------------------------------------

template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::boundingBox(Vec3d& _bbMin, Vec3d& _bbMax) {

    int n_vertices(mesh_.n_vertices());
    for (int i = 0; i < n_vertices; ++i) {
        Vec3d p(mesh_.vertex(VertexHandle(i)));
        _bbMin.minimize(p);
        _bbMax.maximize(p);
    }
}

//----------------------------------------------------------------------------


template<class VolumeMeshT>
DrawModes::DrawMode VolumeMeshNodeT<VolumeMeshT>::availableDrawModes() const {
    DrawModes::DrawMode result;

    if (mesh_.n_cells() > 0)
    {
        result |= drawModes_.cellsTransparent;
        result |= drawModes_.cellsFlatShaded;
        result |= drawModes_.cellsSmoothShaded;
        result |= drawModes_.cellsPhongShaded;
        if (colorAttrib_.vertex_colors_available())
            result |= drawModes_.cellsColoredPerVertex;
        if (colorAttrib_.halfface_colors_available())
            result |= drawModes_.cellsColoredPerHalfface;
        if (colorAttrib_.face_colors_available())
            result |= drawModes_.cellsColoredPerFace;
        if (colorAttrib_.cell_colors_available())
            result |= drawModes_.cellsColoredPerCell;
    }

    if (mesh_.n_faces() > 0)
    {
        result |= drawModes_.facesFlatShaded;
        result |= drawModes_.facesSmoothShaded;
        result |= drawModes_.facesPhongShaded;
        if (colorAttrib_.vertex_colors_available())
            result |= drawModes_.facesColoredPerVertex;
        if (colorAttrib_.face_colors_available())
            result |= drawModes_.facesColoredPerFace;
178
179
        if (colorAttrib_.face_colors_available())
            result |= drawModes_.facesColoredPerFaceFlatShaded;
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
        if (texcoordAttrib_.vertex_texcoords_available())
            result |= drawModes_.facesTextured;
        if (texcoordAttrib_.vertex_texcoords_available())
            result |= drawModes_.facesTexturedShaded;
    }

    if (mesh_.n_halffaces() > 0)
    {
        result |= drawModes_.halffacesFlatShaded;
        result |= drawModes_.halffacesSmoothShaded;
        result |= drawModes_.halffacesPhongShaded;
        if (colorAttrib_.vertex_colors_available())
            result |= drawModes_.halffacesColoredPerVertex;
        if (colorAttrib_.halfface_colors_available())
            result |= drawModes_.halffacesColoredPerHalfface;
    }

    if (mesh_.n_edges() > 0)
    {
        result |= drawModes_.edgesWireframe;

        if (mesh_.n_cells () > 0)
            result |= drawModes_.edgesOnCells;
        if (mesh_.n_faces() > 0)
            result |= drawModes_.edgesHiddenLine;
        if (colorAttrib_.edge_colors_available())
            result |= drawModes_.edgesColoredPerEdge;

208
        if (std::is_base_of<HexahedralMeshTopologyKernel, VolumeMeshT>::value)
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
        {
            result |= drawModes_.irregularInnerEdges;
            result |= drawModes_.irregularOuterEdges;
        }
    }

    if (mesh_.n_halfedges() > 0)
    {
        result |= drawModes_.halfedgesWireframe;

        if (mesh_.n_faces() > 0)
            result |= drawModes_.halfedgesHiddenLine;
        if (colorAttrib_.halfedge_colors_available())
            result |= drawModes_.halfedgesColoredPerHalfedge;
    }

    if (mesh_.n_vertices() > 0)
    {
        result |= drawModes_.verticesFlatShaded;

        if (colorAttrib_.vertex_colors_available())
            result |= drawModes_.verticesColored;
    }

    return  result;

}


//----------------------------------------------------------------------------


template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::drawCells(GLState& _state, const DrawModes::DrawMode& _drawMode)
{

    ACG::GLState::depthRange(0.01, 1.0);

    cellsBufferManager_.setOptionsFromDrawMode(_drawMode);
    GLState::bindBuffer(GL_ARRAY_BUFFER, cellsBufferManager_.getBuffer());
    GLState::enableClientState(GL_VERTEX_ARRAY);
    GLState::vertexPointer(3, GL_FLOAT, cellsBufferManager_.getStride(), reinterpret_cast<GLvoid*>(0));

    GLState::enableClientState(GL_NORMAL_ARRAY);
    GLState::normalPointer(GL_FLOAT, cellsBufferManager_.getStride(), reinterpret_cast<GLvoid*>(cellsBufferManager_.getNormalOffset()));

    if (_drawMode & (drawModes_.cellsColoredPerCell | drawModes_.cellsColoredPerFace | drawModes_.cellsColoredPerHalfface | drawModes_.cellsColoredPerVertex))
    {
        //for a drawmode with colors we have to activate and bind colors
        GLState::enableClientState(GL_COLOR_ARRAY);
        GLState::colorPointer(4, GL_UNSIGNED_BYTE, cellsBufferManager_.getStride(), reinterpret_cast<GLvoid*>(cellsBufferManager_.getColorOffset()));

        GLState::shadeModel(GL_SMOOTH);
        GLState::disable(GL_LIGHTING);
        GLState::enable(GL_DEPTH_TEST);

    }
    else if (_drawMode & drawModes_.cellsSmoothShaded)
    {
        GLState::shadeModel(GL_SMOOTH);
        GLState::enable(GL_LIGHTING);
        GLState::enable(GL_DEPTH_TEST);
    }
    else if (_drawMode & drawModes_.cellsFlatShaded)
    {
        GLState::shadeModel(GL_FLAT);
        GLState::enable(GL_LIGHTING);
        GLState::enable(GL_DEPTH_TEST);
    }
    else if (_drawMode & drawModes_.cellsTransparent)
    {
        GLState::shadeModel(GL_FLAT);
        GLState::disable(GL_LIGHTING);
        GLState::disable(GL_DEPTH_TEST);
        GLState::disableClientState(GL_COLOR_ARRAY);
        Vec4f bc = _state.specular_color();
        _state.set_color(Vec4f(bc[0],bc[1],bc[2],translucency_factor_));
        GLState::enable(GL_BLEND);
        GLState::blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    }

    glDrawArrays(GL_TRIANGLES, 0, cellsBufferManager_.getNumOfVertices());

    if (_drawMode & drawModes_.cellsTransparent)
    {
        _state.set_color(_state.base_color());
        GLState::disable(GL_BLEND);
    }

    GLState::disableClientState(GL_COLOR_ARRAY);
    GLState::bindBuffer(GL_ARRAY_BUFFER, 0);

    ACG::GLState::depthRange(0.0, 1.0);
}

template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::drawFaces(GLState& _state, const DrawModes::DrawMode& _drawMode)
{

    ACG::GLState::depthRange(0.01, 1.0);

    //faces are drawn from both sides, halffaces only when facing the camera
    //however, if we only draw the boundary, we draw halffaces from both sides so we can see them
    //when looking inside the object
    if ((_drawMode & drawModes_.faceBasedDrawModes) || boundary_only_)
    {
        GLState::disable(GL_CULL_FACE);
    }
    else
    {
        GLState::enable(GL_CULL_FACE);
        GLState::cullFace(GL_BACK);
    }

    GLState::enable(GL_DEPTH_TEST);

    facesBufferManager_.setOptionsFromDrawMode(_drawMode);
    GLState::bindBuffer(GL_ARRAY_BUFFER, facesBufferManager_.getBuffer());
    GLState::enableClientState(GL_VERTEX_ARRAY);
    GLState::vertexPointer(3, GL_FLOAT, facesBufferManager_.getStride(), reinterpret_cast<GLvoid*>(0));

    if (_drawMode & (drawModes_.hiddenLineBackgroundFaces))
    {
        GLState::disable(GL_LIGHTING);
        GLState::shadeModel(GL_FLAT);
        GLState::disableClientState(GL_COLOR_ARRAY);
        GLState::disableClientState(GL_NORMAL_ARRAY);
        _state.set_color(_state.clear_color());
    }
    else if (_drawMode & (drawModes_.facesColoredPerFace | drawModes_.facesColoredPerVertex
                     | drawModes_.halffacesColoredPerHalfface | drawModes_.halffacesColoredPerVertex ))
    {
        GLState::enableClientState(GL_COLOR_ARRAY);
        GLState::colorPointer(4, GL_UNSIGNED_BYTE, facesBufferManager_.getStride(), reinterpret_cast<GLvoid*>(facesBufferManager_.getColorOffset()));

        GLState::disable(GL_LIGHTING);
        GLState::shadeModel(GL_SMOOTH);
    }
347
348
349
350
351
352
353
354
355
356
357
358
359
    else if (_drawMode & (drawModes_.facesColoredPerFaceFlatShaded))
    {
        GLState::enable(GL_COLOR_MATERIAL);

        GLState::enableClientState(GL_COLOR_ARRAY);
        GLState::colorPointer(4, GL_UNSIGNED_BYTE, facesBufferManager_.getStride(), reinterpret_cast<GLvoid*>(facesBufferManager_.getColorOffset()));

        GLState::enable(GL_LIGHTING);
        GLState::shadeModel(GL_FLAT);

        GLState::enableClientState(GL_NORMAL_ARRAY);
        GLState::normalPointer(GL_FLOAT, facesBufferManager_.getStride(), reinterpret_cast<GLvoid*>(facesBufferManager_.getNormalOffset()));
    }
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
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
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
    else if (_drawMode & (drawModes_.facesTexturedShaded) )
    {
        glClientActiveTexture(GL_TEXTURE0);
        ACG::GLState::texcoordPointer(2, GL_FLOAT, facesBufferManager_.getStride(), reinterpret_cast<GLvoid*>(facesBufferManager_.getTexCoordOffset()));
        ACG::GLState::enableClientState(GL_TEXTURE_COORD_ARRAY);

        GLState::enable(GL_LIGHTING);
        GLState::disableClientState(GL_COLOR_ARRAY);

        GLState::enableClientState(GL_NORMAL_ARRAY);
        GLState::normalPointer(GL_FLOAT, facesBufferManager_.getStride(), reinterpret_cast<GLvoid*>(facesBufferManager_.getNormalOffset()));

        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
        GLState::shadeModel(GL_SMOOTH);
    }
    else if (_drawMode & (drawModes_.facesTextured) )
    {
        glClientActiveTexture(GL_TEXTURE0);
        ACG::GLState::texcoordPointer(2, GL_FLOAT, facesBufferManager_.getStride(), reinterpret_cast<GLvoid*>(facesBufferManager_.getTexCoordOffset()));
        ACG::GLState::enableClientState(GL_TEXTURE_COORD_ARRAY);

        GLState::disableClientState(GL_COLOR_ARRAY);
        GLState::disableClientState(GL_NORMAL_ARRAY);

        GLState::disable(GL_LIGHTING);
        GLState::shadeModel(GL_SMOOTH);

        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    }
    else
    {
        GLState::enable(GL_LIGHTING);
        GLState::disableClientState(GL_COLOR_ARRAY);

        GLState::enableClientState(GL_NORMAL_ARRAY);
        GLState::normalPointer(GL_FLOAT, facesBufferManager_.getStride(), reinterpret_cast<GLvoid*>(facesBufferManager_.getNormalOffset()));

        GLState::shadeModel(GL_SMOOTH);
    }

    glDrawArrays(GL_TRIANGLES, 0, facesBufferManager_.getNumOfVertices());

    GLState::disableClientState(GL_COLOR_ARRAY);

    GLState::bindBuffer(GL_ARRAY_BUFFER, 0);

    if (_drawMode & (drawModes_.edgesHiddenLine | drawModes_.halfedgesHiddenLine))
        _state.set_color(_state.base_color());

    ACG::GLState::depthRange(0.0, 1.0);
}

template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::drawEdges(GLState& _state, const DrawModes::DrawMode& _drawMode)
{
    ACG::GLState::depthRange(0.0, 1.0);

    edgesBufferManager_.setDefaultColor(_state.specular_color());
    edgesBufferManager_.setOptionsFromDrawMode(_drawMode);

    GLState::bindBuffer(GL_ARRAY_BUFFER, edgesBufferManager_.getBuffer());
    GLState::enableClientState(GL_VERTEX_ARRAY);
    GLState::vertexPointer(3, GL_FLOAT, edgesBufferManager_.getStride(), reinterpret_cast<GLvoid*>(0));

    if (_drawMode & ( drawModes_.edgesColoredPerEdge | drawModes_.halfedgesColoredPerHalfedge |
                      drawModes_.irregularInnerEdges | drawModes_.irregularOuterEdges ))
    {
        GLState::enableClientState(GL_COLOR_ARRAY);
        GLState::colorPointer(4, GL_UNSIGNED_BYTE, edgesBufferManager_.getStride(), reinterpret_cast<GLvoid*>(edgesBufferManager_.getColorOffset()));

        GLState::disable(GL_LIGHTING);
        GLState::shadeModel(GL_SMOOTH);

        glLineWidth(_state.line_width() * 2.0f);
    }
    else
    {
        _state.set_color( _state.specular_color() );

        ACG::GLState::disable(GL_LIGHTING);
        ACG::GLState::shadeModel(GL_FLAT);

        GLState::disableClientState(GL_NORMAL_ARRAY);
    }


    glDrawArrays(GL_LINES, 0, edgesBufferManager_.getNumOfVertices());
    glLineWidth(_state.line_width());

    GLState::disableClientState(GL_COLOR_ARRAY);

    GLState::bindBuffer(GL_ARRAY_BUFFER, 0);

}

template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::drawVertices(GLState& _state, const DrawModes::DrawMode& _drawMode)
{
    verticesBufferManager_.setOptionsFromDrawMode(_drawMode);
    GLState::bindBuffer(GL_ARRAY_BUFFER, verticesBufferManager_.getBuffer());
    GLState::enableClientState(GL_VERTEX_ARRAY);
    GLState::vertexPointer(3, GL_FLOAT, verticesBufferManager_.getStride(), reinterpret_cast<GLvoid*>(0));

    GLState::depthRange(0.0,1.0);

    if (_drawMode & ( drawModes_.verticesColored ))
    {
        GLState::enableClientState(GL_COLOR_ARRAY);
        GLState::colorPointer(4, GL_UNSIGNED_BYTE, verticesBufferManager_.getStride(), reinterpret_cast<GLvoid*>(verticesBufferManager_.getColorOffset()));

        GLState::disable(GL_LIGHTING);
        GLState::shadeModel(GL_SMOOTH);
    }
    else
    {
        _state.set_color( _state.specular_color() );

        ACG::GLState::disable(GL_LIGHTING);
        ACG::GLState::shadeModel(GL_FLAT);

        GLState::disableClientState(GL_NORMAL_ARRAY);
    }

    glDrawArrays(GL_POINTS, 0, verticesBufferManager_.getNumOfVertices());

    GLState::disableClientState(GL_COLOR_ARRAY);

    GLState::bindBuffer(GL_ARRAY_BUFFER, 0);

}

template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::drawSelection(GLState& _state, const DrawModes::DrawMode& _drawMode)
{

    //save current shader
    GLint currentProgramm;
    glGetIntegerv(GL_CURRENT_PROGRAM, &currentProgramm);
    //disable shader for drawing of the selecttion
    ACG::GLState::useProgram(0);

    GLState::enable(GL_DEPTH_TEST);
    GLState::depthFunc(GL_LEQUAL);
    _state.set_color( selection_color_ );

    GLState::disable(GL_LIGHTING);
    GLState::shadeModel(GL_FLAT);
    glDisable(GL_CULL_FACE);
    GLState::disableClientState(GL_NORMAL_ARRAY);
    GLState::disableClientState(GL_COLOR_ARRAY);

    GLState::disable(GL_TEXTURE_2D);

    GLState::enableClientState(GL_VERTEX_ARRAY);

    if ((_drawMode & drawModes_.cellBasedDrawModes) && !(_drawMode & drawModes_.vertexBasedDrawModes))
        vertexSelectionBufferManager_.enableVertexOnCellPrimitives();
    else
        vertexSelectionBufferManager_.enableVertexPrimitives();

    if ((_drawMode & (drawModes_.cellBasedDrawModes | drawModes_.edgesOnCells)) && !(_drawMode & (drawModes_.edgeBasedDrawModes & ~drawModes_.edgesOnCells)))
        edgeSelectionBufferManager_.enableEdgeOnCellPrimitives();
    else
        edgeSelectionBufferManager_.enableEdgePrimitives();

    if ((_drawMode & drawModes_.cellBasedDrawModes) && !(_drawMode & (drawModes_.faceBasedDrawModes | drawModes_.halffaceBasedDrawModes)))
        faceSelectionBufferManager_.enableFaceOnCellPrimitives();
    else
        faceSelectionBufferManager_.enableFacePrimitives();

    cellSelectionBufferManager_.enableCellPrimitives();

    glLineWidth(1.5*_state.line_width());

    GLState::depthRange(0.0,1.0);

    GLState::bindBuffer(GL_ARRAY_BUFFER, vertexSelectionBufferManager_.getBuffer());
    GLState::vertexPointer(3, GL_FLOAT, 0, 0);
    glDrawArrays(GL_POINTS, 0, vertexSelectionBufferManager_.getNumOfVertices());

    GLState::bindBuffer(GL_ARRAY_BUFFER, edgeSelectionBufferManager_.getBuffer());
    GLState::vertexPointer(3, GL_FLOAT, 0, 0);
    glDrawArrays(GL_LINES, 0, edgeSelectionBufferManager_.getNumOfVertices());

    GLState::depthRange(0.01,1.0);

    GLState::bindBuffer(GL_ARRAY_BUFFER, faceSelectionBufferManager_.getBuffer());
    GLState::vertexPointer(3, GL_FLOAT, 0, 0);
    glDrawArrays(GL_TRIANGLES, 0, faceSelectionBufferManager_.getNumOfVertices());

    GLState::bindBuffer(GL_ARRAY_BUFFER, cellSelectionBufferManager_.getBuffer());
    GLState::vertexPointer(3, GL_FLOAT, 0, 0);
    glDrawArrays(GL_TRIANGLES, 0, cellSelectionBufferManager_.getNumOfVertices());

    GLState::depthRange(0.0,1.0);

    _state.set_color(_state.base_color());

    GLState::bindBuffer(GL_ARRAY_BUFFER, 0);


    glLineWidth(_state.line_width());

    ACG::GLState::useProgram(currentProgramm);

}

template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::invalidateAllBuffers()
{
    invalidateAllDrawBuffers();
    invalidateAllPickingBuffers();
    invalidateAllSelectionBuffers();
}

template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::invalidateAllDrawBuffers()
{
    cellsBufferManager_.invalidate();
    facesBufferManager_.invalidate();
    edgesBufferManager_.invalidate();
    verticesBufferManager_.invalidate();
}

template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::invalidateAllPickingBuffers()
{
    cellPickBufferManager_.invalidate();
    facePickBufferManager_.invalidate();
    edgePickBufferManager_.invalidate();
    vertexPickBufferManager_.invalidate();
}

template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::invalidateAllSelectionBuffers()
{
    cellSelectionBufferManager_.invalidate();
    faceSelectionBufferManager_.invalidate();
    edgeSelectionBufferManager_.invalidate();
    vertexSelectionBufferManager_.invalidate();
}

template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::draw(GLState& _state, const DrawModes::DrawMode& _drawMode) {

    //save state
    GLboolean lighting = false;
    glGetBooleanv(GL_LIGHTING, &lighting);
    GLboolean color_material = false;
    glGetBooleanv(GL_COLOR_MATERIAL, &color_material);
    GLboolean blend = false;
    glGetBooleanv(GL_BLEND, &blend);
    GLboolean depth = false;
    glGetBooleanv(GL_DEPTH_TEST, &depth);
    GLenum prev_depth = _state.depthFunc();
    GLboolean cullFace = false;
    glGetBooleanv(GL_CULL_FACE, &cullFace);
    GLint cullFaceMode;
    glGetIntegerv(GL_CULL_FACE_MODE, &cullFaceMode);
    GLint texmode;
    glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &texmode);
    GLboolean texturing;
    glGetBooleanv(GL_TEXTURE_2D,  &texturing);
    const Vec4f oldColor = _state.color();

    // ignore two sided lighting setting and turn it off
    GLboolean lightModel = _state.twosided_lighting();
    _state.set_twosided_lighting(false);

    bool clientStateEnabledVertexArray   = GLState::isClientStateEnabled(GL_VERTEX_ARRAY);
    bool clientStateEnabledColorArray    = GLState::isClientStateEnabled(GL_COLOR_ARRAY);
    bool clientStateEnabledNormalArray   = GLState::isClientStateEnabled(GL_NORMAL_ARRAY);
    bool clientStateEnabledTexCoordArray = GLState::isClientStateEnabled(GL_TEXTURE_COORD_ARRAY);

    DrawModes::DrawMode cellDrawMode   = drawModes_.getFirstCellDrawMode(_drawMode);
    DrawModes::DrawMode faceDrawMode   = drawModes_.getFirstFaceDrawMode(_drawMode);
    DrawModes::DrawMode edgeDrawMode   = drawModes_.getFirstEdgeDrawMode(_drawMode);
    DrawModes::DrawMode vertexDrawMode = drawModes_.getFirstVertexDrawMode(_drawMode);

    if (!face_normals_calculated_)
    {
        if ( (cellDrawMode & drawModes_.cellsFlatShaded) ||
             (faceDrawMode & (drawModes_.facesFlatShaded | drawModes_.halffacesFlatShaded  | drawModes_.facesTexturedShaded)) )
            update_face_normals();
    }
    if (!vertex_normals_calculated_)
    {
        if ( (cellDrawMode & (drawModes_.cellsSmoothShaded | drawModes_.cellsPhongShaded)) ||
             (faceDrawMode & (drawModes_.facesSmoothShaded | drawModes_.halffacesSmoothShaded | drawModes_.facesPhongShaded | drawModes_.halffacesPhongShaded)) )
            update_vertex_normals();
    }

    //the VolumeMeshBufferManager can handle non atomic drawmodes if it consists of one
    // edge based draw mode (except edges on cells) and irregular edges
    edgeDrawMode |= _drawMode & (drawModes_.irregularInnerEdges | drawModes_.irregularOuterEdges);

656
657
658
    // enable twosided lighting for per_face_flat_shaded
    if(faceDrawMode & (drawModes_.facesColoredPerFaceFlatShaded))
      _state.set_twosided_lighting(true);
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759

    if (cellDrawMode)
        drawCells(_state, cellDrawMode);
    else
        cellsBufferManager_.free();
    if (faceDrawMode)
        drawFaces(_state, faceDrawMode);
    else
        facesBufferManager_.free();
    if (edgeDrawMode)
        drawEdges(_state, edgeDrawMode);
    else
        edgesBufferManager_.free();
    if (vertexDrawMode)
        drawVertices(_state, vertexDrawMode);
    else
        verticesBufferManager_.free();

    drawSelection(_state, cellDrawMode | faceDrawMode | edgeDrawMode | vertexDrawMode);


    lastDrawMode_ = cellDrawMode | faceDrawMode | edgeDrawMode | vertexDrawMode;
    lastCellDrawMode_   = cellDrawMode;
    lastFaceDrawMode_   = faceDrawMode;
    lastEdgeDrawMode_   = edgeDrawMode;
    lastVertexDrawMode_ = vertexDrawMode;

    //restore state
    if(lighting)
        ACG::GLState::enable(GL_LIGHTING);
    else
        ACG::GLState::disable(GL_LIGHTING);
    if(color_material)
        ACG::GLState::enable(GL_COLOR_MATERIAL);
    else
        ACG::GLState::disable(GL_COLOR_MATERIAL);
    if(blend)
        ACG::GLState::enable(GL_BLEND);
    else
        ACG::GLState::disable(GL_BLEND);
    if(depth)
        ACG::GLState::enable(GL_DEPTH_TEST);
    else
        ACG::GLState::disable(GL_DEPTH_TEST);
    _state.depthFunc(prev_depth);
    if(cullFace)
        ACG::GLState::enable(GL_CULL_FACE);
    else
        ACG::GLState::disable(GL_CULL_FACE);
    ACG::GLState::cullFace(cullFaceMode);
    if(texturing)
        ACG::GLState::enable(GL_TEXTURE_2D);
    else
        ACG::GLState::disable(GL_TEXTURE_2D);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, texmode);
    _state.set_color(oldColor);

    _state.set_twosided_lighting(lightModel);

    if (clientStateEnabledVertexArray)
        GLState::enableClientState(GL_VERTEX_ARRAY);
    else
        GLState::disableClientState(GL_VERTEX_ARRAY);

    if (clientStateEnabledColorArray)
        GLState::enableClientState(GL_COLOR_ARRAY);
    else
        GLState::disableClientState(GL_COLOR_ARRAY);

    if (clientStateEnabledNormalArray)
        GLState::enableClientState(GL_NORMAL_ARRAY);
    else
        GLState::disableClientState(GL_NORMAL_ARRAY);

    if (clientStateEnabledTexCoordArray)
        GLState::enableClientState(GL_TEXTURE_COORD_ARRAY);
    else
        GLState::disableClientState(GL_TEXTURE_COORD_ARRAY);

}



template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::getCellRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat)
{
    RenderObject ro;
    ro.initFromState(&_state);

    ro.debugName = "VolumeMeshNodeCells";

    //Todo: use DrawModeProperties

    // reset renderobject
    ro.depthTest = true;
    ro.depthWrite = true;
    ro.depthFunc = GL_LESS;
    ro.setMaterial(_mat);

    ro.shaderDesc.clearTextures();

760
    ro.shaderDesc.shadeMode = SG_SHADE_UNLIT;
761
762
763
764
765
766
767

    ro.depthRange = Vec2f(0.01f, 1.0f);

    if (_drawMode & (drawModes_.cellsColoredPerCell | drawModes_.cellsColoredPerFace | drawModes_.cellsColoredPerHalfface | drawModes_.cellsColoredPerVertex))
    {
        ro.shaderDesc.vertexColors = true;
        ro.shaderDesc.numLights = -1;
768
        ro.shaderDesc.shadeMode = SG_SHADE_UNLIT;
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
    }
    else if (_drawMode & drawModes_.cellsSmoothShaded)
    {
        ro.shaderDesc.numLights = 0;
        ro.shaderDesc.shadeMode = SG_SHADE_GOURAUD;
    }
    else if (_drawMode & drawModes_.cellsFlatShaded)
    {
        ro.shaderDesc.numLights = 0;
        ro.shaderDesc.shadeMode = SG_SHADE_FLAT;
    }
    else if (_drawMode & drawModes_.cellsTransparent)
    {
        ro.shaderDesc.shadeMode = SG_SHADE_GOURAUD;
        ro.shaderDesc.numLights = -1;
        ro.depthTest = false;

        ro.diffuse = ACG::Vec3f(_state.specular_color()[0],_state.specular_color()[1],_state.specular_color()[2]);
        ro.ambient = ACG::Vec3f(_state.specular_color()[0],_state.specular_color()[1],_state.specular_color()[2]);
        ro.specular = ACG::Vec3f(_state.specular_color()[0],_state.specular_color()[1],_state.specular_color()[2]);
        ro.emissive = ACG::Vec3f(_state.specular_color()[0],_state.specular_color()[1],_state.specular_color()[2]);

        ro.alpha = translucency_factor_;
        ro.blending = true;
        ro.blendDest = GL_ONE_MINUS_SRC_ALPHA;
        ro.blendSrc = GL_SRC_ALPHA;
    }

    cellsBufferManager_.setOptionsFromDrawMode(_drawMode);
    ro.vertexBuffer = cellsBufferManager_.getBuffer();
    ro.vertexDecl = cellsBufferManager_.getVertexDeclaration();

    ro.glDrawArrays(GL_TRIANGLES, 0, cellsBufferManager_.getNumOfVertices());
802
803
804
    if (cellsBufferManager_.getNumOfVertices() > 0) {
        _renderer->addRenderObject(&ro);
    }
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
}

template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::getFaceRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat)
{
    RenderObject ro;
    ro.initFromState(&_state);

    ro.debugName = "VolumeMeshNodeFaces";

    //Todo: use DrawModeProperties

    // reset renderobject
    ro.depthTest = true;
    ro.depthWrite = true;
    ro.depthFunc = GL_LESS;
    ro.setMaterial(_mat);

    ro.shaderDesc.clearTextures();

    ro.shaderDesc.shadeMode = SG_SHADE_GOURAUD;

    ro.depthRange = Vec2f(0.01f, 1.0f);

    facesBufferManager_.setOptionsFromDrawMode(_drawMode);


    if ((_drawMode & drawModes_.faceBasedDrawModes) || boundary_only_)
        ro.culling = false;
    else
        ro.culling = true;

    if (_drawMode & (drawModes_.hiddenLineBackgroundFaces))
    {
        ro.shaderDesc.numLights = -1;
        ro.shaderDesc.shadeMode = SG_SHADE_FLAT;

        ro.shaderDesc.vertexColors = false;

        ro.diffuse = ACG::Vec3f(_state.clear_color()[0],_state.clear_color()[1],_state.clear_color()[2]);
        ro.ambient = ACG::Vec3f(_state.clear_color()[0],_state.clear_color()[1],_state.clear_color()[2]);
        ro.specular = ACG::Vec3f(_state.clear_color()[0],_state.clear_color()[1],_state.clear_color()[2]);
        ro.emissive = ACG::Vec3f(_state.clear_color()[0],_state.clear_color()[1],_state.clear_color()[2]);
    }
    else if (_drawMode & (drawModes_.facesColoredPerFace | drawModes_.facesColoredPerVertex
                     | drawModes_.halffacesColoredPerHalfface | drawModes_.halffacesColoredPerVertex ))
    {
        ro.shaderDesc.vertexColors = true;
        ro.shaderDesc.numLights = -1;
        ro.shaderDesc.shadeMode = SG_SHADE_GOURAUD;
    }
856
857
858
859
860
861
    else if (_drawMode & drawModes_.facesColoredPerFaceFlatShaded)
    {
        ro.shaderDesc.vertexColors = true;
        ro.shaderDesc.numLights = -1;
        ro.shaderDesc.shadeMode = SG_SHADE_FLAT;
    }
862
863
864
865
866
867
868
869
870
871
    else
    {
        ro.shaderDesc.numLights = 0;
        ro.shaderDesc.vertexColors = false;
    }

    ro.vertexBuffer = facesBufferManager_.getBuffer();
    ro.vertexDecl = facesBufferManager_.getVertexDeclaration();

    ro.glDrawArrays(GL_TRIANGLES, 0, facesBufferManager_.getNumOfVertices());
872
873
874
    if (facesBufferManager_.getNumOfVertices() > 0) {
        _renderer->addRenderObject(&ro);
    }
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
}

template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::getEdgeRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat)
{
    RenderObject ro;
    ro.initFromState(&_state);

    ro.debugName = "VolumeMeshNodeEdges";

    //Todo: use DrawModeProperties

    // reset renderobject
    ro.depthRange = Vec2f(0.0f, 1.0f);
    ro.depthTest = true;
    ro.depthWrite = true;
    ro.depthFunc = GL_LESS;
    ro.setMaterial(_mat);

    ro.shaderDesc.clearTextures();

    // no lighting, as there are no normals anyway
    ro.shaderDesc.shadeMode = SG_SHADE_UNLIT;

    // thick lines
    if (_mat && _mat->lineWidth() > 1.0f)
      ro.setupLineRendering(_mat->lineWidth(), ACG::Vec2f(_state.viewport_width(), _state.viewport_height()));

    edgesBufferManager_.setDefaultColor(_state.specular_color());
    edgesBufferManager_.setOptionsFromDrawMode(_drawMode);

    if (_drawMode & ( drawModes_.edgesColoredPerEdge | drawModes_.halfedgesColoredPerHalfedge |
                      drawModes_.irregularInnerEdges | drawModes_.irregularOuterEdges ))
    {
        ro.shaderDesc.vertexColors = true;
    }
    else
    {
        ro.emissive = ACG::Vec3f(_state.specular_color()[0],_state.specular_color()[1],_state.specular_color()[2]);
    }

    ro.vertexBuffer = edgesBufferManager_.getBuffer();
    ro.vertexDecl = edgesBufferManager_.getVertexDeclaration();

    ro.glDrawArrays(GL_LINES, 0, edgesBufferManager_.getNumOfVertices());
920
921
922
    if (edgesBufferManager_.getNumOfVertices() > 0) {
        _renderer->addRenderObject(&ro);
    }
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
}

template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::getVertexRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat)
{
    RenderObject ro;
    ro.initFromState(&_state);

    ro.debugName = "VolumeMeshNodeVertices";


    //Todo: use DrawModeProperties

    // reset renderobject
    ro.depthRange = Vec2f(0.0f, 1.0f);
    ro.depthTest = true;
    ro.depthWrite = true;
    ro.depthFunc = GL_LESS;
    ro.setMaterial(_mat);

    ro.shaderDesc.clearTextures();

    // no lighting, as there are no normals anyway
    ro.shaderDesc.shadeMode = SG_SHADE_UNLIT;

    // draw with point size
    if (_mat && _mat->pointSize() > 1.0f)
      ro.setupPointRendering(_mat->pointSize(), ACG::Vec2f(_state.viewport_width(), _state.viewport_height()));

    verticesBufferManager_.setDefaultColor(_state.specular_color());
    verticesBufferManager_.setOptionsFromDrawMode(_drawMode);


    if (_drawMode & ( drawModes_.verticesColored ))
      ro.shaderDesc.vertexColors = true;
    else
      ro.emissive = ACG::Vec3f(_state.specular_color()[0],_state.specular_color()[1],_state.specular_color()[2]);

    ro.vertexBuffer = verticesBufferManager_.getBuffer();
    ro.vertexDecl = verticesBufferManager_.getVertexDeclaration();

    ro.glDrawArrays(GL_POINTS, 0, verticesBufferManager_.getNumOfVertices());
965
966
967
    if (verticesBufferManager_.getNumOfVertices() > 0) {
        _renderer->addRenderObject(&ro);
    }
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
}



template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::getSelectionRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat)
{
    RenderObject ro;
    ro.initFromState(&_state);

    ro.debugName = "VolumeMeshNodeSelections";

    ro.setMaterial(_mat);

    ro.depthTest = true;
    ro.depthFunc = GL_LEQUAL;

    ro.shaderDesc.clearTextures();
    ro.shaderDesc.vertexColors = false;
    ro.shaderDesc.numLights = -1;
    ro.shaderDesc.shadeMode = SG_SHADE_UNLIT;

    ro.diffuse = ACG::Vec3f(selection_color_[0],selection_color_[1],selection_color_[2]);
    ro.ambient = ACG::Vec3f(selection_color_[0],selection_color_[1],selection_color_[2]);
    ro.specular = ACG::Vec3f(selection_color_[0],selection_color_[1],selection_color_[2]);
    ro.emissive = ACG::Vec3f(selection_color_[0],selection_color_[1],selection_color_[2]);

    if ((_drawMode & drawModes_.cellBasedDrawModes) && !(_drawMode & drawModes_.vertexBasedDrawModes))
        vertexSelectionBufferManager_.enableVertexOnCellPrimitives();
    else
        vertexSelectionBufferManager_.enableVertexPrimitives();

    if ((_drawMode & (drawModes_.cellBasedDrawModes | drawModes_.edgesOnCells)) && !(_drawMode & (drawModes_.edgeBasedDrawModes & ~drawModes_.edgesOnCells)))
        edgeSelectionBufferManager_.enableEdgeOnCellPrimitives();
    else
        edgeSelectionBufferManager_.enableEdgePrimitives();

    if ((_drawMode & drawModes_.cellBasedDrawModes) && !(_drawMode & (drawModes_.faceBasedDrawModes | drawModes_.halffaceBasedDrawModes)))
        faceSelectionBufferManager_.enableFaceOnCellPrimitives();
    else
        faceSelectionBufferManager_.enableFacePrimitives();

    cellSelectionBufferManager_.enableCellPrimitives();

    ro.depthRange = Vec2f(0.0f,1.0f);

    ro.vertexBuffer = vertexSelectionBufferManager_.getBuffer();
    ro.vertexDecl = vertexSelectionBufferManager_.getVertexDeclaration();
    ro.glDrawArrays(GL_POINTS, 0, vertexSelectionBufferManager_.getNumOfVertices());
    if (vertexSelectionBufferManager_.getNumOfVertices())
    {
      ro.debugName = "VolumeMeshNode.VertexSelections";
      ro.setupPointRendering(_state.point_size(), ACG::Vec2f(_state.viewport_width(), _state.viewport_height()));
      _renderer->addRenderObject(&ro);

      // reset shader templates
      ro.shaderDesc.vertexTemplateFile = "";
      ro.shaderDesc.geometryTemplateFile = "";
      ro.shaderDesc.fragmentTemplateFile = "";
    }

    ro.vertexBuffer = edgeSelectionBufferManager_.getBuffer();
    ro.vertexDecl = edgeSelectionBufferManager_.getVertexDeclaration();
    ro.glDrawArrays(GL_LINES, 0, edgeSelectionBufferManager_.getNumOfVertices());
    if (edgeSelectionBufferManager_.getNumOfVertices())
    {
      ro.debugName = "VolumeMeshNode.EdgeSelections";

      ro.setupLineRendering(_state.line_width(), ACG::Vec2f(_state.viewport_width(), _state.viewport_height()));
      _renderer->addRenderObject(&ro);

      // reset shader templates
      ro.shaderDesc.vertexTemplateFile = "";
      ro.shaderDesc.geometryTemplateFile = "";
      ro.shaderDesc.fragmentTemplateFile = "";
    }

    ro.depthRange = Vec2f(0.01f, 1.0f);

    ro.vertexBuffer = faceSelectionBufferManager_.getBuffer();
    ro.vertexDecl = faceSelectionBufferManager_.getVertexDeclaration();
    ro.glDrawArrays(GL_TRIANGLES, 0, faceSelectionBufferManager_.getNumOfVertices());
    if (faceSelectionBufferManager_.getNumOfVertices())
    {
      ro.debugName = "VolumeMeshNode.FaceSelections";

      _renderer->addRenderObject(&ro);
    }

    ro.vertexBuffer = cellSelectionBufferManager_.getBuffer();
    ro.vertexDecl = cellSelectionBufferManager_.getVertexDeclaration();
    ro.glDrawArrays(GL_TRIANGLES, 0, cellSelectionBufferManager_.getNumOfVertices());
    if (cellSelectionBufferManager_.getNumOfVertices())
    {
      ro.debugName = "VolumeMeshNode.CellSelections";
      _renderer->addRenderObject(&ro);
    }


}

template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat)
{

    DrawModes::DrawMode cellDrawMode   = drawModes_.getFirstCellDrawMode(_drawMode);
    DrawModes::DrawMode faceDrawMode   = drawModes_.getFirstFaceDrawMode(_drawMode);
    DrawModes::DrawMode edgeDrawMode   = drawModes_.getFirstEdgeDrawMode(_drawMode);
    DrawModes::DrawMode vertexDrawMode = drawModes_.getFirstVertexDrawMode(_drawMode);

    if (!face_normals_calculated_)
    {
        if ( (cellDrawMode & drawModes_.cellsFlatShaded) ||
             (faceDrawMode & (drawModes_.facesFlatShaded | drawModes_.halffacesFlatShaded  | drawModes_.facesTexturedShaded)) )
            update_face_normals();
    }
    if (!vertex_normals_calculated_)
    {
        if ( (cellDrawMode & (drawModes_.cellsSmoothShaded | drawModes_.cellsPhongShaded)) ||
             (faceDrawMode & (drawModes_.facesSmoothShaded | drawModes_.halffacesSmoothShaded | drawModes_.facesPhongShaded | drawModes_.halffacesPhongShaded)) )
            update_vertex_normals();
    }

    //the VolumeMeshBufferManager can handle non atomic drawmodes if it consists of one
    // edge based draw mode (except edges on cells) and irregular edges
    edgeDrawMode |= _drawMode & (drawModes_.irregularInnerEdges | drawModes_.irregularOuterEdges);

    if (cellDrawMode)
        getCellRenderObjects(_renderer, _state, cellDrawMode, _mat);
    else
        cellsBufferManager_.free();
    if (faceDrawMode)
        getFaceRenderObjects(_renderer, _state, faceDrawMode, _mat);
    else
        facesBufferManager_.free();
    if (edgeDrawMode)
        getEdgeRenderObjects(_renderer, _state, edgeDrawMode, _mat);
    else
        edgesBufferManager_.free();
    if (vertexDrawMode)
        getVertexRenderObjects(_renderer, _state, vertexDrawMode, _mat);
    else
        verticesBufferManager_.free();

    getSelectionRenderObjects(_renderer, _state, cellDrawMode | faceDrawMode | edgeDrawMode | vertexDrawMode, _mat);

}

//----------------------------------------------------------------------------


template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::pick(GLState& _state, PickTarget _target) {
1121
1122
1123
1124
1125
1126
    bool drawModeOverride = false;
    if(lastDrawMode_ == DrawModes::NONE)  // no last drawmode so the picking renderer
    {                                     // is probably calling this function for rendering
      lastDrawMode_ = drawMode();
      drawModeOverride = true;
    }
1127

1128
1129
1130
1131
1132
1133
1134
1135
   if(_state.compatibilityProfile())
     pickCompat(_state, _target);
   else
   {
     GLState::depthRange(0.01, 1.0);
     if (lastCellDrawMode_)
     {
         //draw cells so the user cannot pick invisible stuff
1136

1137
         GLState::bindBuffer(GL_ARRAY_BUFFER, cellsBufferManager_.getBuffer());
1138

1139
         GLState::vertexPointer(3, GL_FLOAT, cellsBufferManager_.getStride(), reinterpret_cast<GLvoid*>(0));
1140

1141
1142
         Vec4f bc = _state.specular_color();
         _state.set_color(Vec4f(0.0,0.0,0.0,0.0));
1143

1144
         glDrawArrays(GL_TRIANGLES, 0, cellsBufferManager_.getNumOfVertices());
1145

1146
1147
1148
         _state.set_color(bc);
         GLState::bindBuffer(GL_ARRAY_BUFFER, 0);
     }
1149

1150
1151
1152
     if (lastFaceDrawMode_)
     {
         //draw faces so the user cannot pick invisible stuff
1153

1154
1155
         GLState::bindBuffer(GL_ARRAY_BUFFER, facesBufferManager_.getBuffer());
         GLState::vertexPointer(3, GL_FLOAT, facesBufferManager_.getStride(), reinterpret_cast<GLvoid*>(0));
1156

1157
1158
         Vec4f bc = _state.specular_color();
         _state.set_color(Vec4f(0.0,0.0,0.0,0.0));
1159

1160
         glDrawArrays(GL_TRIANGLES, 0, facesBufferManager_.getNumOfVertices());
1161

1162
1163
1164
         _state.set_color(bc);
         GLState::bindBuffer(GL_ARRAY_BUFFER, 0);
     }
1165

1166
     GLenum oldDepthFunc = _state.depthFunc();
1167

1168
     GLState::depthRange(0.0, 1.0);
1169

1170
     _state.set_depthFunc(GL_LEQUAL);
1171

1172
1173
1174
1175
1176
1177
1178
1179
     switch (_target) {
     case PICK_VERTEX: {
         if (lastPickTarget_ != PICK_VERTEX)
             vertexPickBufferManager_.invalidateColors();
         _state.pick_set_maximum(mesh_.n_vertices());
         pickVertices(_state);
         break;
     }
1180

1181
1182
1183
1184
1185
     case PICK_EDGE: {
         _state.pick_set_maximum(mesh_.n_edges());
         pickEdges(_state, 0);
         break;
     }
1186

1187
1188
1189
1190
1191
     case PICK_FACE: {
         _state.pick_set_maximum(mesh_.n_faces());
         pickFaces(_state, 0);
         break;
     }
1192

1193
1194
1195
1196
1197
     case PICK_CELL: {
         _state.pick_set_maximum(mesh_.n_cells());
         pickCells(_state, 0);
         break;
     }
1198

1199
1200
1201
     case PICK_ANYTHING: {
         if (lastPickTarget_ != PICK_ANYTHING)
             vertexPickBufferManager_.invalidateColors();
1202

1203
1204
1205
1206
         int nv = mesh_.n_vertices();
         int ne = mesh_.n_edges();
         int nf = mesh_.n_faces();
         int nc = mesh_.n_cells();
1207

1208
1209
1210
1211
1212
1213
1214
         _state.pick_set_maximum(nv + ne + nf + nc);
         pickVertices(_state);
         pickEdges(_state, nv);
         pickFaces(_state, nv + ne);
         pickCells(_state, nv + ne + nf);
         break;
     }
1215

1216
1217
1218
     default:
         break;
     }
1219

1220
1221
1222
     _state.set_depthFunc(oldDepthFunc);
     lastPickTarget_ = _target;
   }
1223
1224
   if(drawModeOverride)
     lastDrawMode_ = DrawModes::NONE;
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
}

template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::clear_cut_planes()
{
     cellsBufferManager_.clearCutPlanes();
     facesBufferManager_.clearCutPlanes();
     edgesBufferManager_.clearCutPlanes();
     verticesBufferManager_.clearCutPlanes();

     cellSelectionBufferManager_.clearCutPlanes();
     faceSelectionBufferManager_.clearCutPlanes();
     edgeSelectionBufferManager_.clearCutPlanes();
     vertexSelectionBufferManager_.clearCutPlanes();

     cellPickBufferManager_.clearCutPlanes();
     facePickBufferManager_.clearCutPlanes();
     edgePickBufferManager_.clearCutPlanes();
     vertexPickBufferManager_.clearCutPlanes();
}

//----------------------------------------------------------------------------



template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::pickVertices(GLState& _state) {

    if (lastDrawMode_ & drawModes_.vertexBasedDrawModes)
        vertexPickBufferManager_.enableVertexPrimitives();
    else if (lastDrawMode_ & drawModes_.cellBasedDrawModes)
        vertexPickBufferManager_.enableVertexOnCellPrimitives();
    else
        vertexPickBufferManager_.enableVertexPrimitives();

    vertexPickBufferManager_.disableNormals();
    vertexPickBufferManager_.enablePickColors();

1263
    static GLSL::Program* pickVertexShader_;
1264
    static ACG::ShaderGenDesc desc;
1265
1266
1267
    desc.vertexColors = true;
    desc.vertexTemplateFile = "Picking/vertexPassColors.glsl";
    desc.fragmentTemplateFile = "Picking/passColors_fs.glsl";
1268

1269
    // load from cache    
1270
    pickVertexShader_ = ShaderCache::getInstance()->getProgram(&desc,nullptr);
1271

1272
1273
1274
    // check link status
    if(!( pickVertexShader_ && pickVertexShader_->isLinked()))
      return;
1275
    GLState::bindBuffer(GL_ARRAY_BUFFER, vertexPickBufferManager_.getPickBuffer(_state, 0));
1276
    pickVertexShader_->use();
1277
    vertexPickBufferManager_.getVertexDeclaration()->activateShaderPipeline(pickVertexShader_);    
1278

1279
    pickVertexShader_->setUniform("pickVertexOffset", static_cast<int>(_state.pick_current_index()));
1280
    pickVertexShader_->setUniform("mWVP", _state.projection() * _state.modelview());
1281
1282
1283
1284
1285
1286

    float oldPointSize = _state.point_size();
    _state.set_point_size(1.5*_state.point_size());

    glDrawArrays(GL_POINTS, 0, vertexPickBufferManager_.getNumOfVertices());

1287
1288
    vertexPickBufferManager_.getVertexDeclaration()->deactivateShaderPipeline(pickVertexShader_);
    pickVertexShader_->disable();
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
    _state.set_point_size(oldPointSize);

    GLState::bindBuffer(GL_ARRAY_BUFFER, 0);

}

//----------------------------------------------------------------------------


template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::pickEdges(GLState& _state, unsigned int _offset) {

    if ((lastDrawMode_ & (drawModes_.cellBasedDrawModes | drawModes_.edgesOnCells)) && !(lastDrawMode_ & (drawModes_.edgeBasedDrawModes & ~drawModes_.edgesOnCells)))
        edgePickBufferManager_.enableEdgeOnCellPrimitives();
    else
        edgePickBufferManager_.enableEdgePrimitives();

    edgePickBufferManager_.enablePickColors();
    edgePickBufferManager_.disableNormals();
1308
1309
1310
1311
1312
1313
    
    static GLSL::Program* pickVertexShader_;
    static ACG::ShaderGenDesc desc;
    desc.vertexColors = true;
    desc.vertexTemplateFile = "Picking/vertexPassColors.glsl";
    desc.fragmentTemplateFile = "Picking/passColors_fs.glsl";
1314

1315
1316
    // load from cache    
    pickVertexShader_ = ShaderCache::getInstance()->getProgram(&desc,nullptr);
1317

1318
1319
1320
1321
    // check link status
    if(!( pickVertexShader_ && pickVertexShader_->isLinked()))
      return;
    GLState::bindBuffer(GL_ARRAY_BUFFER, edgePickBufferManager_.getPickBuffer(_state, _offset));
1322

1323
1324
    pickVertexShader_->use();
    edgePickBufferManager_.getVertexDeclaration()->activateShaderPipeline(pickVertexShader_);    
1325

1326
1327
1328
    pickVertexShader_->setUniform("pickVertexOffset", static_cast<int>(_state.pick_current_index()));
    pickVertexShader_->setUniform("mWVP", _state.projection() * _state.modelview());
    
1329
1330
1331
1332
1333
    float oldLineWidth = _state.line_width();
    _state.set_line_width(4.0*_state.line_width());

    glDrawArrays(GL_LINES, 0, edgePickBufferManager_.getNumOfVertices());

1334
1335
    edgePickBufferManager_.getVertexDeclaration()->deactivateShaderPipeline(pickVertexShader_);
    pickVertexShader_->disable();
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
    _state.set_line_width(oldLineWidth);

    GLState::bindBuffer(GL_ARRAY_BUFFER, 0);

}

//----------------------------------------------------------------------------


template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::pickFaces(GLState& _state, unsigned int _offset) {

    if (lastDrawMode_ & (drawModes_.faceBasedDrawModes | drawModes_.halffaceBasedDrawModes))
        facePickBufferManager_.enableFacePrimitives();
    else if (lastDrawMode_ & drawModes_.cellBasedDrawModes)
        facePickBufferManager_.enableFaceOnCellPrimitives();
    else
        facePickBufferManager_.enableFacePrimitives();

    facePickBufferManager_.disableNormals();
    facePickBufferManager_.enablePickColors();
1357
1358
1359
1360
1361
1362
    
    static GLSL::Program* pickVertexShader_;
    static ACG::ShaderGenDesc desc;
    desc.vertexColors = true;
    desc.vertexTemplateFile = "Picking/vertexPassColors.glsl";
    desc.fragmentTemplateFile = "Picking/passColors_fs.glsl";
1363

1364
1365
    // load from cache    
    pickVertexShader_ = ShaderCache::getInstance()->getProgram(&desc,nullptr);
1366

1367
1368
1369
1370
1371
1372
1373
    // check link status
    if(!( pickVertexShader_ && pickVertexShader_->isLinked()))
      return;
    GLState::bindBuffer(GL_ARRAY_BUFFER, facePickBufferManager_.getPickBuffer(_state, _offset));
    
    pickVertexShader_->use();
    facePickBufferManager_.getVertexDeclaration()->activateShaderPipeline(pickVertexShader_);    
1374

1375
1376
    pickVertexShader_->setUniform("pickVertexOffset", static_cast<int>(_state.pick_current_index()));
    pickVertexShader_->setUniform("mWVP", _state.projection() * _state.modelview());
1377
1378

    glDrawArrays(GL_TRIANGLES, 0, facePickBufferManager_.getNumOfVertices());
1379
1380
1381
    
    facePickBufferManager_.getVertexDeclaration()->deactivateShaderPipeline(pickVertexShader_);
    pickVertexShader_->disable();
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
    GLState::bindBuffer(GL_ARRAY_BUFFER, 0);
}

//----------------------------------------------------------------------------


template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::pickCells(GLState& _state, unsigned int _offset) {

    cellPickBufferManager_.enablePickColors();
    cellPickBufferManager_.disableNormals();
    cellPickBufferManager_.enableCellPrimitives();
1394
1395
1396
1397
1398
1399
    
    static GLSL::Program* pickVertexShader_;
    static ACG::ShaderGenDesc desc;
    desc.vertexColors = true;
    desc.vertexTemplateFile = "Picking/vertexPassColors.glsl";
    desc.fragmentTemplateFile = "Picking/passColors_fs.glsl";
1400

1401
1402
    // load from cache    
    pickVertexShader_ = ShaderCache::getInstance()->getProgram(&desc,nullptr);
1403

1404
1405
1406
1407
1408
1409
1410
    // check link status
    if(!( pickVertexShader_ && pickVertexShader_->isLinked()))
      return;
    GLState::bindBuffer(GL_ARRAY_BUFFER, cellPickBufferManager_.getPickBuffer(_state, _offset));
    
    pickVertexShader_->use();
    cellPickBufferManager_.getVertexDeclaration()->activateShaderPipeline(pickVertexShader_);    
1411

1412
1413
    pickVertexShader_->setUniform("pickVertexOffset", static_cast<int>(_state.pick_current_index()));
    pickVertexShader_->setUniform("mWVP", _state.projection() * _state.modelview());
1414
1415
1416
1417


    glDrawArrays(GL_TRIANGLES, 0, cellPickBufferManager_.getNumOfVertices());

1418
1419
1420
    
    cellPickBufferManager_.getVertexDeclaration()->deactivateShaderPipeline(pickVertexShader_);
    pickVertexShader_->disable();
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
    GLState::bindBuffer(GL_ARRAY_BUFFER, 0);
}

//----------------------------------------------------------------------------

template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::update_face_normals()
{
    normalAttrib_.update_face_normals();
    face_normals_calculated_ = true;
}

//----------------------------------------------------------------------------

template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::update_vertex_normals()
{
    normalAttrib_.update_vertex_normals();
    vertex_normals_calculated_ = true;
    //update_vertex_normals will also compute face normals
    face_normals_calculated_ = true;
}

//----------------------------------------------------------------------------

template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::add_cut_plane(const Vec3d& _p, const Vec3d& _n, const Vec3d& _xsize,
        const Vec3d& _ysize) {

1450
    add_cut_plane(Plane(_p, _n, _xsize, _ysize));
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
}

template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::set_scaling(double _scale)
{
    scale_ = _scale;
    cellsBufferManager_.setScale(scale_);
    edgesBufferManager_.setScale(scale_);
    cellSelectionBufferManager_.setScale(scale_);
    faceSelectionBufferManager_.setScale(scale_);
    edgeSelectionBufferManager_.setScale(scale_);
    vertexSelectionBufferManager_.setScale(scale_);
    cellPickBufferManager_.setScale(scale_);
    facePickBufferManager_.setScale(scale_);
    edgePickBufferManager_.setScale(scale_);
    vertexPickBufferManager_.setScale(scale_);
}

template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::set_boundary_only(bool _boundary)
{
    boundary_only_ = _boundary;

    cellsBufferManager_.setBoundaryOnly(_boundary);
    facesBufferManager_.setBoundaryOnly(_boundary);
    edgesBufferManager_.setBoundaryOnly(_boundary);
    verticesBufferManager_.setBoundaryOnly(_boundary);

    cellSelectionBufferManager_.setBoundaryOnly(_boundary);
    faceSelectionBufferManager_.setBoundaryOnly(_boundary);
    edgeSelectionBufferManager_.setBoundaryOnly(_boundary);
    vertexSelectionBufferManager_.setBoundaryOnly(_boundary);

    cellPickBufferManager_.setBoundaryOnly(_boundary);
    facePickBufferManager_.setBoundaryOnly(_boundary);
    edgePickBufferManager_.setBoundaryOnly(_boundary);
    vertexPickBufferManager_.setScale(_boundary);

}

template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::set_topology_changed(bool _topology_changed)
{
    if (_topology_changed)
        invalidateAllBuffers();
}

template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::set_geometry_changed(bool _geom_changed)
{
    if (_geom_changed)
        invalidateAllBuffers();
}

template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::set_color_changed(bool _color_changed)
{
    if (_color_changed)
    {
        cellsBufferManager_.invalidateColors();
        facesBufferManager_.invalidateColors();
        edgesBufferManager_.invalidateColors();
        verticesBufferManager_.invalidateColors();
    }

}

template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::set_texture_changed(bool _texture_changed)
{
    if (_texture_changed)
    {
        cellsBufferManager_.invalidateTexCoords();
        facesBufferManager_.invalidateTexCoords();
        edgesBufferManager_.invalidateTexCoords();
        verticesBufferManager_.invalidateTexCoords();
    }

}

template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::set_selection_changed(bool _selection_changed)
{
    if (_selection_changed)
        invalidateAllSelectionBuffers();
}

//----------------------------------------------------------------------------


template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::add_cut_plane(const Plane& _p) {
    cellsBufferManager_.addCutPlane(_p);
    facesBufferManager_.addCutPlane(_p);
    edgesBufferManager_.addCutPlane(_p);
    verticesBufferManager_.addCutPlane(_p);

    cellSelectionBufferManager_.addCutPlane(_p);
    faceSelectionBufferManager_.addCutPlane(_p);
    edgeSelectionBufferManager_.addCutPlane(_p);
    vertexSelectionBufferManager_.addCutPlane(_p);

    cellPickBufferManager_.addCutPlane(_p);
    facePickBufferManager_.addCutPlane(_p);
    edgePickBufferManager_.addCutPlane(_p);
    vertexPickBufferManager_.addCutPlane(_p);
}


//=============================================================================
} // namespace SceneGraph
} // namespace ACG
//=============================================================================