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
25 \*---------------------------------------------------------------------------*/
27 #include "TRIsurfaceFormat.H"
30 #include "IStringStream.H"
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35 Foam::fileFormats::TRIsurfaceFormatCore::TRIsurfaceFormatCore
37 const fileName& filename
49 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
51 Foam::fileFormats::TRIsurfaceFormatCore::~TRIsurfaceFormatCore()
55 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
57 bool Foam::fileFormats::TRIsurfaceFormatCore::read
59 const fileName& filename
65 IFstream is(filename);
70 "fileFormats::TRIsurfaceFormatCore::read(const fileName&)"
72 << "Cannot read file " << filename
76 // uses similar structure as STL, just some points
77 // the rest of the reader resembles the STL binary reader
78 DynamicList<point> dynPoints;
79 DynamicList<label> dynZones;
80 DynamicList<label> dynSizes;
81 HashTable<label> lookup;
83 // place faces without a group in zone0
85 dynSizes.append(zoneI);
86 lookup.insert("zoneI", zoneI);
90 string line = this->getLineNoComment(is);
92 // handle continuations ?
93 // if (line[line.size()-1] == '\\')
95 // line.substr(0, line.size()-1);
96 // line += this->getLineNoComment(is);
99 IStringStream lineStream(line);
103 readScalar(lineStream),
104 readScalar(lineStream),
105 readScalar(lineStream)
108 if (!lineStream) break;
115 readScalar(lineStream),
116 readScalar(lineStream),
117 readScalar(lineStream)
124 readScalar(lineStream),
125 readScalar(lineStream),
126 readScalar(lineStream)
130 // zone/colour in .tri file starts with 0x. Skip.
131 // ie, instead of having 0xFF, skip 0 and leave xFF to
132 // get read as a word and name it "zoneFF"
137 word rawName(lineStream);
138 word name("zone" + rawName(1, rawName.size()-1));
140 HashTable<label>::const_iterator fnd = lookup.find(name);
141 if (fnd != lookup.end())
145 // group appeared out of order
152 zoneI = dynSizes.size();
153 lookup.insert(name, zoneI);
157 dynZones.append(zoneI);
163 forAll(dynSizes, zoneI)
169 dynSizes[nZone] = dynSizes[zoneI];
174 // truncate addressed size
175 dynSizes.setCapacity(nZone);
177 // transfer to normal lists
178 points_.transfer(dynPoints);
179 zoneIds_.transfer(dynZones);
180 sizes_.transfer(dynSizes);
186 // ************************************************************************* //