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