VTK  9.7.1
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
9 #ifndef vtkHDFReaderImplementation_h
10 #define vtkHDFReaderImplementation_h
11 
12 #include "vtkAMRBox.h"
13 #include "vtkDataSetAttributes.h"
14 #include "vtkHDFReader.h"
15 #include "vtk_hdf5.h"
16 
17 #include <array>
18 #include <map>
19 #include <string>
20 #include <vector>
21 
22 VTK_ABI_NAMESPACE_BEGIN
23 class vtkAbstractArray;
24 class vtkBitArray;
25 class vtkDataArray;
26 class vtkDataAssembly;
28 class vtkResourceStream;
29 class vtkStringArray;
30 
36 {
37 public:
39  virtual ~Implementation();
40 
44  bool Open(VTK_FILEPATH const char* fileName, bool quiet = false);
45 
49  bool Open(vtkResourceStream* stream, bool quiet = false);
50 
54  void Close();
55 
59  void CloseMemberGroups();
60 
65  int GetDataSetType() { return this->DataSetType; }
69  vtkHDFReader* GetReader() { return this->Reader; }
73  const std::array<int, 2>& GetVersion() { return this->Version; }
77  template <typename T>
78  bool GetAttribute(const char* attributeName, size_t numberOfElements, T* value);
82  bool HasAttribute(const char* groupName, const char* attributeName);
86  bool HasDataset(const char* datasetName);
91  int GetNumberOfPieces(vtkIdType step = -1);
96  bool GetPartitionExtent(hsize_t partitionIndex, int* extent);
100  std::vector<std::string> GetArrayNames(int attributeType);
104  std::vector<std::string> GetOrderedChildrenOfGroup(const std::string& path);
106 
115  int attributeType, const char* name, const std::vector<hsize_t>& fileExtent);
116  vtkDataArray* NewArray(int attributeType, const char* name, hsize_t offset, hsize_t size);
118  const char* name, vtkIdType offset = -1, vtkIdType size = -1, vtkIdType dimMaxSize = -1);
120 
127  int attributeType, vtkDataArray* array, vtkDataSetAttributes* attributes);
128 
130 
136  vtkDataArray* NewMetadataArray(const char* name, const std::vector<hsize_t>& fileExtent);
137  vtkDataArray* NewMetadataArray(const char* name, hsize_t offset, hsize_t size);
138  std::vector<vtkIdType> GetMetadata(const char* name, hsize_t size, hsize_t offset = 0);
140 
143  std::vector<hsize_t> GetDimensions(const char* dataset);
144 
148  bool IsPathSoftLink(const std::string& path);
149 
151 
156  bool FillAssembly(vtkDataAssembly* data, hid_t assemblyHandle, int assemblyID, std::string path);
158 
162  std::size_t GetNumberOfSteps();
163 
165 
171 
175  vtkIdType GetArrayOffset(vtkIdType step, int attributeType, std::string name);
176 
182 
188  std::array<vtkIdType, 2> GetFieldArraySize(vtkIdType step, std::string name);
189 
193  bool OpenGroupAsVTKGroup(const std::string& groupPath);
194 
198  bool RetrieveHDFInformation(const std::string& rootName, const std::string& groupPrefix = "");
199 
204  bool GetImageAttributes(int WholeExtent[6], double Origin[3], double Spacing[3]);
205 
210  bool GetDimensionsAttribute(int Dimensions[3]);
211 
213 
217  unsigned int GetAMRNumberOfLevels();
218 
224  bool ComputeAMRBlocksPerLevels(unsigned int nLevels);
225 
231  bool ComputeAMROffsetsPerLevels(const std::map<int, vtkDataArraySelection*>& dataArraySelection,
232  vtkIdType step, unsigned int nLevels);
233 
237  bool ReadAMRTopology(
238  vtkOverlappingAMR* data, unsigned int maxLevel, double origin[3], bool isTemporalData);
239 
245  unsigned int level, int attributeType, const std::string& name, hsize_t& offset);
247 
252  vtkSmartPointer<vtkDataObject> GetNewDataSet(int dataSetType, int numPieces);
253 
259  bool ReadHyperTreeGridData(vtkHyperTreeGrid* htg, const vtkDataArraySelection* arraySelection,
260  vtkIdType cellOffset, vtkIdType treeIdsOffset, vtkIdType depthOffset,
261  vtkIdType descriptorOffset, vtkIdType maskOffset, vtkIdType partOffset,
262  vtkIdType verticesPerDepthOffset, vtkIdType XCoordsOffset, vtkIdType YCoordsOffset,
263  vtkIdType ZCoordsOffset, vtkIdType depthLimit, vtkIdType step);
264 
269 
273  bool ReadHyperTreeGridDimensions(vtkHyperTreeGrid* htg, vtkIdType XCoordsOffset,
274  vtkIdType YCoordsOffset, vtkIdType ZCoordsOffset);
275 
281  const vtkDataArraySelection* arraySelection, vtkIdType cellCount);
282 
287  vtkIdType cellOffset, vtkIdType inputCellOffset, vtkIdType step, vtkIdType readableTreeSize);
288 
292  bool AppendMaskForHyperTree(vtkHyperTreeGrid* htg, vtkIdType inputCellOffset,
293  vtkIdType maskOffset, vtkIdType readableTreeSize);
294 
295 private:
296  std::string FileName;
297  vtkResourceStream* Stream = nullptr;
298  vtkNew<vtkMemoryResourceStream> LocalMemStream;
299  hid_t File;
300  hid_t VTKGroup;
301  // in the same order as vtkDataObject::AttributeTypes: POINT, CELL, FIELD
302  std::map<int, hid_t> AttributeDataGroup;
303  int DataSetType;
304  int NumberOfPieces;
305  std::array<int, 2> Version;
306  vtkHDFReader* Reader;
307 
309 
312  struct AMRBlocksInformation
313  {
314  std::vector<int> BlocksPerLevel;
315  std::vector<vtkIdType> BlockOffsetsPerLevel;
316  std::map<std::string, std::vector<vtkIdType>> CellOffsetsPerLevel;
317  std::map<std::string, std::vector<vtkIdType>> PointOffsetsPerLevel;
318 
319  void Clear()
320  {
321  this->BlocksPerLevel.clear();
322  this->BlockOffsetsPerLevel.clear();
323  this->PointOffsetsPerLevel.clear();
324  this->CellOffsetsPerLevel.clear();
325  }
326  };
327 
328  AMRBlocksInformation AMRInformation;
329 
330  bool ReadLevelSpacing(hid_t levelGroupID, double* spacing);
331  bool ReadAMRBoxRawValues(
332  hid_t levelGroupID, std::vector<int>& amrBoxRawData, int level, bool isTemporalData);
333  bool ReadLevelTopology(unsigned int level, const std::string& levelGroupName,
334  vtkOverlappingAMR* data, double origin[3], bool isTemporalData);
336 };
337 
338 VTK_ABI_NAMESPACE_END
339 #endif
340 // VTK-HeaderTest-Exclude: vtkHDFReaderImplementation.h
void AttachDatasetAttributeToArray(int attributeType, vtkDataArray *array, vtkDataSetAttributes *attributes)
Given a named data array and an attribute type, read from the file the special array attribute (scala...
unsigned int GetAMRNumberOfLevels()
Specific public API for AMR support.
std::vector< std::string > GetArrayNames(int attributeType)
Returns the names of arrays for 'attributeType' (point or cell).
bool IsPathSoftLink(const std::string &path)
Return true if current root path is a soft link.
Abstract class used for custom streams.
void Close()
Closes the VTK HDF file and releases any allocated resources.
Read VTK HDF files.
Definition: vtkHDFReader.h:75
std::array< vtkIdType, 2 > GetFieldArraySize(vtkIdType step, std::string name)
Return the field array size (components, tuples) for the current step.
Abstract superclass for all arrays.
bool ReadHyperTreeGridDimensions(vtkHyperTreeGrid *htg, vtkIdType XCoordsOffset, vtkIdType YCoordsOffset, vtkIdType ZCoordsOffset)
Read HTG dimensions and coordinates.
vtkAbstractArray * NewFieldArray(const char *name, vtkIdType offset=-1, vtkIdType size=-1, vtkIdType dimMaxSize=-1)
Reads and returns a new vtkDataArray.
const std::array< int, 2 > & GetVersion()
Returns the version of the VTK HDF implementation.
A dataset containing a grid of vtkHyperTree instances arranged as a rectilinear grid.
Implementation for the vtkHDFReader.
bool FillAssembly(vtkDataAssembly *data)
Fills the given Assembly with the content of the opened HDF file.
vtkDataArray * NewArray(int attributeType, const char *name, const std::vector< hsize_t > &fileExtent)
Reads and returns a new vtkDataArray.
a vtkAbstractArray subclass for strings
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.
int vtkIdType
Definition: vtkType.h:363
Implementation(vtkHDFReader *reader)
vtkDataArray * NewMetadataArray(const char *name, const std::vector< hsize_t > &fileExtent)
Reads a 1D metadata array in a DataArray or a vector of vtkIdType.
vtkIdType GetArrayOffset(vtkIdType step, int attributeType, std::string name)
Methods to query for array offsets when steps are present.
bool HasAttribute(const char *groupName, const char *attributeName)
Return true if the attribute exists in the specified group.
int GetDataSetType()
Type of vtkDataSet stored by the HDF file, such as VTK_IMAGE_DATA or VTK_UNSTRUCTURED_GRID, from vtkTypes.h.
bool HasDataset(const char *datasetName)
Return true if the dataset exists in the specified group root group.
std::size_t GetNumberOfSteps()
Read the number of steps from the opened file.
int GetNumberOfPieces(vtkIdType step=-1)
Returns the number of partitions for this dataset at the time step step if applicable.
static const unsigned int numberOfElements
bool OpenGroupAsVTKGroup(const std::string &groupPath)
Open a sub group of the current file and consider it as the new root file.
bool ComputeAMROffsetsPerLevels(const std::map< int, vtkDataArraySelection * > &dataArraySelection, vtkIdType step, unsigned int nLevels)
Retrieve offset for AMRBox, point/cell/field arrays for each level.
int64_t hid_t
Definition: vtkHDFWriter.h:63
bool GetPartitionExtent(hsize_t partitionIndex, int *extent)
For an ImageData, sets the extent for 'partitionIndex'.
bool CreateHyperTreeGridCellArrays(vtkHyperTreeGrid *htg, std::vector< vtkSmartPointer< vtkAbstractArray >> &cellArrays, const vtkDataArraySelection *arraySelection, vtkIdType cellCount)
Initialize selected Cell arrays for HyperTreeGrid.
bool ReadHyperTreeGridData(vtkHyperTreeGrid *htg, const vtkDataArraySelection *arraySelection, vtkIdType cellOffset, vtkIdType treeIdsOffset, vtkIdType depthOffset, vtkIdType descriptorOffset, vtkIdType maskOffset, vtkIdType partOffset, vtkIdType verticesPerDepthOffset, vtkIdType XCoordsOffset, vtkIdType YCoordsOffset, vtkIdType ZCoordsOffset, vtkIdType depthLimit, vtkIdType step)
Read data and build the HyperTreeGrid from descriptors, mask information and cell data array in the f...
bool ReadHyperTreeGridMetaInfo(vtkHyperTreeGrid *htg)
Read HTG meta-information stored in attributes.
bool GetImageAttributes(int WholeExtent[6], double Origin[3], double Spacing[3])
Retrieve ImageData attributes and store them.
Store on/off settings for data arrays, etc.
vtkResourceStream implementation for memory input.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
represent and manipulate attribute data in a dataset
bool RetrieveHDFInformation(const std::string &rootName, const std::string &groupPrefix="")
Initialize meta information of the implementation based on root name specified.
bool GetDimensionsAttribute(int Dimensions[3])
Retrieve the dimensions attribute and store it (used by StructuredGrid and RectilinearGrid).
vtkIdType GetTemporalOffset(vtkIdType step, const std::string &name)
Get temporal offset value for the given time step of the data.
#define VTK_FILEPATH
dynamic, self-adjusting array of bits
Definition: vtkBitArray.h:32
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...
bool GetAttribute(const char *attributeName, size_t numberOfElements, T *value)
Reads an attribute from the /VTKHDF group.
bool ComputeAMRBlocksPerLevels(unsigned int nLevels)
Retrieve for each required level AMRBlocks size and position.
void CloseMemberGroups()
Close HDF5 groups stored as class members.
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, unsigned int maxLevel, double origin[3], bool isTemporalData)
Read the AMR topology based on offset data on AMRBlocks.
a multi-resolution dataset based on vtkCartesianGrid allowing overlaps
hierarchical representation to use with vtkPartitionedDataSetCollection
bool AppendMaskForHyperTree(vtkHyperTreeGrid *htg, vtkIdType inputCellOffset, vtkIdType maskOffset, vtkIdType readableTreeSize)
Read & add mask data for the current tree.
vtkDataArray * GetStepValues()
Read the values of the steps from the open file.
vtkSmartPointer< vtkDataObject > GetNewDataSet(int dataSetType, int numPieces)
Create a new dataset given its type and the number of pieces.
std::vector< hsize_t > GetDimensions(const char *dataset)
Returns the dimensions of a HDF dataset.
vtkHDFReader * GetReader()
Return the reader this impl is associated to.
std::vector< std::string > GetOrderedChildrenOfGroup(const std::string &path)
Return the name of all children of an HDF group given its path.
bool Open(const char *fileName, bool quiet=false)
Opens this VTK HDF file and checks if it is valid.