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