vtkImageBlend sets input on port 1 instead of connection 1
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
vtkImageAlgorithm has an AddInput method and a SetInput method which are intended to add or set the input at a particular index. These methods in turn call vtkAlgorithm AddInputConnection and SetInputConnection, but translate the index into a port.
The upshot of this is that an attempt to set the second input at index 1 on port 0 instead sets index 0 on port 1. vtkImageBlend uses port 1 exclusively for vtkImageStencil data and the result is a runtime failure with a type mismatch.
Basically the bug is that these are incompatible: void vtkImageAlgorithm::SetInput(int index, vtkDataObject* input)
void vtkAlgorithm::SetInputConnection(int port, vtkAlgorithmOutput* input)
Also, the workaround of calling SetInputConnection directly is difficult to discern as the pipeline documentation is not completely clear. Basically a sequence like the following is necessary:
vtkImageData *input1; vtkImageData *input2; vtkImageData *input3;
blend->SetStencil(stencil); blend->AddInputConnection(0, input1->GetProducerPort()); blend->AddInputConnection(0, input2->GetProducerPort());
// THERE IS NO REMOVEINPUT - WOULD BE GOOD TO HAVE IT blend->RemoveInput( input1->GetProducerPort()); // UNDESIRABLE blend->SetInput(0, 0); // Removes all inputs ???? blend->RemoveInputConnection(0,input2->GetProducerPort()); // seems to do the job.... // Not immediately obvious that calling GetProducerPort() generates a vtkAlgorithmOutput *.
blend->AddInputConnection(0, input3->GetProducerPort());