[vtkusers] Animation without polling?

Jeff Baumes jeff.baumes at kitware.com
Fri Sep 11 09:06:41 EDT 2009


Qt provides a platform-independent animation solution with QTimeLine,
that seems exactly what you are looking for. It would work if you use
QVTKWidget for rendering and its special interactor. I am assuming,
however, that this one issue is not a reason for you to change GUI
toolkits. It would be nice to have equivalent functionality in VTK
itself. You could possibly dig through Qt's code for ideas of how it
avoids blocking other GUI events on different platforms.

Jeff

On Fri, Sep 11, 2009 at 8:48 AM, Guido Rodriguez
<guidorodriguez1952 at hotmail.com> wrote:
> Hi John,
> unfortunately I no hardly anything about MFC. I was hoping for a system
> independent solution.
>
> But maybe somebody can help to apply your suggestion to the (linux) X
> windows system?
> An equivalent of "::PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE )" is readily
> available (XNextEvent or XCheckIfEvent).
> But I have no idea, what AfxGetThread()->PumpMessage() and
> AfxGetThread()->OnIdle() are supposed to do exactly, not to speak about
> implementation with X.
> Moreover, I don't see, which vtk object will handle the queued messages in
> your code snippet. My limited understanding of vtkAnimationScene is that it
> only handles animation events. You'd need a vtkRenderWindowInteractor in
> addition, which would be in charge of the mouse/key event, don't you?. Can I
> find a complete example somewhere, which shows your snippet in context?
>
> Regards,
> Guido
>
> ________________________________
> From: jcplatt at dsl.pipex.com
> To: guidorodriguez1952 at hotmail.com
> CC: vtkusers at vtk.org
> Subject: Re: [vtkusers] Animation without polling?
> Date: Fri, 11 Sep 2009 09:51:30 +0100
>
> Hi,
>
> After rendering each frame, allow any queued messages to be processed -
>
> case vtkCommand::AnimationCueTickEvent:
> {
>     .....
>
>     self->Render();
>     // Allow interaction with the scene and UI.
>     self->Pump();
> }
> break;
>
> This is an MFC implementation of Pump() -
>
> BOOL Pump()
> {
>     MSG msg;
>     while ( ::PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
>     {
>         if ( ! AfxGetThread()->PumpMessage() )
>         {
>             ::PostQuitMessage( 0 );
>             return FALSE;
>         }
>     }
>     LONG lIdle = 0;
>     while ( AfxGetThread()->OnIdle( lIdle++ ) );
>     return TRUE;
> }
>
> This seems to works OK on Windows.
>
> HTH
>
> John.
>
> ----- Original Message -----
> From: Guido Rodriguez
> To: mark.gooding at gmail.com
> Cc: vtkusers at vtk.org
> Sent: Friday, September 11, 2009 8:57 AM
> Subject: Re: [vtkusers] Animation without polling?
> Mark, thank you.
> I have found an example, how vtkAnimationCues and vtkAnimationScenes can be
> used, at http://www.vtk.org/pipermail/vtkusers/2005-April/079340.html. I
> didn't know these animation classes before, and find them very helpful.
>
> But for the specific problem, how to run an animation parallel to listening
> to mouse/key events, I don't see how this helps, yet.
> The example above starts animation with
>   scene->Play();
> How can this coexist with a call to vtkRenderWindowInteractor::Start()?
> Both calls run their own event loop, the one handling animation events, the
> other handling interaction events.
>
> I'm looking forward to your more detailed information.
>
> Regards,
> Guido
>
>> Date: Thu, 10 Sep 2009 17:06:39 +0100
>> Subject: Re: [vtkusers] Animation without polling?
>> From: mark.gooding at gmail.com
>> To: guidorodriguez1952 at hotmail.com
>> CC: vtkusers at vtk.org
>>
>> you shouldn't have to write a complete vtkRenderWindowInteractor, just
>> add an observe to handle AnimationCueTickEvents
>>
>> http://www.vtk.org/doc/nightly/html/classvtkCommand.html
>>
>> i'll try to send you more detailed information later. I don't have my
>> software which did animation to hand right now.
>>
>> Mark
>>
>>
>> 2009/9/10 Guido Rodriguez <guidorodriguez1952 at hotmail.com>:
>> > Dear VTK users/developers,
>> > I ask for guidance, how animated visualization is done right with VTK.
>> > What
>> > I have in mind is an application which calculates, let's say, a
>> > temperature
>> > field, which changes in time. Whenever the field is completely
>> > calculated
>> > for the next time step, the visualization should be updated. In
>> > parallel,
>> > the user should be able to work with the mouse/key controls to rotate
>> > the
>> > view, zoom, interact with 3D widgets, etc.
>> >
>> > The obvious way would be to run VTK in one thread, and the calculation
>> > in
>> > another. Each finished calculation step would notify VTK to update. But
>> > it
>> > doesn't work like this. At least not with the X windows system. When I
>> > call
>> > some pipeline's Update() function from a different thread, I get an
>> > "invalid
>> > thread access".
>> >
>> > Next attempt. I implement an event buffer, which is written to by the
>> > calculation thread, and which is read from by the VTK thread. This works
>> > like a charm. Now VTK can check whether an update is necessary and get
>> > the
>> > required data from the event buffer. But _when_ does VTK check for
>> > updates?
>> > I can't seem to find a solution which sets VTK to sleep until either a
>> > mouse/key event happens or until the calculation thread releases some
>> > lock,
>> > simply because any VTK callback waiting for notification from a
>> > different
>> > thread would stop VTK from reacting to mouse/key events during this
>> > period.
>> >
>> > The only solution I can see is to add a timer event like every 10 ms,
>> > which
>> > checks the event buffer for updates. This works, but is it recommended?
>> > Threading libraries have introduced locks and notification to avoid the
>> > overhead from polling at interactive rates for events that may occur
>> > only
>> > every few seconds. How can good multithreading programming styles be
>> > applied
>> > to VTK?
>> >
>> > I hope the problem is clear. Can a different thread trigger pipeline
>> > updates
>> > under X windows? Or do I have to write my own vtkRenderWindowInteractor?
>> >
>> > Regards,
>> > Guido
>> > ________________________________
>> > With Windows Live, you can organize, edit, and share your photos.
>> > _______________________________________________
>> > 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
>> >
>> >
>
> ________________________________
> Share your memories online with anyone you want anyone you want.
> ________________________________
> _______________________________________________
> 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
>
> ________________________________
> Share your memories online with anyone you want anyone you want.
> _______________________________________________
> 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
>
>



-- 
Jeff Baumes, Ph.D.
R&D Engineer, Kitware Inc.
(518) 881-4932
jeff.baumes at kitware.com



More information about the vtkusers mailing list