<div dir="ltr"><div class="gmail_default"><font face="verdana, sans-serif">Thank you for your help Sebastien. Other issues appeared as well after I have introduced multi-threading. The VTK-related part is finished. Here is a sketch of my solution:</font></div>
<div class="gmail_default"><font face="verdana, sans-serif"><br></font></div><div class="gmail_default"><div class="gmail_default"><font face="courier new, monospace">void timerFunction()</font></div><div class="gmail_default">
<font face="courier new, monospace">{</font></div><div class="gmail_default"><font face="courier new, monospace"> if (render)</font></div><div class="gmail_default"><font face="courier new, monospace"> {</font></div>
<div class="gmail_default"><font face="courier new, monospace"> renderLock->Lock();</font></div><div class="gmail_default"><font face="courier new, monospace"> render=false;</font></div><div class="gmail_default">
<font face="courier new, monospace"> renderLock->Unlock();</font></div><div class="gmail_default"><font face="courier new, monospace"> mainForm.vis->GetRenderWindow()->Render();</font></div><div class="gmail_default">
<font face="courier new, monospace"><span style="white-space:pre"> </span>QApplication::processEvents();</font></div><div class="gmail_default"><font face="courier new, monospace"> }</font></div><div class="gmail_default">
<font face="courier new, monospace">}</font></div></div><div class="gmail_default"><font face="courier new, monospace"><br></font></div><div class="gmail_default"><div class="gmail_default"><div class="gmail_default"><font face="courier new, monospace">void threadFunction()</font></div>
<div class="gmail_default"><font face="courier new, monospace">{</font></div><div class="gmail_default"><font face="courier new, monospace"> while (notFinished)</font></div><div class="gmail_default"><font face="courier new, monospace"> {</font></div>
<div class="gmail_default"><font face="courier new, monospace"> //calculate stuff</font></div><div class="gmail_default"><font face="courier new, monospace"> vtkSmartPointer<vtkPolyData> pd=v->getPoly();</font></div>
<div class="gmail_default"><font face="courier new, monospace"> renderLock->Lock();</font></div><div class="gmail_default"><font face="courier new, monospace"> render=true;</font></div><div class="gmail_default">
<font face="courier new, monospace"> ((vtkPolyDataMapper *)v->actor->GetMapper())->SetInput(pd);</font></div><div class="gmail_default"><font face="courier new, monospace"> v->actor->GetMapper()->Modified();</font></div>
<div class="gmail_default"><font face="courier new, monospace"> renderLock->Unlock();</font></div><div class="gmail_default"><font face="courier new, monospace"> v->actor->GetMapper()->Update();</font></div>
<div class="gmail_default"><font face="courier new, monospace"> }</font></div><div class="gmail_default"><font face="courier new, monospace">}</font></div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Wed, Feb 20, 2013 at 8:06 PM, Sebastien Jourdain <span dir="ltr"><<a href="mailto:sebastien.jourdain@kitware.com" target="_blank">sebastien.jourdain@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">The add actor should be done by the same VTK thread that is rendering.<div>So only one thread can do that action.</div><div>Moreover, you should call Update() on the mapper within each of your thread to reduce the work that will be done by the main vtk thread.</div>
<div><br></div><div>Hope that make sense,</div><div><br></div><div>Seb</div><div><br></div><div>PS: VTK is not thread safe, but I've already done something similar to what you did without any issue.</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div class="h5">On Wed, Feb 20, 2013 at 5:18 PM, Dženan Zukić <span dir="ltr"><<a href="mailto:dzenanz@gmail.com" target="_blank">dzenanz@gmail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">
I have a need to modify the scene from multiple threads.</div>
<div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">
<br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Each thread looks like:</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">{</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">
for (i=1 to 100)</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">create mesh_i;</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">convert it to vtkPolyData;</div>
<div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">if exists actor delete it;</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">create actor with pd;</div>
<div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">add actor to renderer;</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">update display;</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">
}</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">How best to accomplish this? I already tried <a href="http://www.vtk.org/pipermail/vtkusers/2004-April/073478.html" target="_blank">this</a> approach, but it does not work. It always crashes before returning from Render() method. Crashes are at random location in VTK rendering code.</div>
</div>
<br></div></div>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>