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,33 +609,73 @@ 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())
{ {
for (int j = 0; j < 3; j++) // each face put in the stack is selected (and oriented)
if (!CheckOrientation(*fi, j)) 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++)
{ {
Oriented = false; // get one of the adjacent face
fpaux = fp->FFp(j);
iaux = fp->FFi(j);
// if this face has just been swapped the mesh is not orientable if (!fpaux->IsD() && fpaux != fp)
if (fi->IsS())
{ {
Orientable = false; if (!CheckOrientation(*fpaux, iaux))
break; {
} Oriented = false;
SwapEdge(*fi, j); if (!fpaux->IsS())
fi->SetS(); {
assert(CheckOrientation(*fi, j)); SwapEdge(*fpaux, iaux);
assert(CheckOrientation(*fpaux, iaux));
}
else
Orientable = false;
}
// put the oriented face into the stack
if (!fpaux->IsS())
{
fpaux->SetS();
faces.push(fpaux);
}
}
} }
}
} }
if (!Orientable)
break;
} }
} }