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