1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "TRIsurfaceFormat.H"
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 inline void Foam::fileFormats::TRIsurfaceFormat<Face>::writeShell
35 const pointField& pointLst,
40 // simple triangulation about f[0].
41 // better triangulation should have been done before
42 const point& p0 = pointLst[f[0]];
43 for (label fp1 = 1; fp1 < f.size() - 1; ++fp1)
45 label fp2 = f.fcIndex(fp1);
47 const point& p1 = pointLst[f[fp1]];
48 const point& p2 = pointLst[f[fp2]];
50 os << p0.x() << ' ' << p0.y() << ' ' << p0.z() << ' '
51 << p1.x() << ' ' << p1.y() << ' ' << p1.z() << ' '
52 << p2.x() << ' ' << p2.y() << ' ' << p2.z() << ' '
54 << "0x" << hex << zoneI << dec << endl;
59 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
62 Foam::fileFormats::TRIsurfaceFormat<Face>::TRIsurfaceFormat
64 const fileName& filename
71 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
74 bool Foam::fileFormats::TRIsurfaceFormat<Face>::read
76 const fileName& filename
82 TRIsurfaceFormatCore reader(filename);
85 this->storedPoints().transfer(reader.points());
87 // retrieve the original zone information
88 List<label> sizes(reader.sizes().xfer());
89 List<label> zoneIds(reader.zoneIds().xfer());
91 // generate the (sorted) faces
92 List<Face> faceLst(zoneIds.size());
96 // already sorted - generate directly
97 forAll(faceLst, faceI)
99 const label startPt = 3*faceI;
100 faceLst[faceI] = triFace(startPt, startPt+1, startPt+2);
105 // unsorted - determine the sorted order:
106 // avoid SortableList since we discard the main list anyhow
108 sortedOrder(zoneIds, faceMap);
110 // generate sorted faces
111 forAll(faceMap, faceI)
113 const label startPt = 3*faceMap[faceI];
114 faceLst[faceI] = triFace(startPt, startPt+1, startPt+2);
120 this->storedFaces().transfer(faceLst);
122 this->addZones(sizes);
123 this->stitchFaces(SMALL);
129 void Foam::fileFormats::TRIsurfaceFormat<Face>::write
131 const fileName& filename,
132 const MeshedSurfaceProxy<Face>& surf
135 const pointField& pointLst = surf.points();
136 const List<Face>& faceLst = surf.faces();
137 const List<label>& faceMap = surf.faceMap();
139 const List<surfZone>& zones =
141 surf.surfZones().empty()
142 ? surfaceFormatsCore::oneZone(faceLst)
146 const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
148 OFstream os(filename);
153 "fileFormats::TRIsurfaceFormat::write"
154 "(const fileName&, const MeshedSurfaceProxy<Face>&)"
156 << "Cannot open file for writing " << filename
163 const surfZone& zone = zones[zoneI];
167 forAll(zone, localFaceI)
169 const Face& f = faceLst[faceMap[faceIndex++]];
170 writeShell(os, pointLst, f, zoneI);
175 forAll(zone, localFaceI)
177 const Face& f = faceLst[faceIndex++];
178 writeShell(os, pointLst, f, zoneI);
186 void Foam::fileFormats::TRIsurfaceFormat<Face>::write
188 const fileName& filename,
189 const UnsortedMeshedSurface<Face>& surf
192 const pointField& pointLst = surf.points();
193 const List<Face>& faceLst = surf.faces();
195 OFstream os(filename);
200 "fileFormats::TRIsurfaceFormat::write"
201 "(const fileName&, const UnsortedMeshedSurface<Face>&)"
203 << "Cannot open file for writing " << filename
208 // a single zone needs no sorting
209 if (surf.zoneToc().size() == 1)
211 const List<label>& zoneIds = surf.zoneIds();
213 forAll(faceLst, faceI)
215 writeShell(os, pointLst, faceLst[faceI], zoneIds[faceI]);
221 List<surfZone> zoneLst = surf.sortedZones(faceMap);
224 forAll(zoneLst, zoneI)
226 forAll(zoneLst[zoneI], localFaceI)
228 const Face& f = faceLst[faceMap[faceIndex++]];
229 writeShell(os, pointLst, f, zoneI);
236 // ************************************************************************* //