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

Jelle Ogard jelleogard at ymail.com
Wed Aug 19 17:08:17 EDT 2009


Thank you, Kent. TimerEvents are an obvious solution to my problem. I
was able to perform the animation while still interacting with the
scene using the CreateRepeatingTimer in C++. Now I need the same
behavior from python-vtk. I thought that it offers everything that is
possible with the C++ libraries. 
Unfortunately, python-vtk has only CreateTimer and DestroyTimer - no
means to set a Timer duration or creating a repeating timer. Moreover,
using CreateTimer in python-vtk never invokes a TimerEvent.
I am using python-vtk 5.0.3 (a package from Ubuntu Hardy Linux). Do you
know whether the timer issues have been improved in later python-vtk
versions? Who is the maintainer of this package - is it Kitware? I
can't seem to find a changelog of python-vtk, neither a proper website,
forum or mailing list, where its usage can be discussed.

Cheers
Jelle





> Von: kent williams <nkwmailinglists at gmail.com>
> An: Jelle Ogard <jelleogard at ymail.com>
> CC: vtkusers at vtk.org
> Gesendet: Mittwoch, den 19. August 2009, 20:50:27 Uhr
> Betreff: Re: [vtkusers] how to animate a scene that is linked to a  vtkRenderWindowInteractor?
> 
> 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 Ogardwrote:
> > 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