1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 Geomview OFF polyList format. Does triangulation.
28 \*---------------------------------------------------------------------------*/
30 #include "triSurface.H"
32 #include "IStringStream.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
41 bool triSurface::readOFF(const fileName& OFFfileName)
43 IFstream OFFfile(OFFfileName);
47 FatalErrorIn("triSurface::readOFF(const fileName&)")
48 << "Cannot read file " << OFFfileName
53 string hdr = getLineNoComment(OFFfile);
56 FatalErrorIn("triSurface::readOFF(const fileName&)")
57 << "OFF file " << OFFfileName
58 << " does not start with 'OFF'"
63 label nPoints, nEdges, nElems;
65 string line = getLineNoComment(OFFfile);
67 IStringStream lineStream(line);
68 lineStream >> nPoints >> nElems >> nEdges;
72 pointField points(nPoints);
74 forAll(points, pointi)
77 line = getLineNoComment(OFFfile);
79 IStringStream lineStream(line);
80 lineStream >> x >> y >> z;
82 points[pointi] = point(x, y, z);
85 // Read faces & triangulate them,
86 DynamicList<labelledTri> tris(nElems);
88 for (label faceI = 0; faceI < nElems; faceI++)
90 line = getLineNoComment(OFFfile);
92 IStringStream lineStream(line);
107 tris.append(labelledTri(f[0], f[1], f[2], 0));
109 else if (nVerts == 4)
111 tris.append(labelledTri(f[0], f[1], f[2], 0));
112 tris.append(labelledTri(f[2], f[3], f[0], 0));
116 faceList triFaces(f.nTriangles(points));
120 f.triangles(points, nTri, triFaces);
122 forAll(triFaces, triFaceI)
124 const face& f = triFaces[triFaceI];
126 tris.append(labelledTri(f[0], f[1], f[2], 0));
134 *this = triSurface(tris, points);
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
142 } // End namespace Foam
144 // ************************************************************************* //