[vtkusers] Refreshing the vtkRenderWindow

Vivek Gupta vivekg at mac.com
Tue May 4 10:06:53 EDT 2004


Hello,

I wanted to let you know that the Windows Set Timer worked!  Thanks a  
lot for all of the help!

Here are the couple of lines that I had to add just for reference by  
anyone else who might need it:

1) Declaration of the callback

VOID CALLBACK myTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD  
dwTime) {
   renWin->Render();
}

I have my renderWindow declared globally so I have access to it.

2) Actual creation of the timer
   int timer_number = SetTimer( NULL, 0, 20, (TIMERPROC) myTimerProc );

The first parameter would be a handle to the Window that should handle  
it and the second is to give an id to the event.  However in this case  
there is no window that I want to associate it with, just the  
application.  The third parameter how often the event will be generated  
(in milliseconds) and the last is the callback function.

3) Kill the timer after the event loop exits
KillTimer(NULL, timer_number);

4) For more information take a look at this URL:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/ 
WinUI/WindowsUserInterface/Windowing/Timers/UsingTimers.asp

(Sorry if the URL gets wrapped poorly)

Hope this helps anyone else who runs into this problem.

Vivek

On Apr 30, 2004, at 11:45, David Gobbi wrote:

> Hi Vivek,
>
> Yes, that should work.
> I suspect the reason that the last attemp (calling CreateTimer) didn't
> work is that the vtkRenderWindowInteractor has only one timer, so as  
> soon
> as the interactor started making its own CreateTimer calls, your
> CreateTimer calls were ignored.
>
>  - David
>
> On Fri, 30 Apr 2004, Vivek Gupta wrote:
>
>> Hi David,
>>
>> I am actually running under windows and letting VTK handle all of the  
>> windowing.  So I should just create a Windows Timer and in the code  
>> executed from that call render since that will be synchronized with  
>> the main thread?
>>
>> Thanks,
>> Vivek
>>
>> On Friday, April 30, 2004, at 11:33AM, David Gobbi  
>> <dgobbi at imaging.robarts.ca> wrote:
>>
>>> Hi Vivek,
>>>
>>> Instead of using VTK observers, you might want to use a timer  
>>> generated by
>>> whatever GUI toolkit you are using.  E.g. in Tk you would use  
>>> 'after.'
>>>
>>> Please not that these "Timers" don't have anything to do with  
>>> threads,
>>> they are generated by the GUI event loop, which ensures that they are
>>> synchronous with your main thread execution.  If you could call a  
>>> "Render"
>>> from another thread (which you can't), then you wouldn't have to deal
>>> with timers in the first place.
>>>
>>> Good luck!
>>>
>>> - David
>>>
>>> On Fri, 30 Apr 2004, Vivek Gupta wrote:
>>>
>>>> Hi David,
>>>>
>>>> Better....  What happened was interesting.  I left all of my code  
>>>> the same, I have the CreateTimer(VTKI_TIMER_FIRST) right before my  
>>>> AddObserver, before my interactor->Start().  I added the one line  
>>>> you suggested in my observor.
>>>>
>>>> When the code starts it does exactly what you said, it starts  
>>>> printing out my line from the Observor over and over. This is  
>>>> great, since this means it is firing of the event continuously like  
>>>> I want, without my having touched the Window.  However, the minute  
>>>> I interact with the window with my mouse (to rotate the view) the  
>>>> events stop firing in an automated fashing and return to firing  
>>>> only when I am interacting with the window through manipulation  
>>>> with the interactor.
>>>>
>>>> Is their any way I can use some other timer thread to send the  
>>>> VTKRenderer or VTKRenderWindowInteractor a refresh or windows  
>>>> REPAINT event?
>>>>
>>>> Thanks a lot for your help,
>>>> Vivek
>>>>
>>>> On Friday, April 30, 2004, at 11:07AM, David Gobbi  
>>>> <dgobbi at imaging.robarts.ca> wrote:
>>>>
>>>>> 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