<div dir="ltr">Hi Richard,<div><br></div><div>Give VTK 6.1 a try. It was release in January and I believe it has all of these changes in it. There may have been some minor fixes since then but 6.1 is definitely a good starting point. Note that there has been some API changes in VTK 6 so you may have to update some of your code.</div>
<div><br></div><div>For reference, these changes were driven by this work:</div><div><br></div><div><a href="http://www.vtk.org/Wiki/images/3/3b/VTK_SMP_Guide.pdf">http://www.vtk.org/Wiki/images/3/3b/VTK_SMP_Guide.pdf</a><br>
</div><div><br></div><div>Look at the Wiki for info on changes in 6.0:</div><div><br></div><div><a href="http://www.vtk.org/Wiki/VTK">http://www.vtk.org/Wiki/VTK</a><br></div><div><br></div><div>Here is a more detailed example of shallow copy:</div>
<div><br></div><div>global:</div><div><br></div><div>vtkSimpleCriticalSection Lock;</div><div>Lock.Init();</div><div><br></div><div>vtkDataSet* OutputCopy = 0;</div><div><br></div><div>thread 1:</div><div><br></div><div>
filter->Update();</div>
<div>vtkDataSet* output = filter->GetOutput();</div><div><br></div><div>Lock.Lock()</div><div>OutputCopy = output->NewInstance();</div><div>OutputCopy->ShallowCopy(output);</div><div>Lock.Unlock();<br></div><div>
<br></div><div>thread 2:</div><div><br></div><div>vtkDataSet* renderedData;</div><div><br></div><div><div>Lock.Lock()</div></div><div>if (OutputCopy)</div><div> {</div><div> renderedData = OutputCopy->NewInstance();</div>
<div> renderedData->ShallowCopy(OutputCopy);</div><div> OutputCopy = 0;</div><div> }</div><div>Lock.Unlock();</div><div><br></div><div>// Render renderedData here</div><div><br></div><div>Depending on the application, double shallow copy may be overkill but I can't tell without knowing more. Also, I am guessing that you handle messaging between threads in some way.</div>
<div><br></div><div>Best,</div><div>-berk</div><div><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Mar 24, 2014 at 12:37 PM, Richard Whitehead <span dir="ltr"><<a href="mailto:richard.whitehead@vivosight.com" target="_blank">richard.whitehead@vivosight.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Thanks Berk,<div>I had no idea this work was in progress, it looks like you are going to solve the problem for me!!! From the sound of it, you will not be introducing threads and triggers into VTK, that will still be an application domain issue, if I understand correctly?</div>
<div>Please could you explain the couple of lines of code you included, I'm afraid I don't understand what the objects are or why you seem to refer to "output" twice in different ways?</div><div>Are there any time-scales on when this work might reach a released build? I'm working on a medical application and I am very reluctant to use an unstable build, but will do if I have to, the reward in this case would be significant.</div>
<div>Huge thanks,<br></div><div>Richard</div></div><div class="gmail_extra"><div><div class="h5"><br><br><div class="gmail_quote">On 24 March 2014 15:14, Berk Geveci <span dir="ltr"><<a href="mailto:berk.geveci@kitware.com" target="_blank">berk.geveci@kitware.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Let me add my 2 cents.<div><br></div><div>
First of all, make sure that you are using the latest VTK from Git. It makes reference count management thread safe. As long as the reference does not go to 0 while another thread is using an object, it will be fine. Using smart pointers will also be OK. Git VTK has bunch of other thread safety improvements by the way.</div>
<div><br></div><div>Second, when you hand data from the compute thread to the render thread, I would use a shallow copy. Something like:</div><div><br></div><div>copyToRender = output->NewInstance();</div><div>copyToRender->ShallowCopy(output);</div>
<div><br></div><div>Make sure that this is protected by a mutex if the compute thread eventually deletes "output". This would not be needed normally but there is still some garbage collection left that may cause issues. This should make it safe. It will be unnecessary in the future as we clean things more.</div>
<div><br></div><div>Finally, never connect a pipeline across threads. Render should cause filters that belong to another to execute.</div><div><br></div><div>If you are still running into specific thread safety issue, try to trace them with helgrind and please report them to this list or to me directly.</div>
<div><br></div><div>Best,</div><div>-berk</div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Mar 24, 2014 at 11:00 AM, Aashish Chaudhary <span dir="ltr"><<a href="mailto:aashish.chaudhary@kitware.com" target="_blank">aashish.chaudhary@kitware.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">
<div>On Mon, Mar 24, 2014 at 10:53 AM, David Cole <span dir="ltr"><<a href="mailto:dlrdave@aol.com" target="_blank">dlrdave@aol.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Hi Aashish,<br>
<br>
The blog post you pointed to was published in October 2012, and referenced releasing the source code by the end of 2013. Was the source code released? Is there a public repo for it?<br></blockquote><div><br></div></div><div>
At the end of the blog, Rusty answered this question. Please have a look at it. </div><div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
I find it hard to believe that the only thing you had to do was "a vtkSmartPointer trick"...<br></blockquote><div><br></div></div><div>It was not just that but it was part of the core implementation. </div><div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
If there is a way to run, for example, the vtkMarchingCubes filter on a large volumetric dataset, with a pipeline that's in a background non-GUI thread, it sure would be useful to have a snippet of example code that proves it. Or any other long running vtkAlgorithm, for that matter.<br>
</blockquote><div><br></div></div><div>I don't remember what algorithms we ran but they were mostly image based or our own written in VTK. </div><div><br></div><div>- Aashish</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
<br>
Thanks,<br>
David<br>
<br>
</blockquote></div><div><br><br clear="all"><div><br></div>-- <br>| Aashish Chaudhary <br>| R&D Engineer <br>| Kitware Inc. <br>| <a href="http://www.kitware.com" target="_blank">www.kitware.com</a>
</div></div></div>
<br>_______________________________________________<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><br clear="all"><div><br></div></div></div><div class="">-- <br><div dir="ltr"><p style="color:rgb(80,0,80);font-family:Calibri;margin:0cm 0cm 0.0001pt"><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif">Richard Whitehead </span><b><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif;color:rgb(146,39,143)">–</span></b><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif"> Senior Imaging Engineer</span></p>
<p style="color:rgb(80,0,80);font-family:Calibri;margin:0cm 0cm 0.0001pt"><b><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif;color:rgb(146,39,143)">Michelson Diagnostics Ltd</span></b></p><p style="color:rgb(80,0,80);font-family:Calibri;margin:0cm 0cm 0.0001pt">
<b><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif;color:rgb(146,39,143)">M:</span></b><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif"> <a href="tel:%2B44%20%280%297905%20955276" value="+447905955276" target="_blank">+44 (0)7905 955276</a> </span><b><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif;color:rgb(146,39,143)">T:</span></b><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif"> <a href="tel:%2B44%20%280%2920%208308%201695" value="+442083081695" target="_blank">+44 (0)20 8308 1695</a></span></p>
<p style="color:rgb(80,0,80);font-family:Calibri;margin:0cm 0cm 0.0001pt"><b><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif;color:rgb(146,39,143)">E: </span></b><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif;color:rgb(0,176,240)"><a href="mailto:richard.whitehead@vivosight.com" style="color:rgb(17,85,204)" target="_blank"><span style="color:rgb(0,176,240)">richard.whitehead@vivosight.com</span></a></span><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif"> </span><b><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif;color:rgb(146,39,143)">W:</span></b><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif"> </span><span lang="EN" style="font-size:10pt;font-family:Arial,sans-serif;color:rgb(0,176,240)"><a href="http://www.vivosight.com/" style="color:rgb(17,85,204)" target="_blank"><span style="color:rgb(0,176,240)">www.vivosight.com</span></a></span></p>
<p style="color:rgb(80,0,80);font-family:Calibri;margin:0cm 0cm 0.0001pt"><br></p><p style="color:rgb(80,0,80);font-family:Calibri;margin:0cm 0cm 0.0001pt"><a href="http://www.vivosight.com/" target="_blank"><span style="color:windowtext;text-decoration:none"><img src="https://sites.google.com/a/vivosight.com/logo/_/rsrc/1361922206747/home/VivoSight.png" border="0"></span></a></p>
<p style="color:rgb(80,0,80);font-family:Calibri;margin:0cm 0cm 0.0001pt"><br></p><p style="color:rgb(80,0,80);font-family:Calibri;margin:0cm 0cm 0.0001pt"></p><p style="color:rgb(80,0,80);font-family:Calibri;margin:0cm 0cm 0.0001pt">
<span style="font-size:7.5pt;font-family:Arial,sans-serif;color:gray">Michelson Diagnostics Ltd, 1 Grays Farm Production Village, Grays Farm Road, Orpington, Kent BR5 3BD, UK</span></p><p style="color:rgb(80,0,80);font-family:Calibri;margin:0cm 0cm 0.0001pt">
<span style="font-size:7.5pt;font-family:Arial,sans-serif;color:gray">Registered Office: 3 Shearwater, Maidstone, ME16 0DW. Registered in England No. 5732681</span></p></div>
</div></div>
</blockquote></div><br></div></div>