readVTK.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) 2012-2019 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 
36 bool Foam::triSurface::readVTK(const fileName& fName)
37 {
38  // Read (and triangulate) point, faces, zone info
39  fileFormats::VTKsurfaceFormat<triFace> surf(fName);
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)
62  word regionName = zone.name();
63  if (regionName != (string("zone") + name(zoneI)))
64  {
65  regionName = string("patch") + name(zoneI);
66  }
67 
68  patches[zoneI] = geometricSurfacePatch
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  move(tris),
99  patches,
100  move(surf.points())
101  );
102 
103  return true;
104 }
105 
106 
107 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
108 
109 } // End namespace Foam
110 
111 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
Definition: PtrList.C:131
static const word null
An empty word.
Definition: word.H:77
const fvPatchList & patches
Namespace for OpenFOAM.
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
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
const word & regionName(const solver &region)
Definition: solver.H:209
List< geometricSurfacePatch > geometricSurfacePatchList
face triFace(3)
labelList f(nPoints)