Hi all,<br><br>How to use smart pointers with python-VTK?<br><br>Jothy<br><br><div class="gmail_quote">On Mon, Jan 4, 2010 at 11:08 AM, Zein Salah <span dir="ltr">&lt;<a href="mailto:zeinsalah@gmail.com">zeinsalah@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hello everybody,<br>
<br>
I used smart pointers everywhere (return value, the lvalue) and it worked<br>
as supposed to be.<br>
<br>
Many Thanks,<br>
Zein<br>
<br>
@Rocco: Vielen Dank :).<br>
<br>
On Mon, Jan 4, 2010 at 8:55 AM, Rocco Gasteiger &lt;<a href="mailto:post@rocco-gasteiger.de">post@rocco-gasteiger.de</a>&gt; wrote:<br>
&gt; Hello Zein,<br>
&gt;<br>
&gt; I have two assumptions according to your smart pointer usage (I&#39;m not very<br>
&gt; familiar with them until yet):<br>
&gt;<br>
&gt; 1. Maybe your polydata-pointer &quot;polyData&quot; is not valid outside of your<br>
&gt; function &quot; MyClass::GenerateCont(...)&quot;. Your solution could be in returning<br>
&gt; &quot;cutter-&gt;GetOutput()&quot; directly instead of &quot; vtkSmartPointer&lt;vtkPolyData&gt;<br>
&gt; polyData = cutter-&gt;GetOutput(); return polyData;&quot;<br>
&gt;<br>
&gt; 2. According to this VTK-Documentation:<br>
&gt; <a href="http://www.vtk.org/Wiki/Smart_Pointers" target="_blank">http://www.vtk.org/Wiki/Smart_Pointers</a>, the return type of your function<br>
&gt; could not be correct. Maybe you can try &quot;vtkSmartPointer&lt;vtkPolyData&gt;<br>
&gt; MyClass::GenerateCont(...)&quot; instead, additionally with &quot;return<br>
&gt; cutter-&gt;GetOutput();&quot; (like above) in combination with<br>
&gt; &quot;vtkSmartPointer&lt;vtkPolyData&gt; MyPolydata = MyClass::GenerateCont(..)&quot;.<br>
&gt;<br>
&gt; I hope this gives you a little help.<br>
&gt;<br>
&gt; Best regards, Rocco<br>
&gt;<br>
&gt;<br>
&gt; -----Original Message-----<br>
&gt; From: <a href="mailto:vtkusers-bounces@vtk.org">vtkusers-bounces@vtk.org</a> [mailto:<a href="mailto:vtkusers-bounces@vtk.org">vtkusers-bounces@vtk.org</a>] On Behalf<br>
&gt; Of Zein Salah<br>
&gt; Sent: Sunday, January 03, 2010 5:41 PM<br>
&gt; To: <a href="mailto:vtkusers@vtk.org">vtkusers@vtk.org</a><br>
&gt; Subject: [vtkusers] does returning &quot;vtkPolyData&quot; work?<br>
&gt;<br>
&gt; Hallo ,<br>
&gt; In my class, I have a function that SHOULD return a vtkPolyData, which is<br>
&gt; the result of a vtkCutter, as shown below:<br>
&gt;<br>
&gt;<br>
&gt; vtkPolyData* MyClass::GenerateCont(double cntr[], double nrml[])<br>
&gt; {<br>
&gt;<br>
&gt;    vtkSmartPointer&lt;vtkPlane&gt; plane = vtkSmartPointer&lt;vtkPlane&gt;::New();<br>
&gt;    plane-&gt;SetOrigin(cntr[0], cntr[1], cntr[2]);<br>
&gt;    plane-&gt;SetNormal(nrml[0], nrml[1], nrml[2]);<br>
&gt;<br>
&gt;    vtkSmartPointer&lt;vtkCutter&gt; cutter = vtkSmartPointer&lt;vtkCutter&gt;::New();<br>
&gt;<br>
&gt;    cutter-&gt;SetInput(....); // some input vtkpolydata<br>
&gt;    cutter-&gt;SetCutFunction(plane);<br>
&gt;    cutter-&gt;Update();<br>
&gt;<br>
&gt;<br>
&gt;    vtkSmartPointer&lt;vtkPolyData&gt; polyData = cutter-&gt;GetOutput();<br>
&gt;    return polyData;<br>
&gt; }<br>
&gt;<br>
&gt;<br>
&gt; Now I have an array of struct, cArray, where one field of the struct is of<br>
&gt; type vtkPolyData*. When I call the GenerateCont function on the elements<br>
&gt; of the array, as follows<br>
&gt;<br>
&gt;<br>
&gt; for (int i= 0; i&lt;num; i++) {<br>
&gt;     double       cntr[3];      cntr[0] = ...;     cntr[1] = ...;<br>
&gt;      cntr[2] = ...;<br>
&gt;     double       zdir[3];      zdir[0] = ...;            zdir[1] =<br>
&gt; ...;             zdir[2] = ...;<br>
&gt;<br>
&gt;     cArray[i].polyData = GenerateCont(cntr, zdir);<br>
&gt; }<br>
&gt;<br>
&gt; I noticed that the cArray is not updated. I.e. calling function GenerateCont<br>
&gt; does not return the supposed vtkPolyData. By testing whether the function<br>
&gt; GenerateCont works itself, I found that is the vtkCutter generates the<br>
&gt; output as required, only the output value is not returned.<br>
&gt;<br>
&gt; What is wrong I am doing? Is returning a vtkPolyData semantically wrong?<br>
&gt;<br>
&gt;<br>
&gt; Much thanks,<br>
&gt; Zein<br>
&gt; _______________________________________________<br>
&gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;<br>
&gt; Visit other Kitware open-source projects at<br>
&gt; <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
&gt;<br>
&gt; Please keep messages on-topic and check the VTK FAQ at:<br>
&gt; <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
&gt;<br>
&gt; Follow this link to subscribe/unsubscribe:<br>
&gt; <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
&gt;<br>
&gt;<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>
</blockquote></div><br>