readVTK.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) 2012 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 "triSurface.H"
27 #include "VTKsurfaceFormat.H"
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 
34 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
35 
37 {
38  // Read (and triangulate) point, faces, zone info
40 
41  List<labelledTri> tris(surf.faces().size());
42  forAll(tris, i)
43  {
44  const triFace& f = surf[i];
45  tris[i] = labelledTri(f[0], f[1], f[2], 0);
46  }
47 
48  // Add regions from zone
49  const List<surfZone>& surfZones = surf.surfZones();
50 
52 
53  if (surfZones.size())
54  {
55  patches.setSize(surfZones.size());
56  forAll(surfZones, zoneI)
57  {
58  const surfZone& zone = surfZones[zoneI];
59 
60  // Add patch. Convert synthetic 'zone' name into 'patch' for now.
61  // (vtk format does not contain region names)
63  if (regionName != (string("zone") + name(zoneI)))
64  {
65  regionName = string("patch") + name(zoneI);
66  }
67 
69  (
70  (
71  zone.geometricType() != word::null
72  ? zone.geometricType()
73  : "empty"
74  ),
75  regionName,
76  zoneI
77  );
78 
79  // Set triangle regions
80  for (label i = zone.start(); i < zone.start()+zone.size(); i++)
81  {
82  tris[i].region() = zoneI;
83  }
84  }
85  }
86  else
87  {
88  // Add single patch
89  patches[0] = geometricSurfacePatch("empty", "patch0", 0);
90 
91  // Triangle regions already set to 0
92  }
93 
94 
95  // Create triSurface
96  *this = triSurface
97  (
98  tris.xfer(),
99  patches,
100  xferCopy<List<point> >(surf.points())
101  );
102 
103  return true;
104 }
105 
106 
107 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
108 
109 } // End namespace Foam
110 
111 // ************************************************************************* //
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
VTKsurfaceFormat.H
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::List::xfer
Xfer< List< T > > xfer()
Transfer contents to the Xfer container.
Definition: ListI.H:90
Foam::geometricSurfacePatch
The geometricSurfacePatch is like patchIdentifier but for surfaces. Holds type, name and index.
Definition: geometricSurfacePatch.H:53
Foam::zone
Base class for zones.
Definition: zone.H:57
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:74
Foam::MeshedSurface< Face >::faces
const List< Face > & faces() const
Return const access to the faces.
Definition: MeshedSurface.H:301
regionName
Foam::word regionName
Definition: createNamedDynamicFvMesh.H:1
Foam::MeshedSurface< Face >::surfZones
const List< surfZone > & surfZones() const
Const access to the surface zones.
Definition: MeshedSurface.H:309
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:59
Foam::triSurface
Triangulated surface description with patch information.
Definition: triSurface.H:57
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::zone::name
const word & name() const
Return name.
Definition: zone.H:150
Foam::triFace
A triangular face using a FixedList of labels corresponding to mesh vertices.
Definition: triFace.H:68
f
labelList f(nPoints)
Foam::xferCopy
Xfer< T > xferCopy(const T &)
Construct by copying the contents of the arg.
Foam::List< labelledTri >
Foam::surfZone
A surface zone on a MeshedSurface.
Definition: surfZone.H:62
Foam::fileFormats::VTKsurfaceFormat
Provide a means of reading/writing VTK legacy format. The output is never sorted by zone.
Definition: VTKsurfaceFormat.H:55
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
Foam::labelledTri
Triangle with additional region number.
Definition: labelledTri.H:49
patches
patches[0]
Definition: createSingleCellMesh.H:36
Foam::triSurface::readVTK
bool readVTK(const fileName &)
Definition: readVTK.C:36
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47