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 #include <triSurface/triSurface.H>
00030 #include <OpenFOAM/IFstream.H>
00031 #include <OpenFOAM/IStringStream.H>
00032
00033
00034
00035 namespace Foam
00036 {
00037
00038
00039
00040 bool triSurface::readOFF(const fileName& OFFfileName)
00041 {
00042 IFstream OFFfile(OFFfileName);
00043
00044 if (!OFFfile.good())
00045 {
00046 FatalErrorIn("triSurface::readOFF(const fileName&)")
00047 << "Cannot read file " << OFFfileName
00048 << exit(FatalError);
00049 }
00050
00051
00052 string hdr = getLineNoComment(OFFfile);
00053 if (hdr != "OFF")
00054 {
00055 FatalErrorIn("triSurface::readOFF(const fileName&)")
00056 << "OFF file " << OFFfileName
00057 << " does not start with 'OFF'"
00058 << exit(FatalError);
00059 }
00060
00061
00062 label nPoints, nEdges, nElems;
00063
00064 string line = getLineNoComment(OFFfile);
00065 {
00066 IStringStream lineStream(line);
00067 lineStream >> nPoints >> nElems >> nEdges;
00068 }
00069
00070
00071 pointField points(nPoints);
00072
00073 forAll(points, pointi)
00074 {
00075 scalar x, y, z;
00076 line = getLineNoComment(OFFfile);
00077 {
00078 IStringStream lineStream(line);
00079 lineStream >> x >> y >> z;
00080 }
00081 points[pointi] = point(x, y, z);
00082 }
00083
00084
00085 DynamicList<labelledTri> tris(nElems);
00086
00087 for (label faceI = 0; faceI < nElems; faceI++)
00088 {
00089 line = getLineNoComment(OFFfile);
00090 {
00091 IStringStream lineStream(line);
00092
00093 label nVerts;
00094 lineStream >> nVerts;
00095
00096 face f(nVerts);
00097
00098 forAll(f, fp)
00099 {
00100 lineStream >> f[fp];
00101 }
00102
00103
00104 if (nVerts == 3)
00105 {
00106 tris.append(labelledTri(f[0], f[1], f[2], 0));
00107 }
00108 else if (nVerts == 4)
00109 {
00110 tris.append(labelledTri(f[0], f[1], f[2], 0));
00111 tris.append(labelledTri(f[2], f[3], f[0], 0));
00112 }
00113 else
00114 {
00115 faceList triFaces(f.nTriangles(points));
00116
00117 label nTri = 0;
00118
00119 f.triangles(points, nTri, triFaces);
00120
00121 forAll(triFaces, triFaceI)
00122 {
00123 const face& f = triFaces[triFaceI];
00124
00125 tris.append(labelledTri(f[0], f[1], f[2], 0));
00126 }
00127 }
00128 }
00129 }
00130
00131 tris.shrink();
00132
00133 *this = triSurface(tris, points);
00134
00135 return true;
00136 }
00137
00138
00139
00140
00141 }
00142
00143