[vtkusers] vtkRenderWindowInteractor and a device thread
Dingrong Yi
dingryi at sten.sunnybrook.utoronto.ca
Wed Nov 17 21:23:25 EST 2004
Hi David and all VTK Users
I have a Plane Navigator hardware like Flying Birds or 3D mouse to input
x, y, z position and orientation. I want to use the parameters provided by
the device to control the vtkCamera/vtkActor position. Meanwhile, I want
to have the built in funcation of VTKRenderWindowInteractor for mouse
interaction. I used two thread approach as suggested below in David's
Email. However, after the interactor start, the device can not update the
renderwindow. Vivek solved the problem by using a Timer method that is
seperate from the timer of the vtkRenderWindowInteractor. Is there any
other way exist? because I donot know how to embed vtkRendereWindow into
either QT or TK right now. Or please give me an example of embed
vtkRenderWindow with TK/QT. Thanks a lot.
Dingrong
//THe following are the emails between Gobbi and Vivek.
Hi Vivek,
You can only call "Render" from the main thread (i.e. from the thread
that created the vtkRenderWindow).
The proper solution to your problem is to get the device thread to
communicate the coordinate information to the main thread via a mutex
lock (specifically, a vtkMutexLock).
For example, you could have a mutex lock called "renderLock" and four
variables x, y, z and "render":
vtkMutexLock *renderLock = vtkMutexLock::New();
double x, y, z;
int render;
So every time your device wanted to render the window, it would do this:
renderLock->Lock();
<set x, y, and z variables>
render = 1;
renderLock->Unlock();
Then the main thread would have to check every-so-often to see if the
"render" variable is set, you could add an observer for an interactor
"Timer" event to do this:
if (render == 1)
{
renderLock->Lock();
<use x, y and z to set up the scene>
render = 0;
renderLock->Unlock();
window->Render();
}
I have used tricks similar to this for the Flock of Birds, the Logitech
3D Mouse, and the Northern Digital POLARIS in order to separate the
device thread from the main VTK thread.
- David
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dingrong Yi, Ph.D.
Sunnybrook & Women's College Health Sciences Centre -Imaging Research
3080 Yonge Street (@Lawrence) Suite 6020, P.O.Box 89
Toronto ON M4N 3N1
Canada
Tel.: (416) 4823855 (Office),
Fax: (416) 4823807 (Office)
E-mail: dingryi at sten.sunnybrook.utoronto.ca
More information about the vtkusers
mailing list