VTK  9.7.1
vtkHDFUtilities.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 vtkHDFUtilities_h
10 #define vtkHDFUtilities_h
11 
12 #include "vtkDataArray.h"
13 #include "vtkDataObject.h"
14 #include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_7_0 VTK_DEPRECATED_IN_9_6_0
15 #include "vtkIOHDFModule.h" // For export macro
16 #include "vtkStringArray.h"
17 #include "vtkType.h"
18 #include "vtk_hdf5.h"
19 
20 #include <array>
21 #include <string>
22 #include <vector>
23 
24 VTK_ABI_NAMESPACE_BEGIN
25 
26 #if VTK_ID_TYPE_IMPL == VTK_LONG_LONG
27 #define VTK_ID_H5T H5T_NATIVE_LLONG
28 #elif VTK_ID_TYPE_IMPL == VTK_LONG
29 #define VTK_ID_H5T H5T_NATIVE_LONG
30 #elif VTK_ID_TYPE_IMPL == VTK_INT
31 #define VTK_ID_H5T H5T_NATIVE_INT
32 #else
33 #error "No HDF5 type available for vtkIdType"
34 #endif
35 
37 
38 namespace vtkHDFUtilities
39 {
40 const std::string VTKHDF_ROOT_PATH = "/VTKHDF";
41 
42 /*
43  * The number of PolyData topologies saved in vtkHDF format
44  */
45 constexpr std::size_t NUM_POLY_DATA_TOPOS = 4;
46 
47 /*
48  * A vector of the topology names that are saved in vtkHDF
49  * Can be used for the name of the HDF group only
50  */
51 const std::vector<std::string> POLY_DATA_TOPOS{ "Vertices", "Lines", "Polygons", "Strips" };
52 
53 /*
54  * Attribute tag used in the cache storage to indicate arrays related to the geometry of the data
55  * set and not fields of the data set
56  */
57 constexpr int GEOMETRY_ATTRIBUTE_TAG = -42;
58 
59 /*
60  * How many attribute types we have. This returns 3: point, cell and field
61  * attribute types.
62  */
63 VTKIOHDF_EXPORT std::vector<int> GetAttributeTypes();
64 
70 VTKIOHDF_EXPORT bool ReadDataSetType(hid_t groupID, int& dataSetType);
71 
72 /*
73  * Make sure we replace any illegal characters in the objectName (slash, dot) by an underscore, as
74  * they would create a HDF5 subgroup.
75  */
76 VTKIOHDF_EXPORT void MakeObjectNameValid(std::string& objectName);
77 
78 /*
79  * Returns the id to a HDF datatype (H5T) from a VTK datatype
80  * Returns H5I_INVALID_HID if no corresponding type is found
81  */
82 VTKIOHDF_EXPORT hid_t getH5TypeFromVtkType(int dataType);
83 
84 /*
85  * @struct TemporalGeometryOffsets
86  * @brief Use to get the offsets for temporal vtkHDF.
87  *
88  * To use it, create an object using the templated constructor of this struct.
89  * It will fill the object with data that can be then retrieved.
90  */
91 struct VTKIOHDF_EXPORT TemporalGeometryOffsets
92 {
93 public:
95 
96  VTK_DEPRECATED_IN_9_6_0("Member is deprecated. Please use GetOffsets instead.")
97  bool Success = true;
98 
99  vtkIdType PartOffset = 0;
100  vtkIdType PointOffset = 0;
101  std::vector<vtkIdType> CellOffsets;
102  std::vector<vtkIdType> ConnectivityOffsets;
103 
104  // Polyhedron
105  vtkIdType FaceConnectivityOffset = 0;
106  vtkIdType PolyhedronToFaceIdOffset = 0;
107  vtkIdType FaceOffset = 0;
108  bool HasPolyhedron = false;
109 
110  template <class T>
111  bool GetOffsets(T* impl, vtkIdType step);
112 };
113 
114 /*
115  * Offsets for temporalHyperTreeGrid
116  */
117 struct VTKIOHDF_EXPORT TemporalHyperTreeGridOffsets
118 {
119 public:
120  bool Success = true;
121  vtkIdType TreeIdsOffset = 0;
122  vtkIdType DepthPerTreeOffset = 0;
123  vtkIdType NumberOfCellsPerTreeDepthOffset = 0;
124  vtkIdType DescriptorsOffset = 0;
125  vtkIdType MaskOffset = 0;
126  vtkIdType XCoordinatesOffset = 0;
127  vtkIdType YCoordinatesOffset = 0;
128  vtkIdType ZCoordinatesOffset = 0;
129  vtkIdType PartOffset = 0;
130 
131  template <class T>
132  TemporalHyperTreeGridOffsets(T* impl, vtkIdType step);
133 };
134 
140 VTK_DEPRECATED_IN_9_7_0("Deprecated. Please use the version with quiet arg.")
141 VTKIOHDF_EXPORT bool Open(const char* fileName, hid_t& fileID);
142 
147 VTKIOHDF_EXPORT bool Open(const char* fileName, hid_t& fileID, bool quiet);
148 
154 VTK_DEPRECATED_IN_9_7_0("Deprecated. Please use the version with quiet arg.")
155 VTKIOHDF_EXPORT bool Open(vtkMemoryResourceStream* stream, hid_t& fileImageID);
156 
162 VTKIOHDF_EXPORT bool Open(vtkMemoryResourceStream* stream, hid_t& fileImageID, bool quiet);
163 
168 template <typename T>
169 VTKIOHDF_EXPORT hid_t TemplateTypeToHdfNativeType();
170 
174 template <typename T>
175 VTKIOHDF_EXPORT bool GetAttribute(
176  hid_t group, const char* attributeName, size_t numberOfElements, T* value);
177 
181 VTKIOHDF_EXPORT bool GetStringAttribute(
182  hid_t groupID, const std::string& name, std::string& attribute);
183 
187 VTKIOHDF_EXPORT std::size_t GetNumberOfSteps(hid_t groupID);
188 
192 VTKIOHDF_EXPORT std::vector<hsize_t> GetDimensions(hid_t fileID, const char* datasetName);
193 
198 
213 VTKIOHDF_EXPORT bool RetrieveHDFInformation(hid_t& rootID, const std::string& rootName,
214  const std::string& groupPrefix, hid_t& groupID, std::array<int, 2>& version, int& dataSetType,
215  int& numberOfPieces, std::map<int, hid_t>& attributeDataGroup);
216 VTK_DEPRECATED_IN_9_7_0("Deprecated. Please use the groupPrefix version instead.")
217 VTKIOHDF_EXPORT bool RetrieveHDFInformation(hid_t& fileID, hid_t& groupID,
218  const std::string& rootName, std::array<int, 2>& version, int& dataSetType, int& numberOfPieces,
219  std::array<hid_t, 3>& attributeDataGroup);
220 VTK_DEPRECATED_IN_9_7_0("Deprecated. Please use the std::map version instead.")
221 VTKIOHDF_EXPORT bool RetrieveHDFInformation(hid_t& rootID, const std::string& rootName,
222  const std::string& groupPrefix, hid_t& groupID, std::array<int, 2>& version, int& dataSetType,
223  int& numberOfPieces, std::array<hid_t, 3>& attributeDataGroup);
225 
229 VTKIOHDF_EXPORT herr_t FileInfoCallBack(
230  hid_t loc_id, const char* name, const H5L_info_t* info, void* opdata);
231 
233 
236 VTK_DEPRECATED_IN_9_7_0("Deprecated. Please use the std::map version instead.")
237 VTKIOHDF_EXPORT std::vector<std::string> GetArrayNames(
238  const std::array<hid_t, 3>& attributeDataGroup, int attributeType);
239 VTKIOHDF_EXPORT std::vector<std::string> GetArrayNames(
240  const std::map<int, hid_t>& attributeDataGroup, int attributeType);
242 
246 VTKIOHDF_EXPORT std::vector<std::string> GetOrderedChildrenOfGroup(
247  hid_t groupID, const std::string& path);
248 
255 VTKIOHDF_EXPORT hid_t OpenDataSet(
256  hid_t group, const char* name, hid_t* nativeType, std::vector<hsize_t>& dims);
257 
259 
271 VTKIOHDF_EXPORT vtkDataArray* NewArrayForGroup(hid_t dataset, hid_t nativeType,
272  const std::vector<hsize_t>& dims, const std::vector<hsize_t>& parameterExtent);
273 VTKIOHDF_EXPORT vtkDataArray* NewArrayForGroup(
274  hid_t group, const char* name, const std::vector<hsize_t>& parameterExtent);
276 
283 VTKIOHDF_EXPORT std::vector<vtkIdType> GetMetadata(
284  hid_t group, const char* name, hsize_t size, hsize_t offset);
285 
291 VTKIOHDF_EXPORT std::array<vtkIdType, 2> GetFieldArraySize(
292  hid_t group, vtkIdType step, std::string name);
293 
297 VTKIOHDF_EXPORT vtkIdType GetArrayOffset(
298  hid_t group, vtkIdType step, int attributeType, std::string name);
299 
301 
306 VTK_DEPRECATED_IN_9_7_0("Deprecated. Please use the std::map version instead.")
307 VTKIOHDF_EXPORT vtkAbstractArray* NewFieldArray(const std::array<hid_t, 3>& attributeDataGroup,
308  const char* name, vtkIdType offset, vtkIdType size, vtkIdType dimMaxSize);
309 VTKIOHDF_EXPORT vtkAbstractArray* NewFieldArray(const std::map<int, hid_t>& attributeDataGroup,
310  const char* name, vtkIdType offset, vtkIdType size, vtkIdType dimMaxSize);
312 
313 VTKIOHDF_EXPORT vtkStringArray* NewStringArray(
314  hid_t dataset, std::vector<hsize_t> dims, std::vector<hsize_t> fileExtent);
315 }
316 
317 VTK_ABI_NAMESPACE_END
318 #include "vtkHDFUtilities.txx" // for template implementations
319 
320 #endif
321 // VTK-HeaderTest-Exclude: vtkHDFUtilities.h
VTKIOHDF_EXPORT hid_t TemplateTypeToHdfNativeType()
Convert C++ template type T to HDF5 native type this can be constexpr in C++17 standard.
VTKIOHDF_EXPORT std::vector< hsize_t > GetDimensions(hid_t fileID, const char *datasetName)
Returns the dimensions of a HDF dataset of a file.
Abstract superclass for all arrays.
VTKIOHDF_EXPORT std::vector< vtkIdType > GetMetadata(hid_t group, const char *name, hsize_t size, hsize_t offset)
Reads a 1D metadata array in a DataArray or a vector of vtkIdType.
VTKIOHDF_EXPORT herr_t FileInfoCallBack(hid_t loc_id, const char *name, const H5L_info_t *info, void *opdata)
Convenient callback method to retrieve a name when calling a H5Giterate()
VTKIOHDF_EXPORT bool ReadDataSetType(hid_t groupID, int &dataSetType)
Read the dataset type string for the given group, and return the index of the type as defined in vtkT...
VTKIOHDF_EXPORT std::vector< int > GetAttributeTypes()
VTKIOHDF_EXPORT 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'.
a vtkAbstractArray subclass for strings
int vtkIdType
Definition: vtkType.h:363
VTKIOHDF_EXPORT hid_t getH5TypeFromVtkType(int dataType)
VTKIOHDF_EXPORT vtkDataArray * NewArrayForGroup(hid_t dataset, hid_t nativeType, const std::vector< hsize_t > &dims, const std::vector< hsize_t > &parameterExtent)
Reads a vtkDataArray of type T from the attributeType, dataset The array has type 'T' and 'numberOfCo...
static const unsigned int numberOfElements
VTKIOHDF_EXPORT bool GetAttribute(hid_t group, const char *attributeName, size_t numberOfElements, T *value)
Reads an attribute from the group passed to it.
#define VTK_DEPRECATED_IN_9_6_0(reason)
int64_t hid_t
Definition: vtkHDFWriter.h:63
Common utility variables and functions for reader and writer of vtkHDF.
Definition: vtkHDFReader.h:69
vtkResourceStream implementation for memory input.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
VTKIOHDF_EXPORT std::vector< std::string > GetArrayNames(const std::array< hid_t, 3 > &attributeDataGroup, int attributeType)
Returns the names of arrays for 'attributeType' (point or cell).
const std::vector< std::string > POLY_DATA_TOPOS
VTKIOHDF_EXPORT vtkStringArray * NewStringArray(hid_t dataset, std::vector< hsize_t > dims, std::vector< hsize_t > fileExtent)
VTKIOHDF_EXPORT std::vector< std::string > GetOrderedChildrenOfGroup(hid_t groupID, const std::string &path)
Return the name of all children of an HDF group given its path.
VTKIOHDF_EXPORT std::array< vtkIdType, 2 > GetFieldArraySize(hid_t group, vtkIdType step, std::string name)
Return the field array size (components, tuples) for the HDF group.
VTKIOHDF_EXPORT void MakeObjectNameValid(std::string &objectName)
VTKIOHDF_EXPORT bool Open(const char *fileName, hid_t &fileID)
Open a VTK HDF file and checks if it is valid.
VTKIOHDF_EXPORT bool GetStringAttribute(hid_t groupID, const std::string &name, std::string &attribute)
Get string argument, variable or fixed size.
VTKIOHDF_EXPORT std::size_t GetNumberOfSteps(hid_t groupID)
Read the number of steps of an HDF group.
const std::string VTKHDF_ROOT_PATH
constexpr int GEOMETRY_ATTRIBUTE_TAG
VTKIOHDF_EXPORT vtkIdType GetArrayOffset(hid_t group, vtkIdType step, int attributeType, std::string name)
Methods to query for array offsets for the HDF group when steps are present.
VTKIOHDF_EXPORT vtkAbstractArray * NewFieldArray(const std::array< hid_t, 3 > &attributeDataGroup, const char *name, vtkIdType offset, vtkIdType size, vtkIdType dimMaxSize)
Reads and returns a new vtkAbstractArray.
#define VTK_DEPRECATED_IN_9_7_0(reason)
constexpr std::size_t NUM_POLY_DATA_TOPOS
VTKIOHDF_EXPORT bool RetrieveHDFInformation(hid_t &rootID, const std::string &rootName, const std::string &groupPrefix, hid_t &groupID, std::array< int, 2 > &version, int &dataSetType, int &numberOfPieces, std::map< int, hid_t > &attributeDataGroup)
Initialize meta information of the file.