[vtkusers] VTK and QT headaches

Aashish Chaudhary aashish.chaudhary at kitware.com
Tue Dec 14 09:24:24 EST 2010


Hi Alex,

You context is not shared between threads as its indicated in the error.
This is nothing new and you can find lot more information if you google for

"OpenGL share context between threads"

It works in second case because Qt is doing the job of signalling the
function in other thread in thread safe manner.

But looking at your sample code, I am not sure what kind of interaction
issues you are having...

Do you really need two threads? If you do (as I guess you might be loading
data in one and displaying in other), there could be ways around it..

May be this link helps giving you more insight:

http://hacksoflife.blogspot.com/2009/08/creating-opengl-textures-or-vbos-on.html




On Tue, Dec 14, 2010 at 8:45 AM, Alex Southern <mrapsouthern at gmail.com>wrote:

> Hi,
>
> Im running a QThread event loop and trying to execute a
> vtkInteractorWindow->Render() command after each iteration. I have tried two
> approaches so far but neither work well.
>
> The First approach, gives a VTK error and is based on something like this:
> At the initialization stage I pass a pointer to iren. Then in the run()
> function I execute iren->Render();
>
> class myThread : public QThread
> {
>    Q_OBJECT
>
>  public:
>     vtkRenderWindowInteractor *iren;
>     void run();
>    {
>        for (int i = 0; i < 2000; i++)
>        {
>            // process some data
>            iren->Render();
>        }
>    }
> };
>
> This compiles but gives the error in the vtkOutputWindow on each call of
> Render()....
>
> ERROR: In ..\..\Source\VTKGit\Rendering\vtkWin32OpenGLRenderWindow.cxx,
> line 247
> vtkWin32OpenGLRenderWindow (05153168): wglMakeCurrent failed in
> MakeCurrent(), error: The requested resource is in use.
>
> The second approach gives no errors, but results in a very jerky
> interaction. It is implemented by emitting a signal from the for loop after
> every iteration. The threads myRender() signal is connected to a
> updateRenderWindow() slot function i.e.
>
> class myThread : public QThread
> {
>    Q_OBJECT
>
>  public:
>     void run()
>    {
>        for (int i = 0; i < 2000; i++)
>        {
>            // process some data
>            emit myRender();
>        }
>    }
>  signals:
>     void myRender();
> };
>
> class myWindow : public QMainWindow
> {
>    Q_OBJECT
>
> public:
>    myThread Td;
>    vtkRenderWindowInteractor *iren;
>
> public slots:
>    void updateRenderWindow()
>    {
>        iren->Render();
>    }
> }
>
>
> Does anyone have any suggestions as to how I can improve either of these
> methods to give a better interaction?
>
> Thanks
> Alex
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>



-- 
| Aashish Chaudhary
| R&D Engineer
| Kitware Inc.
| www.kitware.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101214/4b38afbc/attachment.htm>


More information about the vtkusers mailing list