VTK  9.3.0
vtkHDFReaderImplementation.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
9 #ifndef vtkHDFReaderImplementation_h
10 #define vtkHDFReaderImplementation_h
11 
12 #include "vtkHDFReader.h"
13 #include "vtk_hdf5.h"
14 #include <array>
15 #include <map>
16 #include <string>
17 #include <vector>
18 
19 VTK_ABI_NAMESPACE_BEGIN
20 class vtkAbstractArray;
21 class vtkDataArray;
22 class vtkStringArray;
23 
29 {
30 public:
32  virtual ~Implementation();
36  bool Open(VTK_FILEPATH const char* fileName);
40  void Close();
45  int GetDataSetType() { return this->DataSetType; }
49  const std::array<int, 2>& GetVersion() { return this->Version; }
53  template <typename T>
54  bool GetAttribute(const char* attributeName, size_t numberOfElements, T* value);
58  template <typename T>
59  bool GetAttribute(hid_t group, const char* attributeName, size_t numberOfElements, T* value);
64  int GetNumberOfPieces(vtkIdType step = -1);
69  bool GetPartitionExtent(hsize_t partitionIndex, int* extent);
73  std::vector<std::string> GetArrayNames(int attributeType);
75 
84  int attributeType, const char* name, const std::vector<hsize_t>& fileExtent);
85  vtkDataArray* NewArray(int attributeType, const char* name, hsize_t offset, hsize_t size);
88 
90 
96  vtkDataArray* NewMetadataArray(const char* name, hsize_t offset, hsize_t size);
97  std::vector<vtkIdType> GetMetadata(const char* name, hsize_t size, hsize_t offset = 0);
99 
102  std::vector<hsize_t> GetDimensions(const char* dataset);
103 
111  bool FillAMR(vtkOverlappingAMR* data, unsigned int maximumLevelsToReadByDefault, double origin[3],
112  vtkDataArraySelection* dataArraySelection[3]);
113 
115 
118  std::size_t GetNumberOfSteps();
119  std::size_t GetNumberOfSteps(hid_t group);
121 
123 
129 
133  vtkIdType GetArrayOffset(vtkIdType step, int attributeType, std::string name);
134 
135 protected:
140  {
141  int Class;
142  size_t Size;
143  int Sign;
145  : Class(H5T_NO_CLASS)
146  , Size(0)
147  , Sign(H5T_SGN_ERROR)
148  {
149  }
150  bool operator<(const TypeDescription& other) const
151  {
152  return Class < other.Class || (Class == other.Class && Size < other.Size) ||
153  (Class == other.Class && Size == other.Size && Sign < other.Sign);
154  }
155  };
156 
162  hid_t OpenDataSet(hid_t group, const char* name, hid_t* nativeType, std::vector<hsize_t>& dims);
167  template <typename T>
174  template <typename T>
176 
178 
191  hid_t group, const char* name, const std::vector<hsize_t>& fileExtent);
192  vtkDataArray* NewArrayForGroup(hid_t dataset, hid_t nativeType, const std::vector<hsize_t>& dims,
193  const std::vector<hsize_t>& fileExtent);
194  template <typename T>
196  hid_t dataset, const std::vector<hsize_t>& fileExtent, hsize_t numberOfComponents);
197  template <typename T>
198  bool NewArray(
199  hid_t dataset, const std::vector<hsize_t>& fileExtent, hsize_t numberOfComponents, T* data);
200  vtkStringArray* NewStringArray(hid_t dataset, hsize_t size);
202 
211 
212 private:
213  std::string FileName;
214  hid_t File;
215  hid_t VTKGroup;
216  // in the same order as vtkDataObject::AttributeTypes: POINT, CELL, FIELD
217  std::array<hid_t, 3> AttributeDataGroup;
218  int DataSetType;
219  int NumberOfPieces;
220  std::array<int, 2> Version;
221  vtkHDFReader* Reader;
222  using ArrayReader = vtkDataArray* (vtkHDFReader::Implementation::*)(hid_t dataset,
223  const std::vector<hsize_t>& fileExtent, hsize_t numberOfComponents);
224  std::map<TypeDescription, ArrayReader> TypeReaderMap;
225 
226  bool ReadDataSetType();
227 
229 
232  bool ComputeAMRBlocksPerLevels(std::vector<int>& levels);
233  bool ReadLevelSpacing(hid_t levelGroupID, double* spacing);
234  bool ReadAMRBoxRawValues(hid_t levelGroupID, std::vector<int>& amrBoxRawData);
235  bool ReadLevelTopology(unsigned int level, const std::string& levelGroupName,
236  vtkOverlappingAMR* data, double origin[3]);
237  bool ReadLevelData(unsigned int level, const std::string& levelGroupName, vtkOverlappingAMR* data,
238  vtkDataArraySelection* dataArraySelection[3]);
240 };
241 
242 VTK_ABI_NAMESPACE_END
243 #endif
244 // VTK-HeaderTest-Exclude: vtkHDFReaderImplementation.h
Abstract superclass for all arrays.
Store on/off settings for data arrays, etc.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
Implementation for the vtkHDFReader.
bool GetPartitionExtent(hsize_t partitionIndex, int *extent)
For an ImageData, sets the extent for 'partitionIndex'.
TypeDescription GetTypeDescription(hid_t type)
Associates a struc of three integers with HDF type.
vtkDataArray * NewArray(hid_t dataset, const std::vector< hsize_t > &fileExtent, hsize_t numberOfComponents)
Reads a vtkDataArray of type T from the attributeType, dataset The array has type 'T' and 'numberOfCo...
vtkDataArray * NewArrayForGroup(hid_t group, const char *name, const std::vector< hsize_t > &fileExtent)
Reads a vtkDataArray of type T from the attributeType, dataset The array has type 'T' and 'numberOfCo...
bool Open(VTK_FILEPATH const char *fileName)
Opens this VTK HDF file and checks if it is valid.
Implementation(vtkHDFReader *reader)
vtkAbstractArray * NewFieldArray(const char *name, vtkIdType offset=-1, vtkIdType size=-1)
Reads and returns a new vtkDataArray.
std::vector< std::string > GetArrayNames(int attributeType)
Returns the names of arrays for 'attributeType' (point or cell).
vtkDataArray * GetStepValues(hid_t group)
Read the values of the steps from the open file.
vtkIdType GetArrayOffset(vtkIdType step, int attributeType, std::string name)
Methods to query for array offsets when steps are present.
vtkDataArray * NewArrayForGroup(hid_t dataset, hid_t nativeType, const std::vector< hsize_t > &dims, const std::vector< hsize_t > &fileExtent)
Reads a vtkDataArray of type T from the attributeType, dataset The array has type 'T' and 'numberOfCo...
vtkDataArray * GetStepValues()
Read the values of the steps from the open file.
vtkDataArray * NewArray(int attributeType, const char *name, const std::vector< hsize_t > &fileExtent)
Reads and returns a new vtkDataArray.
hid_t OpenDataSet(hid_t group, const char *name, hid_t *nativeType, std::vector< hsize_t > &dims)
Opens the hdf5 dataset given the 'group' and 'name'.
const std::array< int, 2 > & GetVersion()
Returns the version of the VTK HDF implementation.
void BuildTypeReaderMap()
Builds a map between native types and GetArray routines for that type.
int GetDataSetType()
Type of vtkDataSet stored by the HDF file, such as VTK_IMAGE_DATA or VTK_UNSTRUCTURED_GRID,...
int GetNumberOfPieces(vtkIdType step=-1)
Returns the number of partitions for this dataset at the time step step if applicable.
bool GetAttribute(hid_t group, const char *attributeName, size_t numberOfElements, T *value)
Reads an attribute from the group passed to it.
bool FillAMR(vtkOverlappingAMR *data, unsigned int maximumLevelsToReadByDefault, double origin[3], vtkDataArraySelection *dataArraySelection[3])
Fills the given AMR data with the content of the opened HDF file.
void Close()
Closes the VTK HDF file and releases any allocated resources.
bool GetAttribute(const char *attributeName, size_t numberOfElements, T *value)
Reads an attribute from the /VTKHDF group.
std::vector< vtkIdType > GetMetadata(const char *name, hsize_t size, hsize_t offset=0)
Reads a 1D metadata array in a DataArray or a vector of vtkIdType.
bool NewArray(hid_t dataset, const std::vector< hsize_t > &fileExtent, hsize_t numberOfComponents, T *data)
Reads a vtkDataArray of type T from the attributeType, dataset The array has type 'T' and 'numberOfCo...
vtkDataArray * NewVtkDataArray()
Create a vtkDataArray based on the C++ template type T.
vtkStringArray * NewStringArray(hid_t dataset, hsize_t size)
Reads a vtkDataArray of type T from the attributeType, dataset The array has type 'T' and 'numberOfCo...
vtkDataArray * NewMetadataArray(const char *name, hsize_t offset, hsize_t size)
Reads a 1D metadata array in a DataArray or a vector of vtkIdType.
std::vector< hsize_t > GetDimensions(const char *dataset)
Returns the dimensions of a HDF dataset.
std::size_t GetNumberOfSteps(hid_t group)
Read the number of steps from the opened file.
std::size_t GetNumberOfSteps()
Read the number of steps from the opened file.
hid_t TemplateTypeToHdfNativeType()
Convert C++ template type T to HDF5 native type this can be constexpr in C++17 standard.
vtkDataArray * NewArray(int attributeType, const char *name, hsize_t offset, hsize_t size)
Reads and returns a new vtkDataArray.
VTKHDF format reader.
Definition: vtkHDFReader.h:58
hierarchical dataset of vtkUniformGrids
a vtkAbstractArray subclass for strings
static const unsigned int numberOfElements
@ level
Definition: vtkX3D.h:395
@ value
Definition: vtkX3D.h:220
@ extent
Definition: vtkX3D.h:345
@ type
Definition: vtkX3D.h:516
@ spacing
Definition: vtkX3D.h:481
@ name
Definition: vtkX3D.h:219
@ size
Definition: vtkX3D.h:253
@ offset
Definition: vtkX3D.h:438
@ data
Definition: vtkX3D.h:315
@ string
Definition: vtkX3D.h:490
Used to store HDF native types in a map.
bool operator<(const TypeDescription &other) const
int vtkIdType
Definition: vtkType.h:315
#define VTK_FILEPATH