[vtk-developers] Re: vtkAlgorithm suggestion

Brad King brad.king at kitware.com
Tue Mar 9 10:45:19 EST 2004


Miller, James V (Research) wrote:

> I just saw the vtkAlgorithm classes in the respository.  I have a 
> suggestion. I noticed the "inputs" and "outputs" are indexed based 
> (inputs are specified via a numeric id).  I think implementing 
> subclasses of Algorithm will be cleaner if the inputs and outputs are 
> specified via strings.  The developer can indicate whatever string names 
> they want to associate with their inputs and outputs.  If none are 
> specified, a default like "Input0" could be used.

This was the approach used in one of our earlier design iterations. 
However, the implementation of the algorithms and executives is much 
simpler and faster when an index is used.  Also if there is a typo in 
the string we do not know until runtime.  There are other and safer ways 
to provide a name-based connection interface.

> The code may look like:
>  
> someAlgorithm->SetInputConnection("gradient", 
> someOtherAlgorithm->GetOutputConnection("gradient"));
>  
> or something like that.

My idea is that one of these approaches can be used:

someAlgorithm->SetInputConnection(vtkSomeAlgorithm::GradientInput,
   someOtherAlgorithm->GetOutputPort(vtkOtherAlgorithm::GradientOutput));

or

someAlgorithm->SetGradientInputConnection(
   someOtherAlgorithm->GetGradientOutputPort());

or a string-based interface could still be added by particular 
algorithms with code like:

void vtkSomeAlgorithm::SetInputConnection(const char* name, /*...*/)
{
   if(strcmp(name, "gradient") == 0)
     {
     this->Superclass::SetInputConnection(0, /*...*/);
     }
}

All of these approaches allow the internal implementation to continue to 
use indices.  The second one is probably the best because it may easily 
be used from the wrapping languages and provides a compile-time check 
for valid input/output port names.

-Brad




More information about the vtk-developers mailing list