X3DsurfaceFormat.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
30 #include "OFstream.H"
31 
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
33 
34 template<class Face>
36 (
37  const fileName& filename,
38  const MeshedSurfaceProxy<Face>& surf,
39  IOstreamOption streamOpt,
40  const dictionary&
41 )
42 {
43  // ASCII only, allow output compression
44  streamOpt.format(IOstreamOption::ASCII);
45 
46  const UList<point>& pointLst = surf.points();
47  const UList<Face>& faceLst = surf.surfFaces();
48  const UList<label>& faceMap = surf.faceMap();
49 
50  // for no zones, suppress the group name
51  const surfZoneList zones =
52  (
53  surf.surfZones().empty()
54  ? surfaceFormatsCore::oneZone(faceLst, word::null)
55  : surf.surfZones()
56  );
57 
58  const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
59 
60  OFstream os(filename, streamOpt);
61  if (!os.good())
62  {
64  << "Cannot write file " << filename << nl
65  << exit(FatalError);
66  }
67 
68  writeHeader(os);
69  beginGroup(os);
70  writeAppearance(os);
71 
72  // NOTE: we could provide an optimized IndexedTriangleSet output for
73  // triangulated surfaces too
74 
75  os <<
76  " <IndexedFaceSet coordIndex='\n";
77 
78  label faceIndex = 0;
79  for (const surfZone& zone : zones)
80  {
81  const label nLocalFaces = zone.size();
82 
83  if (useFaceMap)
84  {
85  for (label i=0; i<nLocalFaces; ++i)
86  {
87  const Face& f = faceLst[faceMap[faceIndex++]];
88 
89  for (const label vrti : f)
90  {
91  os << vrti << ' ';
92  }
93  os << "-1\n";
94  }
95  }
96  else
97  {
98  for (label i=0; i<nLocalFaces; ++i)
99  {
100  const Face& f = faceLst[faceIndex++];
101 
102  for (const label vrti : f)
103  {
104  os << vrti << ' ';
105  }
106  os << "-1\n";
107  }
108  }
109  }
110 
111  os <<
112  "' >\n";
113 
114  writePoints(os, pointLst);
115 
116  os <<
117  " </IndexedFaceSet>\n";
118 
119  endGroup(os);
120  writeFooter(os);
121 }
122 
123 
124 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
A class for handling file names.
Definition: fileName.H:72
static void writeHeader(Ostream &os, const word &fieldName)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
Output to file stream, using an OSstream.
Definition: OFstream.H:49
A surface zone on a MeshedSurface.
Definition: surfZone.H:52
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
A simple container for options an IOstream can normally have.
const pointField & points() const noexcept
Return const access to the points.
const labelUList & faceMap() const noexcept
Const access to the faceMap, zero-sized when unused.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
bool useFaceMap() const noexcept
Can/should use faceMap?
Base class for mesh zones.
Definition: zone.H:59
static void write(const fileName &filename, const MeshedSurfaceProxy< Face > &surf, IOstreamOption streamOpt=IOstreamOption(), const dictionary &=dictionary::null)
Write surface mesh components by proxy.
const UList< surfZone > & surfZones() const noexcept
Const access to the surface zones.
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:105
OBJstream os(runTime.globalPath()/outputName)
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats...
Definition: MeshedSurface.H:75
labelList f(nPoints)
const UList< Face > & surfFaces() const noexcept
Return const access to the faces.
streamFormat format() const noexcept
Get the current stream format.