[vtkusers] Force rendering from a thread

Totte Karlsson totte at dunescientific.com
Tue Jan 13 20:38:46 EST 2015


On 1/13/2015 4:36 PM, David Gobbi wrote:
>
> The rendering in VTK must be done from the main application thread 
> (i.e. the thread that runs the application's main event loop), and in 
> an application, polling is an excellent way for the main loop to check 
> if any other threads require attention.  So my advice is that you 
> become a fan of polling.  In this case, it's the right way forward.
>
I see. Currently I have a very simple polling timer, checking for an 
integer being set to 1 or 0. If the integer is set, I do a render. Works 
fine. Don't need a mutex for that I assume.

> You could, instead, have your thread ask the operating system to send 
> your application some kind of notification that the main loop could 
> respond to, but that would probably be less efficient than polling 
> (and it would be platform-specific).  Or, in Qt, you could take 
> advantage of an asynchronous signal-slot connection and let Qt take 
> care of the details (Qt would either do polling internally, or would 
> use an OS-level notification, I'm not sure which).
>
I'm not familiar with Qt slots, and I have not tried the polling in a ms 
windows application yet. But I guess one can post a custom user message, 
that is intercepted in the apps message loop (which is polling), and 
handle it there. Would just be a call to render();

Obviously I take your word for becoming a fan of polling! Thanks.

>     I have noticed when I execute renderInteractive(), that vtk
>     objects are indeed updated from their sources every time the mouse
>     interactively generate a 'render' somewhere. Not sure how that
>     works. Is it possible to tie in there somewhere?
>
>
> The mouse events are caught by the application's main loop, and the 
> main application thread responds to these events (and performs the 
> render at the end).  So you won't find any insight there about how to 
> do things in a multi-threaded fashion.
>
I assume it is so that the renderInteractive() call creates the 
"application loop", in a console application, since there is only one 
thread?

tk


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150113/dc94e5d6/attachment.html>


More information about the vtkusers mailing list