<div dir="ltr">Ok this is still wrong.<div><br></div><div style>You can not have part of a vtk pipeline shared across 2 thread. Which is the case for you as you call <span style="font-family:'courier new',monospace;font-size:13px">v->actor->GetMapper()->Update(</span><span style="font-family:'courier new',monospace;font-size:13px">);</span> while the actor is already bind to the renderer that is driven by the VTK thread.</div>
<div style><br></div><div style>You should create the mapper and the actor within your thread and transfer the actor to the VTK thread with the locking mechanism.</div><div style>But before giving that actor, as I said, you should call update on the mapper. </div>
<div style><br></div><div style>Basically what you've done could work if you don't call <span style="font-family:'courier new',monospace;font-size:13px">v->actor->GetMapper()->Update(</span><span style="font-family:'courier new',monospace;font-size:13px">);</span></div>
<div style><span style="font-family:'courier new',monospace;font-size:13px"><br></span></div><div style><span style="font-family:'courier new',monospace;font-size:13px">Seb</span></div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Thu, Feb 21, 2013 at 4:21 PM, Dženan Zukić <span dir="ltr"><<a href="mailto:dzenanz@gmail.com" target="_blank">dzenanz@gmail.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"><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-wrap">Â </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="HOEnZb"><div class="h5"><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>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><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>
</div></div></blockquote></div><br></div>