writeSTL.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "triSurface.H"
00028 #include "STLtriangle.H"
00029 #include "primitivePatch.H"
00030 #include "HashTable.H"
00031 #include "hashSignedLabel.H"
00032
00033
00034
00035 namespace Foam
00036 {
00037
00038
00039
00040 void triSurface::writeSTLASCII(Ostream& os) const
00041 {
00042 labelList faceMap;
00043
00044 surfacePatchList myPatches(calcPatches(faceMap));
00045
00046 label faceIndex = 0;
00047 forAll(myPatches, patchI)
00048 {
00049
00050 const surfacePatch& patch = myPatches[patchI];
00051
00052 os << "solid " << patch.name() << endl;
00053
00054 for
00055 (
00056 label patchFaceI = 0;
00057 patchFaceI < patch.size();
00058 patchFaceI++
00059 )
00060 {
00061 const label faceI = faceMap[faceIndex++];
00062
00063 const vector& n = faceNormals()[faceI];
00064
00065 os << " facet normal "
00066 << n.x() << ' ' << n.y() << ' ' << n.z() << endl;
00067 os << " outer loop" << endl;
00068
00069 const labelledTri& f = (*this)[faceI];
00070 const point& pa = points()[f[0]];
00071 const point& pb = points()[f[1]];
00072 const point& pc = points()[f[2]];
00073
00074 os << " vertex "
00075 << pa.x() << ' ' << pa.y() << ' ' << pa.z() << endl;
00076 os << " vertex "
00077 << pb.x() << ' ' << pb.y() << ' ' << pb.z() << endl;
00078 os << " vertex "
00079 << pc.x() << ' ' << pc.y() << ' ' << pc.z() << endl;
00080 os
00081 << " endloop" << endl;
00082 os
00083 << " endfacet" << endl;
00084 }
00085
00086 os << "endsolid " << patch.name() << endl;
00087 }
00088 }
00089
00090
00091 void triSurface::writeSTLBINARY(std::ostream& os) const
00092 {
00093
00094 string header("Foam binary STL", STLheaderSize);
00095 os.write(header.c_str(), STLheaderSize);
00096
00097 label nTris = size();
00098 os.write(reinterpret_cast<char*>(&nTris), sizeof(unsigned int));
00099
00100 const vectorField& normals = faceNormals();
00101
00102 forAll(*this, faceI)
00103 {
00104 const labelledTri& f = (*this)[faceI];
00105
00106
00107 STLpoint n(normals[faceI]);
00108 STLpoint pa(points()[f[0]]);
00109 STLpoint pb(points()[f[1]]);
00110 STLpoint pc(points()[f[2]]);
00111
00112 STLtriangle stlTri(n, pa, pb, pc, f.region());
00113
00114 stlTri.write(os);
00115 }
00116 }
00117
00118
00119
00120
00121 }
00122
00123
Copyright © 2000-2009 OpenCFD Ltd