writeOBJ.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
00028
00029
00030
00031
00032 #include "triSurface.H"
00033
00034
00035
00036 namespace Foam
00037 {
00038
00039
00040
00041 void triSurface::writeOBJ(const bool writeSorted, Ostream& os) const
00042 {
00043
00044 os << "# Wavefront OBJ file" << endl
00045 << "# Regions:" << endl;
00046
00047 labelList faceMap;
00048
00049 surfacePatchList myPatches(calcPatches(faceMap));
00050
00051 const pointField& ps = points();
00052
00053
00054 forAll(myPatches, patchI)
00055 {
00056 os << "# " << patchI << " "
00057 << myPatches[patchI].name() << endl;
00058 }
00059 os << "#" << endl;
00060
00061 os << "# points : " << ps.size() << endl
00062 << "# triangles : " << size() << endl
00063 << "#" << endl;
00064
00065
00066
00067 forAll(ps, pointi)
00068 {
00069 os << "v "
00070 << ps[pointi].x() << ' '
00071 << ps[pointi].y() << ' '
00072 << ps[pointi].z() << endl;
00073 }
00074
00075 if (writeSorted)
00076 {
00077 label faceIndex = 0;
00078
00079 forAll(myPatches, patchI)
00080 {
00081
00082
00083 os << "g " << myPatches[patchI].name() << endl;
00084
00085 for
00086 (
00087 label patchFaceI = 0;
00088 patchFaceI < myPatches[patchI].size();
00089 patchFaceI++
00090 )
00091 {
00092 const label faceI = faceMap[faceIndex++];
00093
00094 os << "f "
00095 << operator[](faceI)[0] + 1 << ' '
00096 << operator[](faceI)[1] + 1 << ' '
00097 << operator[](faceI)[2] + 1
00098
00099 << endl;
00100 }
00101 }
00102 }
00103 else
00104 {
00105 forAll(*this, faceI)
00106 {
00107 os << "f "
00108 << operator[](faceI)[0] + 1 << ' '
00109 << operator[](faceI)[1] + 1 << ' '
00110 << operator[](faceI)[2] + 1
00111
00112 << endl;
00113 }
00114 }
00115 }
00116
00117
00118
00119
00120 }
00121
00122
Copyright © 2000-2009 OpenCFD Ltd