------------------------------------------------------------------------------
| 318 | |
| 319 | //------------------------------------------------------------------------------ |
| 320 | std::vector<vtkSmartPointer<vtkObjectBase>> vtkObjectManager::ImportFromBytes( |
| 321 | vtkSmartPointer<vtkUnsignedCharArray> inputByteArray) |
| 322 | { |
| 323 | this->Clear(); |
| 324 | std::vector<vtkSmartPointer<vtkObjectBase>> strongObjects; |
| 325 | if (inputByteArray == nullptr || inputByteArray->GetNumberOfValues() == 0) |
| 326 | { |
| 327 | return strongObjects; |
| 328 | } |
| 329 | nlohmann::json importJson; |
| 330 | try |
| 331 | { |
| 332 | auto byteRange = vtk::DataArrayValueRange(inputByteArray); |
| 333 | importJson = nlohmann::json::from_cbor(byteRange.begin(), byteRange.end()); |
| 334 | } |
| 335 | catch (nlohmann::json::exception& e) |
| 336 | { |
| 337 | vtkErrorMacro(<< "Failed to parse json from byte array. message=" << e.what()); |
| 338 | } |
| 339 | const auto strongObjectIds = this->ImportFromJSON(importJson); |
| 340 | // Collect strong objects |
| 341 | for (const auto& id : strongObjectIds) |
| 342 | { |
| 343 | if (auto object = this->Context->GetObjectAtId(id)) |
| 344 | { |
| 345 | strongObjects.emplace_back(object); |
| 346 | } |
| 347 | } |
| 348 | return strongObjects; |
| 349 | } |
| 350 | |
| 351 | //------------------------------------------------------------------------------ |
| 352 | vtkTypeUInt32 vtkObjectManager::RegisterObject(vtkSmartPointer<vtkObjectBase> objectBase) |