------------------------------------------------------------------------------
| 1429 | |
| 1430 | //------------------------------------------------------------------------------ |
| 1431 | void vtkAlgorithm::SetNthInputConnection(int port, int index, vtkAlgorithmOutput* input) |
| 1432 | { |
| 1433 | if (!this->InputPortIndexInRange(port, "replace connection")) |
| 1434 | { |
| 1435 | return; |
| 1436 | } |
| 1437 | |
| 1438 | // Get the producer/consumer pair for the connection. |
| 1439 | vtkExecutive* producer = |
| 1440 | (input && input->GetProducer()) ? input->GetProducer()->GetExecutive() : nullptr; |
| 1441 | int producerPort = producer ? input->GetIndex() : 0; |
| 1442 | vtkExecutive* consumer = this->GetExecutive(); |
| 1443 | int consumerPort = port; |
| 1444 | |
| 1445 | // Get the vector of connected input information objects. |
| 1446 | vtkInformationVector* inputs = consumer->GetInputInformation(consumerPort); |
| 1447 | |
| 1448 | // Check for any existing connection with this index. |
| 1449 | vtkInformation* oldInfo = inputs->GetInformationObject(index); |
| 1450 | |
| 1451 | // Get the information object from the producer of the input. |
| 1452 | vtkInformation* newInfo = producer ? producer->GetOutputInformation(producerPort) : nullptr; |
| 1453 | |
| 1454 | // If the connection has not changed, do nothing. |
| 1455 | if (newInfo == oldInfo) |
| 1456 | { |
| 1457 | return; |
| 1458 | } |
| 1459 | |
| 1460 | // Set the connection. |
| 1461 | vtkDebugMacro("Setting connection index " |
| 1462 | << index << " to input port index " << consumerPort << " from output port index " |
| 1463 | << producerPort << " on algorithm " |
| 1464 | << (producer ? producer->GetAlgorithm()->GetObjectDescription() : "nullptr") << "."); |
| 1465 | |
| 1466 | // Add the consumer to the new input's list of consumers. |
| 1467 | if (newInfo) |
| 1468 | { |
| 1469 | vtkExecutive::CONSUMERS()->Append(newInfo, consumer, consumerPort); |
| 1470 | } |
| 1471 | |
| 1472 | // Remove the consumer from the old input's list of consumers. |
| 1473 | if (oldInfo) |
| 1474 | { |
| 1475 | vtkExecutive::CONSUMERS()->Remove(oldInfo, consumer, consumerPort); |
| 1476 | } |
| 1477 | |
| 1478 | // Store the information object in the vector of input connections. |
| 1479 | inputs->SetInformationObject(index, newInfo); |
| 1480 | |
| 1481 | // This algorithm has been modified. |
| 1482 | this->Modified(); |
| 1483 | } |
| 1484 | |
| 1485 | //------------------------------------------------------------------------------ |
| 1486 | void vtkAlgorithm::SetNumberOfInputConnections(int port, int n) |
no test coverage detected