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-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::vtkUnstructuredReader
29
30Description
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
45SourceFiles
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
61namespace Foam
62{
63
64/*---------------------------------------------------------------------------*\
65 Class vtkUnstructuredReader Declaration
66\*---------------------------------------------------------------------------*/
69{
70public:
71
72 // Public Data Types
73
74 //- Enumeration defining the vtk data types
75 enum vtkDataType
76 {
86 };
89
90
91 //- Enumeration defining the vtk dataset types
93 {
97 };
100
101
102 //- Enumeration defining the parse mode - type of data being read
103 enum parseMode
108 CELL_DATA,
110 };
112 static const Enum<parseMode> parseModeNames;
113
114
115private:
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
222public:
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 }
262 {
263 return points_;
264 }
265
266 //- 3D cells
267 const cellShapeList& cells() const noexcept
268 {
269 return cells_;
270 }
273 {
274 return cells_;
275 }
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 }
289 {
290 return faces_;
291 }
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 }
305 {
306 return lines_;
307 }
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 }
324
325 //- Point based fields
326 const objectRegistry& pointData() const noexcept
327 {
328 return pointData_;
329 }
332 {
333 return pointData_;
334 }
335
336 //- Other fields
337 const objectRegistry& otherData() const noexcept
338 {
339 return otherData_;
340 }
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// ************************************************************************* //
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:58
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
Registry of regIOobjects.
Reader for vtk UNSTRUCTURED_GRID legacy files. Supports single CELLS, POINTS etc. entry only.
static const Enum< parseMode > parseModeNames
const faceList & faces() const noexcept
2D cells (=faces)
const objectRegistry & otherData() const noexcept
Other fields.
static const Enum< vtkDataSetType > vtkDataSetTypeNames
const string & header() const noexcept
Header.
const cellShapeList & cells() const noexcept
3D cells
const objectRegistry & pointData() const noexcept
Point based fields.
const objectRegistry & cellData() const noexcept
Cell based fields.
vtkDataSetType
Enumeration defining the vtk dataset types.
pointField & points() noexcept
static const Enum< vtkDataType > vtkDataTypeNames
labelListList & lines() noexcept
const labelList & faceMap() const noexcept
objectRegistry & cellData() noexcept
const labelListList & lines() const noexcept
1D cells (=open lines)
parseMode
Enumeration defining the parse mode - type of data being read.
vtkDataType
Enumeration defining the vtk data types.
const pointField & points() const noexcept
Points.
objectRegistry & pointData() noexcept
const string & dataType() const noexcept
DataType.
objectRegistry & otherData() noexcept
const labelList & lineMap() const noexcept
cellShapeList & cells() noexcept
const labelList & cellMap() const noexcept
static void printFieldStats(const objectRegistry &)
Debug: print contents of objectRegistry.
const string & title() const noexcept
Title.
ClassName("vtkUnstructuredReader")
Runtime type information.
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define ClassName(TypeNameString)
Add typeName information from argument TypeNameString to a class.
Definition: className.H:67
Namespace for OpenFOAM.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
const direction noexcept
Definition: Scalar.H:223
const labelList & cellTypes
Definition: setCellMask.H:33