[vtkusers] Refreshing the vtkRenderWindow

David Gobbi dgobbi at imaging.robarts.ca
Fri Apr 30 11:07:29 EDT 2004


Hi Vivek,

I think I see the problem, the VTK timer is a one-shot timer that
is started, via interactor->CreateTimer(), every time an event occurs.

Try adding
  interactor->CreateTimer(VTKI_TIMER_UPDATE);
after your print statement in your observer method, so that the
timer is re-started every time.

 - David

On Fri, 30 Apr 2004, Vivek Gupta wrote:

> David,
>
> I did try out a simplified version of this with printing to see what
> would happen.  The results aren't quite what I expected. Here is what I
> did:
>
> 1)  I created a callback, currently all this does is print the fact
> that it was called to the console
> 2) From the RenderWindowInteractor I created a timer
> 3) I added an observer to listen to vtkCommand::TimerEvent
>
> What I found was that I get my print out only when interacting with the
> interactor window.  Unfortunately when I am using my external device I
> am not directly interacting with the the renderwindow, so this isn't
> the behavior I wanted.  I'm hoping I can move my cursor around and have
> it update as you described in your idea.
>
> Do I need to write my own event loop? But then I will have problems
> handling the RenderWindowInteractor, right?
>
> Thanks,
> Vivek
>
> On Apr 26, 2004, at 13:38, David Gobbi wrote:
>
> > 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
> >
> >
> > On Mon, 26 Apr 2004, Vivek Gupta wrote:
> >
> >> Hello All,
> >>
> >> I have a case where I have a separate thread that is running and
> >> interfaces with a device.  I use the devices coordinates to update the
> >> location of an actor (3D cursor on the screen).  I also have
> >> vtkRenderWindowInteractor associated with vtkRenderWindow so that in
> >> the
> >> window I can use the built-in abilities to manipulate the camera.
> >> What
> >> I'd like to be able to do is as I manipulate my device is refresh the
> >> vtkRenderWindow to display the actor at the updated coordinates.
> >>
> >> I've tried a variety of methods to do this (vtkRenderWindow->Render(),
> >> this gives some form of openGL error, which I haven't been able to
> >> read)
> >> and none of them seems to work.  Is there a specific way I have to go
> >> about getting the reference to vtkRenderWindow or some other way to
> >> notify it that the actor has been modified so refresh the drawing.
> >> Do I
> >> have use LevelOfDetail in order to set an auto-refresh rate?
> >>
> >> Thanks,
> >> Vivek
> >> _______________________________________________
> >> 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