[Insight-users] Smart pointers as function argument
David Pastor
david.pastor at die.upm.es
Tue Nov 17 05:47:38 EST 2009
Hi,
Actually I did something similar. I was trying this approach instead
int function(IType::Pointer in, IType::Pointer out){
//Filter setup here...
out=filter->GetOutput();
out->Update();
out->DisconnectPipeline();
WriterType::Pointer writer = WriterType::New();
writer->SetFileName("o.mhd" );
writer->SetInput(out);
writer->Update();
}
but this sort of pointer unification does not work. The writer inside of the
function creates the correct image but using a writer over out when is back
to the main does not produce the same image. Actually you get an empty
image. I thought to handle the reference count of the pointers to fix this,
but i'm not sure it will work. I'll try your fashion even though i prefer to
have the return value for exit code purposes.
Thanks
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