Commit 5eba1f2a authored by Jeff Baumes's avatar Jeff Baumes
Browse files

ENH: Added performance test with many actors.

parent 3fc9b82a
......@@ -22,6 +22,7 @@ IF(VTK_USE_DISPLAY)
TestGradientBackground.cxx
TestInteractorTimers.cxx
TestLODActor.cxx
TestManyActors.cxx
TestOrderedTriangulator.cxx
TestOpacity.cxx
TestOSConeCxx.cxx
......
#include "vtkCommand.h"
#include "vtkSphereSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkSmartPointer.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkTimerLog.h"
int TestManyActors(int argc, char* argv[])
{
int numActors = 512;
int numRenders = 100;
bool interact = false;
for (int i = 1; i < argc; ++i)
{
if (!strcmp(argv[i], "-I"))
{
interact = true;
continue;
}
if (!strcmp(argv[i], "-T") ||
!strcmp(argv[i], "-V") ||
!strcmp(argv[i], "-D"))
{
++i;
continue;
}
if (!strcmp(argv[i], "-N"))
{
++i;
numActors = atoi(argv[i]);
continue;
}
if (!strcmp(argv[i], "-R"))
{
++i;
numRenders = atoi(argv[i]);
continue;
}
cerr << argv[0] << " options:" << endl;
cerr << " -N: Number of actors" << endl;
}
vtkSmartPointer<vtkSphereSource> source =
vtkSmartPointer<vtkSphereSource>::New();
vtkSmartPointer<vtkRenderer> ren =
vtkSmartPointer<vtkRenderer>::New();
int side1 = static_cast<int>(
round(pow(numActors, 1.0/3.0)));
int side2 = static_cast<int>(
round(sqrt(numActors/static_cast<double>(side1))));
int side3 = static_cast<int>(
ceil(static_cast<double>(numActors)/side1/side2));
int actorId = 0;
for (int i = 0; i < side1; ++i)
{
for (int j = 0; j < side2; ++j)
{
for (int k = 0; k < side3; ++k)
{
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
mapper->SetInputConnection(source->GetOutputPort());
actor->SetMapper(mapper);
actor->SetPosition(i, j, k);
ren->AddActor(actor);
++actorId;
if (actorId >= numActors)
{
break;
}
}
if (actorId >= numActors)
{
break;
}
}
if (actorId >= numActors)
{
break;
}
}
vtkSmartPointer<vtkRenderWindow> win =
vtkSmartPointer<vtkRenderWindow>::New();
vtkSmartPointer<vtkRenderWindowInteractor> iren =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
vtkSmartPointer<vtkInteractorStyleTrackballCamera> style =
vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
ren->ResetCamera();
win->AddRenderer(ren);
win->SetInteractor(iren);
iren->SetInteractorStyle(style);
cerr << "number of actors: " << numActors << endl;
cerr << "number of renders: " << numRenders << endl;
vtkSmartPointer<vtkTimerLog> timer = vtkSmartPointer<vtkTimerLog>::New();
timer->StartTimer();
iren->Initialize();
iren->SetEventPosition(100, 100);
iren->InvokeEvent(vtkCommand::LeftButtonPressEvent, 0);
timer->StopTimer();
double firstRender = timer->GetElapsedTime();
cerr << "first render time: " << firstRender << endl;
timer->StartTimer();
for (int i = 0; i < numRenders; ++i)
{
iren->SetEventPosition(100, 100 + i);
iren->InvokeEvent(vtkCommand::MouseMoveEvent, 0);
}
iren->InvokeEvent(vtkCommand::LeftButtonReleaseEvent, 0);
timer->StopTimer();
double elapsed = timer->GetElapsedTime();
cerr << "interactive render time: " << elapsed / numRenders << endl;
cerr << "render time per actor: " << elapsed / numRenders / numActors << endl;
if (interact)
{
iren->Start();
}
return 0;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment