[Insight-users] the Problem about seting up a filter pipeline

Luis Ibanez luis . ibanez at kitware . com
Wed, 25 Jun 2003 16:36:54 -0400


Hi Fang,

It looks like you are creating an ITK pipeline
inside your function

        itkWrapFilters

The pipeline is then being created inside,
executed and (unfortunately) being destroyed
at the end of the funcition scope.

The pipeline destroys the output image, so
by the time you return the pointer to your
variable outside the function, the image is
not there anymore.

One way of preventing the destruction of the
input image is to change the signature of your
function for returning a SmartPointer to the
image instead of returning the raw pointer.

Please try something like:

ImageType::Pointer itkWrapFilters( ImageType * input );

In this way, the reference count of the
output image will not drop to zero during
when the execution reaches the end of the
function scope.


Regards


    Luis



----------------------

Shunming Fang wrote:
> Hello, ITK_users,
> I am newbie of ITK, Our lab want to use some of
> filters in itk to deal with image data. I write a
> template function: 
> ImageType* itkWrapFilters(ImageType* Inputimage),
> there, the filter pipeline accepted inputimage and
> process it and then return it as imageobject.my main
> function is like the follow;
>  Image = reader->GetOutput();
> OutImage =itkWrapFilters(Image);
> writer->SetInput(Outimage)
> writer->update;
> 
> When I executed this program, segmentation fault
> happened becaulse OutImage is empty,I checked the
> whole procedure through DBG, I found after
> itkWrapFilter process data(inside function, I found
> result data was there), the dataobject was destructed
> before return. Then, I use smartpointer to try to get
> data, after callimg the pipeline function,
> smartpointer also didn't get data pointer. Anyone know
> how it happen and How I can get the dataobject after
> call filter pipeline function?
> Thanks
> Fang  
> 
> __________________________________
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!
> http://sbc . yahoo . com
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk . org
> http://www . itk . org/mailman/listinfo/insight-users
>