43 #define VOLUMEMESHNODET_CC 47 #include "VolumeMeshNode.hh" 49 #include <ACG/GL/gl.hh> 50 #include <ACG/Utils/VSToolsT.hh> 52 #include <type_traits> 54 #include <ACG/GL/RenderObject.hh> 55 #include <ACG/GL/VertexDeclaration.hh> 56 #include <ACG/GL/IRenderer.hh> 57 #include <ACG/ShaderUtils/GLSLShader.hh> 58 #include <ACG/GL/ShaderCache.hh> 59 #include <ACG/Geometry/Types/PlaneType.hh> 61 #include <OpenVolumeMesh/Mesh/HexahedralMesh.hh> 74 template<
class VolumeMeshT>
85 boundary_only_(false),
86 translucency_factor_(0.1f),
87 selection_color_(
ACG::
Vec4f(1.0f, 0.0f, 0.0f, 1.0f)),
88 statusAttrib_(_statusAttrib),
89 colorAttrib_(_colorAttrib),
90 normalAttrib_(_normalAttrib),
91 texcoordAttrib_(_texcoordAttrib),
92 materialNode_(_matNode),
94 cellsBufferManager_ (_mesh, _statusAttrib, _colorAttrib, _normalAttrib, _texcoordAttrib),
95 facesBufferManager_ (_mesh, _statusAttrib, _colorAttrib, _normalAttrib, _texcoordAttrib),
96 edgesBufferManager_ (_mesh, _statusAttrib, _colorAttrib, _normalAttrib, _texcoordAttrib),
97 verticesBufferManager_(_mesh, _statusAttrib, _colorAttrib, _normalAttrib, _texcoordAttrib),
99 cellSelectionBufferManager_ (_mesh, _statusAttrib, _colorAttrib, _normalAttrib, _texcoordAttrib),
100 faceSelectionBufferManager_ (_mesh, _statusAttrib, _colorAttrib, _normalAttrib, _texcoordAttrib),
101 edgeSelectionBufferManager_ (_mesh, _statusAttrib, _colorAttrib, _normalAttrib, _texcoordAttrib),
102 vertexSelectionBufferManager_(_mesh, _statusAttrib, _colorAttrib, _normalAttrib, _texcoordAttrib),
104 cellPickBufferManager_ (_mesh, _statusAttrib, _colorAttrib, _normalAttrib, _texcoordAttrib),
105 facePickBufferManager_ (_mesh, _statusAttrib, _colorAttrib, _normalAttrib, _texcoordAttrib),
106 edgePickBufferManager_ (_mesh, _statusAttrib, _colorAttrib, _normalAttrib, _texcoordAttrib),
107 vertexPickBufferManager_(_mesh, _statusAttrib, _colorAttrib, _normalAttrib, _texcoordAttrib),
110 lastDrawMode_ (DrawModes::NONE),
111 lastCellDrawMode_ (DrawModes::NONE),
112 lastFaceDrawMode_ (DrawModes::NONE),
113 lastEdgeDrawMode_ (DrawModes::NONE),
114 lastVertexDrawMode_(DrawModes::NONE),
116 face_normals_calculated_(false),
117 vertex_normals_calculated_(false)
119 vertexSelectionBufferManager_.setSelectionOnly(
true);
120 edgeSelectionBufferManager_.setSelectionOnly(
true);
121 faceSelectionBufferManager_.setSelectionOnly(
true);
122 cellSelectionBufferManager_.setSelectionOnly(
true);
128 template<
class VolumeMeshT>
135 template<
class VolumeMeshT>
138 int n_vertices(mesh_.n_vertices());
139 for (
int i = 0; i < n_vertices; ++i) {
149 template<
class VolumeMeshT>
153 if (mesh_.n_cells() > 0)
155 result |= drawModes_.cellsTransparent;
156 result |= drawModes_.cellsFlatShaded;
157 result |= drawModes_.cellsSmoothShaded;
158 result |= drawModes_.cellsPhongShaded;
159 if (colorAttrib_.vertex_colors_available())
160 result |= drawModes_.cellsColoredPerVertex;
161 if (colorAttrib_.halfface_colors_available())
162 result |= drawModes_.cellsColoredPerHalfface;
163 if (colorAttrib_.face_colors_available())
164 result |= drawModes_.cellsColoredPerFace;
165 if (colorAttrib_.cell_colors_available())
166 result |= drawModes_.cellsColoredPerCell;
169 if (mesh_.n_faces() > 0)
171 result |= drawModes_.facesFlatShaded;
172 result |= drawModes_.facesSmoothShaded;
173 result |= drawModes_.facesPhongShaded;
174 if (colorAttrib_.vertex_colors_available())
175 result |= drawModes_.facesColoredPerVertex;
176 if (colorAttrib_.face_colors_available())
177 result |= drawModes_.facesColoredPerFace;
178 if (colorAttrib_.face_colors_available())
179 result |= drawModes_.facesColoredPerFaceFlatShaded;
180 if (texcoordAttrib_.vertex_texcoords_available())
181 result |= drawModes_.facesTextured;
182 if (texcoordAttrib_.vertex_texcoords_available())
183 result |= drawModes_.facesTexturedShaded;
186 if (mesh_.n_halffaces() > 0)
188 result |= drawModes_.halffacesFlatShaded;
189 result |= drawModes_.halffacesSmoothShaded;
190 result |= drawModes_.halffacesPhongShaded;
191 if (colorAttrib_.vertex_colors_available())
192 result |= drawModes_.halffacesColoredPerVertex;
193 if (colorAttrib_.halfface_colors_available())
194 result |= drawModes_.halffacesColoredPerHalfface;
197 if (mesh_.n_edges() > 0)
199 result |= drawModes_.edgesWireframe;
201 if (mesh_.n_cells () > 0)
202 result |= drawModes_.edgesOnCells;
203 if (mesh_.n_faces() > 0)
204 result |= drawModes_.edgesHiddenLine;
205 if (colorAttrib_.edge_colors_available())
206 result |= drawModes_.edgesColoredPerEdge;
208 if (std::is_base_of<HexahedralMeshTopologyKernel, VolumeMeshT>::value)
210 result |= drawModes_.irregularInnerEdges;
211 result |= drawModes_.irregularOuterEdges;
215 if (mesh_.n_halfedges() > 0)
217 result |= drawModes_.halfedgesWireframe;
219 if (mesh_.n_faces() > 0)
220 result |= drawModes_.halfedgesHiddenLine;
221 if (colorAttrib_.halfedge_colors_available())
222 result |= drawModes_.halfedgesColoredPerHalfedge;
225 if (mesh_.n_vertices() > 0)
227 result |= drawModes_.verticesFlatShaded;
229 if (colorAttrib_.vertex_colors_available())
230 result |= drawModes_.verticesColored;
241 template<
class VolumeMeshT>
247 cellsBufferManager_.setOptionsFromDrawMode(_drawMode);
248 GLState::bindBuffer(GL_ARRAY_BUFFER, cellsBufferManager_.getBuffer());
249 GLState::enableClientState(GL_VERTEX_ARRAY);
250 GLState::vertexPointer(3, GL_FLOAT, cellsBufferManager_.getStride(),
reinterpret_cast<GLvoid*
>(0));
252 GLState::enableClientState(GL_NORMAL_ARRAY);
253 GLState::normalPointer(GL_FLOAT, cellsBufferManager_.getStride(),
reinterpret_cast<GLvoid*
>(cellsBufferManager_.getNormalOffset()));
255 if (_drawMode & (drawModes_.cellsColoredPerCell | drawModes_.cellsColoredPerFace | drawModes_.cellsColoredPerHalfface | drawModes_.cellsColoredPerVertex))
258 GLState::enableClientState(GL_COLOR_ARRAY);
259 GLState::colorPointer(4, GL_UNSIGNED_BYTE, cellsBufferManager_.getStride(),
reinterpret_cast<GLvoid*
>(cellsBufferManager_.getColorOffset()));
261 GLState::shadeModel(GL_SMOOTH);
262 GLState::disable(GL_LIGHTING);
263 GLState::enable(GL_DEPTH_TEST);
266 else if (_drawMode & drawModes_.cellsSmoothShaded)
268 GLState::shadeModel(GL_SMOOTH);
269 GLState::enable(GL_LIGHTING);
270 GLState::enable(GL_DEPTH_TEST);
272 else if (_drawMode & drawModes_.cellsFlatShaded)
274 GLState::shadeModel(GL_FLAT);
275 GLState::enable(GL_LIGHTING);
276 GLState::enable(GL_DEPTH_TEST);
278 else if (_drawMode & drawModes_.cellsTransparent)
280 GLState::shadeModel(GL_FLAT);
281 GLState::disable(GL_LIGHTING);
282 GLState::disable(GL_DEPTH_TEST);
283 GLState::disableClientState(GL_COLOR_ARRAY);
286 GLState::enable(GL_BLEND);
287 GLState::blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
290 glDrawArrays(GL_TRIANGLES, 0, cellsBufferManager_.getNumOfVertices());
292 if (_drawMode & drawModes_.cellsTransparent)
295 GLState::disable(GL_BLEND);
298 GLState::disableClientState(GL_COLOR_ARRAY);
299 GLState::bindBuffer(GL_ARRAY_BUFFER, 0);
304 template<
class VolumeMeshT>
313 if ((_drawMode & drawModes_.faceBasedDrawModes) || boundary_only_)
315 GLState::disable(GL_CULL_FACE);
319 GLState::enable(GL_CULL_FACE);
320 GLState::cullFace(GL_BACK);
323 GLState::enable(GL_DEPTH_TEST);
325 facesBufferManager_.setOptionsFromDrawMode(_drawMode);
326 GLState::bindBuffer(GL_ARRAY_BUFFER, facesBufferManager_.getBuffer());
327 GLState::enableClientState(GL_VERTEX_ARRAY);
328 GLState::vertexPointer(3, GL_FLOAT, facesBufferManager_.getStride(),
reinterpret_cast<GLvoid*
>(0));
330 if (_drawMode & (drawModes_.hiddenLineBackgroundFaces))
332 GLState::disable(GL_LIGHTING);
333 GLState::shadeModel(GL_FLAT);
334 GLState::disableClientState(GL_COLOR_ARRAY);
335 GLState::disableClientState(GL_NORMAL_ARRAY);
338 else if (_drawMode & (drawModes_.facesColoredPerFace | drawModes_.facesColoredPerVertex
339 | drawModes_.halffacesColoredPerHalfface | drawModes_.halffacesColoredPerVertex ))
341 GLState::enableClientState(GL_COLOR_ARRAY);
342 GLState::colorPointer(4, GL_UNSIGNED_BYTE, facesBufferManager_.getStride(),
reinterpret_cast<GLvoid*
>(facesBufferManager_.getColorOffset()));
344 GLState::disable(GL_LIGHTING);
345 GLState::shadeModel(GL_SMOOTH);
347 else if (_drawMode & (drawModes_.facesColoredPerFaceFlatShaded))
349 GLState::enable(GL_COLOR_MATERIAL);
351 GLState::enableClientState(GL_COLOR_ARRAY);
352 GLState::colorPointer(4, GL_UNSIGNED_BYTE, facesBufferManager_.getStride(),
reinterpret_cast<GLvoid*
>(facesBufferManager_.getColorOffset()));
354 GLState::enable(GL_LIGHTING);
355 GLState::shadeModel(GL_FLAT);
357 GLState::enableClientState(GL_NORMAL_ARRAY);
358 GLState::normalPointer(GL_FLOAT, facesBufferManager_.getStride(),
reinterpret_cast<GLvoid*
>(facesBufferManager_.getNormalOffset()));
360 else if (_drawMode & (drawModes_.facesTexturedShaded) )
362 glClientActiveTexture(GL_TEXTURE0);
363 ACG::GLState::texcoordPointer(2, GL_FLOAT, facesBufferManager_.getStride(),
reinterpret_cast<GLvoid*
>(facesBufferManager_.getTexCoordOffset()));
366 GLState::enable(GL_LIGHTING);
367 GLState::disableClientState(GL_COLOR_ARRAY);
369 GLState::enableClientState(GL_NORMAL_ARRAY);
370 GLState::normalPointer(GL_FLOAT, facesBufferManager_.getStride(),
reinterpret_cast<GLvoid*
>(facesBufferManager_.getNormalOffset()));
372 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
373 GLState::shadeModel(GL_SMOOTH);
375 else if (_drawMode & (drawModes_.facesTextured) )
377 glClientActiveTexture(GL_TEXTURE0);
378 ACG::GLState::texcoordPointer(2, GL_FLOAT, facesBufferManager_.getStride(),
reinterpret_cast<GLvoid*
>(facesBufferManager_.getTexCoordOffset()));
381 GLState::disableClientState(GL_COLOR_ARRAY);
382 GLState::disableClientState(GL_NORMAL_ARRAY);
384 GLState::disable(GL_LIGHTING);
385 GLState::shadeModel(GL_SMOOTH);
387 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
391 GLState::enable(GL_LIGHTING);
392 GLState::disableClientState(GL_COLOR_ARRAY);
394 GLState::enableClientState(GL_NORMAL_ARRAY);
395 GLState::normalPointer(GL_FLOAT, facesBufferManager_.getStride(),
reinterpret_cast<GLvoid*
>(facesBufferManager_.getNormalOffset()));
397 GLState::shadeModel(GL_SMOOTH);
400 glDrawArrays(GL_TRIANGLES, 0, facesBufferManager_.getNumOfVertices());
402 GLState::disableClientState(GL_COLOR_ARRAY);
404 GLState::bindBuffer(GL_ARRAY_BUFFER, 0);
406 if (_drawMode & (drawModes_.edgesHiddenLine | drawModes_.halfedgesHiddenLine))
412 template<
class VolumeMeshT>
418 edgesBufferManager_.setOptionsFromDrawMode(_drawMode);
420 GLState::bindBuffer(GL_ARRAY_BUFFER, edgesBufferManager_.getBuffer());
421 GLState::enableClientState(GL_VERTEX_ARRAY);
422 GLState::vertexPointer(3, GL_FLOAT, edgesBufferManager_.getStride(),
reinterpret_cast<GLvoid*
>(0));
424 if (_drawMode & ( drawModes_.edgesColoredPerEdge | drawModes_.halfedgesColoredPerHalfedge |
425 drawModes_.irregularInnerEdges | drawModes_.irregularOuterEdges ))
427 GLState::enableClientState(GL_COLOR_ARRAY);
428 GLState::colorPointer(4, GL_UNSIGNED_BYTE, edgesBufferManager_.getStride(),
reinterpret_cast<GLvoid*
>(edgesBufferManager_.getColorOffset()));
430 GLState::disable(GL_LIGHTING);
431 GLState::shadeModel(GL_SMOOTH);
442 GLState::disableClientState(GL_NORMAL_ARRAY);
446 glDrawArrays(GL_LINES, 0, edgesBufferManager_.getNumOfVertices());
449 GLState::disableClientState(GL_COLOR_ARRAY);
451 GLState::bindBuffer(GL_ARRAY_BUFFER, 0);
455 template<
class VolumeMeshT>
458 verticesBufferManager_.setOptionsFromDrawMode(_drawMode);
459 GLState::bindBuffer(GL_ARRAY_BUFFER, verticesBufferManager_.getBuffer());
460 GLState::enableClientState(GL_VERTEX_ARRAY);
461 GLState::vertexPointer(3, GL_FLOAT, verticesBufferManager_.getStride(),
reinterpret_cast<GLvoid*
>(0));
463 GLState::depthRange(0.0,1.0);
465 if (_drawMode & ( drawModes_.verticesColored ))
467 GLState::enableClientState(GL_COLOR_ARRAY);
468 GLState::colorPointer(4, GL_UNSIGNED_BYTE, verticesBufferManager_.getStride(),
reinterpret_cast<GLvoid*
>(verticesBufferManager_.getColorOffset()));
470 GLState::disable(GL_LIGHTING);
471 GLState::shadeModel(GL_SMOOTH);
480 GLState::disableClientState(GL_NORMAL_ARRAY);
483 glDrawArrays(GL_POINTS, 0, verticesBufferManager_.getNumOfVertices());
485 GLState::disableClientState(GL_COLOR_ARRAY);
487 GLState::bindBuffer(GL_ARRAY_BUFFER, 0);
491 template<
class VolumeMeshT>
496 GLint currentProgramm;
497 glGetIntegerv(GL_CURRENT_PROGRAM, ¤tProgramm);
501 GLState::enable(GL_DEPTH_TEST);
502 GLState::depthFunc(GL_LEQUAL);
505 GLState::disable(GL_LIGHTING);
506 GLState::shadeModel(GL_FLAT);
507 glDisable(GL_CULL_FACE);
508 GLState::disableClientState(GL_NORMAL_ARRAY);
509 GLState::disableClientState(GL_COLOR_ARRAY);
511 GLState::disable(GL_TEXTURE_2D);
513 GLState::enableClientState(GL_VERTEX_ARRAY);
515 if ((_drawMode & drawModes_.cellBasedDrawModes) && !(_drawMode & drawModes_.vertexBasedDrawModes))
516 vertexSelectionBufferManager_.enableVertexOnCellPrimitives();
518 vertexSelectionBufferManager_.enableVertexPrimitives();
520 if ((_drawMode & (drawModes_.cellBasedDrawModes | drawModes_.edgesOnCells)) && !(_drawMode & (drawModes_.edgeBasedDrawModes & ~drawModes_.edgesOnCells)))
521 edgeSelectionBufferManager_.enableEdgeOnCellPrimitives();
523 edgeSelectionBufferManager_.enableEdgePrimitives();
525 if ((_drawMode & drawModes_.cellBasedDrawModes) && !(_drawMode & (drawModes_.faceBasedDrawModes | drawModes_.halffaceBasedDrawModes)))
526 faceSelectionBufferManager_.enableFaceOnCellPrimitives();
528 faceSelectionBufferManager_.enableFacePrimitives();
530 cellSelectionBufferManager_.enableCellPrimitives();
534 GLState::depthRange(0.0,1.0);
536 GLState::bindBuffer(GL_ARRAY_BUFFER, vertexSelectionBufferManager_.getBuffer());
537 GLState::vertexPointer(3, GL_FLOAT, 0, 0);
538 glDrawArrays(GL_POINTS, 0, vertexSelectionBufferManager_.getNumOfVertices());
540 GLState::bindBuffer(GL_ARRAY_BUFFER, edgeSelectionBufferManager_.getBuffer());
541 GLState::vertexPointer(3, GL_FLOAT, 0, 0);
542 glDrawArrays(GL_LINES, 0, edgeSelectionBufferManager_.getNumOfVertices());
544 GLState::depthRange(0.01,1.0);
546 GLState::bindBuffer(GL_ARRAY_BUFFER, faceSelectionBufferManager_.getBuffer());
547 GLState::vertexPointer(3, GL_FLOAT, 0, 0);
548 glDrawArrays(GL_TRIANGLES, 0, faceSelectionBufferManager_.getNumOfVertices());
550 GLState::bindBuffer(GL_ARRAY_BUFFER, cellSelectionBufferManager_.getBuffer());
551 GLState::vertexPointer(3, GL_FLOAT, 0, 0);
552 glDrawArrays(GL_TRIANGLES, 0, cellSelectionBufferManager_.getNumOfVertices());
554 GLState::depthRange(0.0,1.0);
558 GLState::bindBuffer(GL_ARRAY_BUFFER, 0);
567 template<
class VolumeMeshT>
570 invalidateAllDrawBuffers();
571 invalidateAllPickingBuffers();
572 invalidateAllSelectionBuffers();
575 template<
class VolumeMeshT>
578 cellsBufferManager_.invalidate();
579 facesBufferManager_.invalidate();
580 edgesBufferManager_.invalidate();
581 verticesBufferManager_.invalidate();
584 template<
class VolumeMeshT>
587 cellPickBufferManager_.invalidate();
588 facePickBufferManager_.invalidate();
589 edgePickBufferManager_.invalidate();
590 vertexPickBufferManager_.invalidate();
593 template<
class VolumeMeshT>
596 cellSelectionBufferManager_.invalidate();
597 faceSelectionBufferManager_.invalidate();
598 edgeSelectionBufferManager_.invalidate();
599 vertexSelectionBufferManager_.invalidate();
602 template<
class VolumeMeshT>
606 GLboolean lighting =
false;
607 glGetBooleanv(GL_LIGHTING, &lighting);
608 GLboolean color_material =
false;
609 glGetBooleanv(GL_COLOR_MATERIAL, &color_material);
610 GLboolean blend =
false;
611 glGetBooleanv(GL_BLEND, &blend);
612 GLboolean depth =
false;
613 glGetBooleanv(GL_DEPTH_TEST, &depth);
615 GLboolean cullFace =
false;
616 glGetBooleanv(GL_CULL_FACE, &cullFace);
618 glGetIntegerv(GL_CULL_FACE_MODE, &cullFaceMode);
620 glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &texmode);
622 glGetBooleanv(GL_TEXTURE_2D, &texturing);
629 bool clientStateEnabledVertexArray = GLState::isClientStateEnabled(GL_VERTEX_ARRAY);
630 bool clientStateEnabledColorArray = GLState::isClientStateEnabled(GL_COLOR_ARRAY);
631 bool clientStateEnabledNormalArray = GLState::isClientStateEnabled(GL_NORMAL_ARRAY);
632 bool clientStateEnabledTexCoordArray = GLState::isClientStateEnabled(GL_TEXTURE_COORD_ARRAY);
639 if (!face_normals_calculated_)
641 if ( (cellDrawMode & drawModes_.cellsFlatShaded) ||
642 (faceDrawMode & (drawModes_.facesFlatShaded | drawModes_.halffacesFlatShaded | drawModes_.facesTexturedShaded)) )
643 update_face_normals();
645 if (!vertex_normals_calculated_)
647 if ( (cellDrawMode & (drawModes_.cellsSmoothShaded | drawModes_.cellsPhongShaded)) ||
648 (faceDrawMode & (drawModes_.facesSmoothShaded | drawModes_.halffacesSmoothShaded | drawModes_.facesPhongShaded | drawModes_.halffacesPhongShaded)) )
649 update_vertex_normals();
654 edgeDrawMode |= _drawMode & (drawModes_.irregularInnerEdges | drawModes_.irregularOuterEdges);
657 if(faceDrawMode & (drawModes_.facesColoredPerFaceFlatShaded))
661 drawCells(_state, cellDrawMode);
663 cellsBufferManager_.free();
665 drawFaces(_state, faceDrawMode);
667 facesBufferManager_.free();
669 drawEdges(_state, edgeDrawMode);
671 edgesBufferManager_.free();
673 drawVertices(_state, vertexDrawMode);
675 verticesBufferManager_.free();
677 drawSelection(_state, cellDrawMode | faceDrawMode | edgeDrawMode | vertexDrawMode);
680 lastDrawMode_ = cellDrawMode | faceDrawMode | edgeDrawMode | vertexDrawMode;
681 lastCellDrawMode_ = cellDrawMode;
682 lastFaceDrawMode_ = faceDrawMode;
683 lastEdgeDrawMode_ = edgeDrawMode;
684 lastVertexDrawMode_ = vertexDrawMode;
713 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, texmode);
718 if (clientStateEnabledVertexArray)
719 GLState::enableClientState(GL_VERTEX_ARRAY);
721 GLState::disableClientState(GL_VERTEX_ARRAY);
723 if (clientStateEnabledColorArray)
724 GLState::enableClientState(GL_COLOR_ARRAY);
726 GLState::disableClientState(GL_COLOR_ARRAY);
728 if (clientStateEnabledNormalArray)
729 GLState::enableClientState(GL_NORMAL_ARRAY);
731 GLState::disableClientState(GL_NORMAL_ARRAY);
733 if (clientStateEnabledTexCoordArray)
734 GLState::enableClientState(GL_TEXTURE_COORD_ARRAY);
736 GLState::disableClientState(GL_TEXTURE_COORD_ARRAY);
742 template<
class VolumeMeshT>
748 ro.debugName =
"VolumeMeshNodeCells";
754 ro.depthWrite =
true;
756 ro.setMaterial(_mat);
764 if (_drawMode & (drawModes_.cellsColoredPerCell | drawModes_.cellsColoredPerFace | drawModes_.cellsColoredPerHalfface | drawModes_.cellsColoredPerVertex))
770 else if (_drawMode & drawModes_.cellsSmoothShaded)
775 else if (_drawMode & drawModes_.cellsFlatShaded)
780 else if (_drawMode & drawModes_.cellsTransparent)
784 ro.depthTest =
false;
791 ro.alpha = translucency_factor_;
794 ro.blendSrc = GL_SRC_ALPHA;
797 cellsBufferManager_.setOptionsFromDrawMode(_drawMode);
799 ro.
vertexDecl = cellsBufferManager_.getVertexDeclaration();
801 ro.glDrawArrays(GL_TRIANGLES, 0, cellsBufferManager_.getNumOfVertices());
802 if (cellsBufferManager_.getNumOfVertices() > 0) {
807 template<
class VolumeMeshT>
813 ro.debugName =
"VolumeMeshNodeFaces";
819 ro.depthWrite =
true;
821 ro.setMaterial(_mat);
829 facesBufferManager_.setOptionsFromDrawMode(_drawMode);
832 if ((_drawMode & drawModes_.faceBasedDrawModes) || boundary_only_)
837 if (_drawMode & (drawModes_.hiddenLineBackgroundFaces))
849 else if (_drawMode & (drawModes_.facesColoredPerFace | drawModes_.facesColoredPerVertex
850 | drawModes_.halffacesColoredPerHalfface | drawModes_.halffacesColoredPerVertex ))
856 else if (_drawMode & drawModes_.facesColoredPerFaceFlatShaded)
869 ro.
vertexDecl = facesBufferManager_.getVertexDeclaration();
871 ro.glDrawArrays(GL_TRIANGLES, 0, facesBufferManager_.getNumOfVertices());
872 if (facesBufferManager_.getNumOfVertices() > 0) {
877 template<
class VolumeMeshT>
883 ro.debugName =
"VolumeMeshNodeEdges";
890 ro.depthWrite =
true;
892 ro.setMaterial(_mat);
904 edgesBufferManager_.setOptionsFromDrawMode(_drawMode);
906 if (_drawMode & ( drawModes_.edgesColoredPerEdge | drawModes_.halfedgesColoredPerHalfedge |
907 drawModes_.irregularInnerEdges | drawModes_.irregularOuterEdges ))
917 ro.
vertexDecl = edgesBufferManager_.getVertexDeclaration();
919 ro.glDrawArrays(GL_LINES, 0, edgesBufferManager_.getNumOfVertices());
920 if (edgesBufferManager_.getNumOfVertices() > 0) {
925 template<
class VolumeMeshT>
931 ro.debugName =
"VolumeMeshNodeVertices";
939 ro.depthWrite =
true;
941 ro.setMaterial(_mat);
953 verticesBufferManager_.setOptionsFromDrawMode(_drawMode);
956 if (_drawMode & ( drawModes_.verticesColored ))
962 ro.
vertexDecl = verticesBufferManager_.getVertexDeclaration();
964 ro.glDrawArrays(GL_POINTS, 0, verticesBufferManager_.getNumOfVertices());
965 if (verticesBufferManager_.getNumOfVertices() > 0) {
972 template<
class VolumeMeshT>
978 ro.debugName =
"VolumeMeshNodeSelections";
980 ro.setMaterial(_mat);
990 ro.
diffuse =
ACG::Vec3f(selection_color_[0],selection_color_[1],selection_color_[2]);
991 ro.ambient =
ACG::Vec3f(selection_color_[0],selection_color_[1],selection_color_[2]);
992 ro.specular =
ACG::Vec3f(selection_color_[0],selection_color_[1],selection_color_[2]);
993 ro.emissive =
ACG::Vec3f(selection_color_[0],selection_color_[1],selection_color_[2]);
995 if ((_drawMode & drawModes_.cellBasedDrawModes) && !(_drawMode & drawModes_.vertexBasedDrawModes))
996 vertexSelectionBufferManager_.enableVertexOnCellPrimitives();
998 vertexSelectionBufferManager_.enableVertexPrimitives();
1000 if ((_drawMode & (drawModes_.cellBasedDrawModes | drawModes_.edgesOnCells)) && !(_drawMode & (drawModes_.edgeBasedDrawModes & ~drawModes_.edgesOnCells)))
1001 edgeSelectionBufferManager_.enableEdgeOnCellPrimitives();
1003 edgeSelectionBufferManager_.enableEdgePrimitives();
1005 if ((_drawMode & drawModes_.cellBasedDrawModes) && !(_drawMode & (drawModes_.faceBasedDrawModes | drawModes_.halffaceBasedDrawModes)))
1006 faceSelectionBufferManager_.enableFaceOnCellPrimitives();
1008 faceSelectionBufferManager_.enableFacePrimitives();
1010 cellSelectionBufferManager_.enableCellPrimitives();
1014 ro.
vertexBuffer = vertexSelectionBufferManager_.getBuffer();
1015 ro.
vertexDecl = vertexSelectionBufferManager_.getVertexDeclaration();
1016 ro.glDrawArrays(GL_POINTS, 0, vertexSelectionBufferManager_.getNumOfVertices());
1017 if (vertexSelectionBufferManager_.getNumOfVertices())
1019 ro.debugName =
"VolumeMeshNode.VertexSelections";
1029 ro.
vertexBuffer = edgeSelectionBufferManager_.getBuffer();
1030 ro.
vertexDecl = edgeSelectionBufferManager_.getVertexDeclaration();
1031 ro.glDrawArrays(GL_LINES, 0, edgeSelectionBufferManager_.getNumOfVertices());
1032 if (edgeSelectionBufferManager_.getNumOfVertices())
1034 ro.debugName =
"VolumeMeshNode.EdgeSelections";
1047 ro.
vertexBuffer = faceSelectionBufferManager_.getBuffer();
1048 ro.
vertexDecl = faceSelectionBufferManager_.getVertexDeclaration();
1049 ro.glDrawArrays(GL_TRIANGLES, 0, faceSelectionBufferManager_.getNumOfVertices());
1050 if (faceSelectionBufferManager_.getNumOfVertices())
1052 ro.debugName =
"VolumeMeshNode.FaceSelections";
1057 ro.
vertexBuffer = cellSelectionBufferManager_.getBuffer();
1058 ro.
vertexDecl = cellSelectionBufferManager_.getVertexDeclaration();
1059 ro.glDrawArrays(GL_TRIANGLES, 0, cellSelectionBufferManager_.getNumOfVertices());
1060 if (cellSelectionBufferManager_.getNumOfVertices())
1062 ro.debugName =
"VolumeMeshNode.CellSelections";
1069 template<
class VolumeMeshT>
1078 if (!face_normals_calculated_)
1080 if ( (cellDrawMode & drawModes_.cellsFlatShaded) ||
1081 (faceDrawMode & (drawModes_.facesFlatShaded | drawModes_.halffacesFlatShaded | drawModes_.facesTexturedShaded)) )
1082 update_face_normals();
1084 if (!vertex_normals_calculated_)
1086 if ( (cellDrawMode & (drawModes_.cellsSmoothShaded | drawModes_.cellsPhongShaded)) ||
1087 (faceDrawMode & (drawModes_.facesSmoothShaded | drawModes_.halffacesSmoothShaded | drawModes_.facesPhongShaded | drawModes_.halffacesPhongShaded)) )
1088 update_vertex_normals();
1093 edgeDrawMode |= _drawMode & (drawModes_.irregularInnerEdges | drawModes_.irregularOuterEdges);
1096 getCellRenderObjects(_renderer, _state, cellDrawMode, _mat);
1098 cellsBufferManager_.free();
1100 getFaceRenderObjects(_renderer, _state, faceDrawMode, _mat);
1102 facesBufferManager_.free();
1104 getEdgeRenderObjects(_renderer, _state, edgeDrawMode, _mat);
1106 edgesBufferManager_.free();
1108 getVertexRenderObjects(_renderer, _state, vertexDrawMode, _mat);
1110 verticesBufferManager_.free();
1112 getSelectionRenderObjects(_renderer, _state, cellDrawMode | faceDrawMode | edgeDrawMode | vertexDrawMode, _mat);
1119 template<
class VolumeMeshT>
1121 bool drawModeOverride =
false;
1122 if(lastDrawMode_ == DrawModes::NONE)
1124 lastDrawMode_ = drawMode();
1125 drawModeOverride =
true;
1128 if(_state.compatibilityProfile())
1129 pickCompat(_state, _target);
1132 GLState::depthRange(0.01, 1.0);
1133 if (lastCellDrawMode_)
1137 GLState::bindBuffer(GL_ARRAY_BUFFER, cellsBufferManager_.getBuffer());
1139 GLState::vertexPointer(3, GL_FLOAT, cellsBufferManager_.getStride(),
reinterpret_cast<GLvoid*
>(0));
1144 glDrawArrays(GL_TRIANGLES, 0, cellsBufferManager_.getNumOfVertices());
1147 GLState::bindBuffer(GL_ARRAY_BUFFER, 0);
1150 if (lastFaceDrawMode_)
1154 GLState::bindBuffer(GL_ARRAY_BUFFER, facesBufferManager_.getBuffer());
1155 GLState::vertexPointer(3, GL_FLOAT, facesBufferManager_.getStride(),
reinterpret_cast<GLvoid*
>(0));
1160 glDrawArrays(GL_TRIANGLES, 0, facesBufferManager_.getNumOfVertices());
1163 GLState::bindBuffer(GL_ARRAY_BUFFER, 0);
1166 GLenum oldDepthFunc = _state.
depthFunc();
1168 GLState::depthRange(0.0, 1.0);
1174 if (lastPickTarget_ != PICK_VERTEX)
1175 vertexPickBufferManager_.invalidateColors();
1177 pickVertices(_state);
1183 pickEdges(_state, 0);
1189 pickFaces(_state, 0);
1195 pickCells(_state, 0);
1199 case PICK_ANYTHING: {
1200 if (lastPickTarget_ != PICK_ANYTHING)
1201 vertexPickBufferManager_.invalidateColors();
1203 int nv = mesh_.n_vertices();
1204 int ne = mesh_.n_edges();
1205 int nf = mesh_.n_faces();
1206 int nc = mesh_.n_cells();
1209 pickVertices(_state);
1210 pickEdges(_state, nv);
1211 pickFaces(_state, nv + ne);
1212 pickCells(_state, nv + ne + nf);
1221 lastPickTarget_ = _target;
1223 if(drawModeOverride)
1224 lastDrawMode_ = DrawModes::NONE;
1227 template<
class VolumeMeshT>
1230 cellsBufferManager_.clearCutPlanes();
1231 facesBufferManager_.clearCutPlanes();
1232 edgesBufferManager_.clearCutPlanes();
1233 verticesBufferManager_.clearCutPlanes();
1235 cellSelectionBufferManager_.clearCutPlanes();
1236 faceSelectionBufferManager_.clearCutPlanes();
1237 edgeSelectionBufferManager_.clearCutPlanes();
1238 vertexSelectionBufferManager_.clearCutPlanes();
1240 cellPickBufferManager_.clearCutPlanes();
1241 facePickBufferManager_.clearCutPlanes();
1242 edgePickBufferManager_.clearCutPlanes();
1243 vertexPickBufferManager_.clearCutPlanes();
1250 template<
class VolumeMeshT>
1253 if (lastDrawMode_ & drawModes_.vertexBasedDrawModes)
1254 vertexPickBufferManager_.enableVertexPrimitives();
1255 else if (lastDrawMode_ & drawModes_.cellBasedDrawModes)
1256 vertexPickBufferManager_.enableVertexOnCellPrimitives();
1258 vertexPickBufferManager_.enableVertexPrimitives();
1260 vertexPickBufferManager_.disableNormals();
1261 vertexPickBufferManager_.enablePickColors();
1265 desc.vertexColors =
true;
1266 desc.vertexTemplateFile =
"Picking/vertexPassColors.glsl";
1267 desc.fragmentTemplateFile =
"Picking/passColors_fs.glsl";
1270 pickVertexShader_ = ShaderCache::getInstance()->getProgram(&desc,
nullptr);
1273 if(!( pickVertexShader_ && pickVertexShader_->
isLinked()))
1275 GLState::bindBuffer(GL_ARRAY_BUFFER, vertexPickBufferManager_.getPickBuffer(_state, 0));
1276 pickVertexShader_->
use();
1277 vertexPickBufferManager_.getVertexDeclaration()->activateShaderPipeline(pickVertexShader_);
1285 glDrawArrays(GL_POINTS, 0, vertexPickBufferManager_.getNumOfVertices());
1287 vertexPickBufferManager_.getVertexDeclaration()->deactivateShaderPipeline(pickVertexShader_);
1291 GLState::bindBuffer(GL_ARRAY_BUFFER, 0);
1298 template<
class VolumeMeshT>
1301 if ((lastDrawMode_ & (drawModes_.cellBasedDrawModes | drawModes_.edgesOnCells)) && !(lastDrawMode_ & (drawModes_.edgeBasedDrawModes & ~drawModes_.edgesOnCells)))
1302 edgePickBufferManager_.enableEdgeOnCellPrimitives();
1304 edgePickBufferManager_.enableEdgePrimitives();
1306 edgePickBufferManager_.enablePickColors();
1307 edgePickBufferManager_.disableNormals();
1311 desc.vertexColors =
true;
1312 desc.vertexTemplateFile =
"Picking/vertexPassColors.glsl";
1313 desc.fragmentTemplateFile =
"Picking/passColors_fs.glsl";
1316 pickVertexShader_ = ShaderCache::getInstance()->getProgram(&desc,
nullptr);
1319 if(!( pickVertexShader_ && pickVertexShader_->
isLinked()))
1321 GLState::bindBuffer(GL_ARRAY_BUFFER, edgePickBufferManager_.getPickBuffer(_state, _offset));
1323 pickVertexShader_->
use();
1324 edgePickBufferManager_.getVertexDeclaration()->activateShaderPipeline(pickVertexShader_);
1332 glDrawArrays(GL_LINES, 0, edgePickBufferManager_.getNumOfVertices());
1334 edgePickBufferManager_.getVertexDeclaration()->deactivateShaderPipeline(pickVertexShader_);
1338 GLState::bindBuffer(GL_ARRAY_BUFFER, 0);
1345 template<
class VolumeMeshT>
1348 if (lastDrawMode_ & (drawModes_.faceBasedDrawModes | drawModes_.halffaceBasedDrawModes))
1349 facePickBufferManager_.enableFacePrimitives();
1350 else if (lastDrawMode_ & drawModes_.cellBasedDrawModes)
1351 facePickBufferManager_.enableFaceOnCellPrimitives();
1353 facePickBufferManager_.enableFacePrimitives();
1355 facePickBufferManager_.disableNormals();
1356 facePickBufferManager_.enablePickColors();
1360 desc.vertexColors =
true;
1361 desc.vertexTemplateFile =
"Picking/vertexPassColors.glsl";
1362 desc.fragmentTemplateFile =
"Picking/passColors_fs.glsl";
1365 pickVertexShader_ = ShaderCache::getInstance()->getProgram(&desc,
nullptr);
1368 if(!( pickVertexShader_ && pickVertexShader_->
isLinked()))
1370 GLState::bindBuffer(GL_ARRAY_BUFFER, facePickBufferManager_.getPickBuffer(_state, _offset));
1372 pickVertexShader_->
use();
1373 facePickBufferManager_.getVertexDeclaration()->activateShaderPipeline(pickVertexShader_);
1378 glDrawArrays(GL_TRIANGLES, 0, facePickBufferManager_.getNumOfVertices());
1380 facePickBufferManager_.getVertexDeclaration()->deactivateShaderPipeline(pickVertexShader_);
1382 GLState::bindBuffer(GL_ARRAY_BUFFER, 0);
1388 template<
class VolumeMeshT>
1391 cellPickBufferManager_.enablePickColors();
1392 cellPickBufferManager_.disableNormals();
1393 cellPickBufferManager_.enableCellPrimitives();
1397 desc.vertexColors =
true;
1398 desc.vertexTemplateFile =
"Picking/vertexPassColors.glsl";
1399 desc.fragmentTemplateFile =
"Picking/passColors_fs.glsl";
1402 pickVertexShader_ = ShaderCache::getInstance()->getProgram(&desc,
nullptr);
1405 if(!( pickVertexShader_ && pickVertexShader_->
isLinked()))
1407 GLState::bindBuffer(GL_ARRAY_BUFFER, cellPickBufferManager_.getPickBuffer(_state, _offset));
1409 pickVertexShader_->
use();
1410 cellPickBufferManager_.getVertexDeclaration()->activateShaderPipeline(pickVertexShader_);
1416 glDrawArrays(GL_TRIANGLES, 0, cellPickBufferManager_.getNumOfVertices());
1419 cellPickBufferManager_.getVertexDeclaration()->deactivateShaderPipeline(pickVertexShader_);
1421 GLState::bindBuffer(GL_ARRAY_BUFFER, 0);
1426 template<
class VolumeMeshT>
1430 face_normals_calculated_ =
true;
1435 template<
class VolumeMeshT>
1439 vertex_normals_calculated_ =
true;
1441 face_normals_calculated_ =
true;
1446 template<
class VolumeMeshT>
1448 const Vec3d& _ysize) {
1450 add_cut_plane(
Plane(_p, _n, _xsize, _ysize));
1453 template<
class VolumeMeshT>
1457 cellsBufferManager_.setScale(scale_);
1458 edgesBufferManager_.setScale(scale_);
1459 cellSelectionBufferManager_.setScale(scale_);
1460 faceSelectionBufferManager_.setScale(scale_);
1461 edgeSelectionBufferManager_.setScale(scale_);
1462 vertexSelectionBufferManager_.setScale(scale_);
1463 cellPickBufferManager_.setScale(scale_);
1464 facePickBufferManager_.setScale(scale_);
1465 edgePickBufferManager_.setScale(scale_);
1466 vertexPickBufferManager_.setScale(scale_);
1469 template<
class VolumeMeshT>
1472 boundary_only_ = _boundary;
1474 cellsBufferManager_.setBoundaryOnly(_boundary);
1475 facesBufferManager_.setBoundaryOnly(_boundary);
1476 edgesBufferManager_.setBoundaryOnly(_boundary);
1477 verticesBufferManager_.setBoundaryOnly(_boundary);
1479 cellSelectionBufferManager_.setBoundaryOnly(_boundary);
1480 faceSelectionBufferManager_.setBoundaryOnly(_boundary);
1481 edgeSelectionBufferManager_.setBoundaryOnly(_boundary);
1482 vertexSelectionBufferManager_.setBoundaryOnly(_boundary);
1484 cellPickBufferManager_.setBoundaryOnly(_boundary);
1485 facePickBufferManager_.setBoundaryOnly(_boundary);
1486 edgePickBufferManager_.setBoundaryOnly(_boundary);
1487 vertexPickBufferManager_.setScale(_boundary);
1491 template<
class VolumeMeshT>
1494 if (_topology_changed)
1495 invalidateAllBuffers();
1498 template<
class VolumeMeshT>
1502 invalidateAllBuffers();
1505 template<
class VolumeMeshT>
1510 cellsBufferManager_.invalidateColors();
1511 facesBufferManager_.invalidateColors();
1512 edgesBufferManager_.invalidateColors();
1513 verticesBufferManager_.invalidateColors();
1518 template<
class VolumeMeshT>
1521 if (_texture_changed)
1523 cellsBufferManager_.invalidateTexCoords();
1524 facesBufferManager_.invalidateTexCoords();
1525 edgesBufferManager_.invalidateTexCoords();
1526 verticesBufferManager_.invalidateTexCoords();
1531 template<
class VolumeMeshT>
1534 if (_selection_changed)
1535 invalidateAllSelectionBuffers();
1541 template<
class VolumeMeshT>
1543 cellsBufferManager_.addCutPlane(_p);
1544 facesBufferManager_.addCutPlane(_p);
1545 edgesBufferManager_.addCutPlane(_p);
1546 verticesBufferManager_.addCutPlane(_p);
1548 cellSelectionBufferManager_.addCutPlane(_p);
1549 faceSelectionBufferManager_.addCutPlane(_p);
1550 edgeSelectionBufferManager_.addCutPlane(_p);
1551 vertexSelectionBufferManager_.addCutPlane(_p);
1553 cellPickBufferManager_.addCutPlane(_p);
1554 facePickBufferManager_.addCutPlane(_p);
1555 edgePickBufferManager_.addCutPlane(_p);
1556 vertexPickBufferManager_.addCutPlane(_p);
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
const Vec4f & specular_color() const
get specular color
static void depthRange(GLclampd _zNear, GLclampd _zFar)
replaces glDepthRange, supports locking
Namespace providing different geometric functions concerning angles.
void clearTextures()
disables texture support and removes all texture types
static void texcoordPointer(GLint _size, GLenum _type, GLsizei _stride, const GLvoid *_pointer)
replaces glTexcoordPointer, supports locking
void update_face_normals()
updates face normals
void lineWidth(float _sz)
set line width (default: 1.0)
void update_vertex_normals()
updates vertex normals
pick any of the prior targets (should be implemented for all nodes)
VectorT< float, 3 > Vec3f
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
void pointSize(float _sz)
set point size (default: 1.0)
void set_twosided_lighting(bool _b)
set whether transparent or solid objects should be drawn
const GLMatrixd & projection() const
get projection matrix
VolumeMeshNodeT(const VolumeMesh &_mesh, OpenVolumeMesh::StatusAttrib &_statusAttrib, OpenVolumeMesh::ColorAttrib< Vec4f > &_colorAttrib, OpenVolumeMesh::NormalAttrib< VolumeMesh > &_normalAttrib, OpenVolumeMesh::TexCoordAttrib< Vec2f > &_texcoordAttrib, const MaterialNode *_matNode, BaseNode *_parent=0, std::string _name="<VolumeMeshNode>")
Constructor.
void set_color(const Vec4f &_col)
set color
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
int viewport_width() const
get viewport width
size_t pick_current_index() const
Returns the current color picking index (can be used for caching)
float point_size() const
get point size
float line_width() const
get line width
void set_depthFunc(const GLenum &_depth_func)
Call glDepthFunc() to actually change the depth comparison function, and store the new value in this ...
const Vec4f & clear_color() const
get background color
void disable()
Resets to standard rendering pipeline.
Vec2f depthRange
glDepthRange: (znear, zmax)
Interface class between scenegraph and renderer.
Vec3f diffuse
material definitions
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
GLenum depthFunc
GL_LESS, GL_LEQUAL, GL_GREATER ..
VectorT< float, 2 > Vec2f
void setupPointRendering(float _pointSize, const Vec2f &_screenSize)
Setup rendering of circle points.
A data structure basing on PolyhedralMesh with specializations for hexahedra.
void set_point_size(float _f)
set point size
static void useProgram(GLuint _program)
replaces glUseProgram, supports locking
bool twosided_lighting()
get whether transparenet or solid objects should be drawn
void set_line_width(float _f)
set line width
const Vec4f & base_color() const
get base color (used when lighting is off)
GLuint vertexBuffer
VBO, IBO ids, ignored if VAO is provided.
int viewport_height() const
get viewport height
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking
virtual void addRenderObject(RenderObject *_renderObject)
Callback for the scenegraph nodes, which send new render objects via this function.
void setupLineRendering(float _lineWidth, const Vec2f &_screenSize)
Setup rendering of thick lines.
const GLMatrixd & modelview() const
get modelview matrix
const Vec4f & color()
set color
ShaderGenDesc shaderDesc
Drawmode and other shader params.
PickTarget
What target to use for picking.
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
static void cullFace(GLenum _mode)
replaces glCullFace, supports locking
bool isLinked()
Returns if the program object has been succesfully linked.
GLenum blendDest
glBlendFunc: GL_SRC_ALPHA, GL_ZERO, GL_ONE, GL_ONE_MINUS_SRC_ALPHA ...
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
static void enableClientState(GLenum _cap)
replaces glEnableClientState, supports locking
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
void setUniform(const char *_name, GLint _value)
Set int uniform to specified value.
bool pick_set_maximum(size_t _idx)
Set the maximal number of primitives/components of your object.
void use()
Enables the program object for using.