[vtkusers] Force rendering from a thread

David Gobbi david.gobbi at gmail.com
Tue Jan 13 19:36:40 EST 2015


On Tue, Jan 13, 2015 at 5:01 PM, Totte Karlsson <totte at dunescientific.com>
wrote:

>
> The update of internal data in the subject may be performed in a thread
> and I have now come across the fact that one can't call render() from such.
> Instead, one need to communicate that a render() is needed trough some data
> variable. This can be done but setting up a timer that checks every so
> often, and if the variable is 'set', do a render in the timer callback. But
> I never been a big fan of that kind of pulling. So I wonder if there is
> another, more direct way?
>

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.

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 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.

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


More information about the vtkusers mailing list