VTK  9.6.20260206
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 "vtkAMRBox.h"
13#include "vtkHDFReader.h"
14#include "vtk_hdf5.h"
15
16#include <array>
17#include <map>
18#include <string>
19#include <vector>
20
21VTK_ABI_NAMESPACE_BEGIN
23class vtkBitArray;
24class vtkDataArray;
25class vtkDataAssembly;
28class vtkStringArray;
29
35{
36public:
38 virtual ~Implementation();
39
43 bool Open(VTK_FILEPATH const char* fileName);
44
48 bool Open(vtkResourceStream* stream);
49
53 void Close();
58 int GetDataSetType() { return this->DataSetType; }
62 vtkHDFReader* GetReader() { return this->Reader; }
66 const std::array<int, 2>& GetVersion() { return this->Version; }
70 template <typename T>
71 bool GetAttribute(const char* attributeName, size_t numberOfElements, T* value);
75 bool HasAttribute(const char* groupName, const char* attributeName);
79 bool HasDataset(const char* datasetName);
89 bool GetPartitionExtent(hsize_t partitionIndex, int* extent);
93 std::vector<std::string> GetArrayNames(int attributeType);
97 std::vector<std::string> GetOrderedChildrenOfGroup(const std::string& path);
99
108 int attributeType, const char* name, const std::vector<hsize_t>& fileExtent);
109 vtkDataArray* NewArray(int attributeType, const char* name, hsize_t offset, hsize_t size);
111 const char* name, vtkIdType offset = -1, vtkIdType size = -1, vtkIdType dimMaxSize = -1);
113
115
121 vtkDataArray* NewMetadataArray(const char* name, hsize_t offset, hsize_t size);
122 std::vector<vtkIdType> GetMetadata(const char* name, hsize_t size, hsize_t offset = 0);
124
127 std::vector<hsize_t> GetDimensions(const char* dataset);
128
132 bool IsPathSoftLink(const std::string& path);
133
135
140 bool FillAssembly(vtkDataAssembly* data, hid_t assemblyHandle, int assemblyID, std::string path);
142
146 std::size_t GetNumberOfSteps();
147
149
155
159 vtkIdType GetArrayOffset(vtkIdType step, int attributeType, std::string name);
160
166 std::array<vtkIdType, 2> GetFieldArraySize(vtkIdType step, std::string name);
167
171 bool OpenGroupAsVTKGroup(const std::string& groupPath);
172
176 bool RetrieveHDFInformation(const std::string& rootName, const std::string& groupPrefix = "");
177
182 bool GetImageAttributes(int WholeExtent[6], double Origin[3], double Spacing[3]);
183
185
191 unsigned int GetAMRNumberOfLevels();
192
198 bool ComputeAMRBlocksPerLevels(unsigned int nLevels);
199
206 vtkDataArraySelection* dataArraySelection[3], vtkIdType step, unsigned int nLevels);
207
211 bool ReadAMRTopology(vtkOverlappingAMR* data, double origin[3], bool isTemporalData);
212
218 unsigned int level, int attributeType, const std::string& name, hsize_t& offset);
220
225 vtkSmartPointer<vtkDataObject> GetNewDataSet(int dataSetType, int numPieces);
226
233 vtkIdType cellOffset, vtkIdType treeIdsOffset, vtkIdType depthOffset,
234 vtkIdType descriptorOffset, vtkIdType maskOffset, vtkIdType partOffset,
235 vtkIdType verticesPerDepthOffset, vtkIdType depthLimit, vtkIdType step);
236
241
246
251 std::vector<vtkSmartPointer<vtkAbstractArray>>& cellArrays,
252 const vtkDataArraySelection* arraySelection, vtkIdType cellCount);
253
258 vtkIdType cellOffset, vtkIdType inputCellOffset, vtkIdType step, vtkIdType readableTreeSize);
259
264 vtkIdType maskOffset, vtkIdType readableTreeSize);
265
266private:
267 std::string FileName;
268 vtkResourceStream* Stream = nullptr;
269 vtkNew<vtkMemoryResourceStream> LocalMemStream;
270 hid_t File;
271 hid_t VTKGroup;
272 // in the same order as vtkDataObject::AttributeTypes: POINT, CELL, FIELD
273 std::array<hid_t, 3> AttributeDataGroup;
274 int DataSetType;
275 int NumberOfPieces;
276 std::array<int, 2> Version;
277 vtkHDFReader* Reader;
278
280
283 struct AMRBlocksInformation
284 {
285 std::vector<int> BlocksPerLevel;
286 std::vector<vtkIdType> BlockOffsetsPerLevel;
287 std::map<std::string, std::vector<vtkIdType>> CellOffsetsPerLevel;
288 std::map<std::string, std::vector<vtkIdType>> PointOffsetsPerLevel;
289
290 void Clear()
291 {
292 this->BlocksPerLevel.clear();
293 this->BlockOffsetsPerLevel.clear();
294 this->PointOffsetsPerLevel.clear();
295 this->CellOffsetsPerLevel.clear();
296 }
297 };
298
299 AMRBlocksInformation AMRInformation;
300
301 bool ReadLevelSpacing(hid_t levelGroupID, double* spacing);
302 bool ReadAMRBoxRawValues(
303 hid_t levelGroupID, std::vector<int>& amrBoxRawData, int level, bool isTemporalData);
304 bool ReadLevelTopology(unsigned int level, const std::string& levelGroupName,
305 vtkOverlappingAMR* data, double origin[3], bool isTemporalData);
307};
308
309VTK_ABI_NAMESPACE_END
310#endif
311// 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.
unsigned int GetAMRNumberOfLevels()
Specific public API for AMR support.
Implementation(vtkHDFReader *reader)
bool GetAMRTemporalOffsetForAttributeType(unsigned int level, int attributeType, const std::string &name, hsize_t &offset)
Get the temporal offset for a specific attribute Return true if the offset arg was set,...
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 ReadHyperTreeGridMetaInfo(vtkHyperTreeGrid *htg)
Read HTG meta-information stored in attributes.
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 AppendCellDataForHyperTree(std::vector< vtkSmartPointer< vtkAbstractArray > > &cellArrays, vtkIdType cellOffset, vtkIdType inputCellOffset, vtkIdType step, vtkIdType readableTreeSize)
Read & add cell data for the tree currently processed.
bool ReadAMRTopology(vtkOverlappingAMR *data, double origin[3], bool isTemporalData)
Read the AMR topology based on offset data on AMRBlocks.
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 RetrieveHDFInformation(const std::string &rootName, const std::string &groupPrefix="")
Initialize meta information of the implementation based on root name specified.
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 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 ComputeAMROffsetsPerLevels(vtkDataArraySelection *dataArraySelection[3], vtkIdType step, unsigned int nLevels)
Retrieve offset for AMRBox, point/cell/field arrays for each level.
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 ComputeAMRBlocksPerLevels(unsigned int nLevels)
Retrieve for each required level AMRBlocks size and position.
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:354
#define VTK_FILEPATH