Hi, <br>I think that the source of your problem is that when you press &#39;a&#39;, 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.<br>
<br>Hope that helps.<br>Jerome<br><br><div class="gmail_quote">2009/10/29 Steve Chall <span dir="ltr">&lt;<a href="mailto:stevec@renci.org">stevec@renci.org</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Dear fellow VTK enthusiasts:<br>
I&#39;d like to trigger an animation from a keypress event, and then stop the<br>
animation with the same keypress event.  I&#39;ve subclassed<br>
vtkInteractorStyleTrackballCamera with an OnKeyPress() method that looks a<br>
lot like what&#39;s included below.  When the user presses a key,<br>
myInteractorStyleTrackballCamera::OnKeyPress() is invoked, which (for the<br>
selected key, say &#39;a&#39;) toggles myObject&#39;s isAnimating Boolean flag.  If<br>
after toggling the flag is true, I want to start an animation loop.  If<br>
after toggling it&#39;s false, I want to stop that same loop.  But once I start<br>
the loop I can&#39;t penetrate with another &#39;a&#39; keypress (or anything else other<br>
than a &lt;Ctrl-C&gt;) to change the flag back to false and thus stop the loop.<br>
How can I interrupt the &quot;while (isAnimating)&quot; loop once it starts?<br>
<br>
(I&#39;ve also subclassed vtkRenderWindowInteractor because its Start() function<br>
seems like a place for interrupts, but I don&#39;t know what to do with it.)<br>
<br>
Thanks for any help you may be able to provide.<br>
<br>
-Steve Chall<br>
 Senior Research Software Developer<br>
 Renaissance Computing Institute<br>
 Phone: 919-515-0051<br>
 Email: <a href="mailto:stevec@renci.org">stevec@renci.org</a><br>
<br>
// Pseudo C++ source code segments follow:<br>
<br>
...<br>
myClass::Animate()<br>
{<br>
  while (isAnimating)<br>
  {<br>
    this-&gt;RenderNextFrame();<br>
  }<br>
}<br>
...<br>
<br>
myClass *myObject = new myClass;<br>
<br>
...<br>
void myInteractorStyleTrackballCamera::OnKeyPress()<br>
{<br>
  switch (this-&gt;Interactor-&gt;GetKeyCode())<br>
  {<br>
    case &#39;a&#39;:<br>
    case &#39;A&#39;:<br>
      if (myObject)<br>
      {<br>
        myObject-&gt;isAnimating = !(myObject-&gt;isAnimating);<br>
<br>
        if (myObject-&gt;isAnimating)<br>
        {<br>
          myObject-&gt;Animate();<br>
        }<br>
/* This is sort of what I&#39;d like to do:<br>
        else<br>
        {<br>
          myObject-&gt;StopAnimating();<br>
        }<br>
      }<br>
*/<br>
      break;<br>
<br>
    default:<br>
      break;<br>
  }<br>
<br>
  vtkInteractorStyleTrackballCamera::OnKeyPress();<br>
}<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
</blockquote></div><br>