[Insight-users] Smart pointers as function argument
David Pastor
david.pastor at die.upm.es
Tue Nov 17 06:55:12 EST 2009
Hi,
It worked passing the argument by reference of course...
int function(int, &out){
}
Anyway, as there is no a block in the pipeline image representing the image
itself, it could exist some sort of a checkpoint or node where you can grab
the image from not bound to any filter in particular. I don't know it this
is already possible or it clashes with ITK design.
Cheers
D. Pastor
----- Original Message -----
From: "Richard Beare" <richard.beare at gmail.com>
To: "David Pastor" <david.pastor at die.upm.es>
Sent: Tuesday, November 17, 2009 12:30 AM
Subject: Re: [Insight-users] Smart pointers as function argument
> 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