VTK  9.3.20240919
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 "vtkHDF5ScopedHandle.h"
14#include "vtkIOHDFModule.h" // For export macro
15#include "vtkLogger.h"
16#include "vtkPolyData.h"
17#include "vtkSmartPointer.h"
18#include "vtkStringArray.h"
19#include "vtkType.h"
20
21#include <array>
22#include <string>
23#include <vector>
24
25VTK_ABI_NAMESPACE_BEGIN
26
27namespace vtkHDFUtilities
28{
29const std::string VTKHDF_ROOT_PATH = "/VTKHDF";
30
31/*
32 * The number of PolyData topologies saved in vtkHDF format
33 */
34constexpr std::size_t NUM_POLY_DATA_TOPOS = 4;
35
36/*
37 * A vector of the topology names that are saved in vtkHDF
38 * Can be used for the name of the HDF group only
39 */
40const std::vector<std::string> POLY_DATA_TOPOS{ "Vertices", "Lines", "Polygons", "Strips" };
41
42/*
43 * Attribute tag used in the cache storage to indicate arrays related to the geometry of the data
44 * set and not fields of the data set
45 */
46constexpr int GEOMETRY_ATTRIBUTE_TAG = -42;
47
48/*
49 * How many attribute types we have. This returns 3: point, cell and field
50 * attribute types.
51 */
52constexpr static int GetNumberOfAttributeTypes()
53{
54 return 3;
55}
56
57/*
58 * How many attribute types we have as data array. This returns 2: point and cell.
59 */
60constexpr static int GetNumberOfDataArrayTypes()
61{
62 return 2;
63}
64
65/*
66 * Make sure we replace any illegal characters in the objectName (slash, dot) by an underscore, as
67 * they would create a HDF5 subgroup.
68 */
69VTKIOHDF_EXPORT void MakeObjectNameValid(std::string& objectName);
70
71/*
72 * Returns the id to a HDF datatype (H5T) from a VTK datatype
73 * Returns H5I_INVALID_HID if no corresponding type is found
74 */
75VTKIOHDF_EXPORT hid_t getH5TypeFromVtkType(int dataType);
76
77VTK_DEPRECATED_IN_9_4_0("Please use TemporalGeometryOffsets struct instead.")
78struct VTKIOHDF_EXPORT TransientGeometryOffsets
79{
80public:
81 bool Success = true;
82 vtkIdType PartOffset = 0;
83 vtkIdType PointOffset = 0;
84 std::vector<vtkIdType> CellOffsets;
85 std::vector<vtkIdType> ConnectivityOffsets;
86
87 template <class T>
89};
90
91/*
92 * @struct TemporalGeometryOffsets
93 * @brief Use to get the offsets for temporal vtkHDF.
94 *
95 * To use it, create an object using the templated constructor of this struct.
96 * It will fill the object with data that can be then retrieved.
97 */
98struct VTKIOHDF_EXPORT TemporalGeometryOffsets
99{
100public:
101 bool Success = true;
102 vtkIdType PartOffset = 0;
103 vtkIdType PointOffset = 0;
104 std::vector<vtkIdType> CellOffsets;
105 std::vector<vtkIdType> ConnectivityOffsets;
106
107 template <class T>
109};
110
115VTKIOHDF_EXPORT bool Open(const char* fileName, hid_t& fileID);
116
121template <typename T>
123
127template <typename T>
128VTKIOHDF_EXPORT bool GetAttribute(
129 hid_t group, const char* attributeName, size_t numberOfElements, T* value);
130
134VTKIOHDF_EXPORT std::size_t GetNumberOfSteps(hid_t groupID);
135
139VTKIOHDF_EXPORT std::vector<hsize_t> GetDimensions(hid_t fileID, const char* datasetName);
140
144VTKIOHDF_EXPORT bool RetrieveHDFInformation(hid_t& fileID, hid_t& groupID,
145 const std::string& rootName, std::array<int, 2>& version, int& dataSetType, int& numberOfPieces,
146 std::array<hid_t, 3>& attributeDataGroup);
147
151VTKIOHDF_EXPORT herr_t FileInfoCallBack(
152 hid_t loc_id, const char* name, const H5L_info_t* info, void* opdata);
153
157VTKIOHDF_EXPORT std::vector<std::string> GetArrayNames(
158 const std::array<hid_t, 3>& attributeDataGroup, int attributeType);
159
163VTKIOHDF_EXPORT std::vector<std::string> GetOrderedChildrenOfGroup(
164 hid_t groupID, const std::string& path);
165
172VTKIOHDF_EXPORT hid_t OpenDataSet(
173 hid_t group, const char* name, hid_t* nativeType, std::vector<hsize_t>& dims);
174
176
188VTKIOHDF_EXPORT vtkDataArray* NewArrayForGroup(hid_t dataset, hid_t nativeType,
189 const std::vector<hsize_t>& dims, const std::vector<hsize_t>& parameterExtent);
191 hid_t group, const char* name, const std::vector<hsize_t>& parameterExtent);
193
200VTKIOHDF_EXPORT std::vector<vtkIdType> GetMetadata(
201 hid_t group, const char* name, hsize_t size, hsize_t offset);
202
208VTKIOHDF_EXPORT std::array<vtkIdType, 2> GetFieldArraySize(
209 hid_t group, vtkIdType step, std::string name);
210
214VTKIOHDF_EXPORT vtkIdType GetArrayOffset(
215 hid_t group, vtkIdType step, int attributeType, std::string name);
216
222VTKIOHDF_EXPORT vtkAbstractArray* NewFieldArray(const std::array<hid_t, 3>& attributeDataGroup,
223 const char* name, vtkIdType offset, vtkIdType size, vtkIdType dimMaxSize);
224
226 hid_t dataset, std::vector<hsize_t> dims, std::vector<hsize_t> fileExtent);
227}
228
229VTK_ABI_NAMESPACE_END
230#include "vtkHDFUtilities.txx" // for template implementations
231
232#endif
233// VTK-HeaderTest-Exclude: vtkHDFUtilities.h
Abstract superclass for all arrays.
abstract superclass for arrays of numeric data
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
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.
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.
TemporalGeometryOffsets(T *impl, vtkIdType step)
std::vector< vtkIdType > ConnectivityOffsets
std::vector< vtkIdType > ConnectivityOffsets
TransientGeometryOffsets(T *impl, vtkIdType step)
#define VTK_DEPRECATED_IN_9_4_0(reason)
int64_t hid_t
int vtkIdType
Definition vtkType.h:315