output g command even if not sorted

This commit is contained in:
mattijs
2009-08-11 23:08:26 +01:00
parent 6b691f1776
commit 23c6c069c0

View File

@ -41,8 +41,8 @@ namespace Foam
void triSurface::writeOBJ(const bool writeSorted, Ostream& os) const void triSurface::writeOBJ(const bool writeSorted, Ostream& os) const
{ {
// Write header // Write header
os << "# Wavefront OBJ file" << endl os << "# Wavefront OBJ file" << nl
<< "# Regions:" << endl; << "# Regions:" << nl;
labelList faceMap; labelList faceMap;
@ -54,13 +54,13 @@ void triSurface::writeOBJ(const bool writeSorted, Ostream& os) const
forAll(myPatches, patchI) forAll(myPatches, patchI)
{ {
os << "# " << patchI << " " os << "# " << patchI << " "
<< myPatches[patchI].name() << endl; << myPatches[patchI].name() << nl;
} }
os << "#" << endl; os << "#" << nl;
os << "# points : " << ps.size() << endl os << "# points : " << ps.size() << nl
<< "# triangles : " << size() << endl << "# triangles : " << size() << nl
<< "#" << endl; << "#" << nl;
// Write vertex coords // Write vertex coords
@ -69,7 +69,7 @@ void triSurface::writeOBJ(const bool writeSorted, Ostream& os) const
os << "v " os << "v "
<< ps[pointi].x() << ' ' << ps[pointi].x() << ' '
<< ps[pointi].y() << ' ' << ps[pointi].y() << ' '
<< ps[pointi].z() << endl; << ps[pointi].z() << nl;
} }
if (writeSorted) if (writeSorted)
@ -80,7 +80,7 @@ void triSurface::writeOBJ(const bool writeSorted, Ostream& os) const
{ {
// Print all faces belonging to this patch // Print all faces belonging to this patch
os << "g " << myPatches[patchI].name() << endl; os << "g " << myPatches[patchI].name() << nl;
for for
( (
@ -96,20 +96,39 @@ void triSurface::writeOBJ(const bool writeSorted, Ostream& os) const
<< operator[](faceI)[1] + 1 << ' ' << operator[](faceI)[1] + 1 << ' '
<< operator[](faceI)[2] + 1 << operator[](faceI)[2] + 1
//<< " # " << operator[](faceI).region() //<< " # " << operator[](faceI).region()
<< endl; << nl;
} }
} }
} }
else else
{ {
// Get patch (=compact region) per face
labelList patchIDs(size());
forAll(myPatches, patchI)
{
label faceI = myPatches[patchI].start();
forAll(myPatches[patchI], i)
{
patchIDs[faceMap[faceI++]] = patchI;
}
}
label prevPatchI = -1;
forAll(*this, faceI) forAll(*this, faceI)
{ {
if (prevPatchI != patchIDs[faceI])
{
prevPatchI = patchIDs[faceI];
os << "g " << myPatches[patchIDs[faceI]].name() << nl;
}
os << "f " os << "f "
<< operator[](faceI)[0] + 1 << ' ' << operator[](faceI)[0] + 1 << ' '
<< operator[](faceI)[1] + 1 << ' ' << operator[](faceI)[1] + 1 << ' '
<< operator[](faceI)[2] + 1 << operator[](faceI)[2] + 1
//<< " # " << operator[](faceI).region() << nl;
<< endl;
} }
} }
} }