[vtk-developers] question about vtkAlgorithm and pipeline operations

Simon Warfield warfield at bwh.harvard.edu
Sun Aug 21 11:17:25 EDT 2005


I think there is a bug in the handling of ports and indexes of the 
SetInput method from vtkImageAlgorithm.

I would like to be able to run vtkImageBlend on different images.
Most of the examples illustrate the use of vtkImageBlend by doing an 
AddInput, which works fine.
However, I would like to be able to change the input after doing a blend 
in order to do a different blend.

vtkImageBlend inherits AddInput and SetInput methods from 
vtkThreadedImageAlgorithm and vtkImageAlgorithm.
vtkImageAlgorithm essentially forwards these calls to vtkAlgorithm which 
has a number of useful functions for managing connections
which are not exposed directly to code that calls e.g. vtkImageBlend.

  For example, it is not possible to call 
vtkAlgorithm::SetNthInputConnection() without subclassing from 
vtkAlgorithm as it is protected.
Nor does it seem to me there is a RemoveInput method exposed to 
vtkImageBlend. Although there is a RemoveInputConnection in 
vtkImageAlgorithm there is no interface for it in vtkImageBlend. 

Instead, the options are AddInput and SetInput.  AddInput eventually 
simply appends the input to the list of existing inputs through a call 
like this, so it doesn't seem possible to remove an existing input in 
that way:
 // Add this consumer to the input's list of consumers.
  newInfo->Append(vtkExecutive::CONSUMERS(), consumer, consumerPort);

Now, it seems there are ports, and there are indexes.  ports can support 
different types of data.  For example, if you connect a vtkImageData to 
port 1 of vtkImageBlend, you get a type mismatch error of this sort:
ERROR: In 
/opt/x86_64/builds/gcc/release/VTKnightly/VTK/Filtering/vtkDemandDrivenPipeline.cxx, 
line 669
vtkStreamingDemandDrivenPipeline (0xabdd30): Input for connection index 
0 on input port index 1 for algorithm vtkImageBlend(0xa9e8a0) is of type 
vtkImageData, but a vtkImageStencilData is required.

Port 1 is just for vtkImageStencilData.  What vtkImageBlend really wants 
is two inputs of type vtkImageData on index 0 and index 1 of port 0.  An 
interface for this is kind of connection is in 
vtkAlgorithm::SetNthInputConnection:
void vtkAlgorithm::SetNthInputConnection(int port, int index, 
vtkAlgorithmOutput* input)

You can see it takes a port and an index as arguments.

This is managed through the class hierarchy by providing the simpler 
option in vtkImageAlgorithm of doing a SetInput with an index:
                                                                                

//----------------------------------------------------------------------------
void vtkImageAlgorithm::SetInput(int index, vtkDataObject* input)
{
  if(input)
    {
    this->SetInputConnection(index, input->GetProducerPort());
    }
  else
    {
    // Setting a NULL input removes the connection.
    this->SetInputConnection(index, 0);
    }
}


The problem that I see with this is that 
vtkAlgorithm::SetInputConnection is not interested in an index but 
instead in a port. See here:
void vtkAlgorithm::SetInputConnection(int port, vtkAlgorithmOutput* input)

When a vtkImageAlgorithm attempts to set the input at an index, it gets 
forwarded up the class hierarchy to a method which sets the input for a 
port, rather than on the default input port at a particular index.  Of 
course, a port and an index are both just integers so there is no type 
problem in doing this, but I think it is not what was intended based on 
the variable naming and the inability for me to find any way to set a 
particular input connection at a given index on a specific port.

Could somebody who knows more than me about the vtk pipeline mechanism 
and the intended operation of this take a look at it ?

-- 
Simon K. Warfield, Ph.D. warfield at bwh.harvard.edu Phone:617-732-7090
http://www.spl.harvard.edu/~warfield           FAX:  617-582-6033
Associate Professor of Radiology,          Harvard Medical School
Director, Computational Radiology Laboratory
Thorn 329, Dept Radiology,  Brigham and Women's Hospital 
75 Francis St, Boston, MA, 02115
MA 280, Dept Radiology, Children's Hospital Phone: 617-355-4566




More information about the vtk-developers mailing list