<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
</style>
</head>
<body class='hmmessage'>
Many thanks!!!<br>This morning I've actually found the solution using QT....just emitting timer events builting up a QTimer with QT and connecting my main thread to capture those events. In that case I'll call the Render() function staying in the main one....<br><br>Many thanks<br>GC.<br><br><br>&gt; Date: Mon, 18 May 2009 08:52:20 -0600<br>&gt; From: clinton@elemtech.com<br>&gt; To: ilferraresebono@hotmail.it<br>&gt; CC: david.cole@kitware.com; vtkusers@vtk.org<br>&gt; Subject: Re: [vtkusers] threads and refreshing vtkRenderWindow<br>&gt; <br>&gt; <br>&gt; Have you look at this?<br>&gt; http://doc.trolltech.com/qq/qq06-glimpsing.html<br>&gt; It would need adjustments if using VTK instead, and I'm curious if it'll <br>&gt; work just fine.<br>&gt; <br>&gt; But, first, you could try overloading QVTKWidget::paintEvent() to do <br>&gt; nothing.<br>&gt; Then in your QThread::run, you create all your VTK objects and do your <br>&gt; Render() calls from there.<br>&gt; You're getting the wglMakeCurrent error because the context is current <br>&gt; in the main thread, and you're trying to make it current in another <br>&gt; thread as well.  That is not allowed.  <br>&gt; http://msdn.microsoft.com/en-us/library/dd374387(VS.85).aspx<br>&gt; <br>&gt; Clint<br>&gt; <br>&gt; Giancarlo Amati wrote:<br>&gt; &gt; Nope I don't,....I was just telling you how I did organize my <br>&gt; &gt; code...and as you said the Render() function should be called only <br>&gt; &gt; from the thread that the MAIN one, I was simply asking..if calling a <br>&gt; &gt; function which belongs to the main thread (which is the Parent from <br>&gt; &gt; the 2nd one) is the reason that generates the wglMakeCurrent error.<br>&gt; &gt; Moreover, as the documentation about the vtkMutexLock class on the vtk <br>&gt; &gt; website is quite poor, I was just wondering if there were any other <br>&gt; &gt; resource.<br>&gt; &gt;<br>&gt; &gt; My project is mainly about a device system which tracks IReds <br>&gt; &gt; visulalized with VTK, basically what I am doing is a real-time <br>&gt; &gt; animation with QT and VTK. So, as I need to update the VTK scene <br>&gt; &gt; without interfering with the QT events, the QT users group told me <br>&gt; &gt; that the best way is to create a thread which updates the scene. But <br>&gt; &gt; apparently this generates a wglMakeCurrent error for the reasons you <br>&gt; &gt; told me.<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; GC.<br>&gt; &gt;<br>&gt; &gt; ------------------------------------------------------------------------<br>&gt; &gt; Date: Fri, 15 May 2009 11:08:20 -0400<br>&gt; &gt; Subject: Re: [vtkusers] threads and refreshing vtkRenderWindow<br>&gt; &gt; From: david.cole@kitware.com<br>&gt; &gt; To: ilferraresebono@hotmail.it<br>&gt; &gt; CC: vtkusers@vtk.org<br>&gt; &gt;<br>&gt; &gt; Are you asking us to tell you how your program is organized with <br>&gt; &gt; respect to threads? (That's somewhat beyond the scope of the VTK <br>&gt; &gt; mailing list.)<br>&gt; &gt;<br>&gt; &gt; It sounds like your project might be better off single-threaded.<br>&gt; &gt;<br>&gt; &gt; It would be better if you call UpdateMy3DObject from the same thread <br>&gt; &gt; that actually does the rendering.<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; On Fri, May 15, 2009 at 10:59 AM, Giancarlo Amati <br>&gt; &gt; &lt;ilferraresebono@hotmail.it &lt;mailto:ilferraresebono@hotmail.it&gt;&gt; wrote:<br>&gt; &gt;<br>&gt; &gt;     Many thanks,<br>&gt; &gt;<br>&gt; &gt;     what I have is a mainWindow which has functions for rendering and<br>&gt; &gt;     then a thread that calls a kind of "UpdateMy3Dobjects" function<br>&gt; &gt;     which belongs to the mainWindow object. Now,<br>&gt; &gt;     this "UpdateMy3DObjects" function works fine whenever that thread<br>&gt; &gt;     is not running while, I got the wglMakeCurrent error as soon as<br>&gt; &gt;     the thread runs the UpdateMy3Dobjects" function.<br>&gt; &gt;     So,<br>&gt; &gt;     as the UpdateMy3Dobjects function calls the RenderWindow-&gt;Render()<br>&gt; &gt;     method (renderwindow buidt in a QVTKWidget object of my GUI)<br>&gt; &gt;     calling that UpdateMy3DObject from the thread does correspond to a<br>&gt; &gt;     call form a thread different from the main one?<br>&gt; &gt;     In that case if I create a global variable, boolean for example<br>&gt; &gt;     which is true when I execute the UpdateMy3DObject function and<br>&gt; &gt;     false otherwise...would it help to synchronize these threads?<br>&gt; &gt;<br>&gt; &gt;     I checked out on the VTK documentation and I found the<br>&gt; &gt;     vktMutexLock class....and i tried to understand the example in the<br>&gt; &gt;     documetation which is a bit difficult honestly, but,....can that<br>&gt; &gt;     class be useful for my project?<br>&gt; &gt;<br>&gt; &gt;     many kind regards.<br>&gt; &gt;     Giancarlo<br>&gt; &gt;<br>&gt; &gt;     ------------------------------------------------------------------------<br>&gt; &gt;     Date: Fri, 15 May 2009 10:19:51 -0400<br>&gt; &gt;     Subject: Re: [vtkusers] threads and refreshing vtkRenderWindow<br>&gt; &gt;     From: david.cole@kitware.com &lt;mailto:david.cole@kitware.com&gt;<br>&gt; &gt;     To: ilferraresebono@hotmail.it &lt;mailto:ilferraresebono@hotmail.it&gt;<br>&gt; &gt;     CC: vtkusers@vtk.org &lt;mailto:vtkusers@vtk.org&gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;     I will not claim to be cleverer, but I think I can answer the<br>&gt; &gt;     question:<br>&gt; &gt;<br>&gt; &gt;     Your mistake is calling vtkObjects from multiple threads without<br>&gt; &gt;     synchonization objects. In general, vtkObjects are only safely<br>&gt; &gt;     accessible by one thread at a time. Multi-thread access means you<br>&gt; &gt;     will have to use some sort of mutexes or locks to guarantee that<br>&gt; &gt;     only one thread at a time will call vtkObject methods.<br>&gt; &gt;     Furthermore, you should only attempt to call Render from the main<br>&gt; &gt;     GUI thread of your application.<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;     Hope this helps,<br>&gt; &gt;     David<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;     On Fri, May 15, 2009 at 9:25 AM, Giancarlo Amati<br>&gt; &gt;     &lt;ilferraresebono@hotmail.it &lt;mailto:ilferraresebono@hotmail.it&gt;&gt;<br>&gt; &gt;     wrote:<br>&gt; &gt;<br>&gt; &gt;         Hello vtkUSERS!!! This is an ash question for only the<br>&gt; &gt;         cleverer!! :D<br>&gt; &gt;<br>&gt; &gt;         I have a thread which modifies some data already in the<br>&gt; &gt;         vtkRenderWindow., now, the problem I have is when I want to<br>&gt; &gt;         refresh the window.<br>&gt; &gt;         I though calling something like renderWindow-&gt;Render() or<br>&gt; &gt;         renderer-&gt;render(), but I get some error messages related to<br>&gt; &gt;         "Resource already in use" and "wglMakeCurrent()" function error.<br>&gt; &gt;<br>&gt; &gt;         Where is my mistake and any idea about how to overcome it?<br>&gt; &gt;<br>&gt; &gt;         Kind regards.<br>&gt; &gt;<br>&gt; &gt;         GC.<br>&gt; &gt;<br>&gt; &gt;         ------------------------------------------------------------------------<br>&gt; &gt;         Scrivi, parla e gioca con i tuoi amici! Scarica Messenger<br>&gt; &gt;         2009! &lt;http://messenger.it/gioca.aspx&gt;<br>&gt; &gt;<br>&gt; &gt;         _______________________________________________<br>&gt; &gt;         Powered by www.kitware.com &lt;http://www.kitware.com&gt;<br>&gt; &gt;<br>&gt; &gt;         Visit other Kitware open-source projects at<br>&gt; &gt;         http://www.kitware.com/opensource/opensource.html<br>&gt; &gt;<br>&gt; &gt;         Please keep messages on-topic and check the VTK FAQ at:<br>&gt; &gt;         http://www.vtk.org/Wiki/VTK_FAQ<br>&gt; &gt;<br>&gt; &gt;         Follow this link to subscribe/unsubscribe:<br>&gt; &gt;         http://www.vtk.org/mailman/listinfo/vtkusers<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;     ------------------------------------------------------------------------<br>&gt; &gt;     Quali sono le parole pił cliccate? Scopri la top!<br>&gt; &gt;     &lt;http://livesearch.it.msn.com/&gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; ------------------------------------------------------------------------<br>&gt; &gt; Quali sono le parole pił cliccate? Scopri la top! <br>&gt; &gt; &lt;http://livesearch.it.msn.com/&gt;<br>&gt; &gt; ------------------------------------------------------------------------<br>&gt; &gt;<br>&gt; &gt; _______________________________________________<br>&gt; &gt; Powered by www.kitware.com<br>&gt; &gt;<br>&gt; &gt; Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html<br>&gt; &gt;<br>&gt; &gt; Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ<br>&gt; &gt;<br>&gt; &gt; Follow this link to subscribe/unsubscribe:<br>&gt; &gt; http://www.vtk.org/mailman/listinfo/vtkusers<br>&gt; &gt;   <br>&gt; <br>&gt; <br><br /><hr />Chiamate gratis da PC a PC? <a href='http://messenger.it/videoconversazioni.aspx' target='_new'>Provale da Messenger!</a></body>
</html>