VTK  9.6.20260112
vtkHDFReaderImplementation.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 vtkHDFReaderImplementation_h
10#define vtkHDFReaderImplementation_h
11
12#include "vtkHDFReader.h"
13#include "vtk_hdf5.h"
14#include <array>
15#include <map>
16#include <string>
17#include <vector>
18
19VTK_ABI_NAMESPACE_BEGIN
21class vtkBitArray;
22class vtkDataArray;
23class vtkDataAssembly;
26class vtkStringArray;
27
33{
34public:
36 virtual ~Implementation();
37
41 bool Open(VTK_FILEPATH const char* fileName);
42
46 bool Open(vtkResourceStream* stream);
47
51 void Close();
56 int GetDataSetType() { return this->DataSetType; }
60 vtkHDFReader* GetReader() { return this->Reader; }
64 const std::array<int, 2>& GetVersion() { return this->Version; }
68 template <typename T>
69 bool GetAttribute(const char* attributeName, size_t numberOfElements, T* value);
73 bool HasAttribute(const char* groupName, const char* attributeName);
77 bool HasDataset(const char* datasetName);
87 bool GetPartitionExtent(hsize_t partitionIndex, int* extent);
91 std::vector<std::string> GetArrayNames(int attributeType);
95 std::vector<std::string> GetOrderedChildrenOfGroup(const std::string& path);
97
106 int attributeType, const char* name, const std::vector<hsize_t>& fileExtent);
107 vtkDataArray* NewArray(int attributeType, const char* name, hsize_t offset, hsize_t size);
109 const char* name, vtkIdType offset = -1, vtkIdType size = -1, vtkIdType dimMaxSize = -1);
111
113
119 vtkDataArray* NewMetadataArray(const char* name, hsize_t offset, hsize_t size);
120 std::vector<vtkIdType> GetMetadata(const char* name, hsize_t size, hsize_t offset = 0);
122
125 std::vector<hsize_t> GetDimensions(const char* dataset);
126
130 bool IsPathSoftLink(const std::string& path);
131
133
138 bool FillAssembly(vtkDataAssembly* data, hid_t assemblyHandle, int assemblyID, std::string path);
140
144 std::size_t GetNumberOfSteps();
145
147
153
157 vtkIdType GetArrayOffset(vtkIdType step, int attributeType, std::string name);
158
164 std::array<vtkIdType, 2> GetFieldArraySize(vtkIdType step, std::string name);
165
169 bool OpenGroupAsVTKGroup(const std::string& groupPath);
170
174 bool RetrieveHDFInformation(const std::string& rootName);
175
180 bool GetImageAttributes(int WholeExtent[6], double Origin[3], double Spacing[3]);
181
183
189 bool ComputeAMRBlocksPerLevels(unsigned int maxLevel);
190
195 vtkDataArraySelection* dataArraySelection[3], vtkIdType step, unsigned int maxLevel);
196
200 bool ReadAMRTopology(vtkOverlappingAMR* data, unsigned int level, unsigned int maxLevel,
201 double origin[3], bool isTemporalData);
202
206 bool ReadAMRData(vtkOverlappingAMR* data, unsigned int level, unsigned int maxLevel,
207 vtkDataArraySelection* dataArraySelection[3], bool isTemporalData);
209
214 vtkSmartPointer<vtkDataObject> GetNewDataSet(int dataSetType, int numPieces);
215
222 vtkIdType cellOffset, vtkIdType treeIdsOffset, vtkIdType depthOffset,
223 vtkIdType descriptorOffset, vtkIdType maskOffset, vtkIdType partOffset,
224 vtkIdType verticesPerDepthOffset, vtkIdType depthLimit, vtkIdType step);
225
230
235
240 std::vector<vtkSmartPointer<vtkAbstractArray>>& cellArrays,
241 const vtkDataArraySelection* arraySelection, vtkIdType cellCount);
242
247 vtkIdType cellOffset, vtkIdType inputCellOffset, vtkIdType step, vtkIdType readableTreeSize);
248
253 vtkIdType maskOffset, vtkIdType readableTreeSize);
254
255private:
256 std::string FileName;
257 vtkResourceStream* Stream = nullptr;
258 vtkNew<vtkMemoryResourceStream> LocalMemStream;
259 hid_t File;
260 hid_t VTKGroup;
261 // in the same order as vtkDataObject::AttributeTypes: POINT, CELL, FIELD
262 std::array<hid_t, 3> AttributeDataGroup;
263 int DataSetType;
264 int NumberOfPieces;
265 std::array<int, 2> Version;
266 vtkHDFReader* Reader;
267
269
272 struct AMRBlocksInformation
273 {
274 std::vector<int> BlocksPerLevel;
275 std::vector<vtkIdType> BlockOffsetsPerLevel;
276 std::map<std::string, std::vector<vtkIdType>> CellOffsetsPerLevel;
277 std::map<std::string, std::vector<vtkIdType>> PointOffsetsPerLevel;
278 std::map<std::string, std::vector<vtkIdType>> FieldOffsetsPerLevel;
279 std::map<std::string, std::vector<vtkIdType>> FieldSizesPerLevel;
280
281 void Clear()
282 {
283 this->BlocksPerLevel.clear();
284 this->BlockOffsetsPerLevel.clear();
285 this->PointOffsetsPerLevel.clear();
286 this->CellOffsetsPerLevel.clear();
287 this->FieldOffsetsPerLevel.clear();
288 this->FieldSizesPerLevel.clear();
289 }
290 };
291
292 AMRBlocksInformation AMRInformation;
293
294 bool ReadLevelSpacing(hid_t levelGroupID, double* spacing);
295 bool ReadAMRBoxRawValues(
296 hid_t levelGroupID, std::vector<int>& amrBoxRawData, int level, bool isTemporalData);
297 bool ReadLevelTopology(unsigned int level, const std::string& levelGroupName,
298 vtkOverlappingAMR* data, double origin[3], bool isTemporalData);
299 bool ReadLevelData(unsigned int level, const std::string& levelGroupName, vtkOverlappingAMR* data,
300 vtkDataArraySelection* dataArraySelection[3], bool isTemporalData);
302};
303
304VTK_ABI_NAMESPACE_END
305#endif
306// VTK-HeaderTest-Exclude: vtkHDFReaderImplementation.h
Abstract superclass for all arrays.
dynamic, self-adjusting array of bits
Definition vtkBitArray.h:31
Store on/off settings for data arrays, etc.
hierarchical representation to use with vtkPartitionedDataSetCollection
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'.
bool HasDataset(const char *datasetName)
Return true if the dataset exists in the specified group root group.
bool OpenGroupAsVTKGroup(const std::string &groupPath)
Open a sub group of the current file and consider it as the new root file.
bool IsPathSoftLink(const std::string &path)
Return true if current root path is a soft link.
const std::array< int, 2 > & GetVersion()
Returns the version of the VTK HDF implementation.
Implementation(vtkHDFReader *reader)
vtkDataArray * NewArray(int attributeType, const char *name, const std::vector< hsize_t > &fileExtent)
Reads and returns a new vtkDataArray.
vtkIdType GetArrayOffset(vtkIdType step, int attributeType, std::string name)
Methods to query for array offsets when steps are present.
std::vector< hsize_t > GetDimensions(const char *dataset)
Returns the dimensions of a HDF dataset.
bool Open(vtkResourceStream *stream)
Opens this VTK HDF stream and checks if it is valid.
vtkSmartPointer< vtkDataObject > GetNewDataSet(int dataSetType, int numPieces)
Create a new dataset given its type and the number of pieces.
bool HasAttribute(const char *groupName, const char *attributeName)
Return true if the attribute exists in the specified group.
vtkHDFReader * GetReader()
Return the reader this impl is associated to.
vtkAbstractArray * NewFieldArray(const char *name, vtkIdType offset=-1, vtkIdType size=-1, vtkIdType dimMaxSize=-1)
Reads and returns a new vtkDataArray.
bool ComputeAMROffsetsPerLevels(vtkDataArraySelection *dataArraySelection[3], vtkIdType step, unsigned int maxLevel)
Retrieve offset for AMRBox, point/cell/field arrays for each level.
bool ReadHyperTreeGridMetaInfo(vtkHyperTreeGrid *htg)
Read HTG meta-information stored in attributes.
bool RetrieveHDFInformation(const std::string &rootName)
Initialize meta information of the implementation based on root name specified.
std::vector< std::string > GetArrayNames(int attributeType)
Returns the names of arrays for 'attributeType' (point or cell).
vtkDataArray * GetStepValues()
Read the values of the steps from the open file.
std::array< vtkIdType, 2 > GetFieldArraySize(vtkIdType step, std::string name)
Return the field array size (components, tuples) for the current step.
bool CreateHyperTreeGridCellArrays(vtkHyperTreeGrid *htg, std::vector< vtkSmartPointer< vtkAbstractArray > > &cellArrays, const vtkDataArraySelection *arraySelection, vtkIdType cellCount)
Initialize selected Cell arrays for HyperTreeGrid.
int GetDataSetType()
Type of vtkDataSet stored by the HDF file, such as VTK_IMAGE_DATA or VTK_UNSTRUCTURED_GRID,...
int GetNumberOfPieces(vtkIdType step=-1)
Returns the number of partitions for this dataset at the time step step if applicable.
bool ReadHyperTreeGridData(vtkHyperTreeGrid *htg, const vtkDataArraySelection *arraySelection, vtkIdType cellOffset, vtkIdType treeIdsOffset, vtkIdType depthOffset, vtkIdType descriptorOffset, vtkIdType maskOffset, vtkIdType partOffset, vtkIdType verticesPerDepthOffset, vtkIdType depthLimit, vtkIdType step)
Read data and build the HyperTreeGrid from descriptors, mask information and cell data array in the f...
bool FillAssembly(vtkDataAssembly *data)
Fills the given Assembly with the content of the opened HDF file.
vtkDataArray * GetStepValues(hid_t group)
Read the values of the steps from the open file.
bool ReadAMRData(vtkOverlappingAMR *data, unsigned int level, unsigned int maxLevel, vtkDataArraySelection *dataArraySelection[3], bool isTemporalData)
Read the AMR data based on offset on point/cell/field datas.
bool AppendCellDataForHyperTree(std::vector< vtkSmartPointer< vtkAbstractArray > > &cellArrays, vtkIdType cellOffset, vtkIdType inputCellOffset, vtkIdType step, vtkIdType readableTreeSize)
Read & add cell data for the tree currently processed.
void Close()
Closes the VTK HDF file and releases any allocated resources.
bool GetAttribute(const char *attributeName, size_t numberOfElements, T *value)
Reads an attribute from the /VTKHDF group.
bool ComputeAMRBlocksPerLevels(unsigned int maxLevel)
Specific public API for AMR support.
bool GetImageAttributes(int WholeExtent[6], double Origin[3], double Spacing[3])
Retrieve ImageData attributes and store them.
std::size_t GetNumberOfSteps()
Read the number of steps from the opened file.
bool ReadAMRTopology(vtkOverlappingAMR *data, unsigned int level, unsigned int maxLevel, double origin[3], bool isTemporalData)
Read the AMR topology based on offset data on AMRBlocks.
bool ReadHyperTreeGridDimensions(vtkHyperTreeGrid *htg)
Read HTG dimensions and coordinates.
bool FillAssembly(vtkDataAssembly *data, hid_t assemblyHandle, int assemblyID, std::string path)
Fills the given Assembly with the content of the opened HDF file.
bool AppendMaskForHyperTree(vtkHyperTreeGrid *htg, vtkIdType inputCellOffset, vtkIdType maskOffset, vtkIdType readableTreeSize)
Read & add mask data for the current tree.
std::vector< std::string > GetOrderedChildrenOfGroup(const std::string &path)
Return the name of all children of an HDF group given its path.
std::vector< vtkIdType > GetMetadata(const char *name, hsize_t size, hsize_t offset=0)
Reads a 1D metadata array in a DataArray or a vector of vtkIdType.
vtkDataArray * NewArray(int attributeType, const char *name, hsize_t offset, hsize_t size)
Reads and returns a new vtkDataArray.
bool Open(const char *fileName)
Opens this VTK HDF file and checks if it is valid.
A dataset containing a grid of vtkHyperTree instances arranged as a rectilinear grid.
vtkResourceStream implementation for memory input.
Allocate and hold a VTK object.
Definition vtkNew.h:167
a multi-resolution dataset based on vtkCartesianGrid allowing overlaps
Abstract class used for custom streams.
Hold a reference to a vtkObjectBase instance.
a vtkAbstractArray subclass for strings
#define vtkDataArray
int64_t hid_t
int vtkIdType
Definition vtkType.h:368
#define VTK_FILEPATH