50 #define VOLUMEMESHBUFFERMANAGERT_CC 52 #include "VolumeMeshBufferManager.hh" 54 template <
class VolumeMesh>
60 mDefaultColor(
ACG::
Vec4f(0.0,0.0,0.0,1.0)),
62 mStatusAttrib(statusAttrib_),
63 mColorAttrib(colorAttrib_),
64 mNormalAttrib(normalAttrib_),
65 mTexcoordAttrib(texcoordAttrib_),
67 mCurrentNumOfVertices(-1),
74 mCurrentPickOffset(-1),
77 mGeometryChanged(true),
78 mNormalsChanged(true),
80 mTexCoordsChanged(true),
82 mPrimitiveMode(PM_NONE),
84 mColorMode(CM_NO_COLORS),
85 mSkipUnselected(false),
86 mShowIrregularInnerEdges(false),
87 mShowIrregularOuterValence2Edges(false),
88 mSkipRegularEdges(false),
90 mCurrentPrimitiveMode(PM_NONE),
91 mCurrentNormalMode(NM_NONE),
92 mCurrentColorMode(CM_NO_COLORS),
93 mCurrentSkipUnselected(false),
94 mCurrentShowIrregularInnerEdges(false),
95 mCurrentShowIrregularOuterValence2Edges(false),
96 mCurrentSkipRegularEdges(false),
97 mCurrentBoundaryOnly(false),
98 mCurrentVertexSize(0),
99 mCurrentNormalOffset(0),
100 mCurrentColorOffset(0),
102 mCellInsidenessValid(),
103 mTexCoordMode(TCM_NONE),
104 mCurrentTexCoordMode(TCM_NONE),
106 mCurrentTexCoordOffset(0)
120 template <
class VolumeMesh>
124 unsigned char *v = (
unsigned char *) &_value;
142 template <
class VolumeMesh>
159 template <
class VolumeMesh>
162 unsigned char* buffer = _buffer + _offset*mVertexSize;
178 template <
class VolumeMesh>
181 unsigned char* buffer = _buffer + _offset*mVertexSize + mColorOffset;
200 template <
class VolumeMesh>
203 unsigned char* buffer = _buffer + _offset*mVertexSize + mColorOffset;
220 template <
class VolumeMesh>
223 unsigned char* buffer = _buffer + _offset*mVertexSize + mNormalOffset;
239 template <
class VolumeMesh>
242 unsigned char* buffer = _buffer + _offset*mVertexSize + mTexCoordOffset;
255 template <
class VolumeMesh>
258 unsigned int currentOffset = 0;
259 mVertexDeclaration.
clear();
264 if (mPrimitiveMode != PM_NONE)
267 currentOffset += 3*
sizeof(float);
270 if (mNormalMode != NM_NONE)
272 mNormalOffset = currentOffset;
274 currentOffset += 3*
sizeof(float);
277 if ((mColorMode != CM_NO_COLORS) || mShowIrregularInnerEdges || mShowIrregularOuterValence2Edges)
279 mColorOffset = currentOffset;
281 currentOffset += 4*
sizeof(char);
284 if ((mTexCoordMode != TCM_NONE))
286 mTexCoordOffset = currentOffset;
287 unsigned char numOfCoords = 0;
288 if (mTexCoordMode == TCM_SINGLE_2D)
291 currentOffset += numOfCoords *
sizeof(float);
294 mVertexSize = currentOffset;
302 template <
class VolumeMesh>
305 if (mNumOfVertices == -1)
307 return mNumOfVertices;
317 template <
class VolumeMesh>
320 if (mDefaultColor != _defaultColor)
323 mDefaultColor = _defaultColor;
335 template <
class VolumeMesh>
339 if (_drawMode & (mDrawModes.cellsColoredPerCell))
341 else if (_drawMode & (mDrawModes.cellsColoredPerFace | mDrawModes.facesColoredPerFace))
343 else if (_drawMode & (mDrawModes.cellsColoredPerHalfface | mDrawModes.halffacesColoredPerHalfface))
345 else if (_drawMode & ( mDrawModes.edgesColoredPerEdge ))
347 else if (_drawMode & (mDrawModes.halfedgesColoredPerHalfedge))
349 else if (_drawMode & (mDrawModes.cellsColoredPerVertex | mDrawModes.facesColoredPerVertex |
350 mDrawModes.halffacesColoredPerVertex | mDrawModes.edgesColoredPerEdge |
351 mDrawModes.verticesColored))
357 if (_drawMode & (mDrawModes.cellsFlatShaded | mDrawModes.halffacesFlatShaded))
359 else if (_drawMode & (mDrawModes.facesFlatShaded | mDrawModes.facesTexturedShaded))
361 else if (_drawMode & (mDrawModes.cellsSmoothShaded | mDrawModes.facesSmoothShaded | mDrawModes.halffacesSmoothShaded |
362 mDrawModes.cellsPhongShaded | mDrawModes.facesPhongShaded | mDrawModes.halffacesPhongShaded))
367 if (_drawMode & (mDrawModes.irregularInnerEdges))
368 mShowIrregularInnerEdges =
true;
370 mShowIrregularInnerEdges =
false;
372 if (_drawMode & (mDrawModes.irregularOuterEdges))
373 mShowIrregularOuterValence2Edges =
true;
375 mShowIrregularOuterValence2Edges =
false;
377 if (!mShowIrregularInnerEdges && !mShowIrregularOuterValence2Edges)
378 mSkipRegularEdges =
false;
380 mSkipRegularEdges =
true;
384 if (_drawMode & (mDrawModes.facesTextured | mDrawModes.facesTexturedShaded))
385 mTexCoordMode = TCM_SINGLE_2D;
387 mTexCoordMode = TCM_NONE;
390 if (_drawMode & (mDrawModes.cellBasedDrawModes))
391 mPrimitiveMode = PM_CELLS;
392 else if (_drawMode & (mDrawModes.facesOnCells))
393 mPrimitiveMode = PM_FACES_ON_CELLS;
394 else if (_drawMode & (mDrawModes.faceBasedDrawModes | mDrawModes.hiddenLineBackgroundFaces))
395 mPrimitiveMode = PM_FACES;
396 else if (_drawMode & (mDrawModes.halffaceBasedDrawModes))
397 mPrimitiveMode = PM_HALFFACES;
398 else if (_drawMode & (mDrawModes.edgesOnCells))
399 mPrimitiveMode = PM_EDGES_ON_CELLS;
400 else if (_drawMode & ((mDrawModes.edgeBasedDrawModes) & ~(mDrawModes.irregularInnerEdges | mDrawModes.irregularOuterEdges)))
401 mPrimitiveMode = PM_EDGES;
402 else if (_drawMode & (mDrawModes.irregularInnerEdges | mDrawModes.irregularOuterEdges))
403 mPrimitiveMode = PM_IRREGULAR_EDGES;
404 else if (_drawMode & (mDrawModes.halfedgeBasedDrawModes))
405 mPrimitiveMode = PM_HALFEDGES;
406 else if (_drawMode & (mDrawModes.verticesOnCells))
407 mPrimitiveMode = PM_VERTICES_ON_CELLS;
408 else if (_drawMode & (mDrawModes.vertexBasedDrawModes))
409 mPrimitiveMode = PM_VERTICES;
411 mPrimitiveMode = PM_NONE;
423 template <
class VolumeMesh>
428 mCellInsidenessValid =
false;
438 template <
class VolumeMesh>
441 cut_planes_.push_back(_p);
443 mCellInsidenessValid =
false;
456 template <
class VolumeMesh>
469 template <
class VolumeMesh>
472 for(
typename std::vector<Plane>::iterator it = cut_planes_.begin(); it != cut_planes_.end(); ++it) {
476 double pn = (pl | it->normal);
477 double px = (pl | it->xdirection);
478 double py = (pl | it->ydirection);
480 if (pn < 0.0 && px > -0.5 && px < 0.5 && py > -0.5 && py < 0.5)
496 template <
class VolumeMesh>
499 if ( cut_planes_.empty() )
return true;
512 template <
class VolumeMesh>
515 if ( cut_planes_.empty() )
return true;
516 Edge e(mMesh.halfedge(_heh));
517 return is_inside(mMesh.vertex(e.from_vertex())) &&
is_inside(mMesh.vertex(e.to_vertex()));
529 template <
class VolumeMesh>
532 if ( cut_planes_.empty() )
return true;
533 Edge e(mMesh.edge(_eh));
534 return is_inside(mMesh.vertex(e.from_vertex())) &&
is_inside(mMesh.vertex(e.to_vertex()));
546 template <
class VolumeMesh>
549 if ( cut_planes_.empty() )
return true;
565 template <
class VolumeMesh>
568 if ( cut_planes_.empty() )
return true;
569 return is_inside(mMesh.halfface_handle(_fh,0));
583 template <
class VolumeMesh>
586 if (!mCellInsidenessValid)
589 return mCellInsideness[_ch.idx()];
599 template <
class VolumeMesh>
602 if (mCellInsideness.size() != mMesh.n_cells())
603 mCellInsideness.resize(mMesh.n_cells());
605 for (
unsigned int i = 0; i < mMesh.n_cells(); i++)
610 if ( cut_planes_.empty() )
617 ACG::Vec3d vertexPos = mScale * mMesh.vertex(*cv_it) + (1-mScale) * cog;
618 if (!
is_inside(vertexPos)) inside =
false;
621 mCellInsideness[i] = inside;
624 mCellInsidenessValid =
true;
635 template <
class VolumeMesh>
638 return mCurrentPrimitiveMode != mPrimitiveMode ||
639 mCurrentNormalMode != mNormalMode ||
640 mCurrentColorMode != mColorMode ||
641 mCurrentSkipUnselected != mSkipUnselected ||
642 mCurrentShowIrregularInnerEdges != mShowIrregularInnerEdges ||
643 mCurrentShowIrregularOuterValence2Edges != mShowIrregularOuterValence2Edges ||
644 mCurrentSkipRegularEdges != mSkipRegularEdges ||
645 mCurrentBoundaryOnly != mBoundaryOnly;
653 template <
class VolumeMesh>
656 mCurrentPrimitiveMode = mPrimitiveMode;
657 mCurrentNormalMode = mNormalMode;
658 mCurrentColorMode = mColorMode;
659 mCurrentSkipUnselected = mSkipUnselected;
660 mCurrentShowIrregularInnerEdges = mShowIrregularInnerEdges;
661 mCurrentShowIrregularOuterValence2Edges = mShowIrregularOuterValence2Edges;
662 mCurrentSkipRegularEdges = mSkipRegularEdges;
663 mCurrentBoundaryOnly = mBoundaryOnly;
664 mCurrentVertexSize = mVertexSize;
665 mCurrentNormalOffset = mNormalOffset;
666 mCurrentColorOffset = mColorOffset;
667 mCurrentNumOfVertices = mNumOfVertices;
679 template <
class VolumeMesh>
682 if(_inner && _valence == 3) {
684 }
else if(_inner && _valence == 5) {
686 }
else if(!_inner && _valence > 3) {
688 }
else if(!_inner && _valence == 2) {
690 }
else if(_inner && _valence > 5) {
701 template <
class VolumeMesh>
704 unsigned int numOfVertices = 0;
708 if (mPrimitiveMode == PM_CELLS)
712 if (mStatusAttrib[*c_it].selected() &&
is_inside(*c_it))
714 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
715 for (
unsigned int i = 0; i < hfs.size(); ++i)
716 numOfVertices += ((mMesh.valence(mMesh.face_handle(hfs[i])))-2)*3;
719 else if (mPrimitiveMode == PM_FACES)
723 if (mStatusAttrib[*f_it].selected() &&
is_inside(*f_it) && (!mBoundaryOnly || mMesh.is_boundary(*f_it)))
724 numOfVertices += ((mMesh.valence(*f_it))-2)*3;
726 else if (mPrimitiveMode == PM_FACES_ON_CELLS)
730 if (mStatusAttrib[*f_it].selected())
733 else if (mPrimitiveMode == PM_HALFFACES)
737 if (mStatusAttrib[*hf_it].selected() &&
is_inside(*hf_it) && (!mBoundaryOnly || mMesh.is_boundary(*hf_it)))
738 numOfVertices += ((mMesh.valence(mMesh.face_handle(*hf_it)))-2)*3;
740 else if (mPrimitiveMode == PM_EDGES)
744 if (mStatusAttrib[*e_it].selected() &&
is_inside(*e_it) && (!mBoundaryOnly || mMesh.is_boundary(*e_it)))
747 else if (mPrimitiveMode == PM_EDGES_ON_CELLS)
751 if (mStatusAttrib[*e_it].selected())
754 else if (mPrimitiveMode == PM_HALFEDGES)
758 if (mStatusAttrib[*he_it].selected() &&
is_inside(*he_it) && (!mBoundaryOnly || mMesh.is_boundary(*he_it)))
761 else if (mPrimitiveMode == PM_VERTICES)
765 if (mStatusAttrib[*v_it].selected() &&
is_inside(*v_it) && (!mBoundaryOnly || mMesh.is_boundary(*v_it)))
768 else if (mPrimitiveMode == PM_VERTICES_ON_CELLS)
772 if (mStatusAttrib[*v_it].selected())
778 if (mPrimitiveMode == PM_VERTICES_ON_CELLS)
780 for (
unsigned int i = 0; i < mMesh.n_vertices(); i++)
783 else if (mPrimitiveMode == PM_VERTICES)
785 for (
unsigned int i = 0; i < mMesh.n_vertices(); i++)
789 else if (mPrimitiveMode == PM_FACES)
793 if (
is_inside(*f_it) && (!mBoundaryOnly || mMesh.is_boundary(*f_it)))
794 numOfVertices += ((mMesh.valence(*f_it))-2)*3;
796 else if (mPrimitiveMode == PM_FACES_ON_CELLS)
802 else if (mPrimitiveMode == PM_HALFFACES)
806 if (
is_inside(*hf_it) && (!mBoundaryOnly || mMesh.is_boundary(*hf_it)))
807 numOfVertices += ((mMesh.valence(mMesh.face_handle(*hf_it)))-2)*3;
809 else if (mPrimitiveMode == PM_CELLS)
816 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
817 for (
unsigned int i = 0; i < hfs.size(); ++i)
818 numOfVertices += ((mMesh.valence(mMesh.face_handle(hfs[i])))-2)*3;
822 else if (mPrimitiveMode == PM_EDGES_ON_CELLS)
827 else if ( mPrimitiveMode == PM_EDGES )
830 if (
is_inside(*e_it) && (!mBoundaryOnly || mMesh.is_boundary(*e_it)))
833 else if ( mPrimitiveMode == PM_IRREGULAR_EDGES )
836 if (
is_inside(*e_it) && (!mBoundaryOnly || mMesh.is_boundary(*e_it)))
838 bool boundary = mMesh.is_boundary(*e_it);
839 unsigned int valence = mMesh.valence(*e_it);
842 if(( boundary && valence == 3) || (!boundary && valence == 4))
continue;
844 if ((!(mShowIrregularOuterValence2Edges)) && ( boundary && valence == 2))
continue;
846 if ((!(mShowIrregularInnerEdges)) && (( !boundary && valence != 4) ||
847 ( boundary && valence < 2) ||
848 ( boundary && valence > 3)))
continue;
853 else if ( mPrimitiveMode == PM_HALFEDGES )
856 if (
is_inside(*he_it) && (!mBoundaryOnly || mMesh.is_boundary(*he_it)))
865 mNumOfVertices = numOfVertices;
875 template <
class VolumeMesh>
878 int incidentCells = 0;
880 if (mMesh.incident_cell(hf0) !=
CellHandle(-1))
884 if (mMesh.incident_cell(hf1) !=
CellHandle(-1))
887 return incidentCells;
897 template <
class VolumeMesh>
900 int incidentCells = 0;
903 if (hec_it->idx() != -1)
906 return incidentCells;
916 template <
class VolumeMesh>
919 int incidentCells = 0;
921 if (vc_it->idx() != -1)
924 return incidentCells;
934 template <
class VolumeMesh>
940 return mCogs[_ch.idx()];
950 template <
class VolumeMesh>
953 if (mCogs.size() != mMesh.n_cells())
954 mCogs.resize(mMesh.n_cells());
960 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
963 for (
unsigned int i = 0; i < hfs.size(); ++i)
966 cog += mMesh.vertex(*hfv_it);
969 cog = 1.0/count * cog;
971 mCogs[c_it->idx()] = cog;
982 template <
class VolumeMesh>
985 return (mGeometryChanged) ||
986 (mVertexSize != mCurrentVertexSize) ||
987 (mPrimitiveMode != mCurrentPrimitiveMode) ||
988 (mNumOfVertices != mCurrentNumOfVertices);
996 template <
class VolumeMesh>
999 return (mColorsChanged) ||
1000 (mVertexSize != mCurrentVertexSize) ||
1001 (mNumOfVertices != mCurrentNumOfVertices) ||
1002 (mPrimitiveMode != mCurrentPrimitiveMode) ||
1003 (mColorOffset != mCurrentColorOffset) ||
1004 (mColorMode != mCurrentColorMode) ||
1005 (mShowIrregularInnerEdges != mCurrentShowIrregularInnerEdges) ||
1006 (mShowIrregularOuterValence2Edges != mCurrentShowIrregularOuterValence2Edges);
1014 template <
class VolumeMesh>
1017 return (mTexCoordsChanged) ||
1018 (mVertexSize != mCurrentVertexSize) ||
1019 (mNumOfVertices != mCurrentNumOfVertices) ||
1020 (mPrimitiveMode != mCurrentPrimitiveMode) ||
1021 (mTexCoordOffset!= mCurrentTexCoordOffset);
1029 template <
class VolumeMesh>
1032 return (mNormalsChanged) ||
1033 (mVertexSize != mCurrentVertexSize) ||
1034 (mPrimitiveMode != mCurrentPrimitiveMode) ||
1035 (mNormalOffset != mCurrentNormalOffset) ||
1036 (mNormalMode != mCurrentNormalMode) ||
1037 (mNumOfVertices != mCurrentNumOfVertices);
1045 template <
class VolumeMesh>
1048 unsigned int pos = 0;
1050 if (mPrimitiveMode == PM_VERTICES)
1052 for (
unsigned int i = 0; i < mMesh.n_vertices(); ++i) {
1053 if (mSkipUnselected && !mStatusAttrib[
VertexHandle(i)].selected())
continue;
1055 if (mBoundaryOnly && !mMesh.is_boundary(
VertexHandle(i)))
continue;
1060 else if (mPrimitiveMode == PM_VERTICES_ON_CELLS)
1062 for (
unsigned int i = 0; i < mMesh.n_vertices(); ++i) {
1063 if (mSkipUnselected && !mStatusAttrib[
VertexHandle(i)].selected())
continue;
1074 else if (mPrimitiveMode == PM_FACES)
1076 std::vector<ACG::Vec3d> vertices;
1080 if (mSkipUnselected && !mStatusAttrib[*f_it].selected())
continue;
1081 if (mBoundaryOnly && !mMesh.is_boundary(*f_it))
continue;
1085 vertices.push_back(mMesh.vertex(*hfv_it));
1087 for (
unsigned int i = 0; i < vertices.size()-2; i++)
1095 else if (mPrimitiveMode == PM_FACES_ON_CELLS)
1097 std::vector<ACG::Vec3d> vertices;
1101 if (mSkipUnselected && !mStatusAttrib[*f_it].selected())
continue;
1104 vertices.push_back(mMesh.vertex(*hfv_it));
1106 for (
int i = 0; i < 2; i++)
1113 for (
unsigned int i = 0; i < vertices.size()-2; i++)
1125 else if (mPrimitiveMode == PM_HALFFACES)
1127 std::vector<ACG::Vec3d> vertices;
1131 if (mSkipUnselected && !mStatusAttrib[*hf_it].selected())
continue;
1132 if (mBoundaryOnly && !mMesh.is_boundary(*hf_it))
continue;
1136 vertices.push_back(mMesh.vertex(*hfv_it));
1138 for (
unsigned int i = 0; i < vertices.size()-2; i++)
1146 else if (mPrimitiveMode == PM_CELLS)
1148 std::vector<ACG::Vec3d> vertices;
1152 if (mSkipUnselected && !mStatusAttrib[*c_it].selected())
continue;
1154 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
1156 for (
unsigned int i = 0; i < hfs.size(); ++i)
1160 vertices.push_back(mScale*mMesh.vertex(*hfv_it)+(1-mScale)*cog);
1162 for (
unsigned int i = 0; i < vertices.size()-2; i++)
1172 else if (mPrimitiveMode == PM_EDGES)
1177 if (mSkipUnselected && !mStatusAttrib[*e_it].selected())
continue;
1178 if (mBoundaryOnly && !mMesh.is_boundary(*e_it))
continue;
1181 Edge e(mMesh.edge(*e_it));
1186 else if (mPrimitiveMode == PM_EDGES_ON_CELLS)
1191 if (mSkipUnselected && !mStatusAttrib[*e_it].selected())
continue;
1193 Edge e(mMesh.edge(*e_it));
1197 if (hec_it->idx() != -1)
1201 addPositionToBuffer(mMesh.vertex(e.from_vertex())*mScale + cog*(1-mScale), _buffer, pos++);
1202 addPositionToBuffer(mMesh.vertex(e.to_vertex()) *mScale + cog*(1-mScale), _buffer, pos++);
1207 else if (mPrimitiveMode == PM_IRREGULAR_EDGES)
1212 if (mSkipUnselected && !mStatusAttrib[*e_it].selected())
continue;
1213 if (mBoundaryOnly && !mMesh.is_boundary(*e_it))
continue;
1216 bool boundary = mMesh.is_boundary(*e_it);
1217 unsigned int valence = mMesh.valence(*e_it);
1219 if(( boundary && valence == 3) ||
1220 (!boundary && valence == 4))
continue;
1222 if ((!mShowIrregularOuterValence2Edges) && ( boundary && valence == 2))
continue;
1224 if ((!mShowIrregularInnerEdges) && (( !boundary && valence != 4) ||
1225 ( boundary && valence < 2) ||
1226 ( boundary && valence > 3)))
continue;
1228 Edge e(mMesh.edge(*e_it));
1233 else if (mPrimitiveMode == PM_HALFEDGES)
1238 if (mSkipUnselected && !mStatusAttrib[*he_it].selected())
continue;
1239 if (mBoundaryOnly && !mMesh.is_boundary(*he_it))
continue;
1242 double lambda = 0.4;
1243 Edge e(mMesh.halfedge(*he_it));
1245 addPositionToBuffer((1-lambda)*mMesh.vertex(e.from_vertex()) + lambda*mMesh.vertex(e.to_vertex()), _buffer, pos++);
1259 template <
class VolumeMesh>
1262 if (mNormalMode == NM_NONE)
return;
1264 unsigned int pos = 0;
1266 if ((mPrimitiveMode == PM_FACES) && (mNormalMode == NM_FACE))
1271 if (mBoundaryOnly && !mMesh.is_boundary(*f_it))
continue;
1274 unsigned int numOfVerticesInFace = mMesh.valence(*f_it);
1276 for (
unsigned int i = 0; i < numOfVerticesInFace - 2; i++)
1284 else if ((mPrimitiveMode == PM_FACES) && (mNormalMode == NM_VERTEX))
1286 std::vector<ACG::Vec3d> normals;
1290 if (mBoundaryOnly && !mMesh.is_boundary(*f_it))
continue;
1294 normals.push_back(mNormalAttrib[*hfv_it]);
1296 for (
unsigned int i = 0; i < normals.size()-2; i++)
1304 else if ((mPrimitiveMode == PM_HALFFACES) && (mNormalMode == NM_HALFFACE))
1309 if (mBoundaryOnly && !mMesh.is_boundary(*hf_it))
continue;
1312 unsigned int numOfVerticesInCell = 0;
1314 ++numOfVerticesInCell;
1316 for (
unsigned int i = 0; i < numOfVerticesInCell- 2; i++)
1324 else if ((mPrimitiveMode == PM_HALFFACES) && (mNormalMode == NM_VERTEX))
1326 std::vector<ACG::Vec3d> normals;
1330 if (mBoundaryOnly && !mMesh.is_boundary(*hf_it))
continue;
1334 normals.push_back(mNormalAttrib[*hfv_it]);
1336 for (
unsigned int i = 0; i < normals.size()-2; i++)
1344 else if ((mPrimitiveMode == PM_CELLS) && (mNormalMode == NM_HALFFACE))
1350 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
1351 for (
unsigned int i = 0; i < hfs.size(); ++i)
1353 ACG::Vec3d normal = -1.0*mNormalAttrib[hfs[i]];
1354 unsigned int numOfVerticesInFace = mMesh.valence(mMesh.face_handle(hfs[i]));
1356 for (
unsigned int i = 0; i < numOfVerticesInFace-2; i++)
1365 else if ((mPrimitiveMode == PM_CELLS) && (mNormalMode == NM_VERTEX))
1367 std::vector<ACG::Vec3d> normals;
1372 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
1374 for (
unsigned int i = 0; i < hfs.size(); ++i)
1378 normals.push_back(mNormalAttrib[*hfv_it]);
1380 for (
unsigned int i = 0; i < normals.size()-2; i++)
1397 template <
class VolumeMesh>
1400 unsigned int pos = 0;
1402 if ((mPrimitiveMode == PM_VERTICES) && (mColorMode == CM_VERTEX))
1404 for (
unsigned int i = 0; i < mMesh.n_vertices(); ++i)
1406 if (mBoundaryOnly && !mMesh.is_boundary(
VertexHandle(i)))
continue;
1412 else if ((mPrimitiveMode == PM_FACES) && (mColorMode == CM_VERTEX))
1414 std::vector<ACG::Vec4f> colors;
1418 if (mBoundaryOnly && !mMesh.is_boundary(*f_it))
continue;
1423 colors.push_back(mColorAttrib[*hfv_it]);
1425 for (
unsigned int i = 0; i < (colors.size()-2); i++)
1433 else if ((mPrimitiveMode == PM_FACES) && (mColorMode == CM_FACE))
1438 if (mBoundaryOnly && !mMesh.is_boundary(*f_it))
continue;
1442 unsigned int numOfVerticesInFace = mMesh.valence(*f_it);
1443 unsigned int numOfDrawnTriangles = numOfVerticesInFace-2;
1445 for (
unsigned int i = 0; i < numOfDrawnTriangles*3; i++)
1449 else if ((mPrimitiveMode == PM_HALFFACES) && (mColorMode == CM_HALFFACE))
1454 if (mBoundaryOnly && !mMesh.is_boundary(*hf_it))
continue;
1458 unsigned int numOfVerticesInFace = mMesh.valence(mMesh.face_handle(*hf_it));
1459 unsigned int numOfDrawnTriangles = numOfVerticesInFace-2;
1461 for (
unsigned int i = 0; i < numOfDrawnTriangles*3; i++)
1465 else if ((mPrimitiveMode == PM_HALFFACES) && (mColorMode == CM_VERTEX))
1467 std::vector<ACG::Vec4f> colors;
1471 if (mBoundaryOnly && !mMesh.is_boundary(*hf_it))
continue;
1476 colors.push_back(mColorAttrib[*hfv_it]);
1478 for (
unsigned int i = 0; i < (colors.size()-2); i++)
1486 else if ((mPrimitiveMode == PM_CELLS) && (mColorMode == CM_CELL))
1493 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
1494 for (
unsigned int i = 0; i < hfs.size(); ++i)
1496 unsigned int numOfVerticesInHalfface = 0;
1498 ++numOfVerticesInHalfface;
1500 unsigned int numOfDrawnFaces = numOfVerticesInHalfface-2;
1501 for (
unsigned int i = 0; i < numOfDrawnFaces*3; i++)
1506 else if ((mPrimitiveMode == PM_CELLS) && (mColorMode == CM_HALFFACE))
1512 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
1513 for (
unsigned int i = 0; i < hfs.size(); ++i)
1516 unsigned int numOfVerticesInHalfface = 0;
1518 ++numOfVerticesInHalfface;
1520 unsigned int numOfDrawnFaces = numOfVerticesInHalfface-2;
1521 for (
unsigned int i = 0; i < numOfDrawnFaces*3; i++)
1526 else if ((mPrimitiveMode == PM_CELLS) && (mColorMode == CM_FACE))
1532 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
1533 for (
unsigned int i = 0; i < hfs.size(); ++i)
1535 ACG::Vec4f color = mColorAttrib[mMesh.face_handle(hfs[i])];
1536 unsigned int numOfVerticesInHalfface = 0;
1538 ++numOfVerticesInHalfface;
1540 unsigned int numOfDrawnFaces = numOfVerticesInHalfface-2;
1541 for (
unsigned int i = 0; i < numOfDrawnFaces*3; i++)
1546 else if ((mPrimitiveMode == PM_CELLS) && (mColorMode == CM_VERTEX))
1548 std::vector<ACG::Vec4f> colors;
1553 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
1554 for (
unsigned int i = 0; i < hfs.size(); ++i)
1558 colors.push_back(mColorAttrib[*hfv_it]);
1560 for (
unsigned int i = 0; i < colors.size()-2; i++)
1569 else if ((mPrimitiveMode == PM_EDGES) && (mColorMode == CM_EDGE))
1574 if (mBoundaryOnly && !mMesh.is_boundary(*e_it))
continue;
1581 else if ((mPrimitiveMode == PM_EDGES) && (mShowIrregularInnerEdges || mShowIrregularOuterValence2Edges))
1586 if (mBoundaryOnly && !mMesh.is_boundary(*e_it))
continue;
1589 bool boundary = mMesh.is_boundary(*e_it);
1590 unsigned int valence = mMesh.valence(*e_it);
1592 bool isIrregularInner = ( boundary && valence < 2) || ( boundary && valence > 3) || (!boundary && valence != 4);
1593 bool isIrregularOuterValence2 = ( boundary && valence == 2);
1597 if (isIrregularInner && mShowIrregularInnerEdges)
1599 else if (isIrregularOuterValence2 && mShowIrregularOuterValence2Edges)
1602 color = mDefaultColor;
1608 else if ( mPrimitiveMode == PM_IRREGULAR_EDGES )
1613 if (mBoundaryOnly && !mMesh.is_boundary(*e_it))
continue;
1616 bool boundary = mMesh.is_boundary(*e_it);
1617 unsigned int valence = mMesh.valence(*e_it);
1619 bool isRegular = ( boundary && valence == 3) || (!boundary && valence == 4);
1620 bool isIrregularInner = ( boundary && valence < 2) || ( boundary && valence > 3) || (!boundary && valence != 4);
1621 bool isIrregularOuterValence2 = ( boundary && valence == 2);
1623 if (isRegular)
continue;
1624 if (isIrregularInner && !mShowIrregularInnerEdges)
continue;
1625 if (isIrregularOuterValence2 && !mShowIrregularOuterValence2Edges)
continue;
1629 if (isIrregularInner && mShowIrregularInnerEdges)
1631 else if (isIrregularOuterValence2 && mShowIrregularOuterValence2Edges)
1634 color = mDefaultColor;
1640 else if ((mPrimitiveMode == PM_HALFEDGES) && (mColorMode == CM_HALFEDGE))
1645 if (mBoundaryOnly && !mMesh.is_boundary(*he_it))
continue;
1661 template <
class VolumeMesh>
1665 unsigned int pos = 0;
1667 if (mTexCoordMode == TCM_NONE)
1670 if (mPrimitiveMode == PM_FACES)
1672 std::vector<ACG::Vec2f> texCoords;
1676 if (mBoundaryOnly && !mMesh.is_boundary(*f_it))
continue;
1681 texCoords.push_back(mTexcoordAttrib[*hfv_it]);
1683 for (
unsigned int i = 0; i < (texCoords.size()-2); i++)
1691 else if (mPrimitiveMode == PM_HALFFACES)
1693 std::vector<ACG::Vec2f> texCoords;
1697 if (mBoundaryOnly && !mMesh.is_boundary(*hf_it))
continue;
1702 texCoords.push_back(mTexcoordAttrib[*hfv_it]);
1704 for (
unsigned int i = 0; i < (texCoords.size()-2); i++)
1723 template <
class VolumeMesh>
1726 unsigned int pos = 0;
1728 if (mPrimitiveMode == PM_VERTICES)
1730 for (
unsigned int i = 0; i < mMesh.n_vertices(); ++i)
1732 if (mBoundaryOnly && !mMesh.is_boundary(
VertexHandle(i)))
continue;
1738 if (mPrimitiveMode == PM_VERTICES_ON_CELLS)
1740 for (
unsigned int i = 0; i < mMesh.n_vertices(); ++i) {
1743 for (
unsigned int j = 0; j < numOfIncidentCells; j++)
1747 else if (mPrimitiveMode == PM_EDGES)
1752 if (mBoundaryOnly && !mMesh.is_boundary(*e_it))
continue;
1759 else if (mPrimitiveMode == PM_EDGES_ON_CELLS)
1766 for (
unsigned int i = 0; i < numOfIncidentCells*2;i++)
1770 else if (mPrimitiveMode == PM_FACES)
1775 if (mBoundaryOnly && !mMesh.is_boundary(*f_it))
continue;
1779 unsigned int numOfVertices = 0;
1783 for (
unsigned int i = 0; i < (numOfVertices-2)*3; i++)
1787 else if (mPrimitiveMode == PM_FACES_ON_CELLS)
1794 unsigned int numOfVerticesInHalfface = 0;
1796 ++numOfVerticesInHalfface;
1798 for (
int i = 0; i < 2; i++)
1804 for (
unsigned int i = 0; i < (numOfVerticesInHalfface-2)*3; i++)
1810 else if (mPrimitiveMode == PM_CELLS)
1817 std::vector<HalfFaceHandle> hfs = mMesh.cell(*c_it).halffaces();
1818 for (
unsigned int i = 0; i < hfs.size(); ++i)
1820 unsigned int numOfVerticesInHalfface = 0;
1822 ++numOfVerticesInHalfface;
1824 unsigned int numOfDrawnFaces = numOfVerticesInHalfface-2;
1825 for (
unsigned int i = 0; i < numOfDrawnFaces*3; i++)
1839 template <
class VolumeMesh>
1851 mNumOfVertices = -1;
1858 unsigned int bufferSize = mVertexSize * numOfVertices;
1864 GL_ARRAY_BUFFER, GL_READ_WRITE);
1886 std::cerr <<
"error while mapping buffer" << std::endl;
1892 mInvalidated =
false;
1893 mGeometryChanged =
false;
1894 mColorsChanged =
false;
1895 mNormalsChanged =
false;
1896 mTexCoordsChanged =
false;
1911 template <
class VolumeMesh>
1914 if (_offset != mCurrentPickOffset || _state.
pick_current_index() != mGlobalPickOffset)
1928 mNumOfVertices = -1;
1935 unsigned int bufferSize = mVertexSize * numOfVertices;
1957 std::cerr <<
"error while mapping buffer" << std::endl;
1962 mCurrentPickOffset = _offset;
1964 mInvalidated =
false;
1965 mGeometryChanged =
false;
1966 mColorsChanged =
false;
1967 mTexCoordsChanged =
false;
1977 template <
class VolumeMesh>
1988 template <
class VolumeMesh>
1991 mInvalidated =
true;
1992 mNumOfVertices = -1;
1993 mGeometryChanged =
true;
1994 mColorsChanged =
true;
1995 mTexCoordsChanged =
true;
1996 mNormalsChanged =
true;
1998 mCellInsidenessValid =
false;
2004 template <
class VolumeMesh>
2007 mInvalidated =
true;
2008 mColorsChanged =
true;
2014 template <
class VolumeMesh>
2017 mInvalidated =
true;
2018 mNormalsChanged =
true;
2024 template <
class VolumeMesh>
2027 mInvalidated =
true;
2028 mTexCoordsChanged =
true;
2036 template <
class VolumeMesh>
ACG::Vec4f getValenceColorCode(unsigned int _valence, bool _inner) const
Returns a color code for irregular edges.
unsigned int pick_current_index() const
Returns the current color picking index (can be used for caching)
void invalidateColors()
Invalidates colors.
bool is_inside(const ACG::Vec3d &_p)
Tests whether the given point is inside w.r.t. all cut planes.
void disableColors()
Disables colors.
void calculateCellInsideness()
Calculates for all cells whether they are inside w.r.t. all cut planes.
bool colorsNeedRebuild()
Checks whether colors need to be rebuild.
bool normalsNeedRebuild()
Checks whether normals need to be rebuild.
VectorT< float, 4 > Vec4f
void buildTexCoordBuffer(unsigned char *_buffer)
Adds texture coordinates to the buffer.
void invalidate()
Invalidates the buffer.
void clearCutPlanes()
Removes all cut planes.
GLuint getBuffer()
Returns the name of the buffer.
static void genBuffers(GLsizei n, GLuint *buffers)
void setOptionsFromDrawMode(ACG::SceneGraph::DrawModes::DrawMode _drawMode)
Configures the buffer manager's options from a DrawMode.
void enablePerFaceColors()
Enables per face colors.
void saveOptions()
State that the current buffer was built with the current options.
void buildColorBuffer(unsigned char *_buffer)
Adds all colors to the buffer.
void enablePerHalfedgeColors()
Enables per halfedge colors.
void invalidateNormals()
Invalidates normals.
void enablePerHalffaceNormals()
Enables per halfface normals.
void addColorToBuffer(ACG::Vec4uc _color, unsigned char *_buffer, unsigned int _offset)
Adds a color to the buffer.
static void deleteBuffers(GLsizei n, const GLuint *buffers)
ACG::Vec3d getCOG(OpenVolumeMesh::CellHandle _ch)
Returns the center of gravity of the given cell.
Vec4uc pick_get_name_color(unsigned int _idx)
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.
static void bindBuffer(GLenum _target, GLuint _buffer)
replaces glBindBuffer, supports locking
bool positionsNeedRebuild()
Checks whether positions need to be rebuild.
void buildNormalBuffer(unsigned char *_buffer)
Adds all normals to the buffer.
void addUCharToBuffer(unsigned char _value, unsigned char *&_buffer)
Adds an unsigned char to the buffer.
This class creates buffers that can be used to render open volume meshs.
GLuint getPickBuffer(ACG::GLState &_state, unsigned int _offset)
Returns the name of the pick buffer.
void enablePerFaceNormals()
Enables per face normals.
void addNormalToBuffer(ACG::Vec3d _normal, unsigned char *_buffer, unsigned int _offset)
Adds a normal to the buffer.
static void bufferData(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage)
void free()
Deletes the buffers on the GPU.
void disableNormals()
Disables normals.
void addTexCoordToBuffer(ACG::Vec2f _texCoord, unsigned char *_buffer, unsigned int _offset)
Adds a texture coordnate to the buffer.
bool texCoordsNeedRebuild()
Checks whether texture coordinates need to be rebuild.
static GLboolean unmapBuffer(GLenum target)
void calculateCOGs()
Calculates the center of gravity for all cells.
void invalidateGeometry()
Invalidates geometry.
void addFloatToBuffer(float _value, unsigned char *&_buffer)
Adds a float to the buffer.
void enablePerCellColors()
Enables per cell colors.
void calculateVertexDeclaration()
Constructs a VertexDeclaration, the size and the offsets for the vertices stored in the buffer...
Namespace providing different geometric functions concerning angles.
void countNumOfVertices()
Counts the number of vertices that need to be stored in the buffer.
void setDefaultColor(ACG::Vec4f _defaultColor)
Sets the default color.
static GLvoid * mapBuffer(GLenum target, GLenum access)
void enablePerEdgeColors()
Enables per edge colors.
void buildPickColorBuffer(ACG::GLState &_state, unsigned int _offset, unsigned char *_buffer)
Adds all picking colors to the buffer.
void enablePerVertexNormals()
Enables per vertex normals.
void addElement(const VertexElement *_pElement)
void invalidateTexCoords()
Invalidates texture coordinates.
void addCutPlane(const typename VolumeMeshBufferManager< VolumeMesh >::Plane &_p)
Adds a cut plane.
void buildVertexBuffer(unsigned char *_buffer)
Adds all vertices to the buffer.
void addPositionToBuffer(ACG::Vec3d _position, unsigned char *_buffer, unsigned int _offset)
Adds a position to the buffer.
void enablePerHalffaceColors()
Enables per halfface colors.
unsigned int getNumOfVertices()
Returns the number of vertices stored in the buffer.
bool optionsChanged()
Tests whether the options were changed since the last time building the buffer.
VectorT< double, 3 > Vec3d
void enablePerVertexColors()
Enables per vertex colors.