1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 inline void Foam::fileFormats::TRIsurfaceFormat<Face>::writeShell
36 const pointField& pointLst,
41 // simple triangulation about f[0].
42 // better triangulation should have been done before
43 const point& p0 = pointLst[f[0]];
44 for (label fp1 = 1; fp1 < f.size() - 1; ++fp1)
46 label fp2 = f.fcIndex(fp1);
48 const point& p1 = pointLst[f[fp1]];
49 const point& p2 = pointLst[f[fp2]];
51 os << p0.x() << ' ' << p0.y() << ' ' << p0.z() << ' '
52 << p1.x() << ' ' << p1.y() << ' ' << p1.z() << ' '
53 << p2.x() << ' ' << p2.y() << ' ' << p2.z() << ' '
55 << "0x" << hex << zoneI << dec << endl;
60 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
63 Foam::fileFormats::TRIsurfaceFormat<Face>::TRIsurfaceFormat
65 const fileName& filename
72 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
75 bool Foam::fileFormats::TRIsurfaceFormat<Face>::read
77 const fileName& filename
83 TRIsurfaceFormatCore reader(filename);
86 this->storedPoints().transfer(reader.points());
88 // retrieve the original zone information
89 List<label> sizes(reader.sizes().xfer());
90 List<label> zoneIds(reader.zoneIds().xfer());
92 // generate the (sorted) faces
93 List<Face> faceLst(zoneIds.size());
97 // already sorted - generate directly
98 forAll(faceLst, faceI)
100 const label startPt = 3*faceI;
101 faceLst[faceI] = triFace(startPt, startPt+1, startPt+2);
106 // unsorted - determine the sorted order:
107 // avoid SortableList since we discard the main list anyhow
109 sortedOrder(zoneIds, faceMap);
111 // generate sorted faces
112 forAll(faceMap, faceI)
114 const label startPt = 3*faceMap[faceI];
115 faceLst[faceI] = triFace(startPt, startPt+1, startPt+2);
121 this->storedFaces().transfer(faceLst);
123 this->addZones(sizes);
124 this->stitchFaces(SMALL);
130 void Foam::fileFormats::TRIsurfaceFormat<Face>::write
132 const fileName& filename,
133 const MeshedSurfaceProxy<Face>& surf
136 const pointField& pointLst = surf.points();
137 const List<Face>& faceLst = surf.faces();
138 const List<label>& faceMap = surf.faceMap();
140 const List<surfZone>& zones =
142 surf.surfZones().size() > 1
147 const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
149 OFstream os(filename);
154 "fileFormats::TRIsurfaceFormat::write"
155 "(const fileName&, const MeshedSurfaceProxy<Face>&)"
157 << "Cannot open file for writing " << filename
164 const surfZone& zone = zones[zoneI];
168 forAll(zone, localFaceI)
170 const Face& f = faceLst[faceMap[faceIndex++]];
171 writeShell(os, pointLst, f, zoneI);
176 forAll(zone, localFaceI)
178 const Face& f = faceLst[faceIndex++];
179 writeShell(os, pointLst, f, zoneI);
187 void Foam::fileFormats::TRIsurfaceFormat<Face>::write
189 const fileName& filename,
190 const UnsortedMeshedSurface<Face>& surf
193 const pointField& pointLst = surf.points();
194 const List<Face>& faceLst = surf.faces();
196 OFstream os(filename);
201 "fileFormats::TRIsurfaceFormat::write"
202 "(const fileName&, const UnsortedMeshedSurface<Face>&)"
204 << "Cannot open file for writing " << filename
209 // a single zone needs no sorting
210 if (surf.zoneToc().size() == 1)
212 const List<label>& zoneIds = surf.zoneIds();
214 forAll(faceLst, faceI)
216 writeShell(os, pointLst, faceLst[faceI], zoneIds[faceI]);
222 List<surfZone> zoneLst = surf.sortedZones(faceMap);
225 forAll(zoneLst, zoneI)
227 forAll(zoneLst[zoneI], localFaceI)
229 const Face& f = faceLst[faceMap[faceIndex++]];
230 writeShell(os, pointLst, f, zoneI);
237 // ************************************************************************* //