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

Method ImportFromJSON

Serialization/Manager/vtkObjectManager.cxx:200–268  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

198
199//------------------------------------------------------------------------------
200std::vector<vtkTypeUInt32> vtkObjectManager::ImportFromJSON(const nlohmann::json& importJson)
201{
202 std::vector<vtkTypeUInt32> strongObjectIds;
203 try
204 {
205 // Register all the states.
206 auto statesIter = importJson.find("States");
207 if (statesIter != importJson.end())
208 {
209 for (const auto& state : statesIter->items())
210 {
211 this->Context->RegisterState(state.value());
212 const auto identifier = state.value().at("Id").get<vtkTypeUInt32>();
213 if (state.value().find("vtk-object-manager-kept-alive") != state.value().end() &&
214 (state.value().at("vtk-object-manager-kept-alive").get<bool>() == true))
215 {
216 strongObjectIds.emplace_back(identifier);
217 }
218 }
219 }
220 }
221 catch (nlohmann::json::exception& e)
222 {
223 vtkErrorMacro(<< "Failed to import states from byte array. message=" << e.what());
224 }
225 try
226 {
227 // Register all the blobs.
228 auto blobsIter = importJson.find("Blobs");
229 if (blobsIter != importJson.end())
230 {
231 for (const auto& blob : blobsIter->items())
232 {
233 auto hash = blob.key();
234 auto byteArray = vtk::TakeSmartPointer(vtkTypeUInt8Array::New());
235 if (blob.value().is_object())
236 {
237 // when import json from a file, the type is object, and values must be copied into a
238 // vector.
239 const auto values = blob.value().at("bytes").get<std::vector<vtkTypeUInt8>>();
240 if (!values.empty())
241 {
242 auto* bytePtr = const_cast<vtkTypeUInt8*>(values.data());
243 const vtkIdType numValues = static_cast<vtkIdType>(values.size());
244 byteArray->SetArray(bytePtr, numValues, /*save=*/1);
245 }
246 }
247 else
248 {
249 const auto& values = blob.value().get_binary();
250 if (!values.empty())
251 {
252 auto* bytePtr = const_cast<vtkTypeUInt8*>(values.data());
253 const vtkIdType numValues = static_cast<vtkIdType>(values.size());
254 byteArray->SetArray(bytePtr, numValues, /*save=*/1);
255 }
256 }
257 this->Context->RegisterBlob(byteArray, hash);

Callers 2

ImportMethod · 0.95
ImportFromBytesMethod · 0.95

Calls 15

get_binaryMethod · 0.80
NewFunction · 0.50
findMethod · 0.45
endMethod · 0.45
itemsMethod · 0.45
RegisterStateMethod · 0.45
valueMethod · 0.45
atMethod · 0.45
emplace_backMethod · 0.45
whatMethod · 0.45
keyMethod · 0.45

Tested by

no test coverage detected