VTK  9.6.20260311
vtkObjectManager.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
19#ifndef vtkObjectManager_h
20#define vtkObjectManager_h
21
22#include "vtkObject.h"
23
24#include "vtkSerializationManagerModule.h" // for export macro
25
26#include "vtkDeserializer.h" // for vtkDeserializer
27#include "vtkInvoker.h" // for vtkInvoker
28#include "vtkLogger.h" // for vtkLogger::Verbosity enum
29#include "vtkNew.h" // for vtkNew
30#include "vtkSerializer.h" // for vtkSerializer
31#include "vtkSession.h" // for vtkSessionObjectManagerRegistrarFunc
32#include "vtkSmartPointer.h" // for vtkSmartPointer
33#include "vtkTypeUInt32Array.h" // for vtkTypeUInt32Array
34
35#include <string> // for string
36#include <vector> // for vector
37
38VTK_ABI_NAMESPACE_BEGIN
40class vtkTypeUInt8Array;
41
42class VTKSERIALIZATIONMANAGER_EXPORT vtkObjectManager : public vtkObject
43{
44public:
47 void PrintSelf(ostream& os, vtkIndent indent) override;
48
50
53 virtual bool Initialize();
56
61 const std::vector<vtkSessionObjectManagerRegistrarFunc>& registrars);
63 const vtkSessionObjectManagerRegistrarFunc* registrars, std::size_t count);
64
70
75 bool UnRegisterObject(vtkTypeUInt32 identifier);
76
78
84 bool RegisterState(const std::string& state);
85 bool RegisterState(const nlohmann::json& state);
87
91 bool UnRegisterState(vtkTypeUInt32 identifier);
92
98 vtkTypeUInt32 GetId(vtkSmartPointer<vtkObjectBase> objectBase);
99
105 std::string GetState(vtkTypeUInt32 id);
106
112
114
122 std::vector<vtkTypeUInt32> GetAllDependencies(vtkTypeUInt32 identifier);
125
130 std::vector<std::string> GetBlobHashes(const std::vector<vtkTypeUInt32>& ids);
131
138 vtkSmartPointer<vtkTypeUInt8Array> GetBlob(const std::string& hash, bool copy = false) const;
139
144 bool RegisterBlob(const std::string& hash, vtkSmartPointer<vtkTypeUInt8Array> blob);
145
149 bool UnRegisterBlob(const std::string& hash);
150
156
161
166
176 void UpdateStatesFromObjects(const std::vector<vtkTypeUInt32>& identifiers);
177
179
182 bool UpdateObjectFromState(const std::string& state);
183 bool UpdateObjectFromState(const nlohmann::json& state);
185
189 void UpdateStateFromObject(vtkTypeUInt32 identifier);
190
197 void Clear();
198
199 std::string Invoke(
200 vtkTypeUInt32 identifier, const std::string& methodName, const std::string& args);
201 nlohmann::json Invoke(
202 vtkTypeUInt32 identifier, const std::string& methodName, const nlohmann::json& args);
203
206
211 void Export(const std::string& filename, int indentLevel = -1, char indentChar = ' ');
212
218 void Import(const std::string& stateFileName, const std::string& blobFileName);
219
225
230 std::vector<vtkSmartPointer<vtkObjectBase>> ImportFromBytes(
232
237
242
243 static vtkTypeUInt32 ROOT() { return 0; }
244
245 vtkGetSmartPointerMacro(Serializer, vtkSerializer);
246 vtkGetSmartPointerMacro(Deserializer, vtkDeserializer);
247 vtkGetSmartPointerMacro(Invoker, vtkInvoker);
248
250
265
266protected:
269
275
276 static const char* OWNERSHIP_KEY() { return "manager"; }
277
278private:
279 vtkObjectManager(const vtkObjectManager&) = delete;
280 void operator=(const vtkObjectManager&) = delete;
281
282 std::vector<vtkTypeUInt32> ImportFromJSON(const nlohmann::json& json);
283};
284VTK_ABI_NAMESPACE_END
285#endif
Deserialize VTK objects from JSON.
a simple class to control print indentation
Definition vtkIndent.h:108
Deserialize VTK objects from JSON.
Definition vtkInvoker.h:31
@ VERBOSITY_INVALID
Definition vtkLogger.h:214
Shared context used by vtkSerializer and vtkDeserializer
Allocate and hold a VTK object.
Definition vtkNew.h:167
vtkObjectManager maintains internal instances of vtkSerializer and a vtkDeserializer to serialize and...
void Import(const std::string &stateFileName, const std::string &blobFileName)
Reads state from state file and blobs from blob file.
bool InitializeDefaultHandlers()
Loads the default (de)serialization handlers and constructors for VTK classes.
vtkSmartPointer< vtkUnsignedCharArray > ExportToBytes()
Exports the states and blobs to a vtkUnsignedCharArray.
bool RegisterState(const std::string &state)
Adds state into an internal container and returns a unique identifier.
bool UnRegisterObject(vtkTypeUInt32 identifier)
Removes an object and it's state.
vtkLogger::Verbosity ObjectManagerLogVerbosity
vtkNew< vtkInvoker > Invoker
vtkNew< vtkDeserializer > Deserializer
void UpdateStatesFromObjects()
Serialize registered objects into states.
bool UnRegisterBlob(const std::string &hash)
Removes a blob stored at hash.
vtkSmartPointer< vtkObjectBase > GetObjectAtId(vtkTypeUInt32 id)
Get object at id.
void UpdateStatesFromObjects(const std::vector< vtkTypeUInt32 > &identifiers)
This method is similar to void UpdateStatesFromObjects().
void Export(const std::string &filename, int indentLevel=-1, char indentChar=' ')
Writes state of all registered objects to filename.states.json The blobs are written into filename....
bool RegisterState(const nlohmann::json &state)
Adds state into an internal container and returns a unique identifier.
nlohmann::json Invoke(vtkTypeUInt32 identifier, const std::string &methodName, const nlohmann::json &args)
vtkSmartPointer< vtkTypeUInt32Array > GetAllDependenciesAsVTKDataArray(vtkTypeUInt32 identifier)
Returns a non-empty vector of identifiers of all objects that depend on an object with the given iden...
bool InitializeExtensionModuleHandlers(const vtkSessionObjectManagerRegistrarFunc *registrars, std::size_t count)
void SetObjectManagerLogVerbosity(vtkLogger::Verbosity verbosity)
Set/Get the log verbosity of messages that are emitted when data is uploaded to GPU memory.
vtkSmartPointer< vtkMarshalContext > Context
std::size_t GetTotalBlobMemoryUsage()
vtkLogger::Verbosity GetObjectManagerLogVerbosity()
Set/Get the log verbosity of messages that are emitted when data is uploaded to GPU memory.
void PruneUnusedObjects()
Removes all objects that are neither referenced by this manager or any other object.
vtkSmartPointer< vtkTypeUInt8Array > GetBlob(const std::string &hash, bool copy=false) const
Returns a blob stored at hash.
std::string Invoke(vtkTypeUInt32 identifier, const std::string &methodName, const std::string &args)
~vtkObjectManager() override
bool UnRegisterState(vtkTypeUInt32 identifier)
Removes a state at id.
void UpdateObjectsFromStates()
Deserialize registered states into vtk objects.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkNew< vtkSerializer > Serializer
void PruneUnusedStates()
Removes all states whose corresponding objects no longer exist.
static vtkTypeUInt32 ROOT()
void UpdateStateFromObject(vtkTypeUInt32 identifier)
Serialize object at identifier into the state.
vtkTypeUInt32 RegisterObject(vtkSmartPointer< vtkObjectBase > objectBase)
Adds object into an internal container and returns a unique identifier.
vtkTypeUInt32 GetId(vtkSmartPointer< vtkObjectBase > objectBase)
Get the identifier for object.
bool RegisterBlob(const std::string &hash, vtkSmartPointer< vtkTypeUInt8Array > blob)
Specifies a blob for hash.
virtual bool Initialize()
Loads the default (de)serialization handlers and constructors for VTK classes.
bool UpdateObjectFromState(const std::string &state)
Deserialize the state into vtk object.
void PruneUnusedBlobs()
Removes all blob(s) whose hash is not found in the state of any object registered directly or indirec...
std::vector< std::string > GetBlobHashes(const std::vector< vtkTypeUInt32 > &ids)
Returns a non-empty vector of hash strings that correspond to blobs used by the registered objects at...
bool UpdateObjectFromState(const nlohmann::json &state)
Deserialize the state into vtk object.
std::size_t GetTotalVTKDataObjectMemoryUsage()
bool InitializeExtensionModuleHandlers(const std::vector< vtkSessionObjectManagerRegistrarFunc > &registrars)
Loads user provided handlers.
std::vector< vtkTypeUInt32 > GetAllDependencies(vtkTypeUInt32 identifier)
Returns a non-empty vector of identifiers of all objects that depend on an object with the given iden...
std::vector< vtkSmartPointer< vtkObjectBase > > ImportFromBytes(vtkSmartPointer< vtkUnsignedCharArray > byteArray)
Imports the states and blobs from a vtkUnsignedCharArray previously exported via ExportToBytes(); Ret...
std::string GetState(vtkTypeUInt32 id)
Get state of the object at id.
static vtkObjectManager * New()
static const char * OWNERSHIP_KEY()
void Clear()
Reset to initial state.
Serialize VTK objects to JSON.
Hold a reference to a vtkObjectBase instance.
This header file provides the C API for working with standalone/remote visualization applications.
int(* vtkSessionObjectManagerRegistrarFunc)(void *ser, void *deser, void *invoker, const char **error)
Definition vtkSession.h:99