VTK  9.7.20260726
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
9
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
23VTK_ABI_NAMESPACE_BEGIN
24
26{
27public:
28 hid_t GetRoot() { return this->Root; }
29 hid_t GetFile() { return this->File; }
30 hid_t GetStepsGroup(hid_t currentGroup);
31
32 void SetChunkSize(int chunkSize) { this->ChunkSize = chunkSize; };
33 void SetCompressionLevel(int level) { this->CompressionLevel = level; };
34
41 bool WriteHeader(hid_t group, const char* hdfType);
42
50 bool CreateFile(bool overwrite, const std::string& filename);
51
56 bool OpenFile();
57
63 void CloseFile();
64
70 bool OpenSubfile(const std::string& filename);
71
73
78 void SetSubFilesReady(bool status) { this->SubFilesReady = status; }
79 bool GetSubFilesReady() { return this->SubFilesReady; }
81
86
93 typedef struct
94 {
95 const char* hdfGroupName;
98
102 std::vector<PolyDataTopos> GetCellArraysForTopos(vtkPolyData* polydata);
103
104 // Creation utility functions
105
110 vtkHDF::ScopedH5DHandle CreateAndWriteHdfDataset(hid_t group, hid_t type, hid_t source_type,
111 const char* name, const std::vector<hsize_t>& dimensions, const void* data);
112
118 vtkHDF::ScopedH5SHandle CreateSimpleDataspace(const std::vector<hsize_t>& dimensions);
119
124 vtkHDF::ScopedH5AHandle CreateScalarAttribute(hid_t group, const char* name, int value);
125
131 vtkHDF::ScopedH5AHandle CreateVectorAttribute(
132 hid_t group, const char* name, hid_t type, hsize_t size, const void* data);
133
138 vtkHDF::ScopedH5AHandle CreateStringAttribute(
139 hid_t group, const char* name, const std::string& value);
140
145 vtkHDF::ScopedH5GHandle CreateHdfGroup(hid_t group, const char* name);
146
151 vtkHDF::ScopedH5GHandle CreateHdfGroupWithLinkOrder(hid_t group, const char* name);
152
157 bool CreateSoftLink(hid_t group, const char* groupName, const char* targetLink);
158
164 hid_t group, const char* filename, const char* source, const char* targetLink);
165
169 vtkHDF::ScopedH5GHandle OpenExistingGroup(hid_t group, const char* name);
170
174 vtkHDF::ScopedH5DHandle OpenDataset(hid_t group, const char* name);
175
181 hsize_t GetDataSetSize(hid_t group, const char* name);
182
186 std::string GetGroupName(hid_t group);
187
192 vtkHDF::ScopedH5DHandle CreateHdfDataset(
193 hid_t group, const char* name, hid_t type, hid_t dataspace);
194
200 vtkHDF::ScopedH5DHandle CreateHdfDataset(
201 hid_t group, const char* name, hid_t type, const std::vector<hsize_t>& dimensions);
202
210 bool CreateVirtualDataset(hid_t group, const char* name, hid_t type, int numComp);
211
213
220 bool WriteSumSteps(hid_t group, const char* name);
221 bool WriteSumStepsPolyData(hid_t group, const char* name);
223
229 vtkHDF::ScopedH5SHandle CreateDataspaceFromArray(
230 vtkAbstractArray* dataArray, const std::vector<hsize_t>& dims = {});
231
237 vtkHDF::ScopedH5DHandle CreateDatasetFromDataArray(hid_t group, const char* name, hid_t type,
238 vtkAbstractArray* dataArray, const std::vector<hsize_t>& dims = {});
239
244 vtkHDF::ScopedH5DHandle CreateSingleRowDataset(
245 hid_t group, const char* name, const std::vector<vtkIdType>& values);
246
248
253 hid_t group, const char* name, hid_t type, hsize_t cols, const std::vector<hsize_t>& chunkSize);
254 bool InitDynamicDataset(hid_t group, const char* name, hid_t type,
255 const std::vector<hsize_t>& dims, const std::vector<hsize_t>& chunkSize);
257
265 hid_t dataset, const std::vector<vtkIdType>& value, bool offset, bool trim = false);
266
271 bool AddFieldDataSizeValueToDataset(hid_t dataset, vtkIdType* value, vtkIdType size, bool offset);
272
281 bool AddArrayToDataset(hid_t dataset, vtkAbstractArray* dataArray, int trim = 0,
282 const std::vector<hsize_t>& dims = {});
283
290 bool AddOrCreateDataset(hid_t group, const char* name, hid_t type, vtkAbstractArray* dataArray,
291 const std::vector<hsize_t>& dims = {});
292
300 bool AddOrCreateSingleRowDataset(hid_t group, const char* name,
301 const std::vector<vtkIdType>& value, bool offset = false, bool trim = false);
302
311 hid_t group, const char* name, vtkIdType* value, vtkIdType size, bool offset = false);
312
316 vtkHDF::ScopedH5GHandle GetSubfileNonNullPart(const std::string& blockPath, int& type);
317
324
325 Implementation(vtkHDFWriter* writer);
327
328private:
329 vtkHDFWriter* Writer;
330 vtkHDF::ScopedH5FHandle File;
331 vtkHDF::ScopedH5GHandle Root;
332 vtkHDF::ScopedH5GHandle StepsGroup;
333 std::vector<vtkHDF::ScopedH5FHandle> Subfiles;
334 std::vector<std::string> SubfileNames;
335 bool SubFilesReady = false;
336
337 // Forwarded constant properties from the writer
338 int ChunkSize = 25000;
339 int CompressionLevel = 0;
340
341 const std::array<std::string, 4> PrimitiveNames = { { "Vertices", "Lines", "Polygons",
342 "Strips" } };
343
348 hsize_t GetNumberOfCellsSubfile(const std::string& basePath, std::size_t subfileId, hsize_t part,
349 bool isPolyData, const std::string& groupName);
350
356 char GetPrimitive(hid_t group);
357
365 hsize_t GetSubfileNumberOf(const std::string& base, const std::string& qualifier,
366 std::size_t subfileId, hsize_t part, char primitive = 0xff);
367
368 std::string GetBasePath(const std::string& fullPath);
369
373 bool DatasetAndGroupExist(const std::string& dataset, hid_t group);
374
380 bool GetSubFilesDatasetSize(
381 const std::string& datasetPath, const std::string& groupName, hsize_t& totalSize);
382
383 // Possible indexing mode of VTKHDF datasets. See `GetDatasetIndexationMode`
384 enum class IndexingMode
385 {
386 Points,
387 Cells,
388 Connectivity,
389 TreeDepths,
390 Trees,
391 Descriptor,
392 HTGCoords,
393 MetaData,
394 Undefined
395 };
396
404 IndexingMode GetDatasetIndexationMode(const std::string& path);
405};
406
407VTK_ABI_NAMESPACE_END
408#endif
409// VTK-HeaderTest-Exclude: vtkHDFWriterImplementation.h
Abstract superclass for all arrays.
object to represent cell connectivity
general representation of visualization data
bool GetSubFilesReady()
Inform the implementation that all the data has been written in subfiles, and that the virtual datase...
vtkHDF::ScopedH5AHandle CreateScalarAttribute(hid_t group, const char *name, int value)
Create a scalar integer attribute in the given group.
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.
vtkHDF::ScopedH5DHandle CreateHdfDataset(hid_t group, const char *name, hid_t type, const std::vector< hsize_t > &dimensions)
Create a dataset in the given group It internally creates a dataspace from a rank and dimensions Retu...
vtkHDF::ScopedH5GHandle CreateHdfGroup(hid_t group, const char *name)
Retrieve group if it exists, create it if needed.
hid_t GetStepsGroup(hid_t currentGroup)
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.
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"...
bool CreateFile(bool overwrite, const std::string &filename)
Create the file from the filename and create the root VTKHDF group.
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...
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...
vtkHDF::ScopedH5DHandle OpenDataset(hid_t group, const char *name)
Open and return an existing dataset using its group id and dataset name.
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.
hsize_t GetDataSetSize(hid_t group, const char *name)
Get size of 1D dataset.
bool OpenFile()
Open existing VTKHDF file and set Root and File members.
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, const std::vector< hsize_t > &chunkSize)
Create a chunked dataset with an empty extendable dataspace using chunking Return true if the operati...
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.
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.
Implementation(vtkHDFWriter *writer)
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.
bool CreateSoftLink(hid_t group, const char *groupName, const char *targetLink)
Create a soft link to the real group containing the block dataset.
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.
void CreateArraysFromNonNullPart(hid_t group, vtkDataObject *data)
Initialize empty data object array structures from a base group.
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.
void CloseFile()
Close currently handled file, open using CreateFile or OpenFile.
vtkHDF::ScopedH5GHandle GetSubfileNonNullPart(const std::string &blockPath, int &type)
Find the first non null part for the given path in all subfiles.
vtkHDF::ScopedH5DHandle CreateAndWriteHdfDataset(hid_t group, hid_t type, hid_t source_type, const char *name, const 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...
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.
std::vector< PolyDataTopos > GetCellArraysForTopos(vtkPolyData *polydata)
Get the cell array for the POLY_DATA_TOPOS.
bool CreateStepsGroup(hid_t group)
Create the steps group in the given group.
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.
void SetSubFilesReady(bool status)
Inform the implementation that all the data has been written in subfiles, and that the virtual datase...
bool InitDynamicDataset(hid_t group, const char *name, hid_t type, const std::vector< hsize_t > &dims, const std::vector< hsize_t > &chunkSize)
Create a chunked dataset with an empty extendable dataspace using chunking Return true if the operati...
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.
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.
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...
vtkHDF::ScopedH5SHandle CreateSimpleDataspace(const std::vector< hsize_t > &dimensions)
Create a HDF dataspace It is simple (not scalar or null) which means that it is an array of elements ...
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.
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"...
concrete dataset represents vertices, lines, polygons, and triangle strips
Stores a group name and the corresponding cell array.
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
@ Cells
A cell specified by degrees of freedom held in arrays.
int64_t hid_t
int vtkIdType
Definition vtkType.h:363