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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::vtkUnstructuredReader
28 
29 Description
30  Reader for vtk UNSTRUCTURED_GRID legacy files.
31  Supports single CELLS, POINTS etc. entry only.
32 
33  - all integer types (int, unsigned_int, long etc.) become Foam::label
34  - all real types (float, double) become Foam::scalar
35  - POINTS becomes OpenFOAM points
36  - CELLS gets split into OpenFOAM
37  - cells
38  - faces
39  - lines
40  - CELL_DATA or POINT_DATA gets stored on the corresponding objectRegistry
41  in original vtk numbering order so use e.g. faceMap() to go from entry
42  in faces() back to vtk numbering.
43 
44 SourceFiles
45  vtkUnstructuredReader.C
46 
47 \*---------------------------------------------------------------------------*/
48 
49 #ifndef vtkUnstructuredReader_H
50 #define vtkUnstructuredReader_H
51 
52 #include "foamVtkCore.H"
53 #include "objectRegistry.H"
54 #include "cellShapeList.H"
55 #include "HashSet.H"
56 #include "Enum.H"
57 
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 
60 namespace Foam
61 {
62 
63 /*---------------------------------------------------------------------------*\
64  Class vtkUnstructuredReader Declaration
65 \*---------------------------------------------------------------------------*/
66 
68 {
69 public:
70 
71  // Public data types
72 
73  //- Enumeration defining the vtk data types
74  enum vtkDataType
75  {
83  VTK_ID
84  };
85 
87 
88 
89  //- Enumeration defining the vtk dataset types
90  enum vtkDataSetType
91  {
95  };
96 
98 
99 
100  //- Enumeration defining the parse mode - type of data being read
101  enum parseMode
102  {
107  POINT_DATA
108  };
109 
110  static const Enum<parseMode> parseModeNames;
111 
112 
113 private:
114 
115  //- Header
116  string header_;
117 
118  //- Title
119  string title_;
120 
121  //- DataType
122  string dataType_;
123 
124 
125  // Geometry
126 
127  //- Points
128  pointField points_;
129 
130  //- 3D cells.
131  cellShapeList cells_;
132 
133  //- Map from cells back to original ID
134  labelList cellMap_;
135 
136  //- 2D cells (=faces)
137  faceList faces_;
138 
139  //- Map from faces back to original ID
140  labelList faceMap_;
141 
142  //- 1D cells (=edges)
143  labelListList lines_;
144 
145  labelList lineMap_;
146 
147 
148  // Data
149 
150  //- Cell based fields
151  objectRegistry cellData_;
152 
153  //- Point based fields
154  objectRegistry pointData_;
155 
156  //- Other fields
157  objectRegistry otherData_;
158 
159 
160 
161  // Private Member Functions
162 
163  template<class T>
164  void readBlock
165  (
166  Istream& inFile,
167  const label n,
168  List<T>& list
169  ) const;
170 
171  void warnUnhandledType
172  (
173  Istream& inFile,
174  const label type,
175  labelHashSet& warningGiven
176  ) const;
177 
178  //- Split cellTypes into cells, faces and lines
179  void extractCells
180  (
181  Istream& inFile,
182  const labelList& cellTypes,
183  const labelList& cellVertData
184  );
185 
186  //- Read single field and stores it on the objectRegistry.
187  void readField
188  (
189  ISstream& inFile,
190  objectRegistry& obj,
191  const word& arrayName,
192  const word& dataType,
193  const label size
194  ) const;
195 
196  //- Reads fields, stores them on the objectRegistry. Returns a list of
197  // read fields
198  wordList readFieldArray
199  (
200  ISstream& inFile,
201  objectRegistry& obj,
202  const label wantedSize
203  ) const;
204 
205  objectRegistry& selectRegistry(const parseMode readMode);
206 
207  void read(ISstream& inFile);
208 
209  //- No copy assignment
210  void operator=(const vtkUnstructuredReader&) = delete;
211 
212 
213 public:
214 
215  //- Runtime type information
216  ClassName("vtkUnstructuredReader");
217 
218  // Constructors
219 
220  //- Construct from Istream, read all
222 
223 
224  // Member Functions
225 
226  //- Header
227  const string header() const
228  {
229  return header_;
230  }
231 
232  //- Title
233  const string& title() const
234  {
235  return title_;
236  }
237 
238  //- DataType
239  const string& dataType() const
240  {
241  return dataType_;
242  }
243 
244 
245  //- Points
246  const pointField& points() const
247  {
248  return points_;
249  }
250 
251  pointField& points()
252  {
253  return points_;
254  }
255 
256  //- 3D cells.
257  const cellShapeList& cells() const
258  {
259  return cells_;
260  }
261 
263  {
264  return cells_;
265  }
266 
267  const labelList& cellMap() const
268  {
269  return cellMap_;
270  }
271 
272  //- 2D cells (=faces)
273  const faceList& faces() const
274  {
275  return faces_;
276  }
277 
278  faceList& faces()
279  {
280  return faces_;
281  }
282 
283  const labelList& faceMap() const
284  {
285  return faceMap_;
286  }
287 
288  //- 1D cells (=open lines)
289  const labelListList& lines() const
290  {
291  return lines_;
292  }
293 
295  {
296  return lines_;
297  }
298 
299  const labelList& lineMap() const
300  {
301  return lineMap_;
302  }
303 
304  //- Cell based fields
305  const objectRegistry& cellData() const
306  {
307  return cellData_;
308  }
309 
311  {
312  return cellData_;
313  }
314 
315  //- Point based fields
316  const objectRegistry& pointData() const
317  {
318  return pointData_;
319  }
320 
322  {
323  return pointData_;
324  }
325 
326  //- Other fields
327  const objectRegistry& otherData() const
328  {
329  return otherData_;
330  }
331 
333  {
334  return otherData_;
335  }
336 
337 
338  //- Debug: print contents of objectRegistry
339  template<class Type>
340  void printFieldStats(const objectRegistry&) const;
341 
342 };
343 
344 
345 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
346 
347 } // End namespace Foam
348 
349 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
350 
351 #ifdef NoRepository
353 #endif
354 
355 
356 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
357 
358 #endif
359 
360 // ************************************************************************* //
Foam::vtkUnstructuredReader::vtkDataSetTypeNames
static const Enum< vtkDataSetType > vtkDataSetTypeNames
Definition: vtkUnstructuredReader.H:96
Foam::vtkUnstructuredReader::lineMap
const labelList & lineMap() const
Definition: vtkUnstructuredReader.H:298
Foam::vtkUnstructuredReader::vtkDataSetType
vtkDataSetType
Enumeration defining the vtk dataset types.
Definition: vtkUnstructuredReader.H:89
Foam::vtkUnstructuredReader::cellMap
const labelList & cellMap() const
Definition: vtkUnstructuredReader.H:266
Foam::Enum< vtkDataType >
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::vtkUnstructuredReader::faces
const faceList & faces() const
2D cells (=faces)
Definition: vtkUnstructuredReader.H:272
Foam::vtkUnstructuredReader::POLYDATA
Definition: vtkUnstructuredReader.H:104
Foam::vtkUnstructuredReader::cellData
const objectRegistry & cellData() const
Cell based fields.
Definition: vtkUnstructuredReader.H:304
Foam::vtkUnstructuredReader::parseModeNames
static const Enum< parseMode > parseModeNames
Definition: vtkUnstructuredReader.H:109
Foam::vtkUnstructuredReader::VTK_FLOAT
Definition: vtkUnstructuredReader.H:79
Foam::vtkUnstructuredReader::VTK_STRING
Definition: vtkUnstructuredReader.H:81
Foam::vtkUnstructuredReader
Reader for vtk UNSTRUCTURED_GRID legacy files. Supports single CELLS, POINTS etc. entry only.
Definition: vtkUnstructuredReader.H:66
Foam::vtkUnstructuredReader::points
const pointField & points() const
Points.
Definition: vtkUnstructuredReader.H:245
cellShapeList.H
vtkUnstructuredReaderTemplates.C
objectRegistry.H
Foam::vtkUnstructuredReader::pointData
const objectRegistry & pointData() const
Point based fields.
Definition: vtkUnstructuredReader.H:315
Foam::vtkUnstructuredReader::UNSTRUCTURED_GRID
Definition: vtkUnstructuredReader.H:103
Foam::ISstream
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:55
Foam::vtkUnstructuredReader::VTK_ULONG
Definition: vtkUnstructuredReader.H:78
Foam::vtkUnstructuredReader::printFieldStats
void printFieldStats(const objectRegistry &) const
Debug: print contents of objectRegistry.
Definition: vtkUnstructuredReaderTemplates.C:55
Foam::vtkUnstructuredReader::faces
faceList & faces()
Definition: vtkUnstructuredReader.H:277
Foam::HashSet< label, Hash< label > >
Foam::vtkUnstructuredReader::pointData
objectRegistry & pointData()
Definition: vtkUnstructuredReader.H:320
Foam::vtkUnstructuredReader::VTK_INT
Definition: vtkUnstructuredReader.H:75
Foam::vtkUnstructuredReader::VTK_FIELD
Definition: vtkUnstructuredReader.H:91
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::vtkUnstructuredReader::vtkUnstructuredReader
vtkUnstructuredReader(const objectRegistry &obr, ISstream &)
Construct from Istream, read all.
Definition: vtkUnstructuredReader.C:506
Foam::vtkUnstructuredReader::vtkDataType
vtkDataType
Enumeration defining the vtk data types.
Definition: vtkUnstructuredReader.H:73
Foam::vtkUnstructuredReader::VTK_SCALARS
Definition: vtkUnstructuredReader.H:92
Foam::Field< vector >
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::vtkUnstructuredReader::otherData
const objectRegistry & otherData() const
Other fields.
Definition: vtkUnstructuredReader.H:326
Foam::vtkUnstructuredReader::title
const string & title() const
Title.
Definition: vtkUnstructuredReader.H:232
Foam::vtkUnstructuredReader::cells
cellShapeList & cells()
Definition: vtkUnstructuredReader.H:261
Foam::vtkUnstructuredReader::dataType
const string & dataType() const
DataType.
Definition: vtkUnstructuredReader.H:238
Foam::vtkUnstructuredReader::header
const string header() const
Header.
Definition: vtkUnstructuredReader.H:226
Foam::vtkUnstructuredReader::VTK_UINT
Definition: vtkUnstructuredReader.H:76
HashSet.H
Foam::vtkUnstructuredReader::VTK_VECTORS
Definition: vtkUnstructuredReader.H:93
Foam::vtkUnstructuredReader::ClassName
ClassName("vtkUnstructuredReader")
Runtime type information.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
cellTypes
const labelList & cellTypes
Definition: setCellMask.H:33
Foam::vtkUnstructuredReader::cellData
objectRegistry & cellData()
Definition: vtkUnstructuredReader.H:309
Foam::vtkUnstructuredReader::otherData
objectRegistry & otherData()
Definition: vtkUnstructuredReader.H:331
Foam::List< cellShape >
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::vtkUnstructuredReader::faceMap
const labelList & faceMap() const
Definition: vtkUnstructuredReader.H:282
foamVtkCore.H
Foam::vtkUnstructuredReader::NOMODE
Definition: vtkUnstructuredReader.H:102
Foam::vtkUnstructuredReader::VTK_ID
Definition: vtkUnstructuredReader.H:82
Foam::vtkUnstructuredReader::VTK_LONG
Definition: vtkUnstructuredReader.H:77
Foam::vtkUnstructuredReader::lines
const labelListList & lines() const
1D cells (=open lines)
Definition: vtkUnstructuredReader.H:288
Foam::vtkUnstructuredReader::POINT_DATA
Definition: vtkUnstructuredReader.H:106
Foam::vtkUnstructuredReader::vtkDataTypeNames
static const Enum< vtkDataType > vtkDataTypeNames
Definition: vtkUnstructuredReader.H:85
Foam::vtkUnstructuredReader::lines
labelListList & lines()
Definition: vtkUnstructuredReader.H:293
Foam::vtkUnstructuredReader::points
pointField & points()
Definition: vtkUnstructuredReader.H:250
Foam::vtkUnstructuredReader::CELL_DATA
Definition: vtkUnstructuredReader.H:105
Foam::vtkUnstructuredReader::VTK_DOUBLE
Definition: vtkUnstructuredReader.H:80
Foam::vtkUnstructuredReader::parseMode
parseMode
Enumeration defining the parse mode - type of data being read.
Definition: vtkUnstructuredReader.H:100
Foam::vtkUnstructuredReader::cells
const cellShapeList & cells() const
3D cells.
Definition: vtkUnstructuredReader.H:256
Enum.H