Fix IsOrientedMesh

This commit is contained in:
Massimiliano Corsini 2005-12-19 15:13:06 +00:00
parent 47da0f6a24
commit 34acf11b61
1 changed files with 57 additions and 14 deletions

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.23 2005/12/16 13:13:44 cignoni
Reimplemented SelfIntersection
Revision 1.22 2005/12/16 10:54:59 corsini Revision 1.22 2005/12/16 10:54:59 corsini
Reimplement isOrientedMesh Reimplement isOrientedMesh
@ -606,35 +609,75 @@ namespace vcg {
static void IsOrientedMesh(MeshType &m, bool &Oriented, bool &Orientable) static void IsOrientedMesh(MeshType &m, bool &Oriented, bool &Orientable)
{ {
FaceIterator fi; // This algorithms requires FF topology
assert(m.HasFFTopology());
Orientable = true; Orientable = true;
Oriented = true; Oriented = true;
// check the orientation of each face // Ensure that each face is deselected
FaceIterator fi;
for (fi = m.face.begin(); fi != m.face.end(); ++fi)
fi->ClearS();
// initialize stack
stack<FacePointer> faces;
// for each face of the mesh
FacePointer fp,fpaux;
int iaux;
for (fi = m.face.begin(); fi != m.face.end(); ++fi) for (fi = m.face.begin(); fi != m.face.end(); ++fi)
{ {
if (!fi->IsD()) if (!fi->IsD() && !fi->IsS())
{ {
// each face put in the stack is selected (and oriented)
fi->SetS();
faces.push(&(*fi));
// empty the stack
while (!faces.empty())
{
fp = faces.top();
faces.pop();
// make consistently oriented the adjacent faces
for (int j = 0; j < 3; j++) for (int j = 0; j < 3; j++)
if (!CheckOrientation(*fi, j)) {
// get one of the adjacent face
fpaux = fp->FFp(j);
iaux = fp->FFi(j);
if (!fpaux->IsD() && fpaux != fp)
{
if (!CheckOrientation(*fpaux, iaux))
{ {
Oriented = false; Oriented = false;
// if this face has just been swapped the mesh is not orientable if (!fpaux->IsS())
if (fi->IsS())
{ {
SwapEdge(*fpaux, iaux);
assert(CheckOrientation(*fpaux, iaux));
}
else
Orientable = false; Orientable = false;
break;
} }
SwapEdge(*fi, j); // put the oriented face into the stack
fi->SetS();
assert(CheckOrientation(*fi, j)); if (!fpaux->IsS())
{
fpaux->SetS();
faces.push(fpaux);
} }
} }
} }
} }
}
if (!Orientable)
break;
}
}
static bool SelfIntersections(MeshType &m, std::vector<FaceType*> &ret) static bool SelfIntersections(MeshType &m, std::vector<FaceType*> &ret)
{ {