[vtkusers] More efficient way to present animation of multiple 3D surfaces?

Steve Chall stevec at renci.org
Tue May 29 13:30:44 EDT 2007


Dear folks:
Please accept my apologies if I'm unfairly prevailing upon your patience,
but I'm resubmitting the following because, looking over my last submission,
I may have incorrectly created the impression that the solution was
included.  I guess I'd think that VTK would not infrequently be used to
interactively show multiple different vtkPolyData surfaces, but I haven't
yet run across any examples or discussion.  Thanks for your help.

I've created an animation showing a sequence of 3D surfaces, but I'm getting
< 2 frames/sec display rate and I'll bet I'm taking an inefficient path to
my goal.  Here's what I'm doing:  I have kMaxFrames (could be hundreds or
even thousands) of 2D arrays of elevation values that I'm reading into a
corresponding number of vtkPoints objects according to Amy's
recommendations, then adding the points to each of an array of vtkPolyData
objects, then filtering each of those with its own vtkDelaunay2D filter.
Then in an infinite loop I keep stepping through each of the vtkDelauney2D
objects, assigning it in turn as the mapper's input connection (Please
search for "?????" in the following code for the line in question).  But
it's slow.  Should I somehow use vtkAppendPolyData::SetInputByNumber()?

// Begin C++:


// (include files)

double grid[kMaxFrames][kxDimension][kyDimension];
vtkPoints *points[kMaxFrames];
vtkPolyData *polyData[kMaxFrames];
vtkDelaunay2D *delaunay[kMaxFrames];

int main()
{
// ...Assume that grid is full of kMaxFrames frames of
// elevation data, each frame of which is arranged as
// a regular array of kxDimension x kyDimension
// elevation values...

for (int i = 0; i < kMaxFrames; i++) // For each frame...
  {
  // ...create a bunch of points from the original data...
  points[i] = vtkPoints::New();
  points[i]->SetNumberOfPoints(kxDimension * kyDimension);

  for (int j = 0; j < kxDimension; j++)
    {
    for (int k = 0; k < kyDimension; k++)
      {
      points[i]->SetPoint(j * kyDimension + k, (float)j, (float)k,
                              grid[i][j][k]);
      }
    }

  // ...set as points in a vtkPolyData object...
  polyData[i] = vtkPolyData::New();
  polyData[i]->SetPoints(points[i]);  

  // ...and run that vtkPolydata object through a vtkDelaunay2D 
  //  filter to auto-generate connectivity:
  delaunay[i] = vtkDelaunay2D::New();
  delaunay[i]->SetInput(polyData[i]);
  delaunay[i]->SetTolerance(0.001);
  } // end for i 

vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
vtkActor *actor = vtkActor::New();
actor->SetMapper(mapper);
vtkRenderer *ren1= vtkRenderer::New();
ren1->AddActor(actor);
ren1->SetBackground( 0.0, 0.0, 0.1 );
ren1->ResetCamera();
ren1->GetActiveCamera()->SetPosition(53, -330, 410);
ren1->GetActiveCamera()->SetClippingRange(400, 850);
ren1->GetActiveCamera()->SetViewUp(0.037, 0.71, 0.70);
ren1->GetActiveCamera()->SetFocalPoint(146, 85, -11);

vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren1);
renWin->SetSize(600, 600);
int frame = -1;

while(1) 
// Here's the part that's slow.  No problems with the preceding code.
{
  frame++;
  frame %= kMaxFrames;
  mapper->SetInputConnection(delaunay[frame]->GetOutputPort()); // ?????
  renWin->Render();
}

// (Delete everything dynamically allocated)

return 0;
}

Thank you for any further suggestions.

-Steve







More information about the vtkusers mailing list