Skip to content

Serialization support for VTK objects

Auto generate ser-des code

Auto generate (de)serialization code in C++ for classes annotated by the VTK_MARSHALAUTO wrapping hint.

VTK implements custom (de)serialization functions for some classes that do not trivially serialize with the property parser. VTK_MARSHALMANUAL is used for classes with hand-written serialization code.

These three are the important handlers:

  1. A serializer function

    nlohmann:json Serialize_vtkClassName(vtkObjectBase*, vtkSerializer*)
  2. A deserializer function

    void Deserialize_vtkClassName(const nlohmann::json&, vtkObjectBase*, vtkDeserializer*)
  3. A registrar function

    int RegisterHandlers_vtkClassNameSerDes(void* ser, void* deser)

    that registers:

    • a serializer function with a serializer instance
    • a deserializer function with a deserializer instance
    • a constructor of the VTK class with a deserializer instance

Marshallable classes derived from vtkObjectBase are serialized into json format using the vtkObjectManager class. An object is represented with a unique integer identifier.

Object manager

Serialization

You can register objects with a vtkObjectManager instance and call UpdateStatesFromObjects, GetState(identifier) to obtain a serialized state of the registered objects and all their dependency objects that are serializable.

Deserialization

You can register a json state (stringified) with a vtkObjectManager instance and call UpdateObjectsFromStates, GetObjectAtId(identifier) to deserialize and retrieve the objects.

Blobs

All vtkDataArray are hashed and stored as unique blobs to prevent multiple copies of the same data within the state. The contents of a data array within a state are represented with a hash string. You can fetch and register blobs using GetBlob and RegisterBlob.

Dependencies

You can retrieve all dependent object identifiers using vtkObjectManager::GetAllDependencies(identifier)

Edited by Jaswant Panchumarti (Kitware)

Merge request reports