[vtkusers] Vtk interactor

tom fogal tfogal at apollo.sr.unh.edu
Thu Jun 10 10:01:10 EDT 2004


Mutex locking must be done in two places, minimum. Pretty much, you want to
acquire a lock before doing anything with a shared resource.
I'm not very familiar with thread libraries other than POSIX threads
(pthreads) but with pthreads you would want something like:

-----
/* psuedo code; this won't compile as is! */
#inlude <pthread.h>
pthread_mutex_t render;

main() {
	vtkRenderer *ren = vtkRenderer::New();
	vtkRenderWindow *ren_wind = vtkRenderWindow::New();
	pthread_mutex_init(&render, NULL);

	/* normal setup stuff, data readers filters etc -- pipeline setup */

	pthread_mutex_lock(mut_pcl);
	ren_wind->Render();
	pthread_mutex_unlock(mut_pcl);
}

... in other thread ...

void CustomInteractor::OnLButtonDown(HWND wnd,UINT nFlags,int X,int Y) {
	pthread_mutex_lock(mut_pcl);
	/* do what you want to do w/ mouse button down */
	pthread_mutex_unlock(mut_pcl);
}
-----

I was assuming the IsAnimating() call was to detect if rendering was underway,
in which case you would want to do nothing..

HTH,

-tom

 <000501c44ee1$eeb00e20$8c0aa8c0 at questtw.questglobal.com>"R K Shyam Prakash" wr
ites:
>Hello Tom/Users,
>		I tried to lock using a vtkMutexLock just before calling
>Render() in the animation thread. But it did not work. The application
>still crashes when the user clicks on the render window when the
>animation is in progress. I am not sure if what I did was right. If you
>have a sample code, that will be of great help ?
>
>Thanks
>Shyam
>
>
>> -----Original Message-----
>> From: vtkusers-bounces at vtk.org 
>> [mailto:vtkusers-bounces at vtk.org] On Behalf Of tom fogal
>> Sent: Wednesday, June 09, 2004 11:42 PM
>> To: R K Shyam Prakash
>> Cc: vtkusers at vtk.org
>> Subject: Re: [vtkusers] Vtk interactor
>> 
>> 
>> Use a mutex.
>> Threading libraries usually provide a 'mutex_lock()' function 
>> that will block until the mutex is acquired.
>> 
>> HTH,
>> 
>> -tom
>> 
>>  <005a01c44e4c$6097f930$8c0aa8c0 at questtw.questglobal.com>"R K 
>> Shyam Prakash" writes:
>> >Hello,
>> >
>> >	I am using vtk4.2.2 with MFC (VC++6.0). I am trying to animate 
>> >rotation of a cylinder in a separate thread. However, if any mouse 
>> >events are fired during animation, program crashes as two 
>> threads are 
>> >accessing simultaneously. So I would like to block my 
>> interactor until 
>> >the animation is complete. How can I achieve this. I tried 
>> overriding 
>> >vtkWin32RenderWindowInteractor. Following is the code.
>> >
>> >void CustomInteractor::OnLButtonDown(HWND wnd,UINT 
>> nFlags,int X,int Y){
>> >	if(model->IsAnimating()){
>> >		return;
>> >	}
>> >
>> >	
>> >this->vtkWin32RenderWindowInteractor::OnLButtonDown(wnd,nFlags,X,Y);
>> >}
>> >
>> >Initially it works fine. When the animation starts, it successfully 
>> >blocks the mouse events. However, even after animation is completed
>> >(model->IsAnimating() returns false), the interactor (super 
>> class) does 
>> >not process the mouse events. Am I doing some thing wrong 
>> here? Please 
>> >suggest.
>> >
>> >Thanks
>> >Shyam



More information about the vtkusers mailing list