ENH: triSurface: added sorted writing for STL

This commit is contained in:
mattijs
2013-08-13 10:16:29 +01:00
parent bb0ace809d
commit 66ac8ec1cc
4 changed files with 84 additions and 35 deletions

View File

@ -52,12 +52,8 @@ void triSurface::writeOBJ(const bool writeSorted, Ostream& os) const
// Print patch names as comment
forAll(myPatches, patchI)
{
const surfacePatch& patch = myPatches[patchI];
if (patch.size() > 0)
{
os << "# " << patchI << " " << patch.name() << nl;
}
os << "# " << patchI << " "
<< myPatches[patchI].name() << nl;
}
os << "#" << nl;
@ -81,29 +77,25 @@ void triSurface::writeOBJ(const bool writeSorted, Ostream& os) const
forAll(myPatches, patchI)
{
const surfacePatch& patch = myPatches[patchI];
// Print all faces belonging to this patch
if (patch.size() > 0)
os << "g " << myPatches[patchI].name() << nl;
for
(
label patchFaceI = 0;
patchFaceI < myPatches[patchI].size();
patchFaceI++
)
{
os << "g " << patch.name() << nl;
const label faceI = faceMap[faceIndex++];
for
(
label patchFaceI = 0;
patchFaceI < patch.size();
patchFaceI++
)
{
const label faceI = faceMap[faceIndex++];
os << "f "
<< operator[](faceI)[0] + 1 << ' '
<< operator[](faceI)[1] + 1 << ' '
<< operator[](faceI)[2] + 1
//<< " # " << operator[](faceI).region()
<< nl;
}
os << "f "
<< operator[](faceI)[0] + 1 << ' '
<< operator[](faceI)[1] + 1 << ' '
<< operator[](faceI)[2] + 1
//<< " # " << operator[](faceI).region()
<< nl;
}
}
}

View File

@ -31,20 +31,20 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::triSurface::writeSTLASCII(Ostream& os) const
void Foam::triSurface::writeSTLASCII(const bool writeSorted, Ostream& os) const
{
labelList faceMap;
surfacePatchList myPatches(calcPatches(faceMap));
label faceIndex = 0;
forAll(myPatches, patchI)
if (writeSorted)
{
// Print all faces belonging to this region
const surfacePatch& patch = myPatches[patchI];
if (patch.size() > 0)
label faceIndex = 0;
forAll(myPatches, patchI)
{
// Print all faces belonging to this region
const surfacePatch& patch = myPatches[patchI];
os << "solid " << patch.name() << endl;
for
@ -80,6 +80,63 @@ void Foam::triSurface::writeSTLASCII(Ostream& os) const
os << "endsolid " << patch.name() << endl;
}
}
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 currentPatchI = -1;
forAll(*this, faceI)
{
if (currentPatchI != patchIDs[faceI])
{
if (currentPatchI != -1)
{
// Have already valid patch. Close it.
os << "endsolid " << myPatches[currentPatchI].name()
<< nl;
}
currentPatchI = patchIDs[faceI];
os << "solid " << myPatches[currentPatchI].name() << nl;
}
const vector& n = faceNormals()[faceI];
os << " facet normal "
<< n.x() << ' ' << n.y() << ' ' << n.z() << nl
<< " outer loop" << endl;
const labelledTri& f = (*this)[faceI];
const point& pa = points()[f[0]];
const point& pb = points()[f[1]];
const point& pc = points()[f[2]];
os << " vertex "
<< pa.x() << ' ' << pa.y() << ' ' << pa.z() << nl
<< " vertex "
<< pb.x() << ' ' << pb.y() << ' ' << pb.z() << nl
<< " vertex "
<< pc.x() << ' ' << pc.y() << ' ' << pc.z() << nl
<< " endloop" << nl
<< " endfacet" << endl;
}
if (currentPatchI != -1)
{
os << "endsolid " << myPatches[currentPatchI].name()
<< nl;
}
}
}

View File

@ -448,7 +448,7 @@ void Foam::triSurface::write
}
else if (ext == "stl")
{
return writeSTLASCII(OFstream(name)());
return writeSTLASCII(sort, OFstream(name)());
}
else if (ext == "stlb")
{

View File

@ -138,7 +138,7 @@ class triSurface
//- Write to Ostream in ASCII STL format.
// Each region becomes 'solid' 'endsolid' block.
void writeSTLASCII(Ostream&) const;
void writeSTLASCII(const bool writeSorted, Ostream&) const;
//- Write to std::ostream in BINARY STL format
void writeSTLBINARY(std::ostream&) const;