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

Steve Chall stevec at renci.org
Fri Oct 30 12:35:47 EDT 2009


Thanks, John.  You’re right, there has been discussion on this in the list,
and not just recently.

 

-Steve

 

  _____  

From: John Platt [mailto:jcplatt at dsl.pipex.com] 
Sent: Thursday, October 29, 2009 2:27 PM
To: Steve Chall; 'Jérôme'
Cc: vtkusers at vtk.org
Subject: Re: [vtkusers] Starting an animation with a keypress,terminating
with another keypress

 

Hi Steve,

 

You may find it simpler to check for an interrupt after rendering each
frame. There has been some discussion on this recently in the list.

 

HTH

 

John.

----- Original Message ----- 

From: Steve Chall <mailto:stevec at renci.org>  

To: 'Jérôme' <mailto:jerome.velut at gmail.com>  

Cc: vtkusers at vtk.org 

Sent: Thursday, October 29, 2009 5:31 PM

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

 

Jérôme,

Yes, precisely: I need to create a new thread to do the animation, and
interrupt that thread on the appropriate keypress.  Googling “vtk thread”
now.  Thanks.

 

-Steve

 


  _____  


From: Jérôme [mailto:jerome.velut at gmail.com] 
Sent: Thursday, October 29, 2009 12:47 PM
To: Steve Chall
Cc: vtkusers at vtk.org
Subject: Re: [vtkusers] Starting an animation with a keypress, terminating
with another keypress

 

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

 


  _____  


_______________________________________________
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/20091030/96dcce5a/attachment.htm>


More information about the vtkusers mailing list