[Insight-users] ImportImageFilter->ItkImage ...

Mr Gaffe lagaffe74130 at yahoo.fr
Tue Dec 21 05:12:59 EST 2004


Thanks jJulien it works,
 
maybe if I can another question about the implementation of static methods in ITK...

myFunction is a static function and it is define in a .h and implemented in a .txx 
so if I put everything in my .h like you said  it works:

typedef typename ImageType::Pointer InputImagePointer; 
static InputImagePointer::Pointer myFunction(...)
 {
....
}
or if I don't want to use the typedef
static typename TImage::Pointer myFunction(...)
 {
....
}
and you guess that My Object is templated using TImage ...
 
BUT, I don't know how to implement it in my .txx and just define the header function in my .h as we do usually (it never compile ....)

.h
       typedef typename ImageType::Pointer InputImagePointer; 
        static InputImagePointer::Pointer myFunction(...);
.txx
static InputImagePointer::Pointer myFunction(...)
{
}

Thanks julien for help,
Lagaffe

Julien Jomier <jjomier at cs.unc.edu> wrote:
Hi Lagaffe,

This is an issue with smart pointers.
As you probably know smart pointers delete themselves when there are not 
assigned anymore.
In your case, in myFunction(), the ImportFilter is creating a smart 
pointer as output image, but myFunction() is returning a raw pointer, 
which means that the reference count is not incremented and the output 
pointer is destroyed at the end of the myFunction() scope.
An easy fix is to make your function return a smart pointer and assign a 
smart pointer in your main.

Something like:

ImageType::Pointer myFunction()
{
...
return ImportFilter->GetOuput()
}

and in your program:

typedef int PixelType;
const int Dimension=2, Lx=7, Ly=5;
typedef itk::Image < PixelType, Dimension > ImageType;
ImageType::Pointer inputImage=myFunction(...);

Let us know if that was the problem,

Julien

Mr Gaffe wrote:
> hello,
> 
> I try to build an itkImage with a function wich use an 
> importImageFilter; I can display my image inside my function (so the 
> importation pipeline is ok), but when I try to do the same thing in my 
> program using the return itkImage pointer it doesn't work !
> 
> basically this is my code;
> function:
> 
> ImageType* myFunction(...)
> ... build the image and Import it with itkImportImageFilter
> ... I did an Update
> I can display my Image using std::cout << ImportFilter->GetOuput() 
> <> 
> finally,I return the pointer:
> return ImportFilter->GetOuput()
> 
> In my program:
> typedef int PixelType;
> const int Dimension=2, Lx=7, Ly=5;
> typedef itk::Image < PixelType, Dimension > ImageType;
> ImageType* inputImage=myFunction(...);
> 
> When I try to display std:cout< [input] > pointer value and not all the usual image information .... and if I try 
> to use inputImage to do something it crash !
> 
> I think, I am not using the good return type or something like that?
> 
> thanks for help
> lagaffe
> 
> 
> 
> 
> ------------------------------------------------------------------------
> Découvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage pour vos 
> mails !
> Créez votre Yahoo! Mail 
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users


		
---------------------------------
 Découvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage pour vos mails !
Créez votre Yahoo! Mail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20041221/ba1958d1/attachment.html


More information about the Insight-users mailing list