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
76  {
83  VTK_DOUBLE,
84  VTK_STRING,
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  {
105  NOMODE,
110  };
111 
112  static const Enum<parseMode> parseModeNames;
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 
262  {
263  return points_;
264  }
265 
266  //- 3D cells
267  const cellShapeList& cells() const noexcept
268  {
269  return cells_;
270  }
271 
273  {
274  return cells_;
275  }
276 
277  const labelList& cellMap() const noexcept
278  {
279  return cellMap_;
280  }
282  //- 2D cells (=faces)
283  const faceList& faces() const noexcept
284  {
285  return faces_;
286  }
287 
289  {
290  return faces_;
291  }
292 
293  const labelList& faceMap() const noexcept
294  {
295  return faceMap_;
296  }
298  //- 1D cells (=open lines)
299  const labelListList& lines() const noexcept
300  {
301  return lines_;
302  }
303 
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  }
321  {
322  return cellData_;
323  }
325  //- Point based fields
326  const objectRegistry& pointData() const noexcept
327  {
328  return pointData_;
329  }
330 
332  {
333  return pointData_;
334  }
335 
336  //- Other fields
338  {
339  return otherData_;
340  }
341 
343  {
344  return otherData_;
345  }
346 
348  //- Debug: print contents of objectRegistry
349  template<class Type>
350  static void printFieldStats(const objectRegistry&);
351 };
352 
353 
354 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
356 } // End namespace Foam
357 
358 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
359 
360 #ifdef NoRepository
362 #endif
363 
364 
365 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
366 
367 #endif
368 
369 // ************************************************************************* //
const labelListList & lines() const noexcept
1D cells (=open lines)
const labelList & lineMap() const noexcept
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
List< cellShape > cellShapeList
List of cellShape.
Definition: cellShapeList.H:32
Reader for vtk UNSTRUCTURED_GRID legacy files. Supports single CELLS, POINTS etc. entry only...
const pointField & points() const noexcept
Points.
vtkDataSetType
Enumeration defining the vtk dataset types.
const labelList & faceMap() const noexcept
const cellShapeList & cells() const noexcept
3D cells
static const Enum< parseMode > parseModeNames
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
const labelList & cellMap() const noexcept
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
const string & header() const noexcept
Header.
const string & dataType() const noexcept
DataType.
A class for handling words, derived from Foam::string.
Definition: word.H:63
const objectRegistry & cellData() const noexcept
Cell based fields.
vtkUnstructuredReader(const objectRegistry &obr, ISstream &is)
Construct from input stream, read all.
const labelList & cellTypes
Definition: setCellMask.H:27
const direction noexcept
Definition: Scalar.H:258
const string & title() const noexcept
Title.
vtkDataType
Enumeration defining the vtk data types.
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:51
ClassName("vtkUnstructuredReader")
Runtime type information.
const objectRegistry & pointData() const noexcept
Point based fields.
static const Enum< vtkDataType > vtkDataTypeNames
parseMode
Enumeration defining the parse mode - type of data being read.
static void printFieldStats(const objectRegistry &)
Debug: print contents of objectRegistry.
static const Enum< vtkDataSetType > vtkDataSetTypeNames
List< label > labelList
A List of labels.
Definition: List.H:62
Registry of regIOobjects.
const objectRegistry & otherData() const noexcept
Other fields.
const faceList & faces() const noexcept
2D cells (=faces)
Namespace for OpenFOAM.