[vtkusers] Slow multiple QVTKWidget2 drawing when sharing polydata
Doug Hamilton
doug.hamil at gmail.com
Sun Mar 18 22:52:05 EDT 2012
Hello,
I'm working on porting an application made from a mixture of VTK 5.4 and
wxWidgets to VTK 5.11 and Qt 4.8. I have multiple (up to 4) QVTKWidget2s
on the screen to display the same data from different viewpoints. Each
widget has its own mapper and actor objects, but the mappers all share the
same polydata source. It works well until I modify the polydata source and
mark it with source->Modified(). This makes each QVTKWidget2 take a long
time to render the first time, and then they all work smoothly again. I
assume they're rebuilding display lists or something. Is there any way to
improve this performance? Below is an example application that
demonstrates the issue. Press the space key to modify the sphereSource
object and then subsequent interactions with the QVTKWidget2 objects will
be slow for the first render. Perhaps I'm not creating multiple views
correctly. Thank you ahead of time for the help!
Thanks,
Doug
SlowQVTKWidget2::SlowQVTKWidget2(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
QSplitter *splitter = new QSplitter(this);
QVTKWidget2 *w1 = new QVTKWidget2();
QVTKWidget2 *w2 = new QVTKWidget2();
splitter->addWidget(w1);
splitter->addWidget(w2);
// Create sphereSource which is shared by the vtkPolyDataMappers for both
QVTKWidgets
//
sphereSource = vtkSmartPointer<vtkSphereSource>::New();
sphereSource->SetPhiResolution(500);
sphereSource->SetThetaResolution(500);
sphereSource->Update();
// Create the sphereMapper for the left QVTKWidget, set its source to the
sphereSource
// Also create an actor for the left QVTKWidget
vtkSmartPointer<vtkPolyDataMapper> sphereMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
sphereMapper->SetInputConnection(sphereSource->GetOutputPort());
vtkSmartPointer<vtkActor> sphereActor = vtkSmartPointer<vtkActor>::New();
sphereActor->SetMapper(sphereMapper);
sphereMapper->Update();
// sphereMapper2 Uses the same sphereSource as sphereMapper
// Also, create sphereActor2 which uses sphereMapper2
vtkSmartPointer<vtkPolyDataMapper> sphereMapper2
=vtkSmartPointer<vtkPolyDataMapper>::New();
sphereMapper2->SetInputConnection(sphereSource->GetOutputPort());
vtkSmartPointer<vtkActor> sphereActor2 = vtkSmartPointer<vtkActor>::New();
sphereActor2->SetMapper(sphereMapper2);
sphereMapper2->Update();
// cube1
vtkSmartPointer<vtkCubeSource> cubeSource =
vtkSmartPointer<vtkCubeSource>::New();
cubeSource->Update();
vtkSmartPointer<vtkPolyDataMapper> cubeMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
cubeMapper->SetInputConnection(cubeSource->GetOutputPort());
vtkSmartPointer<vtkActor> cubeActor = vtkSmartPointer<vtkActor>::New();
cubeActor->SetMapper(cubeMapper);
// cube2
vtkSmartPointer<vtkPolyDataMapper> cubeMapper2 =
vtkSmartPointer<vtkPolyDataMapper>::New();
cubeMapper2->SetInputConnection(cubeSource->GetOutputPort());
vtkSmartPointer<vtkActor> cubeActor2 = vtkSmartPointer<vtkActor>::New();
cubeActor2->SetMapper(cubeMapper2);
// VTK Renderer
vtkSmartPointer<vtkRenderer> leftRenderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderer> rightRenderer =
vtkSmartPointer<vtkRenderer>::New();
cubeActor->SetPosition(0,2,0);
cubeActor2->SetPosition(0,2,0);
// Add both actors to each renderer
leftRenderer->AddActor(cubeActor);
leftRenderer->AddActor(sphereActor);
rightRenderer->AddActor(cubeActor2);
rightRenderer->AddActor(sphereActor2);
// VTK/Qt wedded
w1->GetRenderWindow()->AddRenderer(leftRenderer);
w2->GetRenderWindow()->AddRenderer(rightRenderer);
this->resize(800,600);
this->setCentralWidget(splitter);
}
void SlowQVTKWidget2::keyPressEvent(QKeyEvent *event){
// When spacebar is pressed, we adjust sphereSource's data and mark it as
modified.
// This causes a slow down when the user manipulates the QVTKWidgets.
if(event->key() == 32)
{
this->sphereSource->SetThetaResolution(600);
this->sphereSource->Modified();
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120318/90a97a20/attachment.htm>
More information about the vtkusers
mailing list