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 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 
29 #include "X3DsurfaceFormat.H"
30 #include "OFstream.H"
31 
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
33 
34 template<class Face>
36 (
37  const fileName& filename,
38  const MeshedSurfaceProxy<Face>& surf,
39  const dictionary&
40 )
41 {
42  const UList<point>& pointLst = surf.points();
43  const UList<Face>& faceLst = surf.surfFaces();
44  const UList<label>& faceMap = surf.faceMap();
45 
46  // for no zones, suppress the group name
47  const surfZoneList zones =
48  (
49  surf.surfZones().empty()
50  ? surfaceFormatsCore::oneZone(faceLst, word::null)
51  : surf.surfZones()
52  );
53 
54  const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
55 
56  OFstream os(filename);
57  if (!os.good())
58  {
60  << "Cannot open file for writing " << filename
61  << exit(FatalError);
62  }
63 
64  writeHeader(os);
65  beginGroup(os);
66  writeAppearance(os);
67 
68  // NOTE: we could provide an optimized IndexedTriangleSet output for
69  // triangulated surfaces too
70 
71  os <<
72  " <IndexedFaceSet coordIndex='\n";
73 
74  label faceIndex = 0;
75  for (const surfZone& zone : zones)
76  {
77  const label nLocalFaces = zone.size();
78 
79  if (useFaceMap)
80  {
81  for (label i=0; i<nLocalFaces; ++i)
82  {
83  const Face& f = faceLst[faceMap[faceIndex++]];
84 
85  for (const label vrti : f)
86  {
87  os << vrti << ' ';
88  }
89  os << "-1\n";
90  }
91  }
92  else
93  {
94  for (label i=0; i<nLocalFaces; ++i)
95  {
96  const Face& f = faceLst[faceIndex++];
97 
98  for (const label vrti : f)
99  {
100  os << vrti << ' ';
101  }
102  os << "-1\n";
103  }
104  }
105  }
106 
107  os <<
108  "' >\n";
109 
110  writePoints(os, pointLst);
111 
112  os <<
113  " </IndexedFaceSet>\n";
114 
115  endGroup(os);
116  writeFooter(os);
117 }
118 
119 
120 // ************************************************************************* //
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeFast.C:94
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::MeshedSurfaceProxy::useFaceMap
bool useFaceMap() const
Use faceMap?
Definition: MeshedSurfaceProxy.H:186
X3DsurfaceFormat.H
Foam::zone
Base class for mesh zones.
Definition: zone.H:63
Foam::MeshedSurfaceProxy::points
const pointField & points() const
Return const access to the points.
Definition: MeshedSurfaceProxy.H:160
Foam::writeHeader
static void writeHeader(Ostream &os, const word &fieldName)
Definition: rawSurfaceWriterImpl.C:49
Foam::MeshedSurfaceProxy
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats.
Definition: MeshedSurface.H:78
Foam::MeshedSurfaceProxy::faceMap
const labelUList & faceMap() const
Const access to the faceMap, zero-sized when unused.
Definition: MeshedSurfaceProxy.H:180
OFstream.H
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::fileFormats::X3DsurfaceFormat::write
static void write(const fileName &filename, const MeshedSurfaceProxy< Face > &surf, const dictionary &options=dictionary::null)
Write surface mesh components by proxy.
Definition: X3DsurfaceFormat.C:36
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::OFstream
Output to file stream, using an OSstream.
Definition: OFstream.H:99
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
f
labelList f(nPoints)
Foam::List< surfZone >
Foam::surfZone
A surface zone on a MeshedSurface.
Definition: surfZone.H:65
Foam::UList
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:103
Foam::MeshedSurfaceProxy::surfFaces
const UList< Face > & surfFaces() const
Return const access to the faces.
Definition: MeshedSurfaceProxy.H:166
Foam::IOstream::good
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:216
Foam::MeshedSurfaceProxy::surfZones
const UList< surfZone > & surfZones() const
Const access to the surface zones.
Definition: MeshedSurfaceProxy.H:174