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

Julien Jomier jjomier at cs.unc.edu
Tue Dec 21 06:12:58 EST 2004


Hi Lagaffe,

I assume your function is inside the class MyObject.

In your .h:

typedef TImage ImageType;
typedef typename ImageType::Pointer InputImagePointer;
static InputImagePointer myFunction(...);

In your .txx:

template<class TImage>
MyObject<TImage>::InputImagePointer
MyObject<TImage>
::myFunction(...)
{
....
}

hope that helps,

Julien

Mr Gaffe wrote:
> 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 k! now 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, Dimensi! on > ImageType;
>      > ImageType* inputImage=myFunction(...);
>      >
>      > When I try to display std:cout<
>     <<>> 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 
> <http://fr.rd.yahoo.com/mail/taglines/*http://fr.rd.yahoo.com/evt=25917/*http://fr.rd.yahoo.com/mail_fr/mail_campaigns/splash/taglines_250/default/*http://fr.promotions.yahoo.com/mail/creer28.html> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> 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