I often use the function AddInputData or AddInputConnection of vtkAppendPolydata that inherits vtkDataObjectAlgorithm to add multiple polydatas form a big one. That’s a very easy way to combine a few of different polydatas to only one.
But I found that it can give me a strange result if I use AddInputConnection method sometimes.

Part code:

vtkSmartPointer APolydata = vtkSmartPointer::New();
// ... 
for (int i = 1; i < 17; i++)
    APolydata->AddInputConnection( actor[i]->GetMapper()->GetOutputPort() );
APolydata->AddInputConnection( another->GetMapper()->GetInput() ); 

vtkPolydata *pd = APolydata->GetOutput();

I use the following test code to output the information of the final polydata:

printf( "GetNumberOfPoints: %d, n", pd->GetNumberOfPoints() );

double bounds[6];
pd->GetBounds( bounds );
printf( "bounds: %lf, %lf, %lf, %lf, %lf, %lfn", 

It gives me this:

GetNumberOfPoints: 0
bounds: 1, -1, 1, -1, 1, -1

That’s weird.
Then I read vtk source code, the difference of AddInputData and AddInputConnection shows me some tips.

void vtkDataObjectAlgorithm::AddInputData(vtkDataObject* input)
  this->AddInputData(0, input);

void vtkDataObjectAlgorithm::AddInputData(int index, vtkDataObject* input)
  this->AddInputDataInternal(index, input);

void AddInputDataInternal(int port, vtkDataObject *input)
    { this->AddInputDataObject(port, input); }

void vtkAlgorithm::AddInputDataObject(int port, vtkDataObject *input)
    vtkTrivialProducer* tp = vtkTrivialProducer::New();
    this->AddInputConnection(port, tp->GetOutputPort());

AddInputData uses a vtkTrivialProducer object to support stand-alone object to be connected as input in a pipeline. After that, AddInputConnection helps to create a complete pipeline.
Finally, I use AddInputData to replace AddInputConnection in the original code, it works.


Leave a Reply

Your email address will not be published. Required fields are marked *

You cannot copy content of this page