That&#39;s much clearer now!<br>If your reader and cast filter are not in the same place (focus), <br>the smart pointer has deleted the reader. Now it&#39;s sure. The simplest<br>work around (but not the fanciest/cutest) would be:<br>
<br>reader-&gt;Update( );<br>vtkImagedata* readerOutput = vtkImageData::SafeDownCast( reader-&gt;GetOutputDataObject( 0, 0 ));<br>vtkImageData* myImage = vtkImageData::New( );<br>myImage-&gt;DeepCopy( readerOutput );<br><br>
Then you can use myImage everywhere you want. Don&#39;t forget to Delete( ) it, since it is not a SmartPointer but a simple New() allocation.<br><br>HTH<br>Jerome<br><br><br><div class="gmail_quote">2011/6/8 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;">Hi Jerome,<br>
Thank you for your answer.<br>
<br>
The problem is that the reader and the cast are not done at the same<br>
place so that&#39;s why I have a vtkImageData which is transmitted in<br>
another parts of the code.<br>
I use a vtkImageData to have some informations such as dimensions,<br>
center, etc and because we use other types so we have sometimes to<br>
translate from vtkImageData to another image type (custom image types or<br>
QImage for instance).<br>
<br>
I understand I break the pipeline doing this as I have :<br>
reader-&gt;imageData | break<br>
imageData-&gt;cast-&gt;mapper-&gt; etc<br>
instead of : reader-&gt;cast-&gt;mapper-&gt; etc<br>
But if I want to keep the pipeline complete, I have to transmit a<br>
vtkAlgorithm pointer which is less usable outside of vtk, and actually I<br>
don&#39;t need the beginning of the pipeline, I have enough with the<br>
vtkImageData.<br>
<br>
Actually if I delete the reader pointer I have the same problem, so that<br>
means using the setInput() method as I do involves somewhere a call to<br>
myVtkImageData-&gt;GetProducerPort() which is became null...<br>
<br>
That means also I guess I can&#39;t use the same reader to read a lot of<br>
vtkImageData for instance (which would solve my leak problem), because<br>
somewhere it keeps a reference to the reader which has done the import<br>
in the vtkImageData.<br>
I can&#39;t imagine what happen if I read a first vtkImageData, and then a<br>
second, and try to display or apply a filter to the first one.<br>
<br>
Thanks,<br>
<font color="#888888"><br>
Laurent<br>
</font><div><div></div><div class="h5"><br>
On Wed, 2011-06-08 at 16:42 +0200, Jérôme wrote:<br>
&gt; Hi,<br>
&gt;<br>
&gt; You should use cast-&gt;SetInputConnection( reader-&gt;GetOutputPort( ) );<br>
&gt; instead of the old fashion SetInput.<br>
&gt; IMHO, the problem is that your smart pointer, for some reasons<br>
&gt; (reference count becomes null), decided to deallocate the reader, and<br>
&gt; thus the underlying output.<br>
&gt;<br>
&gt; HTH,<br>
&gt; Jerome<br>
&gt;<br>
&gt; 2011/6/7 Laurent Mundeleer &lt;<a href="mailto:laurent.mundeleer@uclouvain.be">laurent.mundeleer@uclouvain.be</a>&gt;<br>
&gt;         Hi everyone,<br>
&gt;         I have a strange problem in reading a MetaImage.<br>
&gt;         I have a segmentation fault when I access the vtkImageData,<br>
&gt;         but if I use a direct pointer instead of a smartPointer on the<br>
&gt;         vtkImageReader it&#39;s ok (but I have a memory leak).<br>
&gt;<br>
&gt;         What am I doing wrong ?<br>
&gt;         Here are some code extracts of what is working :<br>
&gt;<br>
&gt;         // in reader method :<br>
&gt;         ...<br>
&gt;         vtkImageData *imageData = 0;<br>
&gt;         ...<br>
&gt;<br>
&gt;         vtkMetaImageReader* reader = vtkMetaImageReader::New();<br>
&gt;         //add to replace : vtkSmartPointer&lt;vtkMetaImageReader&gt; reader<br>
&gt;         = vtkSmartPointer&lt;vtkMetaImageReader&gt;::New();<br>
&gt;         // and have no delete at the end of the reading<br>
&gt;         ..<br>
&gt;         reader-&gt;Update();<br>
&gt;         ...<br>
&gt;         imageData = reader-&gt;GetOutput();<br>
&gt;<br>
&gt;         // no delete on the reader<br>
&gt;<br>
&gt;         /------------------------------------------<br>
&gt;<br>
&gt;         // in renderer method :<br>
&gt;            vtkSmartPointer&lt;vtkImageCast&gt; castSource<br>
&gt;         =vtkSmartPointer&lt;vtkImageCast&gt;::New();<br>
&gt;            castSource-&gt;SetOutputScalarTypeToUnsignedChar();<br>
&gt;            castSource-&gt;SetInput(imageData); // seg fault<br>
&gt;            castSource-&gt;Update();<br>
&gt;<br>
&gt;         /---------------------------------------------<br>
&gt;         // or in unit test :<br>
&gt;         vtkImageData*volume = readingMethod();<br>
&gt;         ...<br>
&gt;         double *origin = volume-&gt;GetOrigin(); // seg fault<br>
&gt;<br>
&gt;<br>
&gt;         Thank you for any help,<br>
&gt;         Best Regards,<br>
&gt;<br>
&gt;         ++<br>
&gt;         Laurent<br>
&gt;<br>
&gt;<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>
<br>
<br>
</div></div></blockquote></div><br>