MCPcopy Create free account
hub / github.com/Kitware/VTK / Deserialize_vtkFieldData

Function Deserialize_vtkFieldData

Common/DataModel/vtkFieldDataSerDesHelper.cxx:56–115  ·  view source on GitHub ↗

----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

54
55 //----------------------------------------------------------------------------
56 static void Deserialize_vtkFieldData(
57 const nlohmann::json& state, vtkObjectBase* object, vtkDeserializer* deserializer)
58 {
59 using nlohmann::json;
60 if (auto* fd = vtkFieldData::SafeDownCast(object))
61 {
62 if (auto superDeserializer = deserializer->GetHandler(typeid(vtkFieldData::Superclass)))
63 {
64 superDeserializer(state, object, deserializer);
65 }
66 auto* context = deserializer->GetContext();
67 const auto& stateOfArrays = state["Arrays"];
68 // vector used to keep existing arrays alive so that fd->RemoveArray doesn't destroy the
69 // vtkAbstractArray object.
70 std::vector<vtkSmartPointer<vtkAbstractArray>> arrays;
71 for (auto& stateOfarray : stateOfArrays)
72 {
73 const auto identifier = stateOfarray["Id"].get<vtkTypeUInt32>();
74 auto subObject = context->GetObjectAtId(identifier);
75 deserializer->DeserializeJSON(identifier, subObject);
76 if (auto* array = vtkAbstractArray::SafeDownCast(subObject))
77 {
78 arrays.emplace_back(array);
79 }
80 }
81 // Now remove arrays from the collection.
82 // If arrays already existed before entering this function, it does not invoke
83 // destructor on the vtkAbstractArray because a reference is held by the vector of arrays.
84 if (static_cast<std::size_t>(fd->GetNumberOfArrays()) != arrays.size())
85 {
86 while (fd->GetNumberOfArrays() > 0)
87 {
88 auto* array = fd->GetAbstractArray(0);
89 context->UnRegisterObject(context->GetId(array));
90 fd->RemoveArray(0);
91 }
92 for (const auto& array : arrays)
93 {
94 fd->AddArray(array);
95 }
96 }
97 else
98 {
99 int i = 0;
100 for (const auto& array : arrays)
101 {
102 // vtkFieldData::SetArray only marks the vtkFieldData as modified if the array is
103 // different from the one already present in the vtkFieldData. This is important because
104 // the vtkFieldData::MTime affects the MTime of a vtkPolyData object. We need to be very
105 // careful here because unnecessary modification of the vtkFieldData::MTime will cause the
106 // vtkPolyData to be marked as modified and, in turn, will force a mapper to upload the
107 // data again.
108 fd->SetArray(i, array);
109 ++i;
110 }
111 }
112 VTK_DESERIALIZE_VALUE_FROM_STATE(NumberOfTuples, int, state, fd);
113 VTK_DESERIALIZE_VALUE_FROM_STATE(GhostsToSkip, int, state, fd);

Callers

nothing calls this directly

Calls 13

DeserializeJSONMethod · 0.80
GetAbstractArrayMethod · 0.80
GetHandlerMethod · 0.45
GetContextMethod · 0.45
GetObjectAtIdMethod · 0.45
emplace_backMethod · 0.45
GetNumberOfArraysMethod · 0.45
sizeMethod · 0.45
UnRegisterObjectMethod · 0.45
GetIdMethod · 0.45
RemoveArrayMethod · 0.45
AddArrayMethod · 0.45

Tested by

no test coverage detected