[Insight-users] Primary question: SmartPointer

Ivan Macia imacia@vicomtech.es
Wed May 5 15:04:11 EDT 2004


Hi Jiang,

If you are getting the output of an itk filter the image is already
allocated by the filter itself. Then you should do sth like :

void ClassA::func( )
{
	// Don't allocate memory for ResultImage
	ImageType::Pointer ResultImage = OneFilter( );

}

ImageType::Pointer OneFilter( )
{
	....
	return filter->GetOutput( );
}

or

ImageType* OneFilter( )
{
	....
	return filter->GetOutput( );
}

as the = operator is overloaded also for raw pointers. I haven't tried the
second approach but both should work. I'm not sure if this is what you
intend to do.

Hope that helps

Ivan


-----Mensaje original-----
De: insight-users-admin@itk.org [mailto:insight-users-admin@itk.org]En
nombre de Jiang
Enviado el: miercoles, 05 de mayo de 2004 12:13
Para: ITK
Asunto: [Insight-users] Primary question: SmartPointer


Hi, ITK-users,
I have one question about how to transfer SmartPointer as return value.
The following is my part of code:

typedef .....ImageType

void ClassA::func()
{
ImageType::Pointer ResultImage = ImageType::New();

ResultImage=OneFilter();
}

ImageType* ClassA::OneFilter()
{
.......
Some filter process
.......
         return filter->GetOutput();
}

The program stops at ResultImage=OneFilter();
         I have debugged ClassA::OneFilter, it can work. If I don't use
ClassA::OneFilter() and ResultImage=OneFilter(),
and put
.......
Some filter process
.......
directly in ClassA::func(), then everything is ok. The filter->GetOutput is
correct.
I guess the problem is
ImageType::Pointer ResultImage = ImageType::New();
ResultImage= OneFilter();

Is it wrong way to return SmartPoiner from one function to another function?
How should I do?



Thanks a lot!


Chunyan Jiang




More information about the Insight-users mailing list