| 69 | } |
| 70 | |
| 71 | static void Deserialize_vtkAlgorithm( |
| 72 | const nlohmann::json& state, vtkObjectBase* object, vtkDeserializer* deserializer) |
| 73 | { |
| 74 | using json = nlohmann::json; |
| 75 | auto* algorithm = vtkAlgorithm::SafeDownCast(object); |
| 76 | if (!algorithm) |
| 77 | { |
| 78 | return; |
| 79 | } |
| 80 | VTK_DESERIALIZE_VALUE_FROM_STATE(AbortExecute, int, state, algorithm); |
| 81 | |
| 82 | VTK_DESERIALIZE_VTK_OBJECT_FROM_STATE( |
| 83 | Information, vtkInformation, state, algorithm, deserializer); |
| 84 | |
| 85 | { |
| 86 | const auto* context = deserializer->GetContext(); |
| 87 | const auto iter = state.find("InputDataObjects"); |
| 88 | if ((iter != state.end()) && !iter->is_null()) |
| 89 | { |
| 90 | auto statesOfInputDataObjects = iter->get<json::array_t>(); |
| 91 | if (algorithm->GetNumberOfInputPorts() != static_cast<int>(statesOfInputDataObjects.size())) |
| 92 | { |
| 93 | vtkWarningWithObjectMacro(context, |
| 94 | << deserializer->GetObjectDescription() |
| 95 | << " failed because number of input ports in state (" << statesOfInputDataObjects.size() |
| 96 | << ") does not match for algorithm=" << algorithm->GetObjectDescription() << " (" |
| 97 | << algorithm->GetNumberOfInputPorts() << ")"); |
| 98 | return; |
| 99 | } |
| 100 | for (int port = 0; port < algorithm->GetNumberOfInputPorts(); ++port) |
| 101 | { |
| 102 | std::vector<vtkSmartPointer<vtkDataObject>> inputDataObjects; |
| 103 | auto stateOfInputDataObjects = statesOfInputDataObjects[port].get<json::array_t>(); |
| 104 | const bool hasMultipleConnections = stateOfInputDataObjects.size() > 1; |
| 105 | for (std::size_t index = 0; index < stateOfInputDataObjects.size(); ++index) |
| 106 | { |
| 107 | const auto identifier = stateOfInputDataObjects[index]["Id"].get<vtkTypeUInt32>(); |
| 108 | auto subObject = context->GetObjectAtId(identifier); |
| 109 | deserializer->DeserializeJSON(identifier, subObject); |
| 110 | if (auto* dataObject = vtkDataObject::SafeDownCast(subObject)) |
| 111 | { |
| 112 | if (hasMultipleConnections) |
| 113 | { |
| 114 | inputDataObjects.emplace_back(dataObject); |
| 115 | } |
| 116 | else |
| 117 | { |
| 118 | algorithm->SetInputDataObject(port, dataObject); |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | if (hasMultipleConnections) |
| 123 | { |
| 124 | algorithm->RemoveAllInputConnections(port); |
| 125 | for (auto& dataObject : inputDataObjects) |
| 126 | { |
| 127 | algorithm->AddInputDataObject(port, dataObject); |
| 128 | } |
nothing calls this directly
no test coverage detected