VTK  9.3.20240916
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 "vtkHDFUtilities.h"
17#include "vtkHDFWriter.h"
18
19#include <array>
20#include <string>
21
22VTK_ABI_NAMESPACE_BEGIN
23
25{
26public:
27 hid_t GetRoot() { return this->Root; }
28 hid_t GetFile() { return this->File; }
29 hid_t GetStepsGroup() { return this->StepsGroup; }
30
37 bool WriteHeader(hid_t group, const char* hdfType);
38
46 bool CreateFile(bool overwrite, const std::string& filename);
47
52 bool OpenFile();
53
59 void CloseFile();
60
66 bool OpenSubfile(const std::string& filename);
67
69
74 void SetSubFilesReady(bool status) { this->SubFilesReady = status; }
75 bool GetSubFilesReady() { return this->SubFilesReady; }
77
83
90 typedef struct
91 {
92 const char* hdfGroupName;
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::ScopedH5SHandle CreateUnlimitedSimpleDataspace(hsize_t numCols);
129
134 vtkHDF::ScopedH5GHandle CreateHdfGroup(hid_t group, const char* name);
135
140 vtkHDF::ScopedH5GHandle CreateHdfGroupWithLinkOrder(hid_t group, const char* name);
141
145 herr_t CreateSoftLink(hid_t group, const char* groupName, const char* targetLink);
146
151 hid_t group, const char* filename, const char* source, const char* targetLink);
152
156 vtkHDF::ScopedH5GHandle OpenExistingGroup(hid_t group, const char* name);
157
161 vtkHDF::ScopedH5DHandle OpenDataset(hid_t group, const char* name);
162
166 std::string GetGroupName(hid_t group);
167
172 vtkHDF::ScopedH5DHandle CreateHdfDataset(
173 hid_t group, const char* name, hid_t type, hid_t dataspace);
174
180 vtkHDF::ScopedH5DHandle CreateHdfDataset(
181 hid_t group, const char* name, hid_t type, int rank, const hsize_t dimensions[]);
182
189 vtkHDF::ScopedH5DHandle CreateVirtualDataset(
190 hid_t group, const char* name, hid_t type, int numComp);
191
193
200 bool WriteSumSteps(hid_t group, const char* name);
201 bool WriteSumStepsPolyData(hid_t group, const char* name);
203
209 vtkHDF::ScopedH5DHandle CreateChunkedHdfDataset(hid_t group, const char* name, hid_t type,
210 hid_t dataspace, hsize_t numCols, hsize_t chunkSize[], int compressionLevel = 0);
211
216 vtkHDF::ScopedH5SHandle CreateDataspaceFromArray(vtkAbstractArray* dataArray);
217
222 vtkHDF::ScopedH5DHandle CreateDatasetFromDataArray(
223 hid_t group, const char* name, hid_t type, vtkAbstractArray* dataArray);
224
226
230 vtkHDF::ScopedH5DHandle CreateSingleValueDataset(hid_t group, const char* name, int value);
231 vtkHDF::ScopedH5DHandle Create2DValueDataset(hid_t group, const char* name, int* value, int size);
233
239 bool InitDynamicDataset(hid_t group, const char* name, hid_t type, hsize_t cols,
240 hsize_t chunkSize[], int compressionLevel = 0);
241
248 bool AddSingleValueToDataset(hid_t dataset, int value, bool offset, bool trim = false);
249
254 bool AddFieldDataSizeValueToDataset(hid_t dataset, int* value, int size, bool offset);
255
264 bool AddArrayToDataset(hid_t dataset, vtkAbstractArray* dataArray, int trim = 0);
265
271 bool AddOrCreateDataset(hid_t group, const char* name, hid_t type, vtkAbstractArray* dataArray);
272
281 hid_t group, const char* name, int value, bool offset = false, bool trim = false);
282
291 hid_t group, const char* name, int* value, int size, bool offset = false);
292
295
296private:
297 vtkHDFWriter* Writer;
298 vtkHDF::ScopedH5FHandle File;
299 vtkHDF::ScopedH5GHandle Root;
300 vtkHDF::ScopedH5GHandle StepsGroup;
301 std::vector<vtkHDF::ScopedH5FHandle> Subfiles;
302 std::vector<std::string> SubfileNames;
303 std::string HdfType;
304 bool SubFilesReady = false;
305
306 const std::array<std::string, 4> PrimitiveNames = { { "Vertices", "Lines", "Polygons",
307 "Strips" } };
308
313 hsize_t GetNumberOfCellsSubfile(
314 std::size_t subfileId, hsize_t part, bool isPolyData, const std::string& groupName);
315
321 char GetPrimitive(hid_t group);
322
330 hsize_t GetSubfileNumberOf(
331 const std::string& name, std::size_t subfileId, hsize_t part, char primitive = -1);
332
338 bool GetSubFilesDatasetSize(const char* datasetPath, const char* groupName, hsize_t& totalSize);
339
340 // Possible indexing mode of VTKHDF datasets. See `GetDatasetIndexationMode`
341 enum class IndexingMode
342 {
343 Points,
344 Cells,
345 Connectivity,
346 MetaData,
347 Undefined
348 };
349
357 IndexingMode GetDatasetIndexationMode(hid_t group, const char* name);
358};
359
360VTK_ABI_NAMESPACE_END
361#endif
362// VTK-HeaderTest-Exclude: vtkHDFWriterImplementation.h
Abstract superclass for all arrays.
object to represent cell connectivity
vtkHDF::ScopedH5DHandle CreateSingleValueDataset(hid_t group, const char *name, int value)
Creates a dataset and write a value to it.
bool AddOrCreateDataset(hid_t group, const char *name, hid_t type, vtkAbstractArray *dataArray)
Append the given array to the dataset with the given name, creating it if it does not exist yet.
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.
vtkHDF::ScopedH5GHandle CreateHdfGroup(hid_t group, const char *name)
Create a group in the given group from a dataspace.
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...
vtkHDF::ScopedH5DHandle CreateDatasetFromDataArray(hid_t group, const char *name, hid_t type, vtkAbstractArray *dataArray)
Creates a dataset in the given group from a dataArray and write data to it Returned scoped handle may...
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)
Create a group that keeps track of link creation order Returned scoped handle may be invalid.
bool AddOrCreateSingleValueDataset(hid_t group, const char *name, int value, bool offset=false, bool trim=false)
Append a single integer value to the dataset with name name in group group.
vtkHDF::ScopedH5DHandle CreateVirtualDataset(hid_t group, const char *name, hid_t type, int numComp)
Create a virtual dataset from all the subfiles that have been added.
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.
bool OpenFile()
Open existing VTKHDF file and set Root and File members.
vtkHDF::ScopedH5DHandle CreateHdfDataset(hid_t group, const char *name, hid_t type, int rank, const hsize_t dimensions[])
Create a dataset in the given group It internally creates a dataspace from a rank and dimensions Retu...
vtkHDF::ScopedH5SHandle CreateDataspaceFromArray(vtkAbstractArray *dataArray)
Creates a dataspace to the exact array dimensions Returned scoped handle may be invalid.
bool AddOrCreateFieldDataSizeValueDataset(hid_t group, const char *name, int *value, int size, bool offset=false)
Append a 2D integer value to the dataset with name FieldDataSize.
Implementation(vtkHDFWriter *writer)
vtkHDF::ScopedH5DHandle Create2DValueDataset(hid_t group, const char *name, int *value, int size)
Creates a dataset and write a value to it.
herr_t CreateExternalLink(hid_t group, const char *filename, const char *source, const char *targetLink)
Create an external link to the real group containing the block datatset.
bool CreateStepsGroup()
Create the steps group in the root group.
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 ...
bool AddFieldDataSizeValueToDataset(hid_t dataset, int *value, int size, bool offset)
Add a 2D value of integer type to an existing dataspace which represents the FieldDataSize.
bool AddArrayToDataset(hid_t dataset, vtkAbstractArray *dataArray, int trim=0)
Append a full data array at the end of an existing infinite dataspace.
vtkHDF::ScopedH5DHandle CreateChunkedHdfDataset(hid_t group, const char *name, hid_t type, hid_t dataspace, hsize_t numCols, hsize_t chunkSize[], int compressionLevel=0)
Create a chunked dataset in the given group from a dataspace.
bool AddSingleValueToDataset(hid_t dataset, int value, bool offset, bool trim=false)
Add a single value of integer type to an existing dataspace.
void CloseFile()
Close currently handled file, open using CreateFile or OpenFile.
vtkHDF::ScopedH5SHandle CreateUnlimitedSimpleDataspace(hsize_t numCols)
Create an unlimited HDF dataspace with a dimension of 0 * numCols.
std::vector< PolyDataTopos > GetCellArraysForTopos(vtkPolyData *polydata)
Get the cell array for the POLY_DATA_TOPOS.
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.
herr_t CreateSoftLink(hid_t group, const char *groupName, const char *targetLink)
Create a soft link to the real group containing the block datatset.
void SetSubFilesReady(bool status)
Inform the implementation that all the data has been written in subfiles, and that the virtual datase...
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 ...
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 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 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"...
Writes input dataset to a VTKHDF file.
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 *)
int64_t hid_t