VTK  9.7.1
vtkHDFWriterImplementation.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
10 #ifndef vtkHDFWriterImplementation_h
11 #define vtkHDFWriterImplementation_h
12 
13 #include "vtkAbstractArray.h"
14 #include "vtkCellArray.h"
15 #include "vtkHDF5ScopedHandle.h"
16 #include "vtkHDFWriter.h"
17 #include "vtkType.h"
18 #include "vtk_hdf5.h"
19 
20 #include <array>
21 #include <string>
22 
23 VTK_ABI_NAMESPACE_BEGIN
24 
26 {
27 public:
28  hid_t GetRoot() { return this->Root; }
29  hid_t GetFile() { return this->File; }
30  hid_t GetStepsGroup(hid_t currentGroup);
31 
38  bool WriteHeader(hid_t group, const char* hdfType);
39 
47  bool CreateFile(bool overwrite, const std::string& filename);
48 
53  bool OpenFile();
54 
60  void CloseFile();
61 
67  bool OpenSubfile(const std::string& filename);
68 
70 
75  void SetSubFilesReady(bool status) { this->SubFilesReady = status; }
76  bool GetSubFilesReady() { return this->SubFilesReady; }
78 
82  bool CreateStepsGroup(hid_t group);
83 
90  typedef struct
91  {
92  const char* hdfGroupName;
94  } PolyDataTopos;
95 
99  std::vector<PolyDataTopos> GetCellArraysForTopos(vtkPolyData* polydata);
100 
101  // Creation utility functions
102 
107  vtkHDF::ScopedH5DHandle CreateAndWriteHdfDataset(hid_t group, hid_t type, hid_t source_type,
108  const char* name, int rank, std::vector<hsize_t> dimensions, const void* data);
109 
115  vtkHDF::ScopedH5SHandle CreateSimpleDataspace(int rank, const hsize_t dimensions[]);
116 
121  vtkHDF::ScopedH5AHandle CreateScalarAttribute(hid_t group, const char* name, int value);
122 
128  vtkHDF::ScopedH5AHandle CreateVectorAttribute(
129  hid_t group, const char* name, hid_t type, hsize_t size, const void* data);
130 
135  vtkHDF::ScopedH5AHandle CreateStringAttribute(
136  hid_t group, const char* name, const std::string& value);
137 
142  vtkHDF::ScopedH5GHandle CreateHdfGroup(hid_t group, const char* name);
143 
148  vtkHDF::ScopedH5GHandle CreateHdfGroupWithLinkOrder(hid_t group, const char* name);
149 
154  bool CreateSoftLink(hid_t group, const char* groupName, const char* targetLink);
155 
160  bool CreateExternalLink(
161  hid_t group, const char* filename, const char* source, const char* targetLink);
162 
166  vtkHDF::ScopedH5GHandle OpenExistingGroup(hid_t group, const char* name);
167 
171  vtkHDF::ScopedH5DHandle OpenDataset(hid_t group, const char* name);
172 
177 
182  vtkHDF::ScopedH5DHandle CreateHdfDataset(
183  hid_t group, const char* name, hid_t type, hid_t dataspace);
184 
190  vtkHDF::ScopedH5DHandle CreateHdfDataset(
191  hid_t group, const char* name, hid_t type, int rank, const hsize_t dimensions[]);
192 
200  bool CreateVirtualDataset(hid_t group, const char* name, hid_t type, int numComp);
201 
203 
210  bool WriteSumSteps(hid_t group, const char* name);
211  bool WriteSumStepsPolyData(hid_t group, const char* name);
213 
219  vtkHDF::ScopedH5SHandle CreateDataspaceFromArray(
220  vtkAbstractArray* dataArray, const std::vector<hsize_t>& dims = {});
221 
227  vtkHDF::ScopedH5DHandle CreateDatasetFromDataArray(hid_t group, const char* name, hid_t type,
228  vtkAbstractArray* dataArray, const std::vector<hsize_t>& dims = {});
229 
231 
235  vtkHDF::ScopedH5DHandle CreateSingleRowDataset(
236  hid_t group, const char* name, const std::vector<vtkIdType>& values);
238 
244  bool InitDynamicDataset(hid_t group, const char* name, hid_t type, hsize_t cols,
245  hsize_t chunkSize[], int compressionLevel = 0);
246 
252  bool InitDynamicDataset(hid_t group, const char* name, hid_t type,
253  const std::vector<hsize_t>& dims, hsize_t chunkSize[], int compressionLevel = 0);
254 
262  hid_t dataset, const std::vector<vtkIdType>& value, bool offset, bool trim = false);
263 
269 
278  bool AddArrayToDataset(hid_t dataset, vtkAbstractArray* dataArray, int trim = 0,
279  const std::vector<hsize_t>& dims = {});
280 
287  bool AddOrCreateDataset(hid_t group, const char* name, hid_t type, vtkAbstractArray* dataArray,
288  const std::vector<hsize_t>& dims = {});
289 
297  bool AddOrCreateSingleRowDataset(hid_t group, const char* name,
298  const std::vector<vtkIdType>& value, bool offset = false, bool trim = false);
299 
308  hid_t group, const char* name, vtkIdType* value, vtkIdType size, bool offset = false);
309 
313  vtkHDF::ScopedH5GHandle GetSubfileNonNullPart(const std::string& blockPath, int& type);
314 
321 
322  Implementation(vtkHDFWriter* writer);
323  virtual ~Implementation();
324 
325 private:
326  vtkHDFWriter* Writer;
327  vtkHDF::ScopedH5FHandle File;
328  vtkHDF::ScopedH5GHandle Root;
329  vtkHDF::ScopedH5GHandle StepsGroup;
330  std::vector<vtkHDF::ScopedH5FHandle> Subfiles;
331  std::vector<std::string> SubfileNames;
332  bool SubFilesReady = false;
333 
334  const std::array<std::string, 4> PrimitiveNames = { { "Vertices", "Lines", "Polygons",
335  "Strips" } };
336 
341  hsize_t GetNumberOfCellsSubfile(const std::string& basePath, std::size_t subfileId, hsize_t part,
342  bool isPolyData, const std::string& groupName);
343 
349  char GetPrimitive(hid_t group);
350 
358  hsize_t GetSubfileNumberOf(const std::string& base, const std::string& qualifier,
359  std::size_t subfileId, hsize_t part, char primitive = 0xff);
360 
361  std::string GetBasePath(const std::string& fullPath);
362 
366  bool DatasetAndGroupExist(const std::string& dataset, hid_t group);
367 
373  bool GetSubFilesDatasetSize(
374  const std::string& datasetPath, const std::string& groupName, hsize_t& totalSize);
375 
376  // Possible indexing mode of VTKHDF datasets. See `GetDatasetIndexationMode`
377  enum class IndexingMode
378  {
379  Points,
380  Cells,
381  Connectivity,
382  TreeDepths,
383  Trees,
384  Descriptor,
385  HTGCoords,
386  MetaData,
387  Undefined
388  };
389 
397  IndexingMode GetDatasetIndexationMode(const std::string& path);
398 };
399 
400 VTK_ABI_NAMESPACE_END
401 #endif
402 // VTK-HeaderTest-Exclude: vtkHDFWriterImplementation.h
bool CreateFile(bool overwrite, const std::string &filename)
Create the file from the filename and create the root VTKHDF group.
bool AddOrCreateFieldDataSizeValueDataset(hid_t group, const char *name, vtkIdType *value, vtkIdType size, bool offset=false)
Append a 2D integer value to the dataset with name FieldDataSize.
hid_t GetStepsGroup(hid_t currentGroup)
vtkHDF::ScopedH5AHandle CreateVectorAttribute(hid_t group, const char *name, hid_t type, hsize_t size, const void *data)
Create a vector attribute (1D array) with arbitrary type and size in the given group.
vtkHDF::ScopedH5AHandle CreateStringAttribute(hid_t group, const char *name, const std::string &value)
Create a string attribute in the given group.
void CreateArraysFromNonNullPart(hid_t group, vtkDataObject *data)
Initialize empty data object array structures from a base group.
vtkHDF::ScopedH5DHandle CreateSingleRowDataset(hid_t group, const char *name, const std::vector< vtkIdType > &values)
Creates a dataset and write a row of values to it.
Abstract superclass for all arrays.
vtkHDF::ScopedH5GHandle CreateHdfGroupWithLinkOrder(hid_t group, const char *name)
Retrieve or create a group that keeps track of link creation order Returned scoped handle may be inva...
bool GetSubFilesReady()
Inform the implementation that all the data has been written in subfiles, and that the virtual datase...
int vtkIdType
Definition: vtkType.h:363
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:71
Stores a group name and the corresponding cell array.
bool AddOrCreateSingleRowDataset(hid_t group, const char *name, const std::vector< vtkIdType > &value, bool offset=false, bool trim=false)
Append a single row of integer values to the dataset with name name in group group.
vtkHDF::ScopedH5GHandle CreateHdfGroup(hid_t group, const char *name)
Retrieve group if it exists, create it if needed.
bool AddFieldDataSizeValueToDataset(hid_t dataset, vtkIdType *value, vtkIdType size, bool offset)
Add a 2D value of integer type to an existing dataspace which represents the FieldDataSize.
void SetSubFilesReady(bool status)
Inform the implementation that all the data has been written in subfiles, and that the virtual datase...
bool AddSingleRowToDataset(hid_t dataset, const std::vector< vtkIdType > &value, bool offset, bool trim=false)
Add a single row of integer type to an existing dataspace.
void CloseFile()
Close currently handled file, open using CreateFile or OpenFile.
int64_t hid_t
Definition: vtkHDFWriter.h:63
vtkHDF::ScopedH5DHandle CreateHdfDataset(hid_t group, const char *name, hid_t type, hid_t dataspace)
Create a dataset in the given group from a dataspace Returned scoped handle may be invalid...
vtkHDF::ScopedH5SHandle CreateDataspaceFromArray(vtkAbstractArray *dataArray, const std::vector< hsize_t > &dims={})
Creates a dataspace to the exact array dimensions dims provides the dimensions of the structured data...
bool InitDynamicDataset(hid_t group, const char *name, hid_t type, hsize_t cols, hsize_t chunkSize[], int compressionLevel=0)
Create a chunked dataset with an empty extendable dataspace using chunking and set the desired level ...
vtkHDF::ScopedH5GHandle GetSubfileNonNullPart(const std::string &blockPath, int &type)
Find the first non null part for the given path in all subfiles.
vtkHDF::ScopedH5DHandle OpenDataset(hid_t group, const char *name)
Open and return an existing dataset using its group id and dataset name.
vtkHDF::ScopedH5SHandle CreateSimpleDataspace(int rank, const hsize_t dimensions[])
Create a HDF dataspace It is simple (not scalar or null) which means that it is an array of elements ...
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
vtkHDF::ScopedH5DHandle CreateDatasetFromDataArray(hid_t group, const char *name, hid_t type, vtkAbstractArray *dataArray, const std::vector< hsize_t > &dims={})
Creates a dataset in the given group from a dataArray and write data to it dims provides the dimensio...
bool CreateExternalLink(hid_t group, const char *filename, const char *source, const char *targetLink)
Create an external link to the real group containing the block dataset.
Implementation(vtkHDFWriter *writer)
vtkHDF::ScopedH5AHandle CreateScalarAttribute(hid_t group, const char *name, int value)
Create a scalar integer attribute in the given group.
bool WriteSumStepsPolyData(hid_t group, const char *name)
For temporal multi-piece meta-files, write the dataset name in group group, which must be the "steps"...
bool CreateVirtualDataset(hid_t group, const char *name, hid_t type, int numComp)
Create a virtual dataset from all the subfiles that have been added.
object to represent cell connectivity
Definition: vtkCellArray.h:177
bool WriteHeader(hid_t group, const char *hdfType)
Write version and type attributes to the root group A root must be open for the operation to succeed ...
std::string GetGroupName(hid_t group)
Return the name of a group given its id.
bool OpenFile()
Open existing VTKHDF file and set Root and File members.
bool AddArrayToDataset(hid_t dataset, vtkAbstractArray *dataArray, int trim=0, const std::vector< hsize_t > &dims={})
Append a full data array at the end of an existing infinite dataspace.
bool CreateStepsGroup(hid_t group)
Create the steps group in the given group.
bool CreateSoftLink(hid_t group, const char *groupName, const char *targetLink)
Create a soft link to the real group containing the block dataset.
vtkHDF::ScopedH5DHandle CreateAndWriteHdfDataset(hid_t group, hid_t type, hid_t source_type, const char *name, int rank, std::vector< hsize_t > dimensions, const void *data)
Create a dataset in the given group with the given parameters and write data to it Returned scoped ha...
bool AddOrCreateDataset(hid_t group, const char *name, hid_t type, vtkAbstractArray *dataArray, const std::vector< hsize_t > &dims={})
Append the given array to the dataset with the given name, creating it if it does not exist yet...
Write a data object to a VTKHDF file.
Definition: vtkHDFWriter.h:67
vtkHDF::ScopedH5GHandle OpenExistingGroup(hid_t group, const char *name)
Open and return an existing group thanks to id and a relative or absolute path to this group...
general representation of visualization data
Definition: vtkDataObject.h:55
std::vector< PolyDataTopos > GetCellArraysForTopos(vtkPolyData *polydata)
Get the cell array for the POLY_DATA_TOPOS.
bool OpenSubfile(const std::string &filename)
Open subfile where data has already been written, and needs to be referenced by the main file using v...
bool WriteSumSteps(hid_t group, const char *name)
For temporal multi-piece meta-files, write the dataset name in group group, which must be the "steps"...