[Insight-users] passing itk::BSplineDeformableTransform between functions

Luis Ibanez luis.ibanez at kitware.com
Wed Aug 2 08:10:52 EDT 2006


Hi Ziv,

How about creating the array before calling the function,
and then destroying it after the function returns ?


something like:


void f()
{

itk::BSplineDeformableTransform<>::ParametersType *param = new
                itk::BSplineDeformableTransform<>::ParametersType();

itk::Transform<>::Pointer transformation = itk::Transform<>;
FixedImageType::Pointer fixedImage = FixedImageType::New();
MovingImageType::Pointer movingImage = MovingImageType::New();

transformation->SetParameters( *param );

register(fixedImage, movingImage, transformation);

// Use transformation...

// delete the parameters array.
delete param;

}



It is not particularly pretty, but it should release
the memory correctly.


Please let us know if that works for you.



    Thanks



       Luis



-----------------
Ziv Yaniv wrote:
> Hi all,
> 
> I'm using the itk::BSplineDeformableTransform class and I was wondering 
> how I pass an object of this
> type between functions without causing a memory leak. The problem is 
> that the transformation object only holds a
> pointer to the parameters array and does not give access to the pointer 
> later on so that the user can release the
> memory.
> 
> This is my scenario in pseudocode:
> 
> void f() {
> 
>  itk::Transform<>::Pointer transformation = itk::Transform<>;
>  FixedImageType::Pointer fixedImage = FixedImageType::New();
>  MovingImageType::Pointer movingImage = MovingImageType::New();
> 
>  register(fixedImage, movingImage, transformation);
> 
>           //At this location I have the transformation and I can 
> downcast it to
>           //BSplineDeformableTransform, but I can't get the pointer to 
> the parameters array to release it
> }
> 
> void register(FixedImageType::Pointer & fixedImage,
>              MovingImageType::Pointer & movingImage,
>              itk::Transform<>::Pointer &transformation)
> {
>    itk::BSplineDeformableTransform<>::Pointer bSplineTransformation = 
> itk::BSplineDeformableTransform<>::New();
> 
>    transformation = bSplineTransformation; //point to what will be the 
> result
> 
>               //allocate the parameters array on the heap so that it 
> still exists after we exit the method
>    itk::BSplineDeformableTransform<>::ParametersType *param = new 
> itk::BSplineDeformableTransform<>::ParametersType();
> 
>    bSplineTransformation->SetParameters(*param);
> 
> }
> 
> Perhaps I'm missing something.
> 
>                               thanks
>                                    Ziv
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 
> 




More information about the Insight-users mailing list