[Insight-developers] Interfacing SimpleITK with WrapITK

Gaëtan Lehmann gaetan.lehmann at jouy.inra.fr
Fri Jul 1 08:37:32 EDT 2011


Le 28 juin 11 à 14:46, Bradley Lowekamp a écrit :

> Hello Gaetan,
>

Hi Brad,

> I am wondering if you have any ideas how how to interface simpleITK  
> and wrappITK. I think the only connection that is needed is being  
> able to convert a simpleITK image to and fro the WrapITK image.  
> SimpleITK image class is here:
>
> https://github.com/SimpleITK/SimpleITK/blob/master/Code/Common/include/sitkImage.h
>
> The relevant constructor is:
>
> template <typename TImageType>
>     explicit Image( TImageType* image )
>
> And the related get method:
>
> itk::DataObject* GetImageBase( void );
>     const itk::DataObject* GetImageBase( void ) const;
>
> It seems to me that we are going to need to link the WrapITK library  
> to SimpleITK, and some how let SWIG know that itk::DataObject and  
> itk::Image<>, and itk::VectorImage<>, are wrapped and in the WrapITK  
> library. I am not sure how to do this, nor have I been able to find  
> documentaion on how.
>
> Do you have any suggestion on how to proceed?
>

Wrapping the templated constructor is not direct of course - we have  
to specify with which types we want to instantiate those constructors.
I think it wouldn't be too hard to do that with a %extend block in the  
swig interface file.

The itk::DataObject type might be a little harder because it is called  
itkDataObject in WrapITK, and I wouldn't be surprised that swig can't  
understand that they are the same type. A better solution is probably  
to use %extend again to add some specialized methods:

%extend itk::simple::Image
{
   itkImageUC2 * GetITKImageUC2()
     {
     return dynamic_cast< itkImageUC2 * >(self->GetImageBase());
     }
   itkImageUC3 * GetITKImageUC3()
     {
     return dynamic_cast< itkImageUC3 * >(self->GetImageBase());
     }
   itkImageF2 * GetITKImageF2()
     {
     return dynamic_cast< itkImageF2 * >(self->GetImageBase());
     }
   itkImageF3 * GetITKImageF3()
     {
     return dynamic_cast< itkImageF3 * >(self->GetImageBase());
     }
   itkVectorImageUC3 * GetITKVectorImageUC3()
     {
     return dynamic_cast< itkImageF3 * >(self->GetImageBase());
     }
   // and so on
}

Those %extend block should be generated according to the types  
available in WrapITK. It should be quite easy to add a small piece of  
cmake code to do that in case ITK has been built with wrapping.
The main problem of that approach is that it would force the target  
language to load the ITKCommon module from WrapITK while loading the  
SimpleITK module.

Another solution would be to add a new class to make the conversion  
and wrap it with wrapitk - the same way this is done for ItkVtkGlue.
It might not be very convenient for the final user though, because he  
would have to use an extra class for that simple conversion.
And that would force the build system to build SimpleITK before  
building the wrapping - not necessarily convenient.

In both cases, I wonder if we can have some problems with the static  
linking done in SimpleITK. Can it generate some problems to pass a  
pointer between binaries on some systems?

> By the way, if you do want to build SimpleITK and wrapITK, Hans,  
> implemented the SuperBuild in SimpleITK. Which can be run by running  
> ccmake in the SuperBuild sub-directory:  "ccmake SimpleITK/ 
> SuperBuild". This can enable WrapITK along with simpleITK.

Great! I'll try it.

Gaëtan

-- 
Gaëtan Lehmann
Biologie du Développement et de la Reproduction
INRA de Jouy-en-Josas (France)
tel: +33 1 34 65 29 66    fax: 01 34 65 29 09
http://mima2.jouy.inra.fr  http://www.itk.org
http://www.bepo.fr

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 203 bytes
Desc: Ceci est une signature ?lectronique PGP
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20110701/e5aea008/attachment.pgp>


More information about the Insight-developers mailing list