VTK  9.1.0
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
32class vtkDataArray;
33class vtkStringArray;
34
40{
41public:
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);
91 vtkAbstractArray* NewFieldArray(const char* name);
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
109protected:
114 {
115 int Class;
116 size_t Size;
117 int Sign;
119 : Class(H5T_NO_CLASS)
120 , Size(0)
121 , Sign(H5T_SGN_ERROR)
122 {
123 }
124 bool operator<(const TypeDescription& other) const
125 {
126 return Class < other.Class || (Class == other.Class && Size < other.Size) ||
127 (Class == other.Class && Size == other.Size && Sign < other.Sign);
128 }
129 };
130
131protected:
137 hid_t OpenDataSet(hid_t group, const char* name, hid_t* nativeType, std::vector<hsize_t>& dims);
142 template <typename T>
149 template <typename T>
151
153
165 vtkDataArray* NewArray(hid_t group, const char* name, const std::vector<hsize_t>& fileExtent);
166 template <typename T>
168 hid_t dataset, const std::vector<hsize_t>& fileExtent, hsize_t numberOfComponents);
169 template <typename T>
171 hid_t dataset, const std::vector<hsize_t>& fileExtent, hsize_t numberOfComponents, T* data);
172 vtkStringArray* NewStringArray(hid_t dataset, hsize_t size);
174
183
184private:
185 std::string FileName;
186 hid_t File;
187 hid_t VTKGroup;
188 // in the same order as vtkDataObject::AttributeTypes: POINT, CELL, FIELD
189 std::array<hid_t, 3> AttributeDataGroup;
190 int DataSetType;
191 int NumberOfPieces;
192 std::array<int, 2> Version;
193 vtkHDFReader* Reader;
194 using ArrayReader = vtkDataArray* (vtkHDFReader::Implementation::*)(hid_t dataset,
195 const std::vector<hsize_t>& fileExtent, hsize_t numberOfComponents);
196 std::map<TypeDescription, ArrayReader> TypeReaderMap;
197};
198
199//------------------------------------------------------------------------------
200// explicit template instantiation declaration
201extern template bool vtkHDFReader::Implementation::GetAttribute<int>(
202 const char* attributeName, size_t dim, int* value);
203extern template bool vtkHDFReader::Implementation::GetAttribute<double>(
204 const char* attributeName, size_t dim, double* value);
205
206#endif
207// VTK-HeaderTest-Exclude: vtkHDFReaderImplementation.h
Abstract superclass for all arrays.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:159
Implementation for the vtkHDFReader.
vtkDataArray * NewMetadataArray(const char *name, hsize_t offset, hsize_t size)
Reads a 1D metadata array in a DataArray or a vector of vtkIdType.
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.
const std::array< int, 2 > & GetVersion()
Returns the version of the VTK HDF implementation.
bool Open(VTK_FILEPATH const char *fileName)
Opens this VTK HDF file and checks if it is valid.
std::vector< vtkIdType > GetMetadata(const char *name, hsize_t size)
Implementation(vtkHDFReader *reader)
vtkDataArray * NewArray(int attributeType, const char *name, const std::vector< hsize_t > &fileExtent)
Reads and returns a new vtkDataArray.
std::vector< hsize_t > GetDimensions(const char *dataset)
Returns the dimensions of a HDF dataset.
bool GetAttribute(const char *attributeName, size_t numberOfElements, T *value)
Reads an attribute from the /VTKHDF group.
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'.
std::vector< std::string > GetArrayNames(int attributeType)
Returns the names of arrays for 'attributeType' (point or cell).
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,...
void Close()
Closes the VTK HDF file and releases any allocated resources.
int GetNumberOfPieces()
Returns the number of partitions for this dataset.
vtkAbstractArray * NewFieldArray(const char *name)
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.
vtkDataArray * NewArray(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...
vtkDataArray * NewArray(hid_t dataset, const std::vector< hsize_t > &fileExtent, hsize_t numberOfComponents)
vtkStringArray * NewStringArray(hid_t dataset, hsize_t size)
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:48
a vtkAbstractArray subclass for strings
Used to store HDF native types in a map.
bool operator<(const TypeDescription &other) const
#define VTK_FILEPATH