From cf26c828cc73194dc2aa3c2d565b192f759ec434 Mon Sep 17 00:00:00 2001 From: laurence <laurence> Date: Wed, 8 May 2013 12:09:48 +0100 Subject: [PATCH] ENH: When writing a triSurface to ascii stl or obj, exclude empty patches --- .../triSurface/interfaces/OBJ/writeOBJ.C | 48 +++++++------ .../triSurface/interfaces/STL/writeSTL.C | 67 ++++++++++--------- 2 files changed, 63 insertions(+), 52 deletions(-) diff --git a/src/triSurface/triSurface/interfaces/OBJ/writeOBJ.C b/src/triSurface/triSurface/interfaces/OBJ/writeOBJ.C index 24a68b5a05b..99680f8bb63 100644 --- a/src/triSurface/triSurface/interfaces/OBJ/writeOBJ.C +++ b/src/triSurface/triSurface/interfaces/OBJ/writeOBJ.C @@ -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) { - // Print all faces belonging to this patch - - os << "g " << myPatches[patchI].name() << nl; + const surfacePatch& patch = myPatches[patchI]; - for - ( - label patchFaceI = 0; - patchFaceI < myPatches[patchI].size(); - patchFaceI++ - ) + // Print all faces belonging to this patch + if (patch.size() > 0) { - const label faceI = faceMap[faceIndex++]; - - os << "f " - << operator[](faceI)[0] + 1 << ' ' - << operator[](faceI)[1] + 1 << ' ' - << operator[](faceI)[2] + 1 - //<< " # " << operator[](faceI).region() - << nl; + os << "g " << patch.name() << 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; + } } } } diff --git a/src/triSurface/triSurface/interfaces/STL/writeSTL.C b/src/triSurface/triSurface/interfaces/STL/writeSTL.C index 655787c40a5..63874b185e4 100644 --- a/src/triSurface/triSurface/interfaces/STL/writeSTL.C +++ b/src/triSurface/triSurface/interfaces/STL/writeSTL.C @@ -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++]; - - 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; + os << "solid " << patch.name() << endl; + + for + ( + label patchFaceI = 0; + patchFaceI < patch.size(); + patchFaceI++ + ) + { + const label faceI = faceMap[faceIndex++]; + + 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; + } + + os << "endsolid " << patch.name() << endl; } - - os << "endsolid " << patch.name() << endl; } } -- GitLab