[vtkusers] Waiting for rendering to finish

Christian Lackas lackas at invicro.com
Thu Oct 13 10:31:42 EDT 2011


Hello Everybody,

we have a Qt and VTK based application to visualize image data, where
the user can load and unload data. Everything works well as long as
there is no active rendering going on during these processes.

That said, our application does crash (no surprise here) when we try to
for instance unload data while VTK is rendering the it. And we are
wondering how this is supposed to be handled in general.

For instance, we tried to use

    renderingWindow->WaitForCompletion();

which just calls OpenGLs finish(), and seems to be indeed not to be of
great general use:

    virtual void vtkRenderWindow::WaitForCompletion()
    Block the thread until the actual rendering is finished(). Useful
    for measurement only.

We can successfully detect if the renderingWindow is still busy, by
using CheckInRenderStatus(), however, how can I then block for the
rendering process to finish (typically takes a few seconds for our
cases). We tried the Qt busy wait approach (not ideal, but we could live
with it, given it would work):

    while ( renderingWindow->CheckInRenderStatus() ) {
        QApplication::processEvents();
        sleep(100); // sleep thread for 100ms using ::Sleep or usleep(1)
    }

However, this is an infinite loop, since VTK does not seem to continue
to work here (I assume it has its own kind of event loop that is not
processed here, however, I have not figured it out here. We do see in
the debugger that the actual rendering is done in another thread, but it
seems to wait on something during above waiting loop. Can somebody
explain?).

We also looked into vtkRenderWindow::SetAbortRender(int) and
vtkRenderWindow::SetInAbortCheck(int), but we don't fully understand
what this does, however, it definitely does not do what we want (which
is to stop VTK from using the data it is currently working on). 
Would vtkAlgorithm's AbortExecute() help us here?

The only thing that is working so far is if we do something like this
(in the code handling the button push to unload data for instance):

    if (renderingWindow->CheckInRenderStatus())
        return;

And kind of ignore the user input, as if the button would have been
disabled during this time.
In a more user friendly version, we thought about remembering the user
input and trying again a few ms later, e.g.

    void unloadButtonPushed() {
        if (renderingWindow->CheckInRenderStatus()) {
            QTimer::singleShot(1000, this, SLOT(unloadButtonPushed()));
            return;
        }
        ...
    }

But we would have to use that in a lot of places, for an increasing
number of renderingWindows (and it gets a bit more complicated when it
should handle a second click within the delay gracefully).

In the end, I get the feeling we are missing a fundamental concept,
since the way we use VTK it is very hard to safely remove or replace
data VTK is working on.

Any help and/or pointers to documentation would be highly appreciated.

Thanks,
 Christian

-- 
Dr. Christian Lackas, Managing Partner
inviCRO, LLC -- In Imaging Yours
P: +1 617 933 8733, F: +49 2203 9034722, E: lackas at invicro.com
http://www.invicro.com/  http://www.spect-ct.com/



More information about the vtkusers mailing list