[Insight-users] Smart pointers as function argument

David Pastor david.pastor at die.upm.es
Tue Nov 17 06:17:01 EST 2009


Hi,

In fact, it would be very useful to have some sort of function like 
SetOutput where you tell the filter where to write the output data, so you 
don't need to have more copies and you preserve the pipeline model but 
without depending on the filter to be in your main environment.

Does it sound right?

Cheers
David


> Hi,
>
> I find the same issue - the pipeline model just doesn't scale.
>
> You need the following code at the end of each function that returns
> an image pointer - see my readIm function below. The critical part is
> the Update() call followed by the DisconnectPipeline() call. You can
> ignore the exception handling for non io functions in most cases.
>
> typename TImage::Pointer readIm(std::string filename)
> {
>  typedef typename itk::ImageFileReader<TImage> ReaderType;
>  typename ReaderType::Pointer reader = ReaderType::New();
>  reader->SetFileName(filename.c_str());
>  typename TImage::Pointer result = reader->GetOutput();
>  try
>    {
>    result->Update();
>    }
>  catch(itk::ExceptionObject &ex)
>    {
>    std::cout << ex << std::endl;
>    std::cout << filename << std::endl;
>    return 0;
>    }
>    result->DisconnectPipeline();
>    return(result);
> }
>
>
> On Tue, Nov 17, 2009 at 4:12 AM, David Pastor <david.pastor at die.upm.es> 
> wrote:
>> HI,
>>
>> I'm trying to have a library with some functions I use to process Images
>> with ITK.
>>
>> What I do is:
>>
>> FilterApi f = new FilterApi();
>> InputType::Pointer filtered = InputType::New();
>> f->filtering(reader->getOutput(), filtered, arg1, arg2);
>>
>> inside of filtering I have some filter and filtered = 
>> filter->GetOutput();
>>
>> The function workst, and the filtered image is ok inside the function 
>> range.
>> But in my main framework, the filtered image is null. In other words, the
>> data is lost when you get out from the function and it is not persistent
>> even though i created the pointer in my main.
>>
>> I imagine this is something related to SmartPointers. Is there any way to 
>> do
>> this? it's a bit tiring to write the same blocks of code in each main.
>>
>> cheers
>> david
>>
>>
>>
>> _____________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Kitware offers ITK Training Courses, for more information visit:
>> http://www.kitware.com/products/protraining.html
>>
>> Please keep messages on-topic and check the ITK FAQ at:
>> http://www.itk.org/Wiki/ITK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.itk.org/mailman/listinfo/insight-users
>>
>>
> 



More information about the Insight-users mailing list