[vtkusers] animation loop and interaction

Sean McInerney seanm at nmr.mgh.harvard.edu
Fri Aug 20 19:48:36 EDT 2004


Hi Akshay,

   I don't know if you are familiar with FLTK, but I created a small 
library, vtkFLTK, for integrating VTK and FLTK. Within the vtkFLTK 
examples is an example called 'Cone4' that demonstrates a repeating 
timer callback. Even if you don't use vtkFLTK, the source code may help 
to illustrate the idea. The ViewCVS link is here: 
<http://cvs.sf.net/viewcvs.py/vtkfltk/vtkFLTK/Examples/Cone4/Cone4.cxx?rev=1.19&view=markup>

   Basically, you have a callback function that updates your animation. 
You set a timer to call that function when it expires. The repeating 
part is that before the timer callback function returns, it sets a new 
timer to call itself ... and so on. Timers are generally platform 
dependent, but are implemented by most GUI toolkits.

-Sean

Akshay Sthapit wrote:
> Hi Sean
> 
> I have no idea how to implement a repeating timer? callback.  Can you
> give some more details, or point me towards some literature/examples? 
> This would be extremely helpful.
> 
> Thanks!
> Akshay
> 
> --- Sean McInerney <seanm at nmr.mgh.harvard.edu> wrote:
> 
> 
>>If you use a repeating timout callback, you shouldn't need separate
>>threads.
>>
>>-Sean
>>
>>Akshay Sthapit wrote:
>>
>>>Hi Alex
>>>
>>>What I have done is to add an observer to renderer -
>>>
>>>renderer->AddObserver(vtkCommand::StartEvent, myVtkCB);
>>>
>>>That way it keeps updating the scene (via a "callback") at a rate
>>
>>which
>>
>>>you can control, and all you have to do is manipulate ("interact")
>>
>>the
>>
>>>actors in another thread, and tadaa you got animation.
>>>
>>>Here's my vtkCB class -
>>>
>>>class vtkCB : public vtkCommand {//Callback to update at every
>>
>>graphics
>>
>>>loop
>>>	public:
>>>		static vtkCB *New() {
>>>			return new vtkCB; 
>>>		}
>>>		virtual void Execute(vtkObject *caller, unsigned long, void*
>>>callData) {
>>>			graphicsInterface->refresh();
>>>		}
>>>		void setup(GraphicsInterface *graphicsInterface) {
>>>			this->graphicsInterface = graphicsInterface;
>>>		}
>>>	private:
>>>			GraphicsInterface *graphicsInterface;
>>>};
>>>
>>>Hope this helps.
>>>
>>>Akshay
>>>
>>>
>>>--- Alexandre Popelard <apopelar at enserg.fr> wrote:
>>>
>>>
>>>
>>>>Hi,
>>>>
>>>>I have developed a little volume animation under c++ using a simple
>>>>loop.
>>>>I would now want to be able to interact with the volume during the 
>>>>animation. But if I use vtkRenderWindowInteractor and start(), it
>>>>stops the 
>>>>main animation loop.
>>>>If you have any ideas or examples on how to do that, please let me
>>>>know.
>>>>
>>>>Thanks,
>>>>Alex
>>>>_______________________________________________
>>>>This is the private VTK discussion list. 
>>>>Please keep messages on-topic. Check the FAQ at:
>>>><http://public.kitware.com/cgi-bin/vtkfaq>
>>>>Follow this link to subscribe/unsubscribe:
>>>>http://www.vtk.org/mailman/listinfo/vtkusers
>>>>
>>>
>>>
>>>
>>>__________________________________________________
>>>Do You Yahoo!?
>>>Tired of spam?  Yahoo! Mail has the best spam protection around 
>>>http://mail.yahoo.com 
>>>_______________________________________________
>>>This is the private VTK discussion list. 
>>>Please keep messages on-topic. Check the FAQ at:
>>
>><http://public.kitware.com/cgi-bin/vtkfaq>
>>
>>>Follow this link to subscribe/unsubscribe:
>>>http://www.vtk.org/mailman/listinfo/vtkusers
>>>
>>



More information about the vtkusers mailing list