Skip to content

(io): serialize most objects

Didier WECKMANN requested to merge 739-io-serialize-most-objects into dev

Description

The serialization is done through two classes: SessionSerializer, SessionsDeserializer, and many .hpp with two functions: serialize() and deserialize, depending of the type of data object to serialize.

For exemple, the serializers for meshes and images are coded respectively in Mesh.hpp and Image.hpp. They are good samples to demonstrate how it is possible to use a well known format to serialize objects. The Sight images / meshes are converted into VTK format using Sight helpers and are then saved with the now "standard" VTK way using vtkXMLImageDataWriter for image and vtkXMLPolyDataWriter for meshes.

As a side notes, since the files are stored in a zstd compressed zip file, and since VTK doesn't provide any way to use an output streams, the VTK writers are configured as such (image and mesh are equivalent):

vtkWriter->SetCompressorTypeToNone();
vtkWriter->SetDataModeToBinary();
vtkWriter->WriteToOutputStringOn();
vtkWriter->SetInputData(vtkImage);

This allow us to compress only one time and use fast zstd. Since the compression level can be set independently, some test need to be done to find the best efficiency. For now it is the "default" mode that is used, but better compression ratio at the expense of compression speed (not decompression!) is also possible.

The drawback for using WriteToOutputStringOn() is that the complete data need to be written in memory before being able to serialize it. Shame on VTK for not providing an easy way to use c++ streams...

Most serializers are far more simple as we only write/read values into a Boost property tree, a bit like before, but without the complexity of "atoms" tree. The version management is also quite simple, we write a integer in the tree and read it back. It is up to the user to add the if(version < 666)...

Closes #739 (closed)

Edited by Didier WECKMANN

Merge request reports