Hi, <br>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.<br>
<br>Hope that helps.<br>Jerome<br><br><div class="gmail_quote">2009/10/29 Steve Chall <span dir="ltr"><<a href="mailto:stevec@renci.org">stevec@renci.org</a>></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'd like to trigger an animation from a keypress event, and then stop the<br>
animation with the same keypress event. I've subclassed<br>
vtkInteractorStyleTrackballCamera with an OnKeyPress() method that looks a<br>
lot like what's included below. When the user presses a key,<br>
myInteractorStyleTrackballCamera::OnKeyPress() is invoked, which (for the<br>
selected key, say 'a') toggles myObject's isAnimating Boolean flag. If<br>
after toggling the flag is true, I want to start an animation loop. If<br>
after toggling it's false, I want to stop that same loop. But once I start<br>
the loop I can't penetrate with another 'a' keypress (or anything else other<br>
than a <Ctrl-C>) to change the flag back to false and thus stop the loop.<br>
How can I interrupt the "while (isAnimating)" loop once it starts?<br>
<br>
(I've also subclassed vtkRenderWindowInteractor because its Start() function<br>
seems like a place for interrupts, but I don'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->RenderNextFrame();<br>
}<br>
}<br>
...<br>
<br>
myClass *myObject = new myClass;<br>
<br>
...<br>
void myInteractorStyleTrackballCamera::OnKeyPress()<br>
{<br>
switch (this->Interactor->GetKeyCode())<br>
{<br>
case 'a':<br>
case 'A':<br>
if (myObject)<br>
{<br>
myObject->isAnimating = !(myObject->isAnimating);<br>
<br>
if (myObject->isAnimating)<br>
{<br>
myObject->Animate();<br>
}<br>
/* This is sort of what I'd like to do:<br>
else<br>
{<br>
myObject->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>