[vtkusers] fastest render method for spheres...?!

Benjamin Frigan frigan at itap.physik.uni-stuttgart.de
Thu Feb 4 12:25:14 EST 2010


Hi everyone,

Which render 'method' for displaying a bunch of spheres/cubes/tubes is
the fastest one?
I already tried several things and also searched the user list. Anyway,
I just want to render a few thousand spheres and all methods I tried so
far were quite slow. My sphere resolution was only 30 (both phi & theta).
First, I tried:
sphereSource > mapper > actor > vActor.push_back(actor)
i.e. I had a vector of actors and for each sphere I had one actor. For
setting the position and radius of the spheres I used
sphere->SetCenter(i,j,k) and sphere->SetRadius(...). However, I searched
the user list and someone wrote that it's faster when you use
actor->SetOrigion(i,j,k) and actor->SetScale(...). Honestly, I didn't
see a difference.
I also tried to use vtkglyph3D. But this seems to be slower. You can
find my main() below.

I know that chemists do something like that  to display their molecules.
So how do you solve that when you have, let's say 10,000 atoms?

Thanks,

Ben




int main()
{
  vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
  for(int i=0; i<15; i++)
  {
      for(int j=0; j<15; j++)
      {
          for(int k=0; k<15; k++)
              points->InsertNextPoint(i,j,k);
      }
  }
  vtkSmartPointer<vtkPolyData> polydata =
vtkSmartPointer<vtkPolyData>::New();
  polydata->SetPoints(points);

  vtkSmartPointer<vtkSphereSource> sphereSource =
vtkSmartPointer<vtkSphereSource>::New();
  sphereSource->SetRadius(.3);
  sphereSource->SetPhiResolution(30);
  sphereSource->SetThetaResolution(30);
 
  vtkSmartPointer<vtkGlyph3D> glyph3D = vtkSmartPointer<vtkGlyph3D>::New();
  glyph3D->SetSource(sphereSource->GetOutput());
  glyph3D->SetInput(polydata);
  glyph3D->Update();

  vtkSmartPointer<vtkPolyDataMapper> glyphMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
  glyphMapper->SetInput(glyph3D->GetOutput());

  vtkSmartPointer<vtkActor> glyphActor = vtkSmartPointer<vtkActor>::New();
  glyphActor->SetMapper(glyphMapper);

  vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
  vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);

  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);

  renderer->AddActor(glyphActor);
  renderer->SetBackground(0.1, 0.2, 0.4);

  renderWindow->Render();

  vtkSmartPointer<vtkInteractorStyleTrackballCamera> style =
vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
  renderWindowInteractor->SetInteractorStyle( style );
  renderWindowInteractor->Start();

  return 0;
}






More information about the vtkusers mailing list