FreeFOAM The Cross-Platform CFD Toolkit
VTKsurfaceFormat.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "VTKsurfaceFormat.H"
27 
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
30 template<class Face>
32 (
33  Ostream& os,
34  const UList<Face>& faceLst
35 )
36 {
37  label nNodes = 0;
38 
39  forAll(faceLst, faceI)
40  {
41  nNodes += faceLst[faceI].size();
42  }
43 
44  os << nl
45  << "POLYGONS " << faceLst.size() << ' '
46  << faceLst.size() + nNodes << nl;
47 }
48 
49 
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
51 
52 template<class Face>
54 {}
55 
56 
57 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
58 
59 template<class Face>
61 (
62  const fileName& filename,
63  const MeshedSurfaceProxy<Face>& surf
64 )
65 {
66  const pointField& pointLst = surf.points();
67  const List<Face>& faceLst = surf.faces();
68  const List<label>& faceMap = surf.faceMap();
69 
70  const List<surfZone>& zones =
71  (
72  surf.surfZones().size() > 1
73  ? surf.surfZones()
74  : oneZone(faceLst)
75  );
76 
77  const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
78 
79  OFstream os(filename);
80  if (!os.good())
81  {
83  (
84  "fileFormats::VTKsurfaceFormat::write"
85  "(const fileName&, const MeshedSurfaceProxy<Face>&)"
86  )
87  << "Cannot open file for writing " << filename
88  << exit(FatalError);
89  }
90 
91 
92  writeHeader(os, pointLst);
93  writeHeaderPolygons(os, faceLst);
94 
95  label faceIndex = 0;
96  forAll(zones, zoneI)
97  {
98  const surfZone& zone = zones[zoneI];
99 
100  if (useFaceMap)
101  {
102  forAll(zone, localFaceI)
103  {
104  const Face& f = faceLst[faceMap[faceIndex++]];
105 
106  os << f.size();
107  forAll(f, fp)
108  {
109  os << ' ' << f[fp];
110  }
111  os << ' ' << nl;
112  }
113  }
114  else
115  {
116  forAll(zone, localFaceI)
117  {
118  const Face& f = faceLst[faceIndex++];
119 
120  os << f.size();
121  forAll(f, fp)
122  {
123  os << ' ' << f[fp];
124  }
125  os << ' ' << nl;
126  }
127  }
128  }
129 
130  writeTail(os, zones);
131 }
132 
133 
134 template<class Face>
136 (
137  const fileName& filename,
138  const UnsortedMeshedSurface<Face>& surf
139 )
140 {
141  OFstream os(filename);
142  if (!os.good())
143  {
145  (
146  "fileFormats::VTKsurfaceFormat::write"
147  "(const fileName&, const UnsortedMeshedSurface<Face>&)"
148  )
149  << "Cannot open file for writing " << filename
150  << exit(FatalError);
151  }
152 
153 
154  const List<Face>& faceLst = surf.faces();
155 
156  writeHeader(os, surf.points());
157  writeHeaderPolygons(os, faceLst);
158 
159  forAll(faceLst, faceI)
160  {
161  const Face& f = faceLst[faceI];
162 
163  os << f.size();
164  forAll(f, fp)
165  {
166  os << ' ' << f[fp];
167  }
168  os << ' ' << nl;
169  }
170 
171  writeTail(os, surf.zoneIds());
172 }
173 
174 
175 // ************************ vim: set sw=4 sts=4 et: ************************ //