VTK  9.4.2
EnSightDataSet.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
3
4#ifndef EnSightDataSet_h
5#define EnSightDataSet_h
6
7#include "EnSightFile.h"
8
9#include "vtkSmartPointer.h"
10#include "vtkTransform.h"
11
12#include <string>
13#include <vector>
14
15VTK_ABI_NAMESPACE_BEGIN
18class vtkDataSet;
19class vtkFloatArray;
20class vtkIdTypeArray;
23class vtkStringArray;
25class vtkUniformGrid;
27VTK_ABI_NAMESPACE_END
28
29namespace ensight_gold
30{
31VTK_ABI_NAMESPACE_BEGIN
32
33enum class GridType
34{
35 Unknown,
36 Uniform,
40};
41
43{
45 bool IBlanked = false;
46 bool WithGhost = false;
47 bool HasRange = false;
48};
49
50enum class ElementType
51{
52 Unknown,
53 Point,
54 Bar2,
55 Bar3,
56 Tria3,
57 Tria6,
58 Quad4,
59 Quad8,
60 Tetra4,
61 Tetra10,
64 Penta6,
65 Penta15,
66 Hexa8,
67 Hexa20,
68 NSided,
69 NFaced,
70 GPoint,
71 GBar2,
72 GBar3,
73 GTria3,
74 GTria6,
75 GQuad4,
76 GQuad8,
77 GTetra4,
81 GPenta6,
83 GHexa8,
84 GHexa20,
85 GNSided,
87};
88
90{
91 std::string Name;
92 int NumNodes = 0;
93 // For structured grids only
94 int NumElements = 0;
95 std::vector<int> NumElementsPerType;
96
97 // index into the partitioned dataset collection
98 int PDCIndex = -1;
99
101 : NumElementsPerType(static_cast<int>(ElementType::GNFaced) + 1, 0)
102 {
103 }
104};
105
106using PartInfoMapType = std::map<int, PartInfo>;
107
108enum class VariableType
109{
110 Unknown,
128};
129
131{
133 std::string Name;
134 int Frequency; // only for complex variables
136 EnSightFile ImaginaryFile; // only for complex variables
137 std::vector<float> Constants;
138};
139
145{
146public:
151 bool CheckVersion(const char* casefilename);
152
156 bool ParseCaseFile(const char* casefilename);
157
161 std::vector<double> GetTimeSteps();
162
167 bool outputStructureOnly);
168
173 vtkDataArraySelection* selection, bool outputStructureOnly);
174
179
185 bool GetPartInfo(vtkDataArraySelection* partSelection, vtkDataArraySelection* pointArraySelection,
186 vtkDataArraySelection* cellArraySelection, vtkDataArraySelection* fieldArraySelection,
187 vtkStringArray* partNames);
188
193 vtkDataArraySelection* pointArraySelection, vtkDataArraySelection* cellArraySelection,
194 vtkDataArraySelection* fieldArraySelection);
195
200
205
209 std::vector<double> GetEulerTimeSteps();
210
214 void SetActualTimeValue(double time);
215
219 bool UseStaticMeshCache() const;
220
222
223 /*
224 * Set if this casefile is being read as part of an SOS file. If so, it is expected
225 * that some coordination is handled by the vtkEnSightSOSGoldReader
226 */
227 void SetPartOfSOSFile(bool partOfSOS);
228
247
248private:
249 bool ParseFormatSection();
250 void ParseGeometrySection();
251 void ParseVariableSection();
252 void ParseTimeSection();
253 void ParseFileSection();
254
255 std::string GetFullPath(const std::string& fname);
256 void SetVariableFileFormat();
257 bool IsSectionHeader(std::string line);
258
259 void CreateUniformGridOutput(const GridOptions& opts, vtkUniformGrid* output);
260 void CreateRectilinearGridOutput(const GridOptions& opts, vtkRectilinearGrid* output);
261 void CreateStructuredGridOutput(const GridOptions& opts, vtkStructuredGrid* output);
262 void CreateUnstructuredGridOutput(const GridOptions& opts, vtkUnstructuredGrid* output);
263
264 void PassThroughUniformGrid(const GridOptions& opts, int partId);
265 void PassThroughRectilinearGrid(const GridOptions& opts, int partId);
266 void PassThroughStructuredGrid(const GridOptions& opts, int partId);
267 void PassThroughUnstructuredGrid(const GridOptions& opts, int partId);
268 void PassThroughOptionalSections(const GridOptions& opts, int numPts, int numCells);
269
270 int ReadPartId(EnSightFile& file);
271 void ReadDimensions(bool hasRange, int dimensions[3], int& numPts, int& numCells);
272 void ReadRange(int range[6]);
273 void ReadOptionalValues(int numVals, int* data, std::string sectionName = "");
274 void CheckForOptionalHeader(const std::string& sectionName);
275
276 void ReadCell(
277 ElementType eType, vtkUnstructuredGrid* output, bool padBegin = false, bool padEnd = false);
278 void ReadCell(int cellType, int numNodes, vtkUnstructuredGrid* output, bool padBegin = false,
279 bool padEnd = false);
280 void ReadNSidedSection(int& numElements, vtkUnstructuredGrid* output);
281 void ReadNFacedSection(int& numElements, vtkUnstructuredGrid* output);
282
283 void ReadVariableNodes(EnSightFile& file, const std::string& arrayName, int numComponents,
285 bool isComplex = false, bool isReal = true);
286 void ReadVariableMeasuredNodes(EnSightFile& file, const std::string& arrayName, int numComponents,
288 void ReadVariableElements(EnSightFile& file, const std::string& arrayName, int numComponents,
290 bool isComplex = false, bool isReal = true);
291 vtkSmartPointer<vtkFloatArray> ReadVariableArray(
292 EnSightFile& file, const std::string& sectionHeader, vtkIdType numElements, int numComponents);
293 void ReadVariableConstantCase(VariableOptions& var, vtkPartitionedDataSetCollection* output);
294
295 void ProcessNodeIds(int numPts, vtkDataSet* output);
296 void ProcessElementIds(int numCells, vtkDataSet* output);
297
298 void ProcessGhostCells(int numCells, vtkDataSet* output);
299
300 bool CurrentGeometryFileContainsConnectivity();
301
308 bool ReadRigidBodyEulerParameterFile(const std::string& path);
309
313 bool ReadRigidBodyMatrixLines(
314 std::string& line, const std::string& transType, vtkTransform* transform, bool& applyToVectors);
315
319 bool ApplyRigidBodyTransforms(int partId, std::string partName, vtkDataSet* output);
320
321 EnSightFile CaseFile;
322
323 std::string GeometryFileName;
324 EnSightFile GeometryFile;
325
326 bool IsStaticGeometry = false;
327 // indicates that changing geometry is only coordinates, not connectivity
328 bool GeometryChangeCoordsOnly = false;
329
330 // zero based time step that contains the connectivity.
331 // only used when GeometryChangeCoordsOnly == true
332 int GeometryCStep = -1;
333
335
336 std::string MeasuredFileName;
337 EnSightFile MeasuredFile;
338 int MeasuredPartitionId = -1;
339 std::string MeasuredPartName = "measured particles";
340
341 std::vector<std::string> FilePath;
342
343 bool NodeIdsListed = false;
344 bool ElementIdsListed = false;
345
346 PartInfoMapType PartInfoMap;
347 TimeSetInfoMapType TimeSetInfoMap;
348 FileSetInfoMapType FileSetInfoMap;
349 std::vector<double> AllTimeSteps;
350
351 std::vector<VariableOptions> Variables;
352 double ActualTimeValue = 0.0;
353
354 std::string RigidBodyFileName;
355 EnSightFile RigidBodyFile;
356 EnSightFile EETFile;
357 // We support only version 2 of rigid body transform files for only ensight gold files.
358 // For rigid body transforms, we need to track per part:
359 // 1. transforms to be applied before the Euler transformation
360 // 2. Information about which data to use in the Euler Transform file (eet file)
361 // 3. transforms to be applied after the Euler transformation
362 struct PartTransforms
363 {
364 // Pre and post transforms do not change over time
365 // We have to track each transform separately, because some transforms need to be
366 // applied to geometry and vectors, while others should only be applied to the geometry
367 std::vector<vtkSmartPointer<vtkTransform>> PreTransforms;
368 std::vector<bool> PreTransformsApplyToVectors;
369 std::vector<vtkSmartPointer<vtkTransform>> PostTransforms;
370 std::vector<bool> PostTransformsApplyToVectors;
371
372 // EnSight format requires specifying the eet file per part, but according to the user manual
373 // use of different eet files for the same dataset is not actually allowed
374 std::string EETFilename;
375
376 // title is related to, but not necessarily a part name. for instance, if you have 4 wheel parts
377 // there may only be a single "wheel" title that all wheel parts use, applying the same Euler
378 // rotation to all wheels
379 std::string EETTransTitle;
380 };
381
382 // rigid body files allows for using either part names or part Ids to specify
383 // transforms for parts;
384 bool UsePartNamesRB = true;
385
386 // keeps track of all transforms for each part
387 // if UsePartNamesRB == true, the key is the part name
388 // otherwise, the key name is the partId converted to a string
389 std::map<std::string, PartTransforms> RigidBodyTransforms;
390
391 // map time step to the Euler transform for a part
392 using TimeToEulerTransMapType = std::map<double, vtkSmartPointer<vtkTransform>>;
393
394 // map a title to all of its Euler transforms
395 using TitleToTimeStepMapType = std::map<std::string, TimeToEulerTransMapType>;
396
397 TitleToTimeStepMapType EulerTransformsMap;
398
399 // It's possible for an EnSight dataset to not contain transient data, except for the
400 // Euler transforms. In this case, we will populate EulerTimeSteps so we can use it for
401 // time information, instead of the usual time set
402 bool UseEulerTimeSteps = false;
403 std::vector<double> EulerTimeSteps;
404
405 int NumberOfLoadedParts = 0;
406 vtkSmartPointer<vtkStringArray> LoadedPartNames;
407 bool PartOfSOSFile = true;
408};
409
410VTK_ABI_NAMESPACE_END
411} // end namespace ensight_gold
412
413#endif // EnSightDataSet_h
Handles reading a full EnSight Gold dataset.
void SetPartOfSOSFile(bool partOfSOS)
bool ReadRigidBodyGeometryFile()
Read the rigid body file.
bool UseRigidBodyTimeSteps()
Returns true if the time steps specified in the rigid body files should be used.
std::vector< double > GetTimeSteps()
returns a vector containing all time steps in the dataset
vtkDataObjectMeshCache * GetMeshCache()
bool UseStaticMeshCache() const
Returns true if the static mesh cache will be used.
bool ReadMeasuredGeometry(vtkPartitionedDataSetCollection *output, vtkDataArraySelection *selection, bool outputStructureOnly)
Reads Measured Geometry file.
bool CheckVersion(const char *casefilename)
Parses through case file until version information is found.
bool GetPartInfo(vtkDataArraySelection *partSelection, vtkDataArraySelection *pointArraySelection, vtkDataArraySelection *cellArraySelection, vtkDataArraySelection *fieldArraySelection, vtkStringArray *partNames)
Only grabs Part (block) information from the Geometry file to be used in a vtkDataArraySelection to e...
void SetActualTimeValue(double time)
Set the time value to be used in the next read.
bool HasRigidBodyFile()
Returns true if a rigid body file is specified in the case file.
bool ParseCaseFile(const char *casefilename)
Parses all sections of a case file to get information such as filenames.
void SetPDCInfoForLoadedParts(vtkSmartPointer< vtkIdTypeArray > indices, vtkSmartPointer< vtkStringArray > names)
Sets information about parts to be loaded.
bool ReadVariables(vtkPartitionedDataSetCollection *output, vtkDataArraySelection *partSelection, vtkDataArraySelection *pointArraySelection, vtkDataArraySelection *cellArraySelection, vtkDataArraySelection *fieldArraySelection)
Reads Variable file(s)
std::vector< double > GetEulerTimeSteps()
Get the array of time steps from the rigid body files.
bool ReadGeometry(vtkPartitionedDataSetCollection *output, vtkDataArraySelection *selection, bool outputStructureOnly)
Reads Geometry file, caching the data if not transient.
Store on/off settings for data arrays, etc.
vtkDataObjectMeshCache is a class to store and reuse the mesh of a vtkDataSet, while forwarding data ...
abstract class to specify dataset behavior
Definition vtkDataSet.h:166
dynamic, self-adjusting array of float
dynamic, self-adjusting array of vtkIdType
Composite dataset that groups datasets as a collection.
a dataset that is topologically regular with variable spacing in the three coordinate directions
Hold a reference to a vtkObjectBase instance.
a vtkAbstractArray subclass for strings
topologically regular array of data
describes linear transformations via a 4x4 matrix
image data with blanking
dataset represents arbitrary combinations of all possible cell types
std::map< int, std::shared_ptr< TimeSetInfo > > TimeSetInfoMapType
Definition EnSightFile.h:46
std::map< int, PartInfo > PartInfoMapType
std::map< int, std::shared_ptr< FileSetInfo > > FileSetInfoMapType
Definition EnSightFile.h:55
EnSightFile performs processing on a single file, whether it's a case file, geometry,...
Definition EnSightFile.h:62
std::vector< int > NumElementsPerType
std::vector< float > Constants
int vtkIdType
Definition vtkType.h:315