VTK  9.6.20260304
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
8
9#ifndef vtkHDFUtilities_h
10#define vtkHDFUtilities_h
11
12#include "vtkDataArray.h"
13#include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_7_0 VTK_DEPRECATED_IN_9_6_0
14#include "vtkIOHDFModule.h" // For export macro
15#include "vtkStringArray.h"
16#include "vtkType.h"
17#include "vtk_hdf5.h"
18
19#include <array>
20#include <string>
21#include <vector>
22
23VTK_ABI_NAMESPACE_BEGIN
24
25#if VTK_ID_TYPE_IMPL == VTK_LONG_LONG
26#define VTK_ID_H5T H5T_NATIVE_LLONG
27#elif VTK_ID_TYPE_IMPL == VTK_LONG
28#define VTK_ID_H5T H5T_NATIVE_LONG
29#elif VTK_ID_TYPE_IMPL == VTK_INT
30#define VTK_ID_H5T H5T_NATIVE_INT
31#else
32#error "No HDF5 type available for vtkIdType"
33#endif
34
36
37namespace vtkHDFUtilities
38{
39const std::string VTKHDF_ROOT_PATH = "/VTKHDF";
40
41/*
42 * The number of PolyData topologies saved in vtkHDF format
43 */
44constexpr std::size_t NUM_POLY_DATA_TOPOS = 4;
45
46/*
47 * A vector of the topology names that are saved in vtkHDF
48 * Can be used for the name of the HDF group only
49 */
50const std::vector<std::string> POLY_DATA_TOPOS{ "Vertices", "Lines", "Polygons", "Strips" };
51
52/*
53 * Attribute tag used in the cache storage to indicate arrays related to the geometry of the data
54 * set and not fields of the data set
55 */
56constexpr int GEOMETRY_ATTRIBUTE_TAG = -42;
57
58/*
59 * How many attribute types we have. This returns 3: point, cell and field
60 * attribute types.
61 */
62constexpr static int GetNumberOfAttributeTypes()
63{
64 return 3;
65}
66
67/*
68 * How many attribute types we have as data array. This returns 2: point and cell.
69 */
70constexpr static int GetNumberOfDataArrayTypes()
71{
72 return 2;
73}
74
80bool ReadDataSetType(hid_t groupID, int& dataSetType);
81
82/*
83 * Make sure we replace any illegal characters in the objectName (slash, dot) by an underscore, as
84 * they would create a HDF5 subgroup.
85 */
86VTKIOHDF_EXPORT void MakeObjectNameValid(std::string& objectName);
87
88/*
89 * Returns the id to a HDF datatype (H5T) from a VTK datatype
90 * Returns H5I_INVALID_HID if no corresponding type is found
91 */
92VTKIOHDF_EXPORT hid_t getH5TypeFromVtkType(int dataType);
93
94/*
95 * @struct TemporalGeometryOffsets
96 * @brief Use to get the offsets for temporal vtkHDF.
97 *
98 * To use it, create an object using the templated constructor of this struct.
99 * It will fill the object with data that can be then retrieved.
100 */
101struct VTKIOHDF_EXPORT TemporalGeometryOffsets
102{
103public:
105
106 VTK_DEPRECATED_IN_9_6_0("Member is deprecated. Please use GetOffsets instead.")
107 bool Success = true;
108
113
114 // Polyhedron
118 bool HasPolyhedron = false;
119
120 template <class T>
121 bool GetOffsets(T* impl, vtkIdType step);
122};
123
124/*
125 * Offsets for temporalHyperTreeGrid
126 */
144
150VTK_DEPRECATED_IN_9_7_0("Deprecated. Please use the version with quiet arg.")
151VTKIOHDF_EXPORT bool Open(const char* fileName, hid_t& fileID);
152
157VTKIOHDF_EXPORT bool Open(const char* fileName, hid_t& fileID, bool quiet);
158
164VTK_DEPRECATED_IN_9_7_0("Deprecated. Please use the version with quiet arg.")
165VTKIOHDF_EXPORT bool Open(vtkMemoryResourceStream* stream, hid_t& fileImageID);
166
172VTKIOHDF_EXPORT bool Open(vtkMemoryResourceStream* stream, hid_t& fileImageID, bool quiet);
173
178template <typename T>
180
184template <typename T>
185VTKIOHDF_EXPORT bool GetAttribute(
186 hid_t group, const char* attributeName, size_t numberOfElements, T* value);
187
191bool GetStringAttribute(hid_t groupID, const std::string& name, std::string& attribute);
192
196VTKIOHDF_EXPORT std::size_t GetNumberOfSteps(hid_t groupID);
197
201VTKIOHDF_EXPORT std::vector<hsize_t> GetDimensions(hid_t fileID, const char* datasetName);
202
206VTK_DEPRECATED_IN_9_7_0("Deprecated. Please use the groupPrefix version instead.")
207VTKIOHDF_EXPORT
208bool RetrieveHDFInformation(hid_t& fileID, hid_t& groupID, const std::string& rootName,
209 std::array<int, 2>& version, int& dataSetType, int& numberOfPieces,
210 std::array<hid_t, 3>& attributeDataGroup);
211
226VTKIOHDF_EXPORT bool RetrieveHDFInformation(hid_t& rootID, const std::string& rootName,
227 const std::string& groupPrefix, hid_t& groupID, std::array<int, 2>& version, int& dataSetType,
228 int& numberOfPieces, std::array<hid_t, 3>& attributeDataGroup);
229
233VTKIOHDF_EXPORT herr_t FileInfoCallBack(
234 hid_t loc_id, const char* name, const H5L_info_t* info, void* opdata);
235
239VTKIOHDF_EXPORT std::vector<std::string> GetArrayNames(
240 const std::array<hid_t, 3>& attributeDataGroup, int attributeType);
241
245VTKIOHDF_EXPORT std::vector<std::string> GetOrderedChildrenOfGroup(
246 hid_t groupID, const std::string& path);
247
254VTKIOHDF_EXPORT hid_t OpenDataSet(
255 hid_t group, const char* name, hid_t* nativeType, std::vector<hsize_t>& dims);
256
258
270VTKIOHDF_EXPORT vtkDataArray* NewArrayForGroup(hid_t dataset, hid_t nativeType,
271 const std::vector<hsize_t>& dims, const std::vector<hsize_t>& parameterExtent);
273 hid_t group, const char* name, const std::vector<hsize_t>& parameterExtent);
275
282VTKIOHDF_EXPORT std::vector<vtkIdType> GetMetadata(
283 hid_t group, const char* name, hsize_t size, hsize_t offset);
284
290VTKIOHDF_EXPORT std::array<vtkIdType, 2> GetFieldArraySize(
291 hid_t group, vtkIdType step, std::string name);
292
296VTKIOHDF_EXPORT vtkIdType GetArrayOffset(
297 hid_t group, vtkIdType step, int attributeType, std::string name);
298
304VTKIOHDF_EXPORT vtkAbstractArray* NewFieldArray(const std::array<hid_t, 3>& attributeDataGroup,
305 const char* name, vtkIdType offset, vtkIdType size, vtkIdType dimMaxSize);
306
308 hid_t dataset, std::vector<hsize_t> dims, std::vector<hsize_t> fileExtent);
309}
310
311VTK_ABI_NAMESPACE_END
312#include "vtkHDFUtilities.txx" // for template implementations
313
314#endif
315// VTK-HeaderTest-Exclude: vtkHDFUtilities.h
Abstract superclass for all arrays.
vtkResourceStream implementation for memory input.
a vtkAbstractArray subclass for strings
Common utility variables and functions for reader and writer of vtkHDF.
VTKIOHDF_EXPORT bool RetrieveHDFInformation(hid_t &fileID, hid_t &groupID, const std::string &rootName, std::array< int, 2 > &version, int &dataSetType, int &numberOfPieces, std::array< hid_t, 3 > &attributeDataGroup)
Initialize meta information of the file.
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).
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'.
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...
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< 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.
const std::vector< std::string > POLY_DATA_TOPOS
constexpr std::size_t NUM_POLY_DATA_TOPOS
constexpr int GEOMETRY_ATTRIBUTE_TAG
bool GetStringAttribute(hid_t groupID, const std::string &name, std::string &attribute)
Get string argument, variable or fixed size.
VTKIOHDF_EXPORT vtkStringArray * NewStringArray(hid_t dataset, std::vector< hsize_t > dims, std::vector< hsize_t > fileExtent)
const std::string VTKHDF_ROOT_PATH
static constexpr int GetNumberOfAttributeTypes()
VTKIOHDF_EXPORT std::vector< hsize_t > GetDimensions(hid_t fileID, const char *datasetName)
Returns the dimensions of a HDF dataset of a file.
VTKIOHDF_EXPORT std::size_t GetNumberOfSteps(hid_t groupID)
Read the number of steps of an HDF group.
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 void MakeObjectNameValid(std::string &objectName)
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 bool GetAttribute(hid_t group, const char *attributeName, size_t numberOfElements, T *value)
Reads an attribute from the group passed to it.
VTKIOHDF_EXPORT bool Open(const char *fileName, hid_t &fileID)
Open a VTK HDF file and checks if it is valid.
static constexpr int GetNumberOfDataArrayTypes()
VTKIOHDF_EXPORT hid_t getH5TypeFromVtkType(int dataType)
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.
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 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 std::array< vtkIdType, 2 > GetFieldArraySize(hid_t group, vtkIdType step, std::string name)
Return the field array size (components, tuples) for the HDF group.
bool GetOffsets(T *impl, vtkIdType step)
std::vector< vtkIdType > ConnectivityOffsets
TemporalHyperTreeGridOffsets(T *impl, vtkIdType step)
#define vtkDataArray
#define VTK_DEPRECATED_IN_9_7_0(reason)
#define VTK_DEPRECATED_IN_9_6_0(reason)
int64_t hid_t
int vtkIdType
Definition vtkType.h:363