vtkUnstructuredReader.H
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-2023 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 Class
25  Foam::vtkUnstructuredReader
26 
27 Description
28  Reader for vtk unstructured_grid legacy files. Supports single CELLS, POINTS
29  etc. entry only.
30 
31  - all integer types (int, unsigned_int, long etc.) become Foam::label
32  - all real types (float, double) become Foam::scalar
33  - POINTS becomes OpenFOAM points
34  - CELLS gets split into OpenFOAM
35  - cells
36  - faces
37  - lines
38  - CELL_DATA or POINT_DATA gets stored on the corresponding objectRegistry
39  in original vtk numbering order so use e.g. faceMap() to go from entry
40  in faces() back to vtk numbering.
41 
42 SourceFiles
43  vtkUnstructuredReader.C
44 
45 \*---------------------------------------------------------------------------*/
46 
47 #ifndef vtkUnstructuredReader_H
48 #define vtkUnstructuredReader_H
49 
50 #include "objectRegistry.H"
51 #include "cellShapeList.H"
52 #include "HashSet.H"
53 #include "NamedEnum.H"
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 namespace Foam
58 {
59 
60 /*---------------------------------------------------------------------------*\
61  Class vtkUnstructuredReader Declaration
62 \*---------------------------------------------------------------------------*/
63 
65 {
66 public:
67 
68  // Public data types
69 
70  //- Enumeration defining the vtk data types
71  enum vtkDataType
72  {
79  VTK_STRING,
81  };
82 
84 
85 
86  //- Enumeration defining the vtk dataset types
87  enum vtkDataSetType
88  {
92  };
93 
95 
96 
97  //- Enumeration defining the parse mode - what type of data is being
98  // read
99  enum parseMode
100  {
104  CELL_DATA,
106  };
107 
109 
110 
111  //- Enumeration defining the cell types
112  enum vtkTypes
113  {
117  VTK_LINE = 3,
123  VTK_QUAD = 9,
124  VTK_TETRA = 10,
125  VTK_VOXEL = 11,
127  VTK_WEDGE = 13,
130  VTK_HEXAGONAL_PRISM = 16,
131  };
132 
133 
134 private:
135 
136  // Private Data
137 
138  //- Header
139  string header_;
140 
141  //- Title
142  string title_;
143 
144  //- DataType
145  string dataType_;
146 
147 
148  // Geometry
149 
150  //- Points
151  pointField points_;
152 
153  //- 3D cells.
154  cellShapeList cells_;
155 
156  //- Map from cells back to original ID
157  labelList cellMap_;
158 
159  //- 2D cells (=faces)
160  faceList faces_;
161 
162  //- Map from faces back to original ID
163  labelList faceMap_;
164 
165  //- 1D cells (=edges)
166  labelListList lines_;
167 
168  labelList lineMap_;
169 
170 
171  // Data
172 
173  //- Cell based fields
174  objectRegistry cellData_;
175 
176  //- Point based fields
177  objectRegistry pointData_;
178 
179  //- Other fields
180  objectRegistry otherData_;
181 
182 
183  // Private Member Functions
184 
185  template<class T>
186  void readBlock
187  (
188  Istream& inFile,
189  const label n,
190  List<T>& lst
191  ) const;
192 
193  void warnUnhandledType
194  (
195  Istream& inFile,
196  const label type,
197  labelHashSet& warningGiven
198  ) const;
199 
200  //- Split cellTypes into cells, faces and lines
201  void extractCells
202  (
203  Istream& inFile,
204  const labelList& cellTypes,
205  const labelList& cellVertData
206  );
207 
208  //- Read single field and stores it on the objectRegistry.
209  void readField
210  (
211  ISstream& inFile,
212  objectRegistry& obj,
213  const word& arrayName,
214  const word& dataType,
215  const label size
216  ) const;
217 
218  //- Reads fields, stores them on the objectRegistry. Returns a list of
219  // read fields
220  wordList readFieldArray
221  (
222  ISstream& inFile,
223  objectRegistry& obj,
224  const label wantedSize
225  ) const;
226 
227  objectRegistry& selectRegistry(const parseMode readMode);
228 
229  void read(ISstream& inFile);
230 
231 
232 public:
233 
234  //- Runtime type information
235  ClassName("vtkUnstructuredReader");
236 
237 
238  // Constructors
239 
240  //- Construct from Istream, read all
242 
243 
244  // Member Functions
245 
246  //- Header
247  const string header() const
248  {
249  return header_;
250  }
251 
252  //- Title
253  const string& title() const
254  {
255  return title_;
256  }
257 
258  //- DataType
259  const string& dataType() const
260  {
261  return dataType_;
262  }
263 
264  //- Points
265  const pointField& points() const
266  {
267  return points_;
268  }
269 
270  pointField& points()
271  {
272  return points_;
273  }
274 
275  //- 3D cells.
276  const cellShapeList& cells() const
277  {
278  return cells_;
279  }
280 
282  {
283  return cells_;
284  }
285 
286  const labelList& cellMap() const
287  {
288  return cellMap_;
289  }
290 
291  //- 2D cells (=faces)
292  const faceList& faces() const
293  {
294  return faces_;
295  }
296 
297  faceList& faces()
298  {
299  return faces_;
300  }
301 
302  const labelList& faceMap() const
303  {
304  return faceMap_;
305  }
306 
307  //- 1D cells (=open lines)
308  const labelListList& lines() const
309  {
310  return lines_;
311  }
312 
314  {
315  return lines_;
316  }
317 
318  const labelList& lineMap() const
319  {
320  return lineMap_;
321  }
322 
323  //- Cell based fields
324  const objectRegistry& cellData() const
325  {
326  return cellData_;
327  }
328 
330  {
331  return cellData_;
332  }
333 
334  //- Point based fields
335  const objectRegistry& pointData() const
336  {
337  return pointData_;
338  }
339 
341  {
342  return pointData_;
343  }
344 
345  //- Other fields
346  const objectRegistry& otherData() const
347  {
348  return otherData_;
349  }
350 
352  {
353  return otherData_;
354  }
355 
356  //- Debug: print contents of objectRegistry
357  template<class Type>
358  void printFieldStats(const objectRegistry&) const;
359 
360 
361  // Member Operators
362 
363  //- Disallow default bitwise assignment
364  void operator=(const vtkUnstructuredReader&) = delete;
365 };
366 
367 
368 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
369 
370 } // End namespace Foam
371 
372 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
373 
374 #ifdef NoRepository
376 #endif
377 
378 
379 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
380 
381 #endif
382 
383 // ************************************************************************* //
label n
Generic input stream.
Definition: ISstream.H:55
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
Registry of regIOobjects.
Reader for vtk unstructured_grid legacy files. Supports single CELLS, POINTS etc. entry only.
void operator=(const vtkUnstructuredReader &)=delete
Disallow default bitwise assignment.
const labelList & cellMap() const
vtkUnstructuredReader(const objectRegistry &obr, ISstream &)
Construct from Istream, read all.
vtkDataSetType
Enumeration defining the vtk dataset types.
const labelListList & lines() const
1D cells (=open lines)
static const NamedEnum< vtkDataSetType, 3 > vtkDataSetTypeNames
const objectRegistry & cellData() const
Cell based fields.
const string & dataType() const
DataType.
parseMode
Enumeration defining the parse mode - what type of data is being.
vtkDataType
Enumeration defining the vtk data types.
void printFieldStats(const objectRegistry &) const
Debug: print contents of objectRegistry.
vtkTypes
Enumeration defining the cell types.
const faceList & faces() const
2D cells (=faces)
const objectRegistry & pointData() const
Point based fields.
const labelList & lineMap() const
const string header() const
Header.
const objectRegistry & otherData() const
Other fields.
static const NamedEnum< parseMode, 5 > parseModeNames
const string & title() const
Title.
const labelList & faceMap() const
static const NamedEnum< vtkDataType, 8 > vtkDataTypeNames
ClassName("vtkUnstructuredReader")
Runtime type information.
const cellShapeList & cells() const
3D cells.
const pointField & points() const
Points.
A class for handling words, derived from string.
Definition: word.H:62
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
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488