[vtkusers] how to animate a scene that is linked to a vtkRenderWindowInteractor?

Jelle Ogard jelleogard at ymail.com
Tue Aug 18 06:20:11 EDT 2009


Hello,
I would like to know how to write a program (in python, C++ or others) for VTK, that both
1) refreshes the scene whenever the processor is idle, so that changes in geometry or colors that result from a time-dependent model are immediately propagated to the model view
2) allows the user to make use of the interactive features of a vtkRenderWindowInteractor.

Usually I follow this structure:

...
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

ren.AddActor(...)
renWin.SetSize(500, 500)

iren.Initialize()
renWin.Render()
iren.Start()

But, when I start interaction with "iren.Start()" I can not update the scene anymore by changing the visualization pipeline, because VTK blocks this call until the window is closed. Without using the vtkRenderWindowInteractor, I can do several updates and call renWin.Render() repeatedly to visualize the change over time, but then no interaction is possible. How do I combine both?

Do I have to run iren.Start() in a different thread from the thread where the pipeline is updated over time?
Does the vtkRenderWindowInteractor offer a hook into a calback function?
Do I have to build my own event loop, reacting on mouse and key events and step the model forward in time in between these events?

I'd appreciate if you send some short example that illustrates how this can be done, or if you just outline the required steps.

Cheers,
Jelle



      



More information about the vtkusers mailing list