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

kent williams nkwmailinglists at gmail.com
Wed Aug 19 14:50:27 EDT 2009


I think using separate threads are a bad idea, as VTK is singly threaded.

What you probably want to do is

1) Use vtkRenderWindowInteractor::CreateRepeatingTimer to start a
timer running in your interactor.
2) create your own class derived from vtkCommand, and have it observe
vtkCommand::TimerEvent.

Your class derived from vtkCommand will overload Execute(), and your
Execute() will update the scene.

Now it is possible to have separate threads, with one thread handling
VTK, but you will have to serialize access to the VTK library from
other threads.  This is best managed with a message passing paradigm,
in which case you'll have to define message packets to cover all the
VTK API calls you want to make.  This is rather a big job.

On Tue, Aug 18, 2009 at 5:20 AM, Jelle Ogard<jelleogard at ymail.com> wrote:
> 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
>
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>



More information about the vtkusers mailing list