VTK  9.2.6
vtkHDFReaderImplementation.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkHDFReaderImplementation.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
21 #ifndef vtkHDFReaderImplementation_h
22 #define vtkHDFReaderImplementation_h
23 
24 #include "vtkHDFReader.h"
25 #include "vtk_hdf5.h"
26 #include <array>
27 #include <map>
28 #include <string>
29 #include <vector>
30 
31 class vtkAbstractArray;
32 class vtkDataArray;
33 class vtkStringArray;
34 
40 {
41 public:
43  virtual ~Implementation();
47  bool Open(VTK_FILEPATH const char* fileName);
51  void Close();
56  int GetDataSetType() { return this->DataSetType; }
60  const std::array<int, 2>& GetVersion() { return this->Version; }
64  template <typename T>
65  bool GetAttribute(const char* attributeName, size_t numberOfElements, T* value);
69  int GetNumberOfPieces() { return this->NumberOfPieces; }
74  bool GetPartitionExtent(hsize_t partitionIndex, int* extent);
78  std::vector<std::string> GetArrayNames(int attributeType);
80 
89  int attributeType, const char* name, const std::vector<hsize_t>& fileExtent);
90  vtkDataArray* NewArray(int attributeType, const char* name, hsize_t offset, hsize_t size);
93 
95 
101  vtkDataArray* NewMetadataArray(const char* name, hsize_t offset, hsize_t size);
102  std::vector<vtkIdType> GetMetadata(const char* name, hsize_t size);
104 
107  std::vector<hsize_t> GetDimensions(const char* dataset);
108 
116  bool FillAMR(vtkOverlappingAMR* data, unsigned int maximumLevelsToReadByDefault, double origin[3],
117  vtkDataArraySelection* dataArraySelection[3]);
118 
119 protected:
124  {
125  int Class;
126  size_t Size;
127  int Sign;
129  : Class(H5T_NO_CLASS)
130  , Size(0)
131  , Sign(H5T_SGN_ERROR)
132  {
133  }
134  bool operator<(const TypeDescription& other) const
135  {
136  return Class < other.Class || (Class == other.Class && Size < other.Size) ||
137  (Class == other.Class && Size == other.Size && Sign < other.Sign);
138  }
139  };
140 
141 protected:
147  hid_t OpenDataSet(hid_t group, const char* name, hid_t* nativeType, std::vector<hsize_t>& dims);
152  template <typename T>
159  template <typename T>
161 
163 
176  hid_t group, const char* name, const std::vector<hsize_t>& fileExtent);
177  vtkDataArray* NewArrayForGroup(hid_t dataset, const hid_t nativeType,
178  const std::vector<hsize_t>& dims, const std::vector<hsize_t>& fileExtent);
179  template <typename T>
181  hid_t dataset, const std::vector<hsize_t>& fileExtent, hsize_t numberOfComponents);
182  template <typename T>
183  bool NewArray(
184  hid_t dataset, const std::vector<hsize_t>& fileExtent, hsize_t numberOfComponents, T* data);
185  vtkStringArray* NewStringArray(hid_t dataset, hsize_t size);
187 
196 
197 private:
198  std::string FileName;
199  hid_t File;
200  hid_t VTKGroup;
201  // in the same order as vtkDataObject::AttributeTypes: POINT, CELL, FIELD
202  std::array<hid_t, 3> AttributeDataGroup;
203  int DataSetType;
204  int NumberOfPieces;
205  std::array<int, 2> Version;
206  vtkHDFReader* Reader;
207  using ArrayReader = vtkDataArray* (vtkHDFReader::Implementation::*)(hid_t dataset,
208  const std::vector<hsize_t>& fileExtent, hsize_t numberOfComponents);
209  std::map<TypeDescription, ArrayReader> TypeReaderMap;
210 
211  bool ReadDataSetType();
212 
214 
217  bool ComputeAMRBlocksPerLevels(std::vector<int>& levels);
218  bool ReadLevelSpacing(hid_t levelGroupID, double* spacing);
219  bool ReadAMRBoxRawValues(hid_t levelGroupID, std::vector<int>& amrBoxRawData);
220  bool ReadLevelTopology(unsigned int level, const std::string& levelGroupName,
221  vtkOverlappingAMR* data, double origin[3]);
222  bool ReadLevelData(unsigned int level, const std::string& levelGroupName, vtkOverlappingAMR* data,
223  vtkDataArraySelection* dataArraySelection[3]);
225 };
226 
227 //------------------------------------------------------------------------------
228 // explicit template instantiation declaration
229 extern template bool vtkHDFReader::Implementation::GetAttribute<int>(
230  const char* attributeName, size_t dim, int* value);
231 extern template bool vtkHDFReader::Implementation::GetAttribute<double>(
232  const char* attributeName, size_t dim, double* value);
233 
234 #endif
235 // 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:165
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)
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)
std::vector< std::string > GetArrayNames(int attributeType)
Returns the names of arrays for 'attributeType' (point or cell).
vtkDataArray * NewArray(int attributeType, const char *name, const std::vector< hsize_t > &fileExtent)
Reads and returns a new vtkDataArray.
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)
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,...
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.
int GetNumberOfPieces()
Returns the number of partitions for this dataset.
bool NewArray(hid_t dataset, const std::vector< hsize_t > &fileExtent, hsize_t numberOfComponents, T *data)
vtkDataArray * NewVtkDataArray()
Create a vtkDataArray based on the C++ template type T.
vtkStringArray * NewStringArray(hid_t dataset, hsize_t size)
vtkDataArray * NewArrayForGroup(hid_t dataset, const hid_t nativeType, const std::vector< hsize_t > &dims, const std::vector< hsize_t > &fileExtent)
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.
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)
VTKHDF format reader.
Definition: vtkHDFReader.h:53
hierarchical dataset of vtkUniformGrids
a vtkAbstractArray subclass for strings
static const unsigned int numberOfElements
@ level
Definition: vtkX3D.h:401
@ value
Definition: vtkX3D.h:226
@ extent
Definition: vtkX3D.h:351
@ type
Definition: vtkX3D.h:522
@ spacing
Definition: vtkX3D.h:487
@ name
Definition: vtkX3D.h:225
@ size
Definition: vtkX3D.h:259
@ offset
Definition: vtkX3D.h:444
@ data
Definition: vtkX3D.h:321
@ string
Definition: vtkX3D.h:496
Used to store HDF native types in a map.
bool operator<(const TypeDescription &other) const
#define VTK_FILEPATH