43 #define VOLUMEMESHBUFFERMANAGERT_CC 45 #include "VolumeMeshBufferManager.hh" 47 template <
class VolumeMesh>
53 mDefaultColor(
ACG::
Vec4f(0.0,0.0,0.0,1.0)),
55 mStatusAttrib(statusAttrib_),
56 mColorAttrib(colorAttrib_),
57 mNormalAttrib(normalAttrib_),
58 mTexcoordAttrib(texcoordAttrib_),
60 mCurrentNumOfVertices(-1),
67 mCurrentPickOffset(-1),
70 mGeometryChanged(true),
71 mNormalsChanged(true),
73 mTexCoordsChanged(true),
75 mPrimitiveMode(PM_NONE),
77 mColorMode(CM_NO_COLORS),
78 mSkipUnselected(false),
79 mShowIrregularInnerEdges(false),
80 mShowIrregularOuterValence2Edges(false),
81 mSkipRegularEdges(false),
83 mCurrentPrimitiveMode(PM_NONE),
84 mCurrentNormalMode(NM_NONE),
85 mCurrentColorMode(CM_NO_COLORS),
86 mCurrentSkipUnselected(false),
87 mCurrentShowIrregularInnerEdges(false),
88 mCurrentShowIrregularOuterValence2Edges(false),
89 mCurrentSkipRegularEdges(false),
90 mCurrentBoundaryOnly(false),
91 mCurrentVertexSize(0),
92 mCurrentNormalOffset(0),
93 mCurrentColorOffset(0),
95 mCellInsidenessValid(),
96 mTexCoordMode(TCM_NONE),
97 mCurrentTexCoordMode(TCM_NONE),
99 mCurrentTexCoordOffset(0)
113 template <
class VolumeMesh>
117 unsigned char *v = (
unsigned char *) &_value;
135 template <
class VolumeMesh>
152 template <
class VolumeMesh>
155 unsigned char* buffer = _buffer + _offset*mVertexSize;
171 template <
class VolumeMesh>
174 unsigned char* buffer = _buffer + _offset*mVertexSize + mColorOffset;
193 template <
class VolumeMesh>
196 unsigned char* buffer = _buffer + _offset*mVertexSize + mColorOffset;
213 template <
class VolumeMesh>
216 unsigned char* buffer = _buffer + _offset*mVertexSize + mNormalOffset;
232 template <
class VolumeMesh>
235 unsigned char* buffer = _buffer + _offset*mVertexSize + mTexCoordOffset;
248 template <
class VolumeMesh>
251 unsigned int currentOffset = 0;
252 mVertexDeclaration.
clear();
257 if (mPrimitiveMode != PM_NONE)
260 currentOffset += 3*
sizeof(float);
263 if (mNormalMode != NM_NONE)
265 mNormalOffset = currentOffset;
267 currentOffset += 3*
sizeof(float);
270 if ((mColorMode != CM_NO_COLORS) || mShowIrregularInnerEdges || mShowIrregularOuterValence2Edges)
272 mColorOffset = currentOffset;
274 currentOffset += 4*
sizeof(char);
277 if ((mTexCoordMode != TCM_NONE))
279 mTexCoordOffset = currentOffset;
280 unsigned char numOfCoords = 0;
281 if (mTexCoordMode == TCM_SINGLE_2D)
284 currentOffset += numOfCoords *
sizeof(float);
287 mVertexSize = currentOffset;
295 template <
class VolumeMesh>
298 if (mNumOfVertices == -1)
300 return mNumOfVertices;
310 template <
class VolumeMesh>
313 if (mDefaultColor != _defaultColor)
316 mDefaultColor = _defaultColor;
328 template <
class VolumeMesh>
332 if (_drawMode & (mDrawModes.cellsColoredPerCell))
334 else if (_drawMode & (mDrawModes.cellsColoredPerFace | mDrawModes.facesColoredPerFace | mDrawModes.facesColoredPerFaceFlatShaded))
336 else if (_drawMode & (mDrawModes.cellsColoredPerHalfface | mDrawModes.halffacesColoredPerHalfface))
338 else if (_drawMode & ( mDrawModes.edgesColoredPerEdge ))
340 else if (_drawMode & (mDrawModes.halfedgesColoredPerHalfedge))
342 else if (_drawMode & (mDrawModes.cellsColoredPerVertex | mDrawModes.facesColoredPerVertex |
343 mDrawModes.halffacesColoredPerVertex | mDrawModes.edgesColoredPerEdge |
344 mDrawModes.verticesColored))
350 if (_drawMode & (mDrawModes.cellsFlatShaded | mDrawModes.halffacesFlatShaded))
352 else if (_drawMode & (mDrawModes.facesFlatShaded | mDrawModes.facesTexturedShaded | mDrawModes.facesColoredPerFaceFlatShaded))
354 else if (_drawMode & (mDrawModes.cellsSmoothShaded | mDrawModes.facesSmoothShaded | mDrawModes.halffacesSmoothShaded |
355 mDrawModes.cellsPhongShaded | mDrawModes.facesPhongShaded | mDrawModes.halffacesPhongShaded |
356 mDrawModes.cellsColoredPerCell | mDrawModes.cellsColoredPerFace | mDrawModes.cellsColoredPerHalfface |
357 mDrawModes.facesColoredPerFace | mDrawModes.cellsColoredPerVertex | mDrawModes.cellsTransparent))
362 if (_drawMode & (mDrawModes.irregularInnerEdges))
363 mShowIrregularInnerEdges =
true;
365 mShowIrregularInnerEdges =
false;
367 if (_drawMode & (mDrawModes.irregularOuterEdges))
368 mShowIrregularOuterValence2Edges =
true;
370 mShowIrregularOuterValence2Edges =
false;
372 if (!mShowIrregularInnerEdges && !mShowIrregularOuterValence2Edges)
373 mSkipRegularEdges =
false;
375 mSkipRegularEdges =
true;
379 if (_drawMode & (mDrawModes.facesTextured | mDrawModes.facesTexturedShaded))
380 mTexCoordMode = TCM_SINGLE_2D;
382 mTexCoordMode = TCM_NONE;
385 if (_drawMode & (mDrawModes.cellBasedDrawModes))
386 mPrimitiveMode = PM_CELLS;
387 else if (_drawMode & (mDrawModes.facesOnCells))
388 mPrimitiveMode = PM_FACES_ON_CELLS;
389 else if (_drawMode & (mDrawModes.faceBasedDrawModes | mDrawModes.hiddenLineBackgroundFaces))
390 mPrimitiveMode = PM_FACES;
391 else if (_drawMode & (mDrawModes.halffaceBasedDrawModes))
392 mPrimitiveMode = PM_HALFFACES;
393 else if (_drawMode & (mDrawModes.edgesOnCells))
394 mPrimitiveMode = PM_EDGES_ON_CELLS;
395 else if (_drawMode & ((mDrawModes.edgeBasedDrawModes) & ~(mDrawModes.irregularInnerEdges | mDrawModes.irregularOuterEdges)))
396 mPrimitiveMode = PM_EDGES;
397 else if (_drawMode & (mDrawModes.irregularInnerEdges | mDrawModes.irregularOuterEdges))
398 mPrimitiveMode = PM_IRREGULAR_EDGES;
399 else if (_drawMode & (mDrawModes.halfedgeBasedDrawModes))
400 mPrimitiveMode = PM_HALFEDGES;
401 else if (_drawMode & (mDrawModes.verticesOnCells))
402 mPrimitiveMode = PM_VERTICES_ON_CELLS;
403 else if (_drawMode & (mDrawModes.vertexBasedDrawModes))
404 mPrimitiveMode = PM_VERTICES;
406 mPrimitiveMode = PM_NONE;
418 template <
class VolumeMesh>
423 mCellInsidenessValid =
false;
433 template <
class VolumeMesh>
436 cut_planes_.push_back(_p);
438 mCellInsidenessValid =
false;
451 template <
class VolumeMesh>
464 template <
class VolumeMesh>
467 for(
typename std::vector<Plane>::iterator it = cut_planes_.begin(); it != cut_planes_.end(); ++it) {
471 double pn = (pl | it->normal);
472 double px = (pl | it->xDirection);
473 double py = (pl | it->yDirection);
475 if (pn < 0.0 && px > -0.5 && px < 0.5 && py > -0.5 && py < 0.5)
491 template <
class VolumeMesh>
494 if ( cut_planes_.empty() )
return true;
507 template <
class VolumeMesh>
510 if ( cut_planes_.empty() )
return true;
511 Edge e(mMesh.halfedge(_heh));
512 return is_inside(mMesh.vertex(e.from_vertex())) &&
is_inside(mMesh.vertex(e.to_vertex()));
524 template <
class VolumeMesh>
527 if ( cut_planes_.empty() )
return true;
528 Edge e(mMesh.edge(_eh));
529 return is_inside(mMesh.vertex(e.from_vertex())) &&
is_inside(mMesh.vertex(e.to_vertex()));
541 template <
class VolumeMesh>
544 if ( cut_planes_.empty() )
return true;
560 template <
class VolumeMesh>
563 if ( cut_planes_.empty() )
return true;
564 return is_inside(mMesh.halfface_handle(_fh,0));
578 template <
class VolumeMesh>
581 if (mStatusAttrib[_ch].hidden())
584 if (!mCellInsidenessValid)
587 return mCellInsideness[_ch.idx()];
590 template <
class VolumeMesh>
593 if (mStatusAttrib[_vh].hidden())
598 template <
class VolumeMesh>
601 if (mStatusAttrib[_heh].hidden())
606 template <
class VolumeMesh>
609 if (mStatusAttrib[_eh].hidden())
614 template <
class VolumeMesh>
617 if (mStatusAttrib[_hfh].hidden())
622 template <
class VolumeMesh>
625 if (mStatusAttrib[_fh].hidden())
630 template <
class VolumeMesh>
633 if (mStatusAttrib[_ch].hidden())
645 template <
class VolumeMesh>
648 if (mCellInsideness.size() != mMesh.n_cells())
649 mCellInsideness.resize(mMesh.n_cells());
651 for (
unsigned int i = 0; i < mMesh.n_cells(); i++)
656 if ( cut_planes_.empty() )
663 ACG::Vec3d vertexPos = mScale * mMesh.vertex(*cv_it) + (1-mScale) * cog;
664 if (!
is_inside(vertexPos)) inside =
false;
667 mCellInsideness[i] = inside;
670 mCellInsidenessValid =
true;
681 template <
class VolumeMesh>
684 return mCurrentPrimitiveMode != mPrimitiveMode ||
685 mCurrentNormalMode != mNormalMode ||
686 mCurrentColorMode != mColorMode ||
687 mCurrentSkipUnselected != mSkipUnselected ||
688 mCurrentShowIrregularInnerEdges != mShowIrregularInnerEdges ||
689 mCurrentShowIrregularOuterValence2Edges != mShowIrregularOuterValence2Edges ||
690 mCurrentSkipRegularEdges != mSkipRegularEdges ||
691 mCurrentBoundaryOnly != mBoundaryOnly;
699 template <
class VolumeMesh>
702 mCurrentPrimitiveMode = mPrimitiveMode;
703 mCurrentNormalMode = mNormalMode;
704 mCurrentColorMode = mColorMode;
705 mCurrentSkipUnselected = mSkipUnselected;
706 mCurrentShowIrregularInnerEdges = mShowIrregularInnerEdges;
707 mCurrentShowIrregularOuterValence2Edges = mShowIrregularOuterValence2Edges;
708 mCurrentSkipRegularEdges = mSkipRegularEdges;
709 mCurrentBoundaryOnly = mBoundaryOnly;
710 mCurrentVertexSize = mVertexSize;
711 mCurrentNormalOffset = mNormalOffset;
712 mCurrentColorOffset = mColorOffset;
713 mCurrentNumOfVertices = mNumOfVertices;
725 template <
class VolumeMesh>
728 if(_inner && _valence == 3) {
730 }
else if(_inner && _valence == 5) {
732 }
else if(!_inner && _valence > 3) {
734 }
else if(!_inner && _valence == 2) {
736 }
else if(_inner && _valence > 5) {
747 template <
class VolumeMesh>
750 unsigned int numOfVertices = 0;
754 if (mPrimitiveMode == PM_CELLS)
759 if (mStatusAttrib[*c_it].selected() && should_render(*c_it))
761 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
762 for (
unsigned int i = 0; i < hfs.size(); ++i)
763 numOfVertices += ((mMesh.valence(mMesh.face_handle(hfs[i])))-2)*3;
767 else if (mPrimitiveMode == PM_FACES)
771 if (mStatusAttrib[*f_it].selected() && should_render(*f_it) && (!mBoundaryOnly || mMesh.is_boundary(*f_it)))
772 numOfVertices += ((mMesh.valence(*f_it))-2)*3;
774 else if (mPrimitiveMode == PM_FACES_ON_CELLS)
778 if (mStatusAttrib[*f_it].selected())
781 else if (mPrimitiveMode == PM_HALFFACES)
785 if (mStatusAttrib[*hf_it].selected() && should_render(*hf_it) && (!mBoundaryOnly || mMesh.is_boundary(*hf_it)))
786 numOfVertices += ((mMesh.valence(mMesh.face_handle(*hf_it)))-2)*3;
788 else if (mPrimitiveMode == PM_EDGES)
792 if (mStatusAttrib[*e_it].selected() && should_render(*e_it) && (!mBoundaryOnly || mMesh.is_boundary(*e_it)))
795 else if (mPrimitiveMode == PM_EDGES_ON_CELLS)
799 if (mStatusAttrib[*e_it].selected())
802 else if (mPrimitiveMode == PM_HALFEDGES)
806 if (mStatusAttrib[*he_it].selected() && should_render(*he_it) && (!mBoundaryOnly || mMesh.is_boundary(*he_it)))
809 else if (mPrimitiveMode == PM_VERTICES)
813 if (mStatusAttrib[*v_it].selected() && should_render(*v_it) && (!mBoundaryOnly || mMesh.is_boundary(*v_it)))
816 else if (mPrimitiveMode == PM_VERTICES_ON_CELLS)
820 if (mStatusAttrib[*v_it].selected())
826 if (mPrimitiveMode == PM_VERTICES_ON_CELLS)
828 for (
unsigned int i = 0; i < mMesh.n_vertices(); i++)
831 else if (mPrimitiveMode == PM_VERTICES)
833 for (
unsigned int i = 0; i < mMesh.n_vertices(); i++)
837 else if (mPrimitiveMode == PM_FACES)
841 if (should_render(*f_it) && (!mBoundaryOnly || mMesh.is_boundary(*f_it)))
842 numOfVertices += ((mMesh.valence(*f_it))-2)*3;
844 else if (mPrimitiveMode == PM_FACES_ON_CELLS)
850 else if (mPrimitiveMode == PM_HALFFACES)
854 if (should_render(*hf_it) && (!mBoundaryOnly || mMesh.is_boundary(*hf_it)))
855 numOfVertices += ((mMesh.valence(mMesh.face_handle(*hf_it)))-2)*3;
857 else if (mPrimitiveMode == PM_CELLS)
862 if (should_render(*c_it))
864 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
865 for (
unsigned int i = 0; i < hfs.size(); ++i)
866 numOfVertices += ((mMesh.valence(mMesh.face_handle(hfs[i])))-2)*3;
870 else if (mPrimitiveMode == PM_EDGES_ON_CELLS)
875 else if ( mPrimitiveMode == PM_EDGES )
878 if (should_render(*e_it) && (!mBoundaryOnly || mMesh.is_boundary(*e_it)))
881 else if ( mPrimitiveMode == PM_IRREGULAR_EDGES )
884 if (should_render(*e_it) && (!mBoundaryOnly || mMesh.is_boundary(*e_it)))
886 bool boundary = mMesh.is_boundary(*e_it);
887 unsigned int valence = mMesh.valence(*e_it);
890 if(( boundary && valence == 3) || (!boundary && valence == 4))
continue;
892 if ((!(mShowIrregularOuterValence2Edges)) && ( boundary && valence == 2))
continue;
894 if ((!(mShowIrregularInnerEdges)) && (( !boundary && valence != 4) ||
895 ( boundary && valence < 2) ||
896 ( boundary && valence > 3)))
continue;
901 else if ( mPrimitiveMode == PM_HALFEDGES )
904 if (should_render(*he_it) && (!mBoundaryOnly || mMesh.is_boundary(*he_it)))
913 mNumOfVertices = numOfVertices;
923 template <
class VolumeMesh>
926 int incidentCells = 0;
928 if (mMesh.incident_cell(hf0) !=
CellHandle(-1))
929 if (should_render(mMesh.incident_cell(hf0)))
932 if (mMesh.incident_cell(hf1) !=
CellHandle(-1))
933 if (should_render(mMesh.incident_cell(hf1)))
935 return incidentCells;
945 template <
class VolumeMesh>
948 int incidentCells = 0;
951 if (hec_it->idx() != -1)
952 if (should_render(*hec_it))
954 return incidentCells;
964 template <
class VolumeMesh>
967 int incidentCells = 0;
969 if (vc_it->idx() != -1)
970 if (should_render(*vc_it))
972 return incidentCells;
982 template <
class VolumeMesh>
988 return mCogs[_ch.idx()];
998 template <
class VolumeMesh>
1001 if (mCogs.size() != mMesh.n_cells())
1002 mCogs.resize(mMesh.n_cells());
1008 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
1011 for (
unsigned int i = 0; i < hfs.size(); ++i)
1014 cog += mMesh.vertex(*hfv_it);
1017 cog = 1.0/count * cog;
1019 mCogs[c_it->idx()] = cog;
1030 template <
class VolumeMesh>
1033 return (mGeometryChanged) ||
1034 (mVertexSize != mCurrentVertexSize) ||
1035 (mPrimitiveMode != mCurrentPrimitiveMode) ||
1036 (mNumOfVertices != mCurrentNumOfVertices);
1044 template <
class VolumeMesh>
1047 return (mColorsChanged) ||
1048 (mVertexSize != mCurrentVertexSize) ||
1049 (mNumOfVertices != mCurrentNumOfVertices) ||
1050 (mPrimitiveMode != mCurrentPrimitiveMode) ||
1051 (mColorOffset != mCurrentColorOffset) ||
1052 (mColorMode != mCurrentColorMode) ||
1053 (mShowIrregularInnerEdges != mCurrentShowIrregularInnerEdges) ||
1054 (mShowIrregularOuterValence2Edges != mCurrentShowIrregularOuterValence2Edges);
1062 template <
class VolumeMesh>
1065 return (mTexCoordsChanged) ||
1066 (mVertexSize != mCurrentVertexSize) ||
1067 (mNumOfVertices != mCurrentNumOfVertices) ||
1068 (mPrimitiveMode != mCurrentPrimitiveMode) ||
1069 (mTexCoordOffset!= mCurrentTexCoordOffset);
1077 template <
class VolumeMesh>
1080 return (mNormalsChanged) ||
1081 (mVertexSize != mCurrentVertexSize) ||
1082 (mPrimitiveMode != mCurrentPrimitiveMode) ||
1083 (mNormalOffset != mCurrentNormalOffset) ||
1084 (mNormalMode != mCurrentNormalMode) ||
1085 (mNumOfVertices != mCurrentNumOfVertices);
1093 template <
class VolumeMesh>
1096 unsigned int pos = 0;
1098 if (mPrimitiveMode == PM_VERTICES)
1100 for (
unsigned int i = 0; i < mMesh.n_vertices(); ++i) {
1101 if (mSkipUnselected && !mStatusAttrib[
VertexHandle(i)].selected())
continue;
1103 if (mBoundaryOnly && !mMesh.is_boundary(
VertexHandle(i)))
continue;
1108 else if (mPrimitiveMode == PM_VERTICES_ON_CELLS)
1110 for (
unsigned int i = 0; i < mMesh.n_vertices(); ++i) {
1111 if (mSkipUnselected && !mStatusAttrib[
VertexHandle(i)].selected())
continue;
1117 if (should_render(*vc_it))
1122 else if (mPrimitiveMode == PM_FACES)
1124 std::vector<ACG::Vec3d> vertices;
1128 if (mSkipUnselected && !mStatusAttrib[*f_it].selected())
continue;
1129 if (mBoundaryOnly && !mMesh.is_boundary(*f_it))
continue;
1130 if (!should_render(*f_it))
continue;
1133 vertices.push_back(mMesh.vertex(*hfv_it));
1135 for (
unsigned int i = 0; i < vertices.size()-2; i++)
1143 else if (mPrimitiveMode == PM_FACES_ON_CELLS)
1145 std::vector<ACG::Vec3d> vertices;
1149 if (mSkipUnselected && !mStatusAttrib[*f_it].selected())
continue;
1152 vertices.push_back(mMesh.vertex(*hfv_it));
1154 for (
int i = 0; i < 2; i++)
1159 if (!should_render(ch))
continue;
1161 for (
unsigned int i = 0; i < vertices.size()-2; i++)
1173 else if (mPrimitiveMode == PM_HALFFACES)
1175 std::vector<ACG::Vec3d> vertices;
1179 if (mSkipUnselected && !mStatusAttrib[*hf_it].selected())
continue;
1180 if (mBoundaryOnly && !mMesh.is_boundary(*hf_it))
continue;
1181 if (!should_render(*hf_it))
continue;
1184 vertices.push_back(mMesh.vertex(*hfv_it));
1186 for (
unsigned int i = 0; i < vertices.size()-2; i++)
1194 else if (mPrimitiveMode == PM_CELLS)
1196 std::vector<ACG::Vec3d> vertices;
1200 if (mSkipUnselected && !mStatusAttrib[*c_it].selected())
continue;
1201 if (!should_render(*c_it))
continue;
1202 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
1204 for (
unsigned int i = 0; i < hfs.size(); ++i)
1208 vertices.push_back(mScale*mMesh.vertex(*hfv_it)+(1-mScale)*cog);
1210 for (
unsigned int i = 0; i < vertices.size()-2; i++)
1220 else if (mPrimitiveMode == PM_EDGES)
1225 if (mSkipUnselected && !mStatusAttrib[*e_it].selected())
continue;
1226 if (mBoundaryOnly && !mMesh.is_boundary(*e_it))
continue;
1227 if (!should_render(*e_it))
continue;
1229 Edge e(mMesh.edge(*e_it));
1234 else if (mPrimitiveMode == PM_EDGES_ON_CELLS)
1239 if (mSkipUnselected && !mStatusAttrib[*e_it].selected())
continue;
1241 Edge e(mMesh.edge(*e_it));
1245 if (hec_it->idx() != -1)
1247 if (!should_render(*hec_it))
continue;
1249 addPositionToBuffer(mMesh.vertex(e.from_vertex())*mScale + cog*(1-mScale), _buffer, pos++);
1250 addPositionToBuffer(mMesh.vertex(e.to_vertex()) *mScale + cog*(1-mScale), _buffer, pos++);
1255 else if (mPrimitiveMode == PM_IRREGULAR_EDGES)
1260 if (mSkipUnselected && !mStatusAttrib[*e_it].selected())
continue;
1261 if (mBoundaryOnly && !mMesh.is_boundary(*e_it))
continue;
1262 if (!should_render(*e_it))
continue;
1264 bool boundary = mMesh.is_boundary(*e_it);
1265 unsigned int valence = mMesh.valence(*e_it);
1267 if(( boundary && valence == 3) ||
1268 (!boundary && valence == 4))
continue;
1270 if ((!mShowIrregularOuterValence2Edges) && ( boundary && valence == 2))
continue;
1272 if ((!mShowIrregularInnerEdges) && (( !boundary && valence != 4) ||
1273 ( boundary && valence < 2) ||
1274 ( boundary && valence > 3)))
continue;
1276 Edge e(mMesh.edge(*e_it));
1281 else if (mPrimitiveMode == PM_HALFEDGES)
1286 if (mSkipUnselected && !mStatusAttrib[*he_it].selected())
continue;
1287 if (mBoundaryOnly && !mMesh.is_boundary(*he_it))
continue;
1288 if (!should_render(*he_it))
continue;
1290 double lambda = 0.4;
1291 Edge e(mMesh.halfedge(*he_it));
1293 addPositionToBuffer((1-lambda)*mMesh.vertex(e.from_vertex()) + lambda*mMesh.vertex(e.to_vertex()), _buffer, pos++);
1307 template <
class VolumeMesh>
1310 if (mNormalMode == NM_NONE)
return;
1312 unsigned int pos = 0;
1314 if ((mPrimitiveMode == PM_FACES) && (mNormalMode == NM_FACE))
1319 if (mBoundaryOnly && !mMesh.is_boundary(*f_it))
continue;
1320 if (!should_render(*f_it))
continue;
1322 unsigned int numOfVerticesInFace = mMesh.valence(*f_it);
1324 for (
unsigned int i = 0; i < numOfVerticesInFace - 2; i++)
1332 else if ((mPrimitiveMode == PM_FACES) && (mNormalMode == NM_VERTEX))
1334 std::vector<ACG::Vec3d> normals;
1338 if (mBoundaryOnly && !mMesh.is_boundary(*f_it))
continue;
1339 if (!should_render(*f_it))
continue;
1342 normals.push_back(mNormalAttrib[*hfv_it]);
1344 for (
unsigned int i = 0; i < normals.size()-2; i++)
1352 else if ((mPrimitiveMode == PM_HALFFACES) && (mNormalMode == NM_HALFFACE))
1357 if (mBoundaryOnly && !mMesh.is_boundary(*hf_it))
continue;
1358 if (!should_render(*hf_it))
continue;
1360 unsigned int numOfVerticesInCell = 0;
1362 ++numOfVerticesInCell;
1364 for (
unsigned int i = 0; i < numOfVerticesInCell- 2; i++)
1372 else if ((mPrimitiveMode == PM_HALFFACES) && (mNormalMode == NM_VERTEX))
1374 std::vector<ACG::Vec3d> normals;
1378 if (mBoundaryOnly && !mMesh.is_boundary(*hf_it))
continue;
1379 if (!should_render(*hf_it))
continue;
1382 normals.push_back(mNormalAttrib[*hfv_it]);
1384 for (
unsigned int i = 0; i < normals.size()-2; i++)
1392 else if ((mPrimitiveMode == PM_CELLS) && (mNormalMode == NM_HALFFACE))
1397 if (!should_render(*c_it))
continue;
1398 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
1399 for (
unsigned int i = 0; i < hfs.size(); ++i)
1401 ACG::Vec3d normal = -1.0*mNormalAttrib[hfs[i]];
1402 unsigned int numOfVerticesInFace = mMesh.valence(mMesh.face_handle(hfs[i]));
1404 for (
unsigned int i = 0; i < numOfVerticesInFace-2; i++)
1413 else if ((mPrimitiveMode == PM_CELLS) && (mNormalMode == NM_VERTEX))
1415 std::vector<ACG::Vec3d> normals;
1419 if (!should_render(*c_it))
continue;
1420 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
1422 for (
unsigned int i = 0; i < hfs.size(); ++i)
1426 normals.push_back(mNormalAttrib[*hfv_it]);
1428 for (
unsigned int i = 0; i < normals.size()-2; i++)
1445 template <
class VolumeMesh>
1448 unsigned int pos = 0;
1450 if ((mPrimitiveMode == PM_VERTICES) && (mColorMode == CM_VERTEX))
1452 for (
unsigned int i = 0; i < mMesh.n_vertices(); ++i)
1454 if (mBoundaryOnly && !mMesh.is_boundary(
VertexHandle(i)))
continue;
1460 else if ((mPrimitiveMode == PM_FACES) && (mColorMode == CM_VERTEX))
1462 std::vector<ACG::Vec4f> colors;
1466 if (mBoundaryOnly && !mMesh.is_boundary(*f_it))
continue;
1467 if (!should_render(*f_it))
continue;
1471 colors.push_back(mColorAttrib[*hfv_it]);
1473 for (
unsigned int i = 0; i < (colors.size()-2); i++)
1481 else if ((mPrimitiveMode == PM_FACES) && (mColorMode == CM_FACE))
1486 if (mBoundaryOnly && !mMesh.is_boundary(*f_it))
continue;
1487 if (!should_render(*f_it))
continue;
1490 unsigned int numOfVerticesInFace = mMesh.valence(*f_it);
1491 unsigned int numOfDrawnTriangles = numOfVerticesInFace-2;
1493 for (
unsigned int i = 0; i < numOfDrawnTriangles*3; i++)
1497 else if ((mPrimitiveMode == PM_HALFFACES) && (mColorMode == CM_HALFFACE))
1502 if (mBoundaryOnly && !mMesh.is_boundary(*hf_it))
continue;
1503 if (!should_render(*hf_it))
continue;
1506 unsigned int numOfVerticesInFace = mMesh.valence(mMesh.face_handle(*hf_it));
1507 unsigned int numOfDrawnTriangles = numOfVerticesInFace-2;
1509 for (
unsigned int i = 0; i < numOfDrawnTriangles*3; i++)
1513 else if ((mPrimitiveMode == PM_HALFFACES) && (mColorMode == CM_VERTEX))
1515 std::vector<ACG::Vec4f> colors;
1519 if (mBoundaryOnly && !mMesh.is_boundary(*hf_it))
continue;
1520 if (!should_render(*hf_it))
continue;
1524 colors.push_back(mColorAttrib[*hfv_it]);
1526 for (
unsigned int i = 0; i < (colors.size()-2); i++)
1534 else if ((mPrimitiveMode == PM_CELLS) && (mColorMode == CM_CELL))
1539 if (!should_render(*c_it))
continue;
1541 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
1542 for (
unsigned int i = 0; i < hfs.size(); ++i)
1544 unsigned int numOfVerticesInHalfface = 0;
1546 ++numOfVerticesInHalfface;
1548 unsigned int numOfDrawnFaces = numOfVerticesInHalfface-2;
1549 for (
unsigned int i = 0; i < numOfDrawnFaces*3; i++)
1554 else if ((mPrimitiveMode == PM_CELLS) && (mColorMode == CM_HALFFACE))
1559 if (!should_render(*c_it))
continue;
1560 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
1561 for (
unsigned int i = 0; i < hfs.size(); ++i)
1564 unsigned int numOfVerticesInHalfface = 0;
1566 ++numOfVerticesInHalfface;
1568 unsigned int numOfDrawnFaces = numOfVerticesInHalfface-2;
1569 for (
unsigned int i = 0; i < numOfDrawnFaces*3; i++)
1574 else if ((mPrimitiveMode == PM_CELLS) && (mColorMode == CM_FACE))
1579 if (!should_render(*c_it))
continue;
1580 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
1581 for (
unsigned int i = 0; i < hfs.size(); ++i)
1583 ACG::Vec4f color = mColorAttrib[mMesh.face_handle(hfs[i])];
1584 unsigned int numOfVerticesInHalfface = 0;
1586 ++numOfVerticesInHalfface;
1588 unsigned int numOfDrawnFaces = numOfVerticesInHalfface-2;
1589 for (
unsigned int i = 0; i < numOfDrawnFaces*3; i++)
1594 else if ((mPrimitiveMode == PM_CELLS) && (mColorMode == CM_VERTEX))
1596 std::vector<ACG::Vec4f> colors;
1600 if (!should_render(*c_it))
continue;
1601 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
1602 for (
unsigned int i = 0; i < hfs.size(); ++i)
1606 colors.push_back(mColorAttrib[*hfv_it]);
1608 for (
unsigned int i = 0; i < colors.size()-2; i++)
1617 else if ((mPrimitiveMode == PM_EDGES) && (mColorMode == CM_EDGE))
1622 if (mBoundaryOnly && !mMesh.is_boundary(*e_it))
continue;
1623 if (!should_render(*e_it))
continue;
1629 else if ((mPrimitiveMode == PM_EDGES) && (mShowIrregularInnerEdges || mShowIrregularOuterValence2Edges))
1634 if (mBoundaryOnly && !mMesh.is_boundary(*e_it))
continue;
1635 if (!should_render(*e_it))
continue;
1637 bool boundary = mMesh.is_boundary(*e_it);
1638 unsigned int valence = mMesh.valence(*e_it);
1640 bool isIrregularInner = ( boundary && valence < 2) || ( boundary && valence > 3) || (!boundary && valence != 4);
1641 bool isIrregularOuterValence2 = ( boundary && valence == 2);
1645 if (isIrregularInner && mShowIrregularInnerEdges)
1647 else if (isIrregularOuterValence2 && mShowIrregularOuterValence2Edges)
1650 color = mDefaultColor;
1656 else if ( mPrimitiveMode == PM_IRREGULAR_EDGES )
1661 if (mBoundaryOnly && !mMesh.is_boundary(*e_it))
continue;
1662 if (!should_render(*e_it))
continue;
1664 bool boundary = mMesh.is_boundary(*e_it);
1665 unsigned int valence = mMesh.valence(*e_it);
1667 bool isRegular = ( boundary && valence == 3) || (!boundary && valence == 4);
1668 bool isIrregularInner = ( boundary && valence < 2) || ( boundary && valence > 3) || (!boundary && valence != 4);
1669 bool isIrregularOuterValence2 = ( boundary && valence == 2);
1671 if (isRegular)
continue;
1672 if (isIrregularInner && !mShowIrregularInnerEdges)
continue;
1673 if (isIrregularOuterValence2 && !mShowIrregularOuterValence2Edges)
continue;
1677 if (isIrregularInner && mShowIrregularInnerEdges)
1679 else if (isIrregularOuterValence2 && mShowIrregularOuterValence2Edges)
1682 color = mDefaultColor;
1688 else if ((mPrimitiveMode == PM_HALFEDGES) && (mColorMode == CM_HALFEDGE))
1693 if (mBoundaryOnly && !mMesh.is_boundary(*he_it))
continue;
1694 if (!should_render(*he_it))
continue;
1709 template <
class VolumeMesh>
1713 unsigned int pos = 0;
1715 if (mTexCoordMode == TCM_NONE)
1718 if (mPrimitiveMode == PM_FACES)
1720 std::vector<ACG::Vec2f> texCoords;
1724 if (mBoundaryOnly && !mMesh.is_boundary(*f_it))
continue;
1725 if (!should_render(*f_it))
continue;
1729 texCoords.push_back(mTexcoordAttrib[*hfv_it]);
1731 for (
unsigned int i = 0; i < (texCoords.size()-2); i++)
1739 else if (mPrimitiveMode == PM_HALFFACES)
1741 std::vector<ACG::Vec2f> texCoords;
1745 if (mBoundaryOnly && !mMesh.is_boundary(*hf_it))
continue;
1746 if (!should_render(*hf_it))
continue;
1750 texCoords.push_back(mTexcoordAttrib[*hfv_it]);
1752 for (
unsigned int i = 0; i < (texCoords.size()-2); i++)
1771 template <
class VolumeMesh>
1774 unsigned int pos = 0;
1776 if (mPrimitiveMode == PM_VERTICES)
1778 for (
unsigned int i = 0; i < mMesh.n_vertices(); ++i)
1780 if (mBoundaryOnly && !mMesh.is_boundary(
VertexHandle(i)))
continue;
1786 if (mPrimitiveMode == PM_VERTICES_ON_CELLS)
1788 for (
unsigned int i = 0; i < mMesh.n_vertices(); ++i) {
1791 for (
unsigned int j = 0; j < numOfIncidentCells; j++)
1795 else if (mPrimitiveMode == PM_EDGES)
1800 if (mBoundaryOnly && !mMesh.is_boundary(*e_it))
continue;
1801 if (!should_render(*e_it))
continue;
1807 else if (mPrimitiveMode == PM_EDGES_ON_CELLS)
1814 for (
unsigned int i = 0; i < numOfIncidentCells*2;i++)
1818 else if (mPrimitiveMode == PM_FACES)
1823 if (mBoundaryOnly && !mMesh.is_boundary(*f_it))
continue;
1824 if (!should_render(*f_it))
continue;
1827 unsigned int numOfVertices = 0;
1831 for (
unsigned int i = 0; i < (numOfVertices-2)*3; i++)
1835 else if (mPrimitiveMode == PM_FACES_ON_CELLS)
1842 unsigned int numOfVerticesInHalfface = 0;
1844 ++numOfVerticesInHalfface;
1846 for (
int i = 0; i < 2; i++)
1851 if (!should_render(ch))
continue;
1852 for (
unsigned int i = 0; i < (numOfVerticesInHalfface-2)*3; i++)
1858 else if (mPrimitiveMode == PM_CELLS)
1863 if (!should_render(*c_it))
continue;
1865 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
1866 for (
unsigned int i = 0; i < hfs.size(); ++i)
1868 unsigned int numOfVerticesInHalfface = 0;
1870 ++numOfVerticesInHalfface;
1872 unsigned int numOfDrawnFaces = numOfVerticesInHalfface-2;
1873 for (
unsigned int i = 0; i < numOfDrawnFaces*3; i++)
1887 template <
class VolumeMesh>
1899 mNumOfVertices = -1;
1906 unsigned int bufferSize = mVertexSize * numOfVertices;
1912 GL_ARRAY_BUFFER, GL_READ_WRITE);
1934 std::cerr <<
"error while mapping buffer" << std::endl;
1940 mInvalidated =
false;
1941 mGeometryChanged =
false;
1942 mColorsChanged =
false;
1943 mNormalsChanged =
false;
1944 mTexCoordsChanged =
false;
1959 template <
class VolumeMesh>
1962 if (_offset != mCurrentPickOffset || _state.
pick_current_index() != mGlobalPickOffset)
1976 mNumOfVertices = -1;
1983 unsigned int bufferSize = mVertexSize * numOfVertices;
2005 std::cerr <<
"error while mapping buffer" << std::endl;
2010 mCurrentPickOffset = _offset;
2012 mInvalidated =
false;
2013 mGeometryChanged =
false;
2014 mColorsChanged =
false;
2015 mTexCoordsChanged =
false;
2025 template <
class VolumeMesh>
2036 template <
class VolumeMesh>
2039 mInvalidated =
true;
2040 mNumOfVertices = -1;
2041 mGeometryChanged =
true;
2042 mColorsChanged =
true;
2043 mTexCoordsChanged =
true;
2044 mNormalsChanged =
true;
2046 mCellInsidenessValid =
false;
2052 template <
class VolumeMesh>
2055 mInvalidated =
true;
2056 mColorsChanged =
true;
2062 template <
class VolumeMesh>
2065 mInvalidated =
true;
2066 mNormalsChanged =
true;
2072 template <
class VolumeMesh>
2075 mInvalidated =
true;
2076 mTexCoordsChanged =
true;
2084 template <
class VolumeMesh>
void invalidateGeometry()
Invalidates geometry.
static GLboolean unmapBuffer(GLenum target)
bool positionsNeedRebuild()
Checks whether positions need to be rebuild.
void invalidateColors()
Invalidates colors.
void countNumOfVertices()
Counts the number of vertices that need to be stored in the buffer.
void buildColorBuffer(unsigned char *_buffer)
Adds all colors to the buffer.
Namespace providing different geometric functions concerning angles.
void enablePerVertexColors()
Enables per vertex colors.
VectorT< float, 4 > Vec4f
void saveOptions()
State that the current buffer was built with the current options.
void buildPickColorBuffer(ACG::GLState &_state, unsigned int _offset, unsigned char *_buffer)
Adds all picking colors to the buffer.
void buildTexCoordBuffer(unsigned char *_buffer)
Adds texture coordinates to the buffer.
size_t pick_current_index() const
Returns the current color picking index (can be used for caching)
void clearCutPlanes()
Removes all cut planes.
static void deleteBuffers(GLsizei n, const GLuint *buffers)
Vec4uc pick_get_name_color(size_t _idx)
void enablePerHalfedgeColors()
Enables per halfedge colors.
void addNormalToBuffer(ACG::Vec3d _normal, unsigned char *_buffer, unsigned int _offset)
Adds a normal to the buffer.
void addColorToBuffer(ACG::Vec4uc _color, unsigned char *_buffer, unsigned int _offset)
Adds a color to the buffer.
void addFloatToBuffer(float _value, unsigned char *&_buffer)
Adds a float to the buffer.
void addUCharToBuffer(unsigned char _value, unsigned char *&_buffer)
Adds an unsigned char to the buffer.
void setOptionsFromDrawMode(ACG::SceneGraph::DrawModes::DrawMode _drawMode)
Configures the buffer manager's options from a DrawMode.
int getNumOfIncidentCells(OpenVolumeMesh::FaceHandle _fh)
Returns the number of cells that are incident to the given face and also inside w.r.t. all cut planes.
void calculateVertexDeclaration()
Constructs a VertexDeclaration, the size and the offsets for the vertices stored in the buffer...
GLuint getPickBuffer(ACG::GLState &_state, unsigned int _offset)
Returns the name of the pick buffer.
void disableNormals()
Disables normals.
void disableColors()
Disables colors.
void addElement(const VertexElement *_pElement)
void invalidateNormals()
Invalidates normals.
void calculateCellInsideness()
Calculates for all cells whether they are inside w.r.t. all cut planes.
void invalidateTexCoords()
Invalidates texture coordinates.
void enablePerCellColors()
Enables per cell colors.
void enablePerHalffaceNormals()
Enables per halfface normals.
void invalidate()
Invalidates the buffer.
void addTexCoordToBuffer(ACG::Vec2f _texCoord, unsigned char *_buffer, unsigned int _offset)
Adds a texture coordnate to the buffer.
void setDefaultColor(ACG::Vec4f _defaultColor)
Sets the default color.
void buildVertexBuffer(unsigned char *_buffer)
Adds all vertices to the buffer.
ACG::Vec4f getValenceColorCode(unsigned int _valence, bool _inner) const
Returns a color code for irregular edges.
static GLvoid * mapBuffer(GLenum target, GLenum access)
unsigned int getNumOfVertices()
Returns the number of vertices stored in the buffer.
void free()
Deletes the buffers on the GPU.
This class creates buffers that can be used to render open volume meshs.
bool normalsNeedRebuild()
Checks whether normals need to be rebuild.
void enablePerVertexNormals()
Enables per vertex normals.
void addPositionToBuffer(ACG::Vec3d _position, unsigned char *_buffer, unsigned int _offset)
Adds a position to the buffer.
bool is_inside(const ACG::Vec3d &_p)
Tests whether the given point is inside w.r.t. all cut planes.
bool colorsNeedRebuild()
Checks whether colors need to be rebuild.
void enablePerEdgeColors()
Enables per edge colors.
bool optionsChanged()
Tests whether the options were changed since the last time building the buffer.
static void genBuffers(GLsizei n, GLuint *buffers)
static void bufferData(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage)
void calculateCOGs()
Calculates the center of gravity for all cells.
bool texCoordsNeedRebuild()
Checks whether texture coordinates need to be rebuild.
void enablePerFaceColors()
Enables per face colors.
void enablePerHalffaceColors()
Enables per halfface colors.
ACG::Vec3d getCOG(OpenVolumeMesh::CellHandle _ch)
Returns the center of gravity of the given cell.
void buildNormalBuffer(unsigned char *_buffer)
Adds all normals to the buffer.
void enablePerFaceNormals()
Enables per face normals.
void addCutPlane(const ACG::Geometry::Plane &_p)
Adds a cut plane.
static void bindBuffer(GLenum _target, GLuint _buffer)
replaces glBindBuffer, supports locking
VectorT< double, 3 > Vec3d
GLuint getBuffer()
Returns the name of the buffer.