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 TRI (triangle) file reader. Comes out of e.g. AC3D.
27 lines are 9 floats (3 points, each 3 floats) followed by hex colour.
28 Is converted into regions: regions numbered from 0 up, each colour is
30 Most of reading/stitching taken from STL reader.
32 \*---------------------------------------------------------------------------*/
34 #include "triSurface.H"
38 #include "readHexLabel.H"
39 #include "stringList.H"
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
48 bool triSurface::readTRI(const fileName& TRIfileName)
50 IFstream TRIfile(TRIfileName);
54 FatalErrorIn("triSurface::readTRI(const fileName&)")
55 << "Cannot read file " << TRIfileName
59 SLList<STLpoint> STLpoints;
60 SLList<label> STLlabels;
61 HashTable<label, string> STLsolidNames;
63 // Max region number so far
68 string line = getLineNoComment(TRIfile);
75 IStringStream lineStream(line);
79 readScalar(lineStream),
80 readScalar(lineStream),
81 readScalar(lineStream)
84 if (!lineStream) break;
91 readScalar(lineStream),
92 readScalar(lineStream),
93 readScalar(lineStream)
100 readScalar(lineStream),
101 readScalar(lineStream),
102 readScalar(lineStream)
106 // Region/colour in .tri file starts with 0x. Skip.
111 word rawSolidName(lineStream);
113 word solidName("patch" + rawSolidName(1, rawSolidName.size()-1));
117 HashTable<label, string>::const_iterator findName =
118 STLsolidNames.find(solidName);
120 if (findName != STLsolidNames.end())
126 Pout<< "Mapping triangle colour 0" << rawSolidName
127 << " to region " << maxRegion << " name " << solidName
130 region = maxRegion++;
131 STLsolidNames.insert(solidName, region);
133 STLlabels.append(region);
137 pointField rawPoints(STLpoints.size());
142 SLList<STLpoint>::iterator iter = STLpoints.begin();
143 iter != STLpoints.end();
147 rawPoints[i++] = *iter;
150 setSize(STLlabels.size());
153 SLList<label>::iterator iter = STLlabels.begin();
156 operator[](i)[0] = pointI++;
157 operator[](i)[1] = pointI++;
158 operator[](i)[2] = pointI++;
159 operator[](i).region() = *iter;
163 stitchTriangles(rawPoints);
165 // Convert solidNames into regionNames
166 stringList names(STLsolidNames.toc());
168 patches_.setSize(names.size());
172 patches_[nameI].name() = names[nameI];
173 patches_[nameI].geometricType() = "empty";
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 } // End namespace Foam
184 // ************************************************************************* //