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() ); 
APolydata->Update();

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->ComputeBounds();    
pd->GetBounds( bounds );
printf( "bounds: %lf, %lf, %lf, %lf, %lf, %lfn", 
         bounds[0],bounds[1],bounds[2],bounds[3],bounds[4],bounds[5]);

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)
{
  if(input)
  {
    vtkTrivialProducer* tp = vtkTrivialProducer::New();
    tp->SetOutput(input);
    this->AddInputConnection(port, tp->GetOutputPort());
    tp->Delete();
  }
}

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.


0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments

Tex To PDF
: convert the Latex file which suffix is tex to a PDF file

X
0
Would love your thoughts, please comment.x
()
x