vtkAppendPolyData->AddInput() is very slow for multiple inputs
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
Hi,
I'm trying to use vtkAppendPolyData->AddInput() for multiple inputs. And it look like AddInput() very slow for some reasons in CVS version of VTK Revision: 1.2066 $, $Date: 2004/12/06.
Everything is working well for VTK 4.2 also VTK Revision 1.1883 Am I doing something wrong?
Thanks for the help,
Test Example with illustrate problem: #include <vtkPolyDataMapper.h> #include <vtkRenderWindow.h> #include <vtkActor.h> #include <vtkRenderer.h> #include <vtkRenderWindowInteractor.h> #include <vtkProperty.h> #include <vtkPolyData.h> #include <vtkPoints.h> #include <vtkPointData.h> #include <vtkMath.h> #include <vtkCellArray.h> #include <vtkDoubleArray.h> #include <vtkTimerLog.h>
#include <vtkAppendPolyData.h>
int main( int argc, char *argv[] ) { int NumberOfIterations = 1000; int NumberOfPoints = 120;
// Append vtkAppendPolyData *append = vtkAppendPolyData::New();
for (int i=0; i<NumberOfIterations; i++) { std::cout<<"Processing iteration: "<<i; vtkPolyData *pd = vtkPolyData::New(); vtkCellArray *lines = vtkCellArray::New();
// Create points
vtkPoints *points = vtkPoints::New();
for (int j=0; j<NumberOfPoints; j++)
{
double x[3];
x[0] = vtkMath::Random(0.0, 10.0);
x[1] = vtkMath::Random(0.0, 10.0);
x[2] = vtkMath::Random(0.0, 10.0);
points->InsertNextPoint(x);
}
// Create vectors
vtkDoubleArray *newVectors = vtkDoubleArray::New();
newVectors->SetNumberOfComponents(3);
newVectors->Allocate(NumberOfPoints);
// Create cell
int numLines = 1;
lines->Allocate(lines->EstimateSize(numLines,NumberOfPoints));
for (int j=0; j<numLines; j++)
{
lines->InsertNextCell(NumberOfPoints);
for (int k=0; k<NumberOfPoints; k++)
{
lines->InsertCellPoint(k);
// Add vector
double v[3];
v[0] = vtkMath::Random(0.0, 1.0);
v[1] = vtkMath::Random(0.0, 1.0);
v[2] = vtkMath::Random(0.0, 1.0);
newVectors->InsertNextTuple3(v[1], v[2], v[3]);
}
}
pd->SetPoints(points);
pd->GetPointData()->SetVectors(newVectors);
pd->SetLines(lines);
vtkTimerLog *timer = vtkTimerLog::New();
timer->StartTimer();
append->AddInput(pd); // Append here
timer->StopTimer();
std::cout<<", Time for AddInput: "<< timer->GetElapsedTime() <<" sec. ";
timer->Delete();
// Clean
pd->Delete(); pd = NULL;
lines->Delete(); lines = NULL;
points->Delete(); points = NULL;
newVectors->Delete(); newVectors = NULL;
std::cout<<" done."<<endl;
}
append->Update();
// Let's have a look what we get vtkPolyDataMapper *mapper = vtkPolyDataMapper::New(); mapper->SetInput(append->GetOutput());
vtkActor *actor = vtkActor::New(); actor->SetMapper(mapper);
vtkRenderer *ren= vtkRenderer::New(); ren->SetBackground(0.55, 0.55, 0.55);
vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer( ren ); renWin->SetSize( 800, 800 );
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); iren->SetRenderWindow(renWin);
ren->AddActor(actor); iren->Start();
return 1; }