[vtkusers] Starting an animation with a keypress, terminating with another keypress

Jérôme jerome.velut at gmail.com
Thu Oct 29 12:47:16 EDT 2009


Hi,
I think that the source of your problem is that when you press 'a', you
enter an infinite loop from your main thread. You should call your Animate()
function from another thread. I remember that VTK has built-in thread
manager classes. It could be a solution.

Hope that helps.
Jerome

2009/10/29 Steve Chall <stevec at renci.org>

> Dear fellow VTK enthusiasts:
> I'd like to trigger an animation from a keypress event, and then stop the
> animation with the same keypress event.  I've subclassed
> vtkInteractorStyleTrackballCamera with an OnKeyPress() method that looks a
> lot like what's included below.  When the user presses a key,
> myInteractorStyleTrackballCamera::OnKeyPress() is invoked, which (for the
> selected key, say 'a') toggles myObject's isAnimating Boolean flag.  If
> after toggling the flag is true, I want to start an animation loop.  If
> after toggling it's false, I want to stop that same loop.  But once I start
> the loop I can't penetrate with another 'a' keypress (or anything else
> other
> than a <Ctrl-C>) to change the flag back to false and thus stop the loop.
> How can I interrupt the "while (isAnimating)" loop once it starts?
>
> (I've also subclassed vtkRenderWindowInteractor because its Start()
> function
> seems like a place for interrupts, but I don't know what to do with it.)
>
> Thanks for any help you may be able to provide.
>
> -Steve Chall
>  Senior Research Software Developer
>  Renaissance Computing Institute
>  Phone: 919-515-0051
>  Email: stevec at renci.org
>
> // Pseudo C++ source code segments follow:
>
> ...
> myClass::Animate()
> {
>  while (isAnimating)
>  {
>    this->RenderNextFrame();
>  }
> }
> ...
>
> myClass *myObject = new myClass;
>
> ...
> void myInteractorStyleTrackballCamera::OnKeyPress()
> {
>  switch (this->Interactor->GetKeyCode())
>  {
>    case 'a':
>    case 'A':
>      if (myObject)
>      {
>        myObject->isAnimating = !(myObject->isAnimating);
>
>        if (myObject->isAnimating)
>        {
>          myObject->Animate();
>        }
> /* This is sort of what I'd like to do:
>        else
>        {
>          myObject->StopAnimating();
>        }
>      }
> */
>      break;
>
>    default:
>      break;
>  }
>
>  vtkInteractorStyleTrackballCamera::OnKeyPress();
> }
>
>
>
>
> _______________________________________________
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091029/fe53bd07/attachment.htm>


More information about the vtkusers mailing list