1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "triSurface.H"
28 #include "STLtriangle.H"
29 #include "primitivePatch.H"
30 #include "HashTable.H"
31 #include "hashSignedLabel.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
40 void triSurface::writeSTLASCII(Ostream& os) const
44 surfacePatchList myPatches(calcPatches(faceMap));
47 forAll(myPatches, patchI)
49 // Print all faces belonging to this region
50 const surfacePatch& patch = myPatches[patchI];
52 os << "solid " << patch.name() << endl;
57 patchFaceI < patch.size();
61 const label faceI = faceMap[faceIndex++];
63 const vector& n = faceNormals()[faceI];
65 os << " facet normal "
66 << n.x() << ' ' << n.y() << ' ' << n.z() << endl;
67 os << " outer loop" << endl;
69 const labelledTri& f = (*this)[faceI];
70 const point& pa = points()[f[0]];
71 const point& pb = points()[f[1]];
72 const point& pc = points()[f[2]];
75 << pa.x() << ' ' << pa.y() << ' ' << pa.z() << endl;
77 << pb.x() << ' ' << pb.y() << ' ' << pb.z() << endl;
79 << pc.x() << ' ' << pc.y() << ' ' << pc.z() << endl;
81 << " endloop" << endl;
83 << " endfacet" << endl;
86 os << "endsolid " << patch.name() << endl;
91 void triSurface::writeSTLBINARY(std::ostream& os) const
93 // Write the STL header
94 string header("Foam binary STL", STLheaderSize);
95 os.write(header.c_str(), STLheaderSize);
98 os.write(reinterpret_cast<char*>(&nTris), sizeof(unsigned int));
100 const vectorField& normals = faceNormals();
104 const labelledTri& f = (*this)[faceI];
106 // Convert vector into STL single precision
107 STLpoint n(normals[faceI]);
108 STLpoint pa(points()[f[0]]);
109 STLpoint pb(points()[f[1]]);
110 STLpoint pc(points()[f[2]]);
112 STLtriangle stlTri(n, pa, pb, pc, f.region());
119 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
121 } // End namespace Foam
123 // ************************************************************************* //