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.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 (!mCellInsidenessValid)
584 return mCellInsideness[_ch.idx()];
594 template <
class VolumeMesh>
597 if (mCellInsideness.size() != mMesh.n_cells())
598 mCellInsideness.resize(mMesh.n_cells());
600 for (
unsigned int i = 0; i < mMesh.n_cells(); i++)
605 if ( cut_planes_.empty() )
612 ACG::Vec3d vertexPos = mScale * mMesh.vertex(*cv_it) + (1-mScale) * cog;
613 if (!
is_inside(vertexPos)) inside =
false;
616 mCellInsideness[i] = inside;
619 mCellInsidenessValid =
true;
630 template <
class VolumeMesh>
633 return mCurrentPrimitiveMode != mPrimitiveMode ||
634 mCurrentNormalMode != mNormalMode ||
635 mCurrentColorMode != mColorMode ||
636 mCurrentSkipUnselected != mSkipUnselected ||
637 mCurrentShowIrregularInnerEdges != mShowIrregularInnerEdges ||
638 mCurrentShowIrregularOuterValence2Edges != mShowIrregularOuterValence2Edges ||
639 mCurrentSkipRegularEdges != mSkipRegularEdges ||
640 mCurrentBoundaryOnly != mBoundaryOnly;
648 template <
class VolumeMesh>
651 mCurrentPrimitiveMode = mPrimitiveMode;
652 mCurrentNormalMode = mNormalMode;
653 mCurrentColorMode = mColorMode;
654 mCurrentSkipUnselected = mSkipUnselected;
655 mCurrentShowIrregularInnerEdges = mShowIrregularInnerEdges;
656 mCurrentShowIrregularOuterValence2Edges = mShowIrregularOuterValence2Edges;
657 mCurrentSkipRegularEdges = mSkipRegularEdges;
658 mCurrentBoundaryOnly = mBoundaryOnly;
659 mCurrentVertexSize = mVertexSize;
660 mCurrentNormalOffset = mNormalOffset;
661 mCurrentColorOffset = mColorOffset;
662 mCurrentNumOfVertices = mNumOfVertices;
674 template <
class VolumeMesh>
677 if(_inner && _valence == 3) {
679 }
else if(_inner && _valence == 5) {
681 }
else if(!_inner && _valence > 3) {
683 }
else if(!_inner && _valence == 2) {
685 }
else if(_inner && _valence > 5) {
696 template <
class VolumeMesh>
699 unsigned int numOfVertices = 0;
703 if (mPrimitiveMode == PM_CELLS)
707 if (mStatusAttrib[*c_it].selected() &&
is_inside(*c_it))
709 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
710 for (
unsigned int i = 0; i < hfs.size(); ++i)
711 numOfVertices += ((mMesh.valence(mMesh.face_handle(hfs[i])))-2)*3;
714 else if (mPrimitiveMode == PM_FACES)
718 if (mStatusAttrib[*f_it].selected() &&
is_inside(*f_it) && (!mBoundaryOnly || mMesh.is_boundary(*f_it)))
719 numOfVertices += ((mMesh.valence(*f_it))-2)*3;
721 else if (mPrimitiveMode == PM_FACES_ON_CELLS)
725 if (mStatusAttrib[*f_it].selected())
728 else if (mPrimitiveMode == PM_HALFFACES)
732 if (mStatusAttrib[*hf_it].selected() &&
is_inside(*hf_it) && (!mBoundaryOnly || mMesh.is_boundary(*hf_it)))
733 numOfVertices += ((mMesh.valence(mMesh.face_handle(*hf_it)))-2)*3;
735 else if (mPrimitiveMode == PM_EDGES)
739 if (mStatusAttrib[*e_it].selected() &&
is_inside(*e_it) && (!mBoundaryOnly || mMesh.is_boundary(*e_it)))
742 else if (mPrimitiveMode == PM_EDGES_ON_CELLS)
746 if (mStatusAttrib[*e_it].selected())
749 else if (mPrimitiveMode == PM_HALFEDGES)
753 if (mStatusAttrib[*he_it].selected() &&
is_inside(*he_it) && (!mBoundaryOnly || mMesh.is_boundary(*he_it)))
756 else if (mPrimitiveMode == PM_VERTICES)
760 if (mStatusAttrib[*v_it].selected() &&
is_inside(*v_it) && (!mBoundaryOnly || mMesh.is_boundary(*v_it)))
763 else if (mPrimitiveMode == PM_VERTICES_ON_CELLS)
767 if (mStatusAttrib[*v_it].selected())
773 if (mPrimitiveMode == PM_VERTICES_ON_CELLS)
775 for (
unsigned int i = 0; i < mMesh.n_vertices(); i++)
778 else if (mPrimitiveMode == PM_VERTICES)
780 for (
unsigned int i = 0; i < mMesh.n_vertices(); i++)
784 else if (mPrimitiveMode == PM_FACES)
788 if (
is_inside(*f_it) && (!mBoundaryOnly || mMesh.is_boundary(*f_it)))
789 numOfVertices += ((mMesh.valence(*f_it))-2)*3;
791 else if (mPrimitiveMode == PM_FACES_ON_CELLS)
797 else if (mPrimitiveMode == PM_HALFFACES)
801 if (
is_inside(*hf_it) && (!mBoundaryOnly || mMesh.is_boundary(*hf_it)))
802 numOfVertices += ((mMesh.valence(mMesh.face_handle(*hf_it)))-2)*3;
804 else if (mPrimitiveMode == PM_CELLS)
811 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
812 for (
unsigned int i = 0; i < hfs.size(); ++i)
813 numOfVertices += ((mMesh.valence(mMesh.face_handle(hfs[i])))-2)*3;
817 else if (mPrimitiveMode == PM_EDGES_ON_CELLS)
822 else if ( mPrimitiveMode == PM_EDGES )
825 if (
is_inside(*e_it) && (!mBoundaryOnly || mMesh.is_boundary(*e_it)))
828 else if ( mPrimitiveMode == PM_IRREGULAR_EDGES )
831 if (
is_inside(*e_it) && (!mBoundaryOnly || mMesh.is_boundary(*e_it)))
833 bool boundary = mMesh.is_boundary(*e_it);
834 unsigned int valence = mMesh.valence(*e_it);
837 if(( boundary && valence == 3) || (!boundary && valence == 4))
continue;
839 if ((!(mShowIrregularOuterValence2Edges)) && ( boundary && valence == 2))
continue;
841 if ((!(mShowIrregularInnerEdges)) && (( !boundary && valence != 4) ||
842 ( boundary && valence < 2) ||
843 ( boundary && valence > 3)))
continue;
848 else if ( mPrimitiveMode == PM_HALFEDGES )
851 if (
is_inside(*he_it) && (!mBoundaryOnly || mMesh.is_boundary(*he_it)))
860 mNumOfVertices = numOfVertices;
870 template <
class VolumeMesh>
873 int incidentCells = 0;
875 if (mMesh.incident_cell(hf0) !=
CellHandle(-1))
879 if (mMesh.incident_cell(hf1) !=
CellHandle(-1))
882 return incidentCells;
892 template <
class VolumeMesh>
895 int incidentCells = 0;
898 if (hec_it->idx() != -1)
901 return incidentCells;
911 template <
class VolumeMesh>
914 int incidentCells = 0;
916 if (vc_it->idx() != -1)
919 return incidentCells;
929 template <
class VolumeMesh>
935 return mCogs[_ch.idx()];
945 template <
class VolumeMesh>
948 if (mCogs.size() != mMesh.n_cells())
949 mCogs.resize(mMesh.n_cells());
955 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
958 for (
unsigned int i = 0; i < hfs.size(); ++i)
961 cog += mMesh.vertex(*hfv_it);
964 cog = 1.0/count * cog;
966 mCogs[c_it->idx()] = cog;
977 template <
class VolumeMesh>
980 return (mGeometryChanged) ||
981 (mVertexSize != mCurrentVertexSize) ||
982 (mPrimitiveMode != mCurrentPrimitiveMode) ||
983 (mNumOfVertices != mCurrentNumOfVertices);
991 template <
class VolumeMesh>
994 return (mColorsChanged) ||
995 (mVertexSize != mCurrentVertexSize) ||
996 (mNumOfVertices != mCurrentNumOfVertices) ||
997 (mPrimitiveMode != mCurrentPrimitiveMode) ||
998 (mColorOffset != mCurrentColorOffset) ||
999 (mColorMode != mCurrentColorMode) ||
1000 (mShowIrregularInnerEdges != mCurrentShowIrregularInnerEdges) ||
1001 (mShowIrregularOuterValence2Edges != mCurrentShowIrregularOuterValence2Edges);
1009 template <
class VolumeMesh>
1012 return (mTexCoordsChanged) ||
1013 (mVertexSize != mCurrentVertexSize) ||
1014 (mNumOfVertices != mCurrentNumOfVertices) ||
1015 (mPrimitiveMode != mCurrentPrimitiveMode) ||
1016 (mTexCoordOffset!= mCurrentTexCoordOffset);
1024 template <
class VolumeMesh>
1027 return (mNormalsChanged) ||
1028 (mVertexSize != mCurrentVertexSize) ||
1029 (mPrimitiveMode != mCurrentPrimitiveMode) ||
1030 (mNormalOffset != mCurrentNormalOffset) ||
1031 (mNormalMode != mCurrentNormalMode) ||
1032 (mNumOfVertices != mCurrentNumOfVertices);
1040 template <
class VolumeMesh>
1043 unsigned int pos = 0;
1045 if (mPrimitiveMode == PM_VERTICES)
1047 for (
unsigned int i = 0; i < mMesh.n_vertices(); ++i) {
1048 if (mSkipUnselected && !mStatusAttrib[
VertexHandle(i)].selected())
continue;
1050 if (mBoundaryOnly && !mMesh.is_boundary(
VertexHandle(i)))
continue;
1055 else if (mPrimitiveMode == PM_VERTICES_ON_CELLS)
1057 for (
unsigned int i = 0; i < mMesh.n_vertices(); ++i) {
1058 if (mSkipUnselected && !mStatusAttrib[
VertexHandle(i)].selected())
continue;
1069 else if (mPrimitiveMode == PM_FACES)
1071 std::vector<ACG::Vec3d> vertices;
1075 if (mSkipUnselected && !mStatusAttrib[*f_it].selected())
continue;
1076 if (mBoundaryOnly && !mMesh.is_boundary(*f_it))
continue;
1080 vertices.push_back(mMesh.vertex(*hfv_it));
1082 for (
unsigned int i = 0; i < vertices.size()-2; i++)
1090 else if (mPrimitiveMode == PM_FACES_ON_CELLS)
1092 std::vector<ACG::Vec3d> vertices;
1096 if (mSkipUnselected && !mStatusAttrib[*f_it].selected())
continue;
1099 vertices.push_back(mMesh.vertex(*hfv_it));
1101 for (
int i = 0; i < 2; i++)
1108 for (
unsigned int i = 0; i < vertices.size()-2; i++)
1120 else if (mPrimitiveMode == PM_HALFFACES)
1122 std::vector<ACG::Vec3d> vertices;
1126 if (mSkipUnselected && !mStatusAttrib[*hf_it].selected())
continue;
1127 if (mBoundaryOnly && !mMesh.is_boundary(*hf_it))
continue;
1131 vertices.push_back(mMesh.vertex(*hfv_it));
1133 for (
unsigned int i = 0; i < vertices.size()-2; i++)
1141 else if (mPrimitiveMode == PM_CELLS)
1143 std::vector<ACG::Vec3d> vertices;
1147 if (mSkipUnselected && !mStatusAttrib[*c_it].selected())
continue;
1149 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
1151 for (
unsigned int i = 0; i < hfs.size(); ++i)
1155 vertices.push_back(mScale*mMesh.vertex(*hfv_it)+(1-mScale)*cog);
1157 for (
unsigned int i = 0; i < vertices.size()-2; i++)
1167 else if (mPrimitiveMode == PM_EDGES)
1172 if (mSkipUnselected && !mStatusAttrib[*e_it].selected())
continue;
1173 if (mBoundaryOnly && !mMesh.is_boundary(*e_it))
continue;
1176 Edge e(mMesh.edge(*e_it));
1181 else if (mPrimitiveMode == PM_EDGES_ON_CELLS)
1186 if (mSkipUnselected && !mStatusAttrib[*e_it].selected())
continue;
1188 Edge e(mMesh.edge(*e_it));
1192 if (hec_it->idx() != -1)
1196 addPositionToBuffer(mMesh.vertex(e.from_vertex())*mScale + cog*(1-mScale), _buffer, pos++);
1197 addPositionToBuffer(mMesh.vertex(e.to_vertex()) *mScale + cog*(1-mScale), _buffer, pos++);
1202 else if (mPrimitiveMode == PM_IRREGULAR_EDGES)
1207 if (mSkipUnselected && !mStatusAttrib[*e_it].selected())
continue;
1208 if (mBoundaryOnly && !mMesh.is_boundary(*e_it))
continue;
1211 bool boundary = mMesh.is_boundary(*e_it);
1212 unsigned int valence = mMesh.valence(*e_it);
1214 if(( boundary && valence == 3) ||
1215 (!boundary && valence == 4))
continue;
1217 if ((!mShowIrregularOuterValence2Edges) && ( boundary && valence == 2))
continue;
1219 if ((!mShowIrregularInnerEdges) && (( !boundary && valence != 4) ||
1220 ( boundary && valence < 2) ||
1221 ( boundary && valence > 3)))
continue;
1223 Edge e(mMesh.edge(*e_it));
1228 else if (mPrimitiveMode == PM_HALFEDGES)
1233 if (mSkipUnselected && !mStatusAttrib[*he_it].selected())
continue;
1234 if (mBoundaryOnly && !mMesh.is_boundary(*he_it))
continue;
1237 double lambda = 0.4;
1238 Edge e(mMesh.halfedge(*he_it));
1240 addPositionToBuffer((1-lambda)*mMesh.vertex(e.from_vertex()) + lambda*mMesh.vertex(e.to_vertex()), _buffer, pos++);
1254 template <
class VolumeMesh>
1257 if (mNormalMode == NM_NONE)
return;
1259 unsigned int pos = 0;
1261 if ((mPrimitiveMode == PM_FACES) && (mNormalMode == NM_FACE))
1266 if (mBoundaryOnly && !mMesh.is_boundary(*f_it))
continue;
1269 unsigned int numOfVerticesInFace = mMesh.valence(*f_it);
1271 for (
unsigned int i = 0; i < numOfVerticesInFace - 2; i++)
1279 else if ((mPrimitiveMode == PM_FACES) && (mNormalMode == NM_VERTEX))
1281 std::vector<ACG::Vec3d> normals;
1285 if (mBoundaryOnly && !mMesh.is_boundary(*f_it))
continue;
1289 normals.push_back(mNormalAttrib[*hfv_it]);
1291 for (
unsigned int i = 0; i < normals.size()-2; i++)
1299 else if ((mPrimitiveMode == PM_HALFFACES) && (mNormalMode == NM_HALFFACE))
1304 if (mBoundaryOnly && !mMesh.is_boundary(*hf_it))
continue;
1307 unsigned int numOfVerticesInCell = 0;
1309 ++numOfVerticesInCell;
1311 for (
unsigned int i = 0; i < numOfVerticesInCell- 2; i++)
1319 else if ((mPrimitiveMode == PM_HALFFACES) && (mNormalMode == NM_VERTEX))
1321 std::vector<ACG::Vec3d> normals;
1325 if (mBoundaryOnly && !mMesh.is_boundary(*hf_it))
continue;
1329 normals.push_back(mNormalAttrib[*hfv_it]);
1331 for (
unsigned int i = 0; i < normals.size()-2; i++)
1339 else if ((mPrimitiveMode == PM_CELLS) && (mNormalMode == NM_HALFFACE))
1345 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
1346 for (
unsigned int i = 0; i < hfs.size(); ++i)
1348 ACG::Vec3d normal = -1.0*mNormalAttrib[hfs[i]];
1349 unsigned int numOfVerticesInFace = mMesh.valence(mMesh.face_handle(hfs[i]));
1351 for (
unsigned int i = 0; i < numOfVerticesInFace-2; i++)
1360 else if ((mPrimitiveMode == PM_CELLS) && (mNormalMode == NM_VERTEX))
1362 std::vector<ACG::Vec3d> normals;
1367 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
1369 for (
unsigned int i = 0; i < hfs.size(); ++i)
1373 normals.push_back(mNormalAttrib[*hfv_it]);
1375 for (
unsigned int i = 0; i < normals.size()-2; i++)
1392 template <
class VolumeMesh>
1395 unsigned int pos = 0;
1397 if ((mPrimitiveMode == PM_VERTICES) && (mColorMode == CM_VERTEX))
1399 for (
unsigned int i = 0; i < mMesh.n_vertices(); ++i)
1401 if (mBoundaryOnly && !mMesh.is_boundary(
VertexHandle(i)))
continue;
1407 else if ((mPrimitiveMode == PM_FACES) && (mColorMode == CM_VERTEX))
1409 std::vector<ACG::Vec4f> colors;
1413 if (mBoundaryOnly && !mMesh.is_boundary(*f_it))
continue;
1418 colors.push_back(mColorAttrib[*hfv_it]);
1420 for (
unsigned int i = 0; i < (colors.size()-2); i++)
1428 else if ((mPrimitiveMode == PM_FACES) && (mColorMode == CM_FACE))
1433 if (mBoundaryOnly && !mMesh.is_boundary(*f_it))
continue;
1437 unsigned int numOfVerticesInFace = mMesh.valence(*f_it);
1438 unsigned int numOfDrawnTriangles = numOfVerticesInFace-2;
1440 for (
unsigned int i = 0; i < numOfDrawnTriangles*3; i++)
1444 else if ((mPrimitiveMode == PM_HALFFACES) && (mColorMode == CM_HALFFACE))
1449 if (mBoundaryOnly && !mMesh.is_boundary(*hf_it))
continue;
1453 unsigned int numOfVerticesInFace = mMesh.valence(mMesh.face_handle(*hf_it));
1454 unsigned int numOfDrawnTriangles = numOfVerticesInFace-2;
1456 for (
unsigned int i = 0; i < numOfDrawnTriangles*3; i++)
1460 else if ((mPrimitiveMode == PM_HALFFACES) && (mColorMode == CM_VERTEX))
1462 std::vector<ACG::Vec4f> colors;
1466 if (mBoundaryOnly && !mMesh.is_boundary(*hf_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_CELLS) && (mColorMode == CM_CELL))
1488 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
1489 for (
unsigned int i = 0; i < hfs.size(); ++i)
1491 unsigned int numOfVerticesInHalfface = 0;
1493 ++numOfVerticesInHalfface;
1495 unsigned int numOfDrawnFaces = numOfVerticesInHalfface-2;
1496 for (
unsigned int i = 0; i < numOfDrawnFaces*3; i++)
1501 else if ((mPrimitiveMode == PM_CELLS) && (mColorMode == CM_HALFFACE))
1507 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
1508 for (
unsigned int i = 0; i < hfs.size(); ++i)
1511 unsigned int numOfVerticesInHalfface = 0;
1513 ++numOfVerticesInHalfface;
1515 unsigned int numOfDrawnFaces = numOfVerticesInHalfface-2;
1516 for (
unsigned int i = 0; i < numOfDrawnFaces*3; i++)
1521 else if ((mPrimitiveMode == PM_CELLS) && (mColorMode == CM_FACE))
1527 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
1528 for (
unsigned int i = 0; i < hfs.size(); ++i)
1530 ACG::Vec4f color = mColorAttrib[mMesh.face_handle(hfs[i])];
1531 unsigned int numOfVerticesInHalfface = 0;
1533 ++numOfVerticesInHalfface;
1535 unsigned int numOfDrawnFaces = numOfVerticesInHalfface-2;
1536 for (
unsigned int i = 0; i < numOfDrawnFaces*3; i++)
1541 else if ((mPrimitiveMode == PM_CELLS) && (mColorMode == CM_VERTEX))
1543 std::vector<ACG::Vec4f> colors;
1548 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
1549 for (
unsigned int i = 0; i < hfs.size(); ++i)
1553 colors.push_back(mColorAttrib[*hfv_it]);
1555 for (
unsigned int i = 0; i < colors.size()-2; i++)
1564 else if ((mPrimitiveMode == PM_EDGES) && (mColorMode == CM_EDGE))
1569 if (mBoundaryOnly && !mMesh.is_boundary(*e_it))
continue;
1576 else if ((mPrimitiveMode == PM_EDGES) && (mShowIrregularInnerEdges || mShowIrregularOuterValence2Edges))
1581 if (mBoundaryOnly && !mMesh.is_boundary(*e_it))
continue;
1584 bool boundary = mMesh.is_boundary(*e_it);
1585 unsigned int valence = mMesh.valence(*e_it);
1587 bool isIrregularInner = ( boundary && valence < 2) || ( boundary && valence > 3) || (!boundary && valence != 4);
1588 bool isIrregularOuterValence2 = ( boundary && valence == 2);
1592 if (isIrregularInner && mShowIrregularInnerEdges)
1594 else if (isIrregularOuterValence2 && mShowIrregularOuterValence2Edges)
1597 color = mDefaultColor;
1603 else if ( mPrimitiveMode == PM_IRREGULAR_EDGES )
1608 if (mBoundaryOnly && !mMesh.is_boundary(*e_it))
continue;
1611 bool boundary = mMesh.is_boundary(*e_it);
1612 unsigned int valence = mMesh.valence(*e_it);
1614 bool isRegular = ( boundary && valence == 3) || (!boundary && valence == 4);
1615 bool isIrregularInner = ( boundary && valence < 2) || ( boundary && valence > 3) || (!boundary && valence != 4);
1616 bool isIrregularOuterValence2 = ( boundary && valence == 2);
1618 if (isRegular)
continue;
1619 if (isIrregularInner && !mShowIrregularInnerEdges)
continue;
1620 if (isIrregularOuterValence2 && !mShowIrregularOuterValence2Edges)
continue;
1624 if (isIrregularInner && mShowIrregularInnerEdges)
1626 else if (isIrregularOuterValence2 && mShowIrregularOuterValence2Edges)
1629 color = mDefaultColor;
1635 else if ((mPrimitiveMode == PM_HALFEDGES) && (mColorMode == CM_HALFEDGE))
1640 if (mBoundaryOnly && !mMesh.is_boundary(*he_it))
continue;
1656 template <
class VolumeMesh>
1660 unsigned int pos = 0;
1662 if (mTexCoordMode == TCM_NONE)
1665 if (mPrimitiveMode == PM_FACES)
1667 std::vector<ACG::Vec2f> texCoords;
1671 if (mBoundaryOnly && !mMesh.is_boundary(*f_it))
continue;
1676 texCoords.push_back(mTexcoordAttrib[*hfv_it]);
1678 for (
unsigned int i = 0; i < (texCoords.size()-2); i++)
1686 else if (mPrimitiveMode == PM_HALFFACES)
1688 std::vector<ACG::Vec2f> texCoords;
1692 if (mBoundaryOnly && !mMesh.is_boundary(*hf_it))
continue;
1697 texCoords.push_back(mTexcoordAttrib[*hfv_it]);
1699 for (
unsigned int i = 0; i < (texCoords.size()-2); i++)
1718 template <
class VolumeMesh>
1721 unsigned int pos = 0;
1723 if (mPrimitiveMode == PM_VERTICES)
1725 for (
unsigned int i = 0; i < mMesh.n_vertices(); ++i)
1727 if (mBoundaryOnly && !mMesh.is_boundary(
VertexHandle(i)))
continue;
1733 if (mPrimitiveMode == PM_VERTICES_ON_CELLS)
1735 for (
unsigned int i = 0; i < mMesh.n_vertices(); ++i) {
1738 for (
unsigned int j = 0; j < numOfIncidentCells; j++)
1742 else if (mPrimitiveMode == PM_EDGES)
1747 if (mBoundaryOnly && !mMesh.is_boundary(*e_it))
continue;
1754 else if (mPrimitiveMode == PM_EDGES_ON_CELLS)
1761 for (
unsigned int i = 0; i < numOfIncidentCells*2;i++)
1765 else if (mPrimitiveMode == PM_FACES)
1770 if (mBoundaryOnly && !mMesh.is_boundary(*f_it))
continue;
1774 unsigned int numOfVertices = 0;
1778 for (
unsigned int i = 0; i < (numOfVertices-2)*3; i++)
1782 else if (mPrimitiveMode == PM_FACES_ON_CELLS)
1789 unsigned int numOfVerticesInHalfface = 0;
1791 ++numOfVerticesInHalfface;
1793 for (
int i = 0; i < 2; i++)
1799 for (
unsigned int i = 0; i < (numOfVerticesInHalfface-2)*3; i++)
1805 else if (mPrimitiveMode == PM_CELLS)
1812 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
1813 for (
unsigned int i = 0; i < hfs.size(); ++i)
1815 unsigned int numOfVerticesInHalfface = 0;
1817 ++numOfVerticesInHalfface;
1819 unsigned int numOfDrawnFaces = numOfVerticesInHalfface-2;
1820 for (
unsigned int i = 0; i < numOfDrawnFaces*3; i++)
1834 template <
class VolumeMesh>
1846 mNumOfVertices = -1;
1853 unsigned int bufferSize = mVertexSize * numOfVertices;
1859 GL_ARRAY_BUFFER, GL_READ_WRITE);
1881 std::cerr <<
"error while mapping buffer" << std::endl;
1887 mInvalidated =
false;
1888 mGeometryChanged =
false;
1889 mColorsChanged =
false;
1890 mNormalsChanged =
false;
1891 mTexCoordsChanged =
false;
1906 template <
class VolumeMesh>
1909 if (_offset != mCurrentPickOffset || _state.
pick_current_index() != mGlobalPickOffset)
1923 mNumOfVertices = -1;
1930 unsigned int bufferSize = mVertexSize * numOfVertices;
1952 std::cerr <<
"error while mapping buffer" << std::endl;
1957 mCurrentPickOffset = _offset;
1959 mInvalidated =
false;
1960 mGeometryChanged =
false;
1961 mColorsChanged =
false;
1962 mTexCoordsChanged =
false;
1972 template <
class VolumeMesh>
1983 template <
class VolumeMesh>
1986 mInvalidated =
true;
1987 mNumOfVertices = -1;
1988 mGeometryChanged =
true;
1989 mColorsChanged =
true;
1990 mTexCoordsChanged =
true;
1991 mNormalsChanged =
true;
1993 mCellInsidenessValid =
false;
1999 template <
class VolumeMesh>
2002 mInvalidated =
true;
2003 mColorsChanged =
true;
2009 template <
class VolumeMesh>
2012 mInvalidated =
true;
2013 mNormalsChanged =
true;
2019 template <
class VolumeMesh>
2022 mInvalidated =
true;
2023 mTexCoordsChanged =
true;
2031 template <
class VolumeMesh>
void saveOptions()
State that the current buffer was built with the current options.
Namespace providing different geometric functions concerning angles.
void addPositionToBuffer(ACG::Vec3d _position, unsigned char *_buffer, unsigned int _offset)
Adds a position to the buffer.
void calculateCellInsideness()
Calculates for all cells whether they are inside w.r.t. all cut planes.
void enablePerCellColors()
Enables per cell colors.
Vec4uc pick_get_name_color(size_t _idx)
static void deleteBuffers(GLsizei n, const GLuint *buffers)
bool is_inside(const ACG::Vec3d &_p)
Tests whether the given point is inside w.r.t. all cut planes.
ACG::Vec4f getValenceColorCode(unsigned int _valence, bool _inner) const
Returns a color code for irregular edges.
GLuint getPickBuffer(ACG::GLState &_state, unsigned int _offset)
Returns the name of the pick buffer.
void buildTexCoordBuffer(unsigned char *_buffer)
Adds texture coordinates to the buffer.
void disableColors()
Disables colors.
void enablePerFaceNormals()
Enables per face normals.
VectorT< float, 4 > Vec4f
void invalidateTexCoords()
Invalidates texture coordinates.
size_t pick_current_index() const
Returns the current color picking index (can be used for caching)
void addNormalToBuffer(ACG::Vec3d _normal, unsigned char *_buffer, unsigned int _offset)
Adds a normal to the buffer.
void clearCutPlanes()
Removes all cut planes.
static void bufferData(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage)
void setDefaultColor(ACG::Vec4f _defaultColor)
Sets the default color.
void invalidate()
Invalidates the buffer.
void enablePerHalffaceNormals()
Enables per halfface normals.
static GLvoid * mapBuffer(GLenum target, GLenum access)
This class creates buffers that can be used to render open volume meshs.
void addFloatToBuffer(float _value, unsigned char *&_buffer)
Adds a float to the buffer.
void enablePerVertexNormals()
Enables per vertex normals.
bool texCoordsNeedRebuild()
Checks whether texture coordinates need to be rebuild.
unsigned int getNumOfVertices()
Returns the number of vertices stored in the buffer.
void free()
Deletes the buffers on the GPU.
void buildVertexBuffer(unsigned char *_buffer)
Adds all vertices to the buffer.
void disableNormals()
Disables normals.
static void genBuffers(GLsizei n, GLuint *buffers)
void addElement(const VertexElement *_pElement)
bool colorsNeedRebuild()
Checks whether colors need to be rebuild.
VectorT< double, 3 > Vec3d
void enablePerEdgeColors()
Enables per edge colors.
void enablePerHalfedgeColors()
Enables per halfedge colors.
void addUCharToBuffer(unsigned char _value, unsigned char *&_buffer)
Adds an unsigned char to the buffer.
void enablePerHalffaceColors()
Enables per halfface colors.
bool optionsChanged()
Tests whether the options were changed since the last time building the buffer.
void buildColorBuffer(unsigned char *_buffer)
Adds all colors to the buffer.
void addTexCoordToBuffer(ACG::Vec2f _texCoord, unsigned char *_buffer, unsigned int _offset)
Adds a texture coordnate to the buffer.
void enablePerFaceColors()
Enables per face colors.
void invalidateNormals()
Invalidates normals.
void setOptionsFromDrawMode(ACG::SceneGraph::DrawModes::DrawMode _drawMode)
Configures the buffer manager's options from a DrawMode.
void countNumOfVertices()
Counts the number of vertices that need to be stored in the buffer.
void addColorToBuffer(ACG::Vec4uc _color, unsigned char *_buffer, unsigned int _offset)
Adds a color to the buffer.
static void bindBuffer(GLenum _target, GLuint _buffer)
replaces glBindBuffer, supports locking
static GLboolean unmapBuffer(GLenum target)
bool positionsNeedRebuild()
Checks whether positions need to be rebuild.
void invalidateGeometry()
Invalidates geometry.
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 buildNormalBuffer(unsigned char *_buffer)
Adds all normals to the buffer.
bool normalsNeedRebuild()
Checks whether normals need to be rebuild.
ACG::Vec3d getCOG(OpenVolumeMesh::CellHandle _ch)
Returns the center of gravity of the given cell.
void addCutPlane(const ACG::Geometry::Plane &_p)
Adds a cut plane.
void calculateVertexDeclaration()
Constructs a VertexDeclaration, the size and the offsets for the vertices stored in the buffer...
void invalidateColors()
Invalidates colors.
void enablePerVertexColors()
Enables per vertex colors.
GLuint getBuffer()
Returns the name of the buffer.
void calculateCOGs()
Calculates the center of gravity for all cells.
void buildPickColorBuffer(ACG::GLState &_state, unsigned int _offset, unsigned char *_buffer)
Adds all picking colors to the buffer.