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 | Copyright (C) 2012-2015 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  void extractCells
200  (
201  Istream& inFile,
202  const labelList& cellTypes,
203  const labelList& cellVertData
204  );
205 
206  void readField
207  (
208  ISstream& inFile,
209  objectRegistry& obj,
210  const word& arrayName,
211  const word& dataType,
212  const label size
213  ) const;
214 
215  wordList readFieldArray
216  (
217  ISstream& inFile,
218  objectRegistry& obj,
219  const label wantedSize
220  ) const;
221 
222  objectRegistry& selectRegistry(const parseMode readMode);
223 
224  void read(ISstream& inFile);
225 
226  //- Dissallow assignment
227  void operator=(const vtkUnstructuredReader&);
228 
229 
230 public:
231 
232  //- Runtime type information
233  ClassName("vtkUnstructuredReader");
234 
235  // Constructors
236 
237  //- Construct from Istream, read all
239 
240  // Member Functions
241 
242  //- Header
243  const string header() const
244  {
245  return header_;
246  }
247 
248  //- Title
249  const string& title() const
250  {
251  return title_;
252  }
253 
254  //- DataType
255  const string& dataType() const
256  {
257  return dataType_;
258  }
259 
260 
261  //- Points
262  const pointField& points() const
263  {
264  return points_;
265  }
267  pointField& points()
268  {
269  return points_;
270  }
271 
272  //- 3D cells.
273  const cellShapeList& cells() const
274  {
275  return cells_;
276  }
279  {
280  return cells_;
281  }
283  const labelList& cellMap() const
284  {
285  return cellMap_;
286  }
287 
288  //- 2D cells (=faces)
289  const faceList& faces() const
290  {
291  return faces_;
292  }
294  faceList& faces()
295  {
296  return faces_;
297  }
299  const labelList& faceMap() const
300  {
301  return faceMap_;
302  }
303 
304  //- 1D cells (=open lines)
305  const labelListList& lines() const
306  {
307  return lines_;
308  }
311  {
312  return lines_;
313  }
315  const labelList& lineMap() const
316  {
317  return lineMap_;
318  }
319 
320  //- Cell based fields
321  const objectRegistry& cellData() const
322  {
323  return cellData_;
324  }
327  {
328  return cellData_;
329  }
330 
331  //- Point based fields
332  const objectRegistry& pointData() const
333  {
334  return pointData_;
335  }
338  {
339  return pointData_;
340  }
341 
342  //- Other fields
343  const objectRegistry& otherData() const
344  {
345  return otherData_;
346  }
349  {
350  return otherData_;
351  }
352 
353 
354  //- Debug: print contents of objectRegistry
355  template<class Type>
356  void printFieldStats(const objectRegistry&) const;
357 
358 };
359 
360 
361 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
362 
363 } // End namespace Foam
364 
365 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
366 
367 #ifdef NoRepository
369 #endif
370 
371 
372 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
373 
374 #endif
375 
376 // ************************************************************************* //
const string & title() const
Title.
static const NamedEnum< vtkDataSetType, 3 > vtkDataSetTypeNames
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
static const NamedEnum< vtkDataType, 8 > vtkDataTypeNames
A class for handling words, derived from string.
Definition: word.H:59
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
vtkDataSetType
Enumeration defining the vtk dataset types.
const faceList & faces() const
2D cells (=faces)
Namespace for OpenFOAM.
vtkDataType
Enumeration defining the vtk data types.
label n
ClassName("vtkUnstructuredReader")
Runtime type information.
const labelList & cellMap() const
void printFieldStats(const objectRegistry &) const
Debug: print contents of objectRegistry.
const labelListList & lines() const
1D cells (=open lines)
const labelList & lineMap() const
Generic input stream.
Definition: ISstream.H:51
vtkUnstructuredReader(const objectRegistry &obr, ISstream &)
Construct from Istream, read all.
vtkTypes
Enumeration defining the cell types.
Reader for vtk unstructured_grid legacy files. Supports single CELLS, POINTS etc. entry only...
const string & dataType() const
DataType.
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:589
const objectRegistry & pointData() const
Point based fields.
static const NamedEnum< parseMode, 5 > parseModeNames
Registry of regIOobjects.
const cellShapeList & cells() const
3D cells.
const pointField & points() const
Points.
const labelList & faceMap() const
const string header() const
Header.
parseMode
Enumeration defining the parse mode - what type of data is being.
const objectRegistry & cellData() const
Cell based fields.
const objectRegistry & otherData() const
Other fields.