VTKsurfaceFormatCore.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
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 "VTKsurfaceFormatCore.H"
27 #include "clock.H"
28 
29 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
30 
32 (
33  Ostream& os,
34  const pointField& pointLst
35 )
36 {
37  // Write header
38  os << "# vtk DataFile Version 2.0" << nl
39  << "surface written " << clock::dateTime().c_str() << nl
40  << "ASCII" << nl
41  << nl
42  << "DATASET POLYDATA" << nl;
43 
44  // Write vertex coords
45  os << "POINTS " << pointLst.size() << " float" << nl;
46  forAll(pointLst, ptI)
47  {
48  const point& pt = pointLst[ptI];
49 
50  os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
51  }
52 }
53 
54 
56 (
57  Ostream& os,
58  const UList<surfZone>& zoneLst
59 )
60 {
61  label nFaces = 0;
62  forAll(zoneLst, zoneI)
63  {
64  nFaces += zoneLst[zoneI].size();
65  }
66 
67  // Print zone numbers
68  os << nl
69  << "CELL_DATA " << nFaces << nl
70  << "FIELD attributes 1" << nl
71  << "region 1 " << nFaces << " float" << nl;
72 
73 
74  forAll(zoneLst, zoneI)
75  {
76  forAll(zoneLst[zoneI], localFacei)
77  {
78  if (localFacei)
79  {
80  if (localFacei % 20)
81  {
82  os << ' ';
83  }
84  else
85  {
86  os << nl;
87  }
88  }
89  os << zoneI + 1;
90  }
91  os << nl;
92  }
93 }
94 
95 
97 (
98  Ostream& os,
99  const labelUList& zoneIds
100 )
101 {
102  // Print zone numbers
103  os << nl
104  << "CELL_DATA " << zoneIds.size() << nl
105  << "FIELD attributes 1" << nl
106  << "region 1 " << zoneIds.size() << " float" << nl;
107 
108  forAll(zoneIds, facei)
109  {
110  if (facei)
111  {
112  if (facei % 20)
113  {
114  os << ' ';
115  }
116  else
117  {
118  os << nl;
119  }
120  }
121  os << zoneIds[facei] + 1;
122  }
123  os << nl;
124 }
125 
126 
127 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
const Cmpt & z() const
Definition: VectorI.H:87
static void writeHeader(Ostream &, const pointField &)
Write header information with points.
const Cmpt & y() const
Definition: VectorI.H:81
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
const Cmpt & x() const
Definition: VectorI.H:75
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
static const char nl
Definition: Ostream.H:260
static void writeTail(Ostream &, const UList< surfZone > &)
Write trailing information with zone information.
label size() const
Return the number of elements in the UList.
Definition: UListI.H:311