vtkUnstructuredReader.H
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) 2012-2016 OpenFOAM Foundation
9  Copyright (C) 2021 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 Class
28  Foam::vtkUnstructuredReader
29 
30 Description
31  Reader for vtk UNSTRUCTURED_GRID legacy files.
32  Supports single CELLS, POINTS etc. entry only.
33 
34  - all integer types (int, unsigned_int, long etc.) become Foam::label
35  - all real types (float, double) become Foam::scalar
36  - POINTS becomes OpenFOAM points
37  - CELLS gets split into OpenFOAM
38  - cells
39  - faces
40  - lines
41  - CELL_DATA or POINT_DATA gets stored on the corresponding objectRegistry
42  in original vtk numbering order so use e.g. faceMap() to go from entry
43  in faces() back to vtk numbering.
44 
45 SourceFiles
46  vtkUnstructuredReader.C
47 
48 \*---------------------------------------------------------------------------*/
49 
50 #ifndef vtkUnstructuredReader_H
51 #define vtkUnstructuredReader_H
52 
53 #include "foamVtkCore.H"
54 #include "objectRegistry.H"
55 #include "cellShapeList.H"
56 #include "HashSet.H"
57 #include "Enum.H"
58 
59 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60 
61 namespace Foam
62 {
63 
64 /*---------------------------------------------------------------------------*\
65  Class vtkUnstructuredReader Declaration
66 \*---------------------------------------------------------------------------*/
67 
69 {
70 public:
71 
72  // Public Data Types
73 
74  //- Enumeration defining the vtk data types
75  enum vtkDataType
76  {
85  VTK_ID
86  };
87 
89 
90 
91  //- Enumeration defining the vtk dataset types
92  enum vtkDataSetType
93  {
97  };
98 
100 
101 
102  //- Enumeration defining the parse mode - type of data being read
103  enum parseMode
104  {
109  POINT_DATA
110  };
111 
112  static const Enum<parseMode> parseModeNames;
113 
114 
115 private:
116 
117  //- The VTK version
118  float version_;
119 
120  //- Header
121  string header_;
122 
123  //- Title
124  string title_;
125 
126  //- DataType
127  string dataType_;
128 
129 
130  // Geometry
131 
132  //- Points
133  pointField points_;
134 
135  //- 3D cells.
136  cellShapeList cells_;
137 
138  //- Map from cells back to original ID
139  labelList cellMap_;
140 
141  //- 2D cells (=faces)
142  faceList faces_;
143 
144  //- Map from faces back to original ID
145  labelList faceMap_;
146 
147  //- 1D cells (=edges)
148  labelListList lines_;
149 
150  labelList lineMap_;
151 
152 
153  // Data
154 
155  //- Cell based fields
156  objectRegistry cellData_;
157 
158  //- Point based fields
159  objectRegistry pointData_;
160 
161  //- Other fields
162  objectRegistry otherData_;
163 
164 
165 
166  // Private Member Functions
167 
168  //- Read OFFSETS, CONNECTIVITY arrays
169  static void readOffsetsConnectivity
170  (
171  ISstream& is,
172  const char* entryName,
173  const label nOffsets,
174  labelList& offsets,
175  const label nConnectivity,
176  labelList& connectivity
177  );
178 
179  static void warnUnhandledType
180  (
181  const Istream& is, // For error message
182  const label type,
183  labelHashSet& warningGiven
184  );
185 
186  //- Split cellTypes into cells, faces and lines
187  void extractCells
188  (
189  const Istream& is, // For error message
190  const labelUList& cellTypes,
191  const labelUList& cellOffsets,
192  const labelUList& cellVertData
193  );
194 
195  //- Read single field and stores it on the objectRegistry.
196  void readField
197  (
198  ISstream& inFile,
199  objectRegistry& obj,
200  const word& arrayName,
201  const word& dataType,
202  const label size
203  ) const;
204 
205  //- Reads fields, stores them on the objectRegistry. Returns a list of
206  // read fields
207  wordList readFieldArray
208  (
209  ISstream& inFile,
210  objectRegistry& obj,
211  const label wantedSize
212  ) const;
213 
214  objectRegistry& selectRegistry(const parseMode readMode);
215 
216  void read(ISstream& inFile);
217 
218  //- No copy assignment
219  void operator=(const vtkUnstructuredReader&) = delete;
220 
221 
222 public:
223 
224  //- Runtime type information
225  ClassName("vtkUnstructuredReader");
226 
227 
228  // Constructors
229 
230  //- Construct from input stream, read all
232 
233 
234  // Member Functions
235 
236  //- Header
237  const string& header() const noexcept
238  {
239  return header_;
240  }
241 
242  //- Title
243  const string& title() const noexcept
244  {
245  return title_;
246  }
247 
248  //- DataType
249  const string& dataType() const noexcept
250  {
251  return dataType_;
252  }
253 
254 
255  //- Points
256  const pointField& points() const noexcept
257  {
258  return points_;
259  }
260 
261  pointField& points() noexcept
262  {
263  return points_;
264  }
265 
266  //- 3D cells
267  const cellShapeList& cells() const noexcept
268  {
269  return cells_;
270  }
271 
272  cellShapeList& cells() noexcept
273  {
274  return cells_;
275  }
276 
277  const labelList& cellMap() const noexcept
278  {
279  return cellMap_;
280  }
281 
282  //- 2D cells (=faces)
283  const faceList& faces() const noexcept
284  {
285  return faces_;
286  }
287 
288  faceList& faces() noexcept
289  {
290  return faces_;
291  }
292 
293  const labelList& faceMap() const noexcept
294  {
295  return faceMap_;
296  }
297 
298  //- 1D cells (=open lines)
299  const labelListList& lines() const noexcept
300  {
301  return lines_;
302  }
303 
304  labelListList& lines() noexcept
305  {
306  return lines_;
307  }
308 
309  const labelList& lineMap() const noexcept
310  {
311  return lineMap_;
312  }
313 
314  //- Cell based fields
315  const objectRegistry& cellData() const noexcept
316  {
317  return cellData_;
318  }
319 
320  objectRegistry& cellData() noexcept
321  {
322  return cellData_;
323  }
324 
325  //- Point based fields
326  const objectRegistry& pointData() const noexcept
327  {
328  return pointData_;
329  }
330 
331  objectRegistry& pointData() noexcept
332  {
333  return pointData_;
334  }
335 
336  //- Other fields
337  const objectRegistry& otherData() const noexcept
338  {
339  return otherData_;
340  }
341 
342  objectRegistry& otherData() noexcept
343  {
344  return otherData_;
345  }
346 
347 
348  //- Debug: print contents of objectRegistry
349  template<class Type>
350  static void printFieldStats(const objectRegistry&);
351 };
352 
353 
354 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
355 
356 } // End namespace Foam
357 
358 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
359 
360 #ifdef NoRepository
362 #endif
363 
364 
365 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
366 
367 #endif
368 
369 // ************************************************************************* //
Foam::vtkUnstructuredReader::vtkDataSetTypeNames
static const Enum< vtkDataSetType > vtkDataSetTypeNames
Definition: vtkUnstructuredReader.H:98
Foam::vtkUnstructuredReader::cells
const cellShapeList & cells() const noexcept
3D cells
Definition: vtkUnstructuredReader.H:266
Foam::vtkUnstructuredReader::points
const pointField & points() const noexcept
Points.
Definition: vtkUnstructuredReader.H:255
Foam::vtkUnstructuredReader::faces
const faceList & faces() const noexcept
2D cells (=faces)
Definition: vtkUnstructuredReader.H:282
Foam::vtkUnstructuredReader::vtkDataSetType
vtkDataSetType
Enumeration defining the vtk dataset types.
Definition: vtkUnstructuredReader.H:91
Foam::Enum< vtkDataType >
Foam::vtkUnstructuredReader::cellData
objectRegistry & cellData() noexcept
Definition: vtkUnstructuredReader.H:319
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::vtkUnstructuredReader::printFieldStats
static void printFieldStats(const objectRegistry &)
Debug: print contents of objectRegistry.
Definition: vtkUnstructuredReaderTemplates.C:34
Foam::vtkUnstructuredReader::POLYDATA
Definition: vtkUnstructuredReader.H:106
Foam::vtkUnstructuredReader::lineMap
const labelList & lineMap() const noexcept
Definition: vtkUnstructuredReader.H:308
Foam::vtkUnstructuredReader::pointData
objectRegistry & pointData() noexcept
Definition: vtkUnstructuredReader.H:330
Foam::vtkUnstructuredReader::parseModeNames
static const Enum< parseMode > parseModeNames
Definition: vtkUnstructuredReader.H:111
Foam::vtkUnstructuredReader::VTK_FLOAT
Definition: vtkUnstructuredReader.H:81
Foam::vtkUnstructuredReader::VTK_STRING
Definition: vtkUnstructuredReader.H:83
Foam::vtkUnstructuredReader
Reader for vtk UNSTRUCTURED_GRID legacy files. Supports single CELLS, POINTS etc. entry only.
Definition: vtkUnstructuredReader.H:67
Foam::vtkUnstructuredReader::faceMap
const labelList & faceMap() const noexcept
Definition: vtkUnstructuredReader.H:292
cellShapeList.H
vtkUnstructuredReaderTemplates.C
objectRegistry.H
Foam::vtkUnstructuredReader::UNSTRUCTURED_GRID
Definition: vtkUnstructuredReader.H:105
Foam::ISstream
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:55
Foam::vtkUnstructuredReader::VTK_ULONG
Definition: vtkUnstructuredReader.H:80
Foam::vtkUnstructuredReader::otherData
objectRegistry & otherData() noexcept
Definition: vtkUnstructuredReader.H:341
Foam::vtkUnstructuredReader::lines
const labelListList & lines() const noexcept
1D cells (=open lines)
Definition: vtkUnstructuredReader.H:298
Foam::HashSet< label, Hash< label > >
Foam::vtkUnstructuredReader::VTK_INT
Definition: vtkUnstructuredReader.H:76
Foam::vtkUnstructuredReader::VTK_FIELD
Definition: vtkUnstructuredReader.H:93
Foam::vtkUnstructuredReader::title
const string & title() const noexcept
Title.
Definition: vtkUnstructuredReader.H:242
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::vtkUnstructuredReader::vtkDataType
vtkDataType
Enumeration defining the vtk data types.
Definition: vtkUnstructuredReader.H:74
Foam::vtkUnstructuredReader::VTK_SCALARS
Definition: vtkUnstructuredReader.H:94
Foam::vtkUnstructuredReader::cellData
const objectRegistry & cellData() const noexcept
Cell based fields.
Definition: vtkUnstructuredReader.H:314
Foam::Field< vector >
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::vtkUnstructuredReader::dataType
const string & dataType() const noexcept
DataType.
Definition: vtkUnstructuredReader.H:248
Foam::vtkUnstructuredReader::VTK_UINT
Definition: vtkUnstructuredReader.H:78
HashSet.H
Foam::vtkUnstructuredReader::cells
cellShapeList & cells() noexcept
Definition: vtkUnstructuredReader.H:271
Foam::vtkUnstructuredReader::lines
labelListList & lines() noexcept
Definition: vtkUnstructuredReader.H:303
Foam::vtkUnstructuredReader::VTK_VECTORS
Definition: vtkUnstructuredReader.H:95
Foam::vtkUnstructuredReader::ClassName
ClassName("vtkUnstructuredReader")
Runtime type information.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::vtkUnstructuredReader::VTK_INT64
Definition: vtkUnstructuredReader.H:77
Foam::vtkUnstructuredReader::otherData
const objectRegistry & otherData() const noexcept
Other fields.
Definition: vtkUnstructuredReader.H:336
Foam::vtkUnstructuredReader::header
const string & header() const noexcept
Header.
Definition: vtkUnstructuredReader.H:236
cellTypes
const labelList & cellTypes
Definition: setCellMask.H:33
Foam::List< cellShape >
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::UList< label >
Foam::vtkUnstructuredReader::cellMap
const labelList & cellMap() const noexcept
Definition: vtkUnstructuredReader.H:276
foamVtkCore.H
Foam::vtkUnstructuredReader::vtkUnstructuredReader
vtkUnstructuredReader(const objectRegistry &obr, ISstream &is)
Construct from input stream, read all.
Definition: vtkUnstructuredReader.C:594
Foam::vtkUnstructuredReader::pointData
const objectRegistry & pointData() const noexcept
Point based fields.
Definition: vtkUnstructuredReader.H:325
Foam::vtkUnstructuredReader::points
pointField & points() noexcept
Definition: vtkUnstructuredReader.H:260
Foam::vtkUnstructuredReader::NOMODE
Definition: vtkUnstructuredReader.H:104
Foam::vtkUnstructuredReader::VTK_ID
Definition: vtkUnstructuredReader.H:84
Foam::vtkUnstructuredReader::VTK_LONG
Definition: vtkUnstructuredReader.H:79
Foam::vtkUnstructuredReader::faces
faceList & faces() noexcept
Definition: vtkUnstructuredReader.H:287
Foam::vtkUnstructuredReader::POINT_DATA
Definition: vtkUnstructuredReader.H:108
Foam::vtkUnstructuredReader::vtkDataTypeNames
static const Enum< vtkDataType > vtkDataTypeNames
Definition: vtkUnstructuredReader.H:87
Foam::vtkUnstructuredReader::CELL_DATA
Definition: vtkUnstructuredReader.H:107
Foam::vtkUnstructuredReader::VTK_DOUBLE
Definition: vtkUnstructuredReader.H:82
Foam::vtkUnstructuredReader::parseMode
parseMode
Enumeration defining the parse mode - type of data being read.
Definition: vtkUnstructuredReader.H:102
Enum.H