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