[vtkusers] Rendering performance
Gib Bogle
g.bogle at auckland.ac.nz
Wed Nov 24 00:44:26 EST 2010
I asked about this before, but didn't attract any responses. I have a better
understanding of the issue now, so perhaps my questions will make more sense.
At regular intervals as my simulation program executes, I am rendering a scene
that contains mainly about 1000 small spheres (which move) and about 10000 flat
squares (which do not move). I have discovered that the surprising slowness of
the the rendering is caused by the squares, even though the spheres have
ThetaResolution and PhiResolution both equal to 12, which I guess means 144
faces per sphere, i.e. a total of 144,000 faces. By my calculations rendering
the scene 288 times with spheres alone takes about 4 sec, with the squares alone
takes about 20 sec, and with both spheres and squares about 24 sec. That is,
10,000 squares take 5 times as long as 1000 spheres with 144,000 faces.
Apparently there's something very inefficient about the way I am rendering the
squares. Here is the code for tileMapper (which makes squares):
// Create the square
// Setup points to draw a unit square in the XY plane, at y=0
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkCellArray> vertices = vtkSmartPointer<vtkCellArray>::New();
points->InsertNextPoint(-0.5, 0.0, -0.5);
points->InsertNextPoint( 0.5, 0.0, -0.5);
points->InsertNextPoint( 0.5, 0.0, 0.5);
points->InsertNextPoint(-0.5, 0.0, 0.5);
vtkSmartPointer<vtkPolygon> polygon = vtkSmartPointer<vtkPolygon>::New();
polygon->GetPointIds()->SetNumberOfIds(4); //make a quad
polygon->GetPointIds()->SetId(0, 0);
polygon->GetPointIds()->SetId(1, 1);
polygon->GetPointIds()->SetId(2, 2);
polygon->GetPointIds()->SetId(3, 3);
//Add the polygon to a list of polygons
vtkSmartPointer<vtkCellArray> polygons = vtkSmartPointer<vtkCellArray>::New();
polygons->InsertNextCell(polygon);
//Create a PolyData
vtkSmartPointer<vtkPolyData> polygonPolyData = vtkSmartPointer<vtkPolyData>::New();
polygonPolyData->SetPoints(points);
polygonPolyData->SetPolys(polygons);
//Create a mapper and actor
tileMapper = vtkPolyDataMapper::New();
tileMapper->SetInput(polygonPolyData);
tileMapper->ScalarVisibilityOff();
The square actors are made like this:
actor = vtkActor::New();
actor->SetMapper(tileMapper);
actor->GetProperty()->SetColor(boneColor);
actor->GetProperty()->SetAmbient(0.5);
actor->GetProperty()->SetDiffuse(0.2);
actor->GetProperty()->SetSpecular(0.5);
actor->SetPosition(pos);
ren->AddActor(actor);
then not touched again (in the simulations I report times for.)
I'd be very grateful if someone could give me a clue as to what I'm doing wrong
to make the rendering so slow.
Thanks
Gib
More information about the vtkusers
mailing list