ENH: When writing a triSurface to ascii stl or obj, exclude empty patches

This commit is contained in:
laurence
2013-05-08 12:09:48 +01:00
parent 45fd7105ff
commit cf26c828cc
2 changed files with 58 additions and 47 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -52,8 +52,12 @@ void triSurface::writeOBJ(const bool writeSorted, Ostream& os) const
// Print patch names as comment
forAll(myPatches, patchI)
{
os << "# " << patchI << " "
<< myPatches[patchI].name() << nl;
const surfacePatch& patch = myPatches[patchI];
if (patch.size() > 0)
{
os << "# " << patchI << " " << patch.name() << nl;
}
}
os << "#" << nl;
@ -77,25 +81,29 @@ void triSurface::writeOBJ(const bool writeSorted, Ostream& os) const
forAll(myPatches, patchI)
{
const surfacePatch& patch = myPatches[patchI];
// Print all faces belonging to this patch
os << "g " << myPatches[patchI].name() << nl;
for
(
label patchFaceI = 0;
patchFaceI < myPatches[patchI].size();
patchFaceI++
)
if (patch.size() > 0)
{
const label faceI = faceMap[faceIndex++];
os << "g " << patch.name() << nl;
os << "f "
<< operator[](faceI)[0] + 1 << ' '
<< operator[](faceI)[1] + 1 << ' '
<< operator[](faceI)[2] + 1
//<< " # " << operator[](faceI).region()
<< nl;
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;
}
}
}
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -43,39 +43,42 @@ void Foam::triSurface::writeSTLASCII(Ostream& os) const
// Print all faces belonging to this region
const surfacePatch& patch = myPatches[patchI];
os << "solid " << patch.name() << endl;
for
(
label patchFaceI = 0;
patchFaceI < patch.size();
patchFaceI++
)
if (patch.size() > 0)
{
const label faceI = faceMap[faceIndex++];
os << "solid " << patch.name() << endl;
const vector& n = faceNormals()[faceI];
for
(
label patchFaceI = 0;
patchFaceI < patch.size();
patchFaceI++
)
{
const label faceI = faceMap[faceIndex++];
os << " facet normal "
<< n.x() << ' ' << n.y() << ' ' << n.z() << nl
<< " outer loop" << endl;
const vector& n = faceNormals()[faceI];
const labelledTri& f = (*this)[faceI];
const point& pa = points()[f[0]];
const point& pb = points()[f[1]];
const point& pc = points()[f[2]];
os << " facet normal "
<< n.x() << ' ' << n.y() << ' ' << n.z() << nl
<< " outer loop" << endl;
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;
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;
}
os << "endsolid " << patch.name() << endl;
}
os << "endsolid " << patch.name() << endl;
}
}