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-2018 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  {
80  VTK_ID
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  {
105  POINT_DATA
106  };
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  //- Header
137  string header_;
138 
139  //- Title
140  string title_;
141 
142  //- DataType
143  string dataType_;
144 
145 
146  // Geometry
147 
148  //- Points
149  pointField points_;
150 
151  //- 3D cells.
152  cellShapeList cells_;
153 
154  //- Map from cells back to original ID
155  labelList cellMap_;
156 
157  //- 2D cells (=faces)
158  faceList faces_;
159 
160  //- Map from faces back to original ID
161  labelList faceMap_;
162 
163  //- 1D cells (=edges)
164  labelListList lines_;
165 
166  labelList lineMap_;
167 
168 
169  // Data
170 
171  //- Cell based fields
172  objectRegistry cellData_;
173 
174  //- Point based fields
175  objectRegistry pointData_;
176 
177  //- Other fields
178  objectRegistry otherData_;
179 
180 
181 
182  // Private Member Functions
183 
184  template<class T>
185  void readBlock
186  (
187  Istream& inFile,
188  const label n,
189  List<T>& lst
190  ) const;
191 
192  void warnUnhandledType
193  (
194  Istream& inFile,
195  const label type,
196  labelHashSet& warningGiven
197  ) const;
198 
199  //- Split cellTypes into cells, faces and lines
200  void extractCells
201  (
202  Istream& inFile,
203  const labelList& cellTypes,
204  const labelList& cellVertData
205  );
206 
207  //- Read single field and stores it on the objectRegistry.
208  void readField
209  (
210  ISstream& inFile,
211  objectRegistry& obj,
212  const word& arrayName,
213  const word& dataType,
214  const label size
215  ) const;
216 
217  //- Reads fields, stores them on the objectRegistry. Returns a list of
218  // read fields
219  wordList readFieldArray
220  (
221  ISstream& inFile,
222  objectRegistry& obj,
223  const label wantedSize
224  ) const;
225 
226  objectRegistry& selectRegistry(const parseMode readMode);
227 
228  void read(ISstream& inFile);
229 
230  //- Dissallow assignment
231  void operator=(const vtkUnstructuredReader&);
232 
233 
234 public:
235 
236  //- Runtime type information
237  ClassName("vtkUnstructuredReader");
238 
239  // Constructors
240 
241  //- Construct from Istream, read all
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 
265  //- Points
266  const pointField& points() const
267  {
268  return points_;
269  }
271  pointField& points()
272  {
273  return points_;
274  }
275 
276  //- 3D cells.
277  const cellShapeList& cells() const
278  {
279  return cells_;
280  }
283  {
284  return cells_;
285  }
287  const labelList& cellMap() const
288  {
289  return cellMap_;
290  }
291 
292  //- 2D cells (=faces)
293  const faceList& faces() const
294  {
295  return faces_;
296  }
298  faceList& faces()
299  {
300  return faces_;
301  }
303  const labelList& faceMap() const
304  {
305  return faceMap_;
306  }
307 
308  //- 1D cells (=open lines)
309  const labelListList& lines() const
310  {
311  return lines_;
312  }
315  {
316  return lines_;
317  }
319  const labelList& lineMap() const
320  {
321  return lineMap_;
322  }
323 
324  //- Cell based fields
325  const objectRegistry& cellData() const
326  {
327  return cellData_;
328  }
331  {
332  return cellData_;
333  }
334 
335  //- Point based fields
336  const objectRegistry& pointData() const
337  {
338  return pointData_;
339  }
342  {
343  return pointData_;
344  }
345 
346  //- Other fields
347  const objectRegistry& otherData() const
348  {
349  return otherData_;
350  }
353  {
354  return otherData_;
355  }
356 
357 
358  //- Debug: print contents of objectRegistry
359  template<class Type>
360  void printFieldStats(const objectRegistry&) const;
361 
362 };
363 
364 
365 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
366 
367 } // End namespace Foam
368 
369 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
370 
371 #ifdef NoRepository
373 #endif
374 
375 
376 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
377 
378 #endif
379 
380 // ************************************************************************* //
vtkUnstructuredReader(const objectRegistry &obr, ISstream &)
Construct from Istream, read all.
vtkTypes
Enumeration defining the cell types.
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
const faceList & faces() const
2D cells (=faces)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
const labelList & lineMap() const
const labelList & cellMap() const
Reader for vtk unstructured_grid legacy files. Supports single CELLS, POINTS etc. entry only...
vtkDataSetType
Enumeration defining the vtk dataset types.
const string & title() const
Title.
static const NamedEnum< vtkDataSetType, 3 > vtkDataSetTypeNames
A class for handling words, derived from string.
Definition: word.H:59
const objectRegistry & cellData() const
Cell based fields.
const objectRegistry & otherData() const
Other fields.
const string & dataType() const
DataType.
const cellShapeList & cells() const
3D cells.
vtkDataType
Enumeration defining the vtk data types.
fileName::Type type(const fileName &, const bool followLink=true)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:481
Generic input stream.
Definition: ISstream.H:51
ClassName("vtkUnstructuredReader")
Runtime type information.
parseMode
Enumeration defining the parse mode - what type of data is being.
label n
const labelListList & lines() const
1D cells (=open lines)
const labelList & faceMap() const
const objectRegistry & pointData() const
Point based fields.
Registry of regIOobjects.
const string header() const
Header.
static const NamedEnum< vtkDataType, 8 > vtkDataTypeNames
const pointField & points() const
Points.
Namespace for OpenFOAM.
static const NamedEnum< parseMode, 5 > parseModeNames
void printFieldStats(const objectRegistry &) const
Debug: print contents of objectRegistry.