CountBitLargePolygons const correctness

This commit is contained in:
alemuntoni 2021-03-19 12:16:01 +01:00
parent abcde4bbed
commit 8f953efd04
1 changed files with 29 additions and 20 deletions

View File

@ -168,6 +168,7 @@ public:
typedef CleanMeshType MeshType; typedef CleanMeshType MeshType;
typedef typename MeshType::VertexType VertexType; typedef typename MeshType::VertexType VertexType;
typedef typename MeshType::VertexPointer VertexPointer; typedef typename MeshType::VertexPointer VertexPointer;
typedef typename MeshType::ConstVertexPointer ConstVertexPointer;
typedef typename MeshType::VertexIterator VertexIterator; typedef typename MeshType::VertexIterator VertexIterator;
typedef typename MeshType::ConstVertexIterator ConstVertexIterator; typedef typename MeshType::ConstVertexIterator ConstVertexIterator;
typedef typename MeshType::EdgeIterator EdgeIterator; typedef typename MeshType::EdgeIterator EdgeIterator;
@ -941,20 +942,28 @@ public:
* as a intuitive proof think to a internal vertex that is collapsed onto a border of a polygon: * as a intuitive proof think to a internal vertex that is collapsed onto a border of a polygon:
* it deletes 2 faces, 1 faux edges and 1 vertex so to keep the balance you have to add back the removed vertex. * it deletes 2 faces, 1 faux edges and 1 vertex so to keep the balance you have to add back the removed vertex.
*/ */
static int CountBitLargePolygons(MeshType &m) static int CountBitLargePolygons(const MeshType &m)
{ {
tri::RequirePerFaceFlags(m); //note - using unordered_map to set visited vertices because
UpdateFlags<MeshType>::VertexSetV(m); //the mesh is const (before, the function used vertex flags...).
//could be used std::vector<bool> if the vertex has the Index()
//member function...
std::unordered_map<ConstVertexPointer, bool> vertVisited;
for (ConstVertexIterator vi = m.vert.begin(); vi != m.vert.end(); ++vi)
if (!vi->IsD()) vertVisited[&(*vi)] = true;
// First loop Clear all referenced vertices // First loop Clear all referenced vertices
for (FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) for (ConstFaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi)
if (!fi->IsD()) if (!fi->IsD())
for(int i=0;i<3;++i) fi->V(i)->ClearV(); for(int i=0;i<3;++i){
vertVisited[fi->V(i)] = false;
}
// Second Loop, count (twice) faux edges and mark all vertices touched by non faux edges // Second Loop, count (twice) faux edges and mark all vertices touched by non faux edges
// (e.g vertexes on the boundary of a polygon) // (e.g vertexes on the boundary of a polygon)
int countE = 0; int countE = 0;
for (FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) for (ConstFaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi)
if (!fi->IsD()) { if (!fi->IsD()) {
for(int i=0;i<3;++i) for(int i=0;i<3;++i)
{ {
@ -962,16 +971,16 @@ public:
countE++; countE++;
else else
{ {
fi->V0(i)->SetV(); vertVisited[fi->V0(i)] = true;
fi->V1(i)->SetV(); vertVisited[fi->V1(i)] = true;
} }
} }
} }
// Third Loop, count the number of referenced vertexes that are completely surrounded by faux edges. // Third Loop, count the number of referenced vertexes that are completely surrounded by faux edges.
int countV = 0; int countV = 0;
for (VertexIterator vi = m.vert.begin(); vi != m.vert.end(); ++vi) for (ConstVertexIterator vi = m.vert.begin(); vi != m.vert.end(); ++vi)
if (!vi->IsD() && !vi->IsV()) countV++; if (!vi->IsD() && !(vertVisited[&(*vi)])) countV++;
return m.fn - countE/2 + countV ; return m.fn - countE/2 + countV ;
} }