Fine ! <br>BTW, I mixed my latin and greek ;) I meant &#39;scope&#39; not &#39;focus&#39;. <br>SmartPointer are really scope-dependent, unless you manage their reference count by your own (which I do not advice at all...).<br>
<br>Best regards,<br>Jerome<br><br><div class="gmail_quote">2011/6/9 Laurent Mundeleer <span dir="ltr">&lt;<a href="mailto:laurent.mundeleer@uclouvain.be">laurent.mundeleer@uclouvain.be</a>&gt;</span><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Yes thank you, that&#39;s a solution :)<br>
And actually with this I can keep smartPointers.<br>
<br>
Best regards,<br>
<br>
++<br>
<font color="#888888">Laurent<br>
</font><div><div></div><div class="h5"><br>
<br>
On Wed, 2011-06-08 at 17:45 +0200, Jérôme wrote:<br>
&gt; That&#39;s much clearer now!<br>
&gt; If your reader and cast filter are not in the same place (focus),<br>
&gt; the smart pointer has deleted the reader. Now it&#39;s sure. The simplest<br>
&gt; work around (but not the fanciest/cutest) would be:<br>
&gt;<br>
&gt; reader-&gt;Update( );<br>
&gt; vtkImagedata* readerOutput =<br>
&gt; vtkImageData::SafeDownCast( reader-&gt;GetOutputDataObject( 0, 0 ));<br>
&gt; vtkImageData* myImage = vtkImageData::New( );<br>
&gt; myImage-&gt;DeepCopy( readerOutput );<br>
&gt;<br>
&gt; Then you can use myImage everywhere you want. Don&#39;t forget to<br>
&gt; Delete( ) it, since it is not a SmartPointer but a simple New()<br>
&gt; allocation.<br>
&gt;<br>
&gt; HTH<br>
&gt; Jerome<br>
&gt;<br>
&gt;<br>
&gt; 2011/6/8 Laurent Mundeleer &lt;<a href="mailto:laurent.mundeleer@uclouvain.be">laurent.mundeleer@uclouvain.be</a>&gt;<br>
&gt;         Hi Jerome,<br>
&gt;         Thank you for your answer.<br>
&gt;<br>
&gt;         The problem is that the reader and the cast are not done at<br>
&gt;         the same<br>
&gt;         place so that&#39;s why I have a vtkImageData which is transmitted<br>
&gt;         in<br>
&gt;         another parts of the code.<br>
&gt;         I use a vtkImageData to have some informations such as<br>
&gt;         dimensions,<br>
&gt;         center, etc and because we use other types so we have<br>
&gt;         sometimes to<br>
&gt;         translate from vtkImageData to another image type (custom<br>
&gt;         image types or<br>
&gt;         QImage for instance).<br>
&gt;<br>
&gt;         I understand I break the pipeline doing this as I have :<br>
&gt;         reader-&gt;imageData | break<br>
&gt;         imageData-&gt;cast-&gt;mapper-&gt; etc<br>
&gt;         instead of : reader-&gt;cast-&gt;mapper-&gt; etc<br>
&gt;         But if I want to keep the pipeline complete, I have to<br>
&gt;         transmit a<br>
&gt;         vtkAlgorithm pointer which is less usable outside of vtk, and<br>
&gt;         actually I<br>
&gt;         don&#39;t need the beginning of the pipeline, I have enough with<br>
&gt;         the<br>
&gt;         vtkImageData.<br>
&gt;<br>
&gt;         Actually if I delete the reader pointer I have the same<br>
&gt;         problem, so that<br>
&gt;         means using the setInput() method as I do involves somewhere a<br>
&gt;         call to<br>
&gt;         myVtkImageData-&gt;GetProducerPort() which is became null...<br>
&gt;<br>
&gt;         That means also I guess I can&#39;t use the same reader to read a<br>
&gt;         lot of<br>
&gt;         vtkImageData for instance (which would solve my leak problem),<br>
&gt;         because<br>
&gt;         somewhere it keeps a reference to the reader which has done<br>
&gt;         the import<br>
&gt;         in the vtkImageData.<br>
&gt;         I can&#39;t imagine what happen if I read a first vtkImageData,<br>
&gt;         and then a<br>
&gt;         second, and try to display or apply a filter to the first one.<br>
&gt;<br>
&gt;         Thanks,<br>
&gt;<br>
&gt;         Laurent<br>
&gt;<br>
&gt;<br>
&gt;         On Wed, 2011-06-08 at 16:42 +0200, Jérôme wrote:<br>
&gt;         &gt; Hi,<br>
&gt;         &gt;<br>
&gt;         &gt; You should use<br>
&gt;         cast-&gt;SetInputConnection( reader-&gt;GetOutputPort( ) );<br>
&gt;         &gt; instead of the old fashion SetInput.<br>
&gt;         &gt; IMHO, the problem is that your smart pointer, for some<br>
&gt;         reasons<br>
&gt;         &gt; (reference count becomes null), decided to deallocate the<br>
&gt;         reader, and<br>
&gt;         &gt; thus the underlying output.<br>
&gt;         &gt;<br>
&gt;         &gt; HTH,<br>
&gt;         &gt; Jerome<br>
&gt;         &gt;<br>
&gt;         &gt; 2011/6/7 Laurent Mundeleer &lt;<a href="mailto:laurent.mundeleer@uclouvain.be">laurent.mundeleer@uclouvain.be</a>&gt;<br>
&gt;         &gt;         Hi everyone,<br>
&gt;         &gt;         I have a strange problem in reading a MetaImage.<br>
&gt;         &gt;         I have a segmentation fault when I access the<br>
&gt;         vtkImageData,<br>
&gt;         &gt;         but if I use a direct pointer instead of a<br>
&gt;         smartPointer on the<br>
&gt;         &gt;         vtkImageReader it&#39;s ok (but I have a memory leak).<br>
&gt;         &gt;<br>
&gt;         &gt;         What am I doing wrong ?<br>
&gt;         &gt;         Here are some code extracts of what is working :<br>
&gt;         &gt;<br>
&gt;         &gt;         // in reader method :<br>
&gt;         &gt;         ...<br>
&gt;         &gt;         vtkImageData *imageData = 0;<br>
&gt;         &gt;         ...<br>
&gt;         &gt;<br>
&gt;         &gt;         vtkMetaImageReader* reader =<br>
&gt;         vtkMetaImageReader::New();<br>
&gt;         &gt;         //add to replace :<br>
&gt;         vtkSmartPointer&lt;vtkMetaImageReader&gt; reader<br>
&gt;         &gt;         = vtkSmartPointer&lt;vtkMetaImageReader&gt;::New();<br>
&gt;         &gt;         // and have no delete at the end of the reading<br>
&gt;         &gt;         ..<br>
&gt;         &gt;         reader-&gt;Update();<br>
&gt;         &gt;         ...<br>
&gt;         &gt;         imageData = reader-&gt;GetOutput();<br>
&gt;         &gt;<br>
&gt;         &gt;         // no delete on the reader<br>
&gt;         &gt;<br>
&gt;         &gt;         /------------------------------------------<br>
&gt;         &gt;<br>
&gt;         &gt;         // in renderer method :<br>
&gt;         &gt;            vtkSmartPointer&lt;vtkImageCast&gt; castSource<br>
&gt;         &gt;         =vtkSmartPointer&lt;vtkImageCast&gt;::New();<br>
&gt;         &gt;            castSource-&gt;SetOutputScalarTypeToUnsignedChar();<br>
&gt;         &gt;            castSource-&gt;SetInput(imageData); // seg fault<br>
&gt;         &gt;            castSource-&gt;Update();<br>
&gt;         &gt;<br>
&gt;         &gt;         /---------------------------------------------<br>
&gt;         &gt;         // or in unit test :<br>
&gt;         &gt;         vtkImageData*volume = readingMethod();<br>
&gt;         &gt;         ...<br>
&gt;         &gt;         double *origin = volume-&gt;GetOrigin(); // seg fault<br>
&gt;         &gt;<br>
&gt;         &gt;<br>
&gt;         &gt;         Thank you for any help,<br>
&gt;         &gt;         Best Regards,<br>
&gt;         &gt;<br>
&gt;         &gt;         ++<br>
&gt;         &gt;         Laurent<br>
&gt;         &gt;<br>
&gt;         &gt;<br>
&gt;         &gt;         _______________________________________________<br>
&gt;         &gt;         Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;         &gt;<br>
&gt;         &gt;         Visit other Kitware open-source projects at<br>
&gt;         &gt;         <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
&gt;         &gt;<br>
&gt;         &gt;         Please keep messages on-topic and check the VTK FAQ<br>
&gt;         at:<br>
&gt;         &gt;         <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
&gt;         &gt;<br>
&gt;         &gt;         Follow this link to subscribe/unsubscribe:<br>
&gt;         &gt;         <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
&gt;         &gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
<br>
<br>
</div></div></blockquote></div><br>