[vtkusers] Basic Animation Code

David Doria daviddoria+vtk at gmail.com
Wed Jan 6 13:21:19 EST 2010


On Wed, Jan 6, 2010 at 9:07 AM, David Gobbi <david.gobbi at gmail.com> wrote:
> On Tue, Jan 5, 2010 at 9:28 PM, David Doria <daviddoria+vtk at gmail.com> wrote:
>> On Wed, Dec 16, 2009 at 10:27 PM, Leon Danon <kernelblaha at gmail.com> wrote:
>>> Hi All,
>>>
>>> I'm attempting (and failing) to run a simple animated model where the
>>> position and colour of an actor (in my case a cylider) changes, while at the
>>> same time being rendered.
>>> I have done a bit of googling, but have come up with nothing very useful. My
>>> understanding is that it should be done with threads (one for the renderer,
>>> the other for the model).
>>> Does anyone have a simple example in C++ of how this would be implemented.
>>> It would be greatly appreciated.
>>> Thanks
>>> Leon
>>
>> Surely someone knows how to do this? Is an example of what you want
>> something like a loop to move an object across the scene?
>>
>> pseudo code:
>>
>> for(xposition = 1; xposition < 10; xposition++)
>> {
>>  actor.setposition(xposition,0,0);
>>  render scene
>> }
>>
>> Can anyone translate to VTK?
>>
>> Thanks,
>>
>> David
>
> In general, animation should be done with timer events, because timers
> don't interfere with the other event handling in an application.
>
> Using for/while loops for animation will block the application from
> doing anything _but_ the animation until the loop has completed.
> Threads don't add much benefit over timers and are tricky to use
> because a global VTK mutex lock would be needed, and mistakes in the
> use of threads can easily lead to freezing, crashing, and other
> unpredictable application behavior.
>
> The example Rendering/Testing/Cxx/TestInteractorTimers.cxx gives some
> good clues about how animation can be done in VTK (there are probably
> other, better examples but this one is in C++ and not Tcl or Python).
>
>   David


Here is a demo of using a timer:
http://www.cmake.org/Wiki/VTK/Examples/Utilities/Timer

I'm working on a demo of moving a sphere across a scene. I'll post it
here when it is done (probably over the weekend).

Thanks,

David D.



More information about the vtkusers mailing list