[Insight-users] WrapItk: How to enable the typemap for itk::Meshin external

Gaetan Lehmann gaetan.lehmann at jouy.inra.fr
Tue Mar 13 09:00:46 EST 2007


On Tue, 13 Mar 2007 13:15:11 +0100, toon Huysmans <denhuys at hotmail.com>  
wrote:

> Hello Gaetan,
>
> Thanks for your quick response. The project files are in the attachment.
> Its a very minimal test project, wrapping the RegularSphereMeshSource,
> but it  does show the problem.

I have reproduced the bug. It seem to be a bug in swig: it doesn't  
recognize itk::DefaultDynamicMeshTraits<double,2,2,double> and  
itk::DefaultDynamicMeshTraits<double,2,2,double,float,double> as the same  
entity in the typemap, but recognize it as it should elsewhere.

A simple workaround is to wrap the itk::Mesh class in your project with  
the full template parameter list:

#
# Define the mesh types
#
WRAP_TYPE("itk::Mesh" "M")
   FOREACH(d ${WRAP_ITK_DIMS})
     WRAP_TEMPLATE("${ITKM_D}${d}S"
       "${ITKT_D},${d},itk::DefaultStaticMeshTraits<  
${ITKT_D},${d},${d},${ITKT_D},${ITKT_F},${ITKT_D} >")
     WRAP_TEMPLATE("${ITKM_D}${d}D"
       "${ITKT_D},${d},itk::DefaultDynamicMeshTraits<  
${ITKT_D},${d},${d},${ITKT_D},${ITKT_F},${ITKT_D} >")
   ENDFOREACH(d)
END_WRAP_TYPE()
SET(itk_Wrap_Mesh ${WRAPPER_TEMPLATES})

WRAP_CLASS("itk::Mesh" POINTER)
   SET(WRAPPER_TEMPLATES ${itk_Wrap_Mesh})
END_WRAP_CLASS()

It will give you some warning, but it works.

Please file a bug report on kitware's bugtracker, so we won't forgot to  
fix that.

Luis, can you add me a bug tracker account, so the bug can be assigned to  
me ?

Thanks,

Gaetan


>
> Thanks,
>
> Toon.
>
>> From: "Gaetan Lehmann" <gaetan.lehmann at jouy.inra.fr>
>> To: "Toon Huysmans" <denhuys at hotmail.com>, insight-users at itk.org
>> Subject: Re: [Insight-users] WrapItk: How to enable the typemap for
>> itk::Meshin external projects?
>> Date: Tue, 13 Mar 2007 11:42:19 +0100
>>
>>
>> Hi,
>>
>> First of all, thanks for your interest for WrapITK :-)
>>
>> Can you send me (off list) all the files of your project ?
>> I would be please to test it, and debug WrapITK if needed :-)
>>
>> Thanks,
>>
>> Gaetan
>>
>>
>>
>> On Mon, 12 Mar 2007 16:38:11 +0100, Toon Huysmans <denhuys at hotmail.com>
>> wrote:
>>
>>> Hi,
>>>
>>> How should I add MeshToMeshFilter and a number of descendants to my
>>> python wrappers for itk, using WrapItk stable and itk 2.8.1.?
>>>
>>> Well, so far I have created an external WrapItk project (TestWrapMesh)
>>> consisting of two files:
>>>
>>> CMakeLists.txt :
>>> ------------------------------------------------------------------------
>>> --
>>> PROJECT(TestWrapMesh)
>>> FIND_PACKAGE(WrapITK REQUIRED)
>>>
>>> FIND_PACKAGE(ITK REQUIRED)
>>> INCLUDE_DIRECTORIES(${ITK_INCLUDE_DIRS} )
>>> LINK_DIRECTORIES(${ITK_LIBRARY_DIRS})
>>>
>>> BEGIN_WRAPPER_LIBRARY("TestWrapMesh" Python)
>>>
>>> SET(WRAPPER_LIBRARY_DEPENDS Base)
>>>
>>> SET(WRAPPER_LIBRARY_LINK_LIBRARIES ITKCommon)
>>>
>>> WRAPPER_LIBRARY_CREATE_WRAP_FILES()
>>> WRAPPER_LIBRARY_CREATE_LIBRARY()
>>> ------------------------------------------------------------------------
>>> --
>>>
>>> wrap_itkXXXX.cmake.:
>>> ------------------------------------------------------------------------
>>> --
>>> #
>>> # needed for mesh template
>>> #
>>> WRAP_INCLUDE("itkMesh.h")
>>> WRAP_INCLUDE("itkDefaultStaticMeshTraits.h")
>>> WRAP_INCLUDE("itkDefaultDynamicMeshTraits.h")
>>>
>>> #
>>> # Define the mesh types
>>> #
>>> WRAP_TYPE("itk::Mesh" "M")
>>>   FOREACH(d ${WRAP_ITK_DIMS})
>>>     WRAP_TEMPLATE("${ITKM_D}${d}S"
>>>       "${ITKT_D},${d},itk::DefaultStaticMeshTraits<
>>> ${ITKT_D},${d},${d},${ITKT_D} >")
>>>     WRAP_TEMPLATE("${ITKM_D}${d}D"
>>>       "${ITKT_D},${d},itk::DefaultDynamicMeshTraits<
>>> ${ITKT_D},${d},${d},${ITKT_D} >")
>>>   ENDFOREACH(d)
>>> END_WRAP_TYPE()
>>> SET(itk_Wrap_Mesh ${WRAPPER_TEMPLATES})
>>>
>>> #
>>> # wrap mesh source
>>> #
>>> WRAP_CLASS("itk::MeshSource" POINTER)
>>>   FOREACH(d ${WRAP_ITK_DIMS})
>>>     WRAP_TEMPLATE( "${ITKM_M${ITKM_D}${d}S}" "${ITKT_M${ITKM_D}${d}S}"  
>>> )
>>>     WRAP_TEMPLATE( "${ITKM_M${ITKM_D}${d}D}" "${ITKT_M${ITKM_D}${d}D}"  
>>> )
>>>   ENDFOREACH(d)
>>> END_WRAP_CLASS()
>>>
>>> #
>>> # wrap regular sphere mesh source
>>> #
>>> WRAP_CLASS("itk::RegularSphereMeshSource" POINTER)
>>>   FOREACH(d ${WRAP_ITK_DIMS})
>>>     WRAP_TEMPLATE( "${ITKM_M${ITKM_D}${d}S}" "${ITKT_M${ITKM_D}${d}S}"  
>>> )
>>>     WRAP_TEMPLATE( "${ITKM_M${ITKM_D}${d}D}" "${ITKT_M${ITKM_D}${d}D}"  
>>> )
>>>   ENDFOREACH(d)
>>> END_WRAP_CLASS()
>>> ------------------------------------------------------------------------
>>> --
>>>
>>> It builds fine and when I run a small test, everything seems okay:
>>> ------------------------------------------------------------------------
>>> --
>>> In [1]: import ProjectConfig
>>> In [2]: import TestWrapMesh
>>> In [3]: import itk
>>> In [4]: s = TestWrapMesh.RegularSphereMeshSource.MD3S.New()
>>> In [5]: s.Update()
>>> In [6]: s.GetOutput()
>>>
>>> Out[6]: <C
>>> itk::Mesh<(double,3,itk::DefaultStaticMeshTraits<(double,3,3,double,floa
>>> t,double)>)> instance at
>>> _38275d08_p_itk__MeshTdouble_3_itk__DefaultStaticMeshTraitsTdouble_3_3_d
>>> ouble_float_double_t_t>
>>>
>>> In [7]: itk.Mesh.D3S.New()
>>>
>>> Out[7]: <C
>>> itk::SmartPointer<(itk::Mesh<(double,3,itk::DefaultStaticMeshTraits<(dou
>>> ble,3,3,double,float,double)>)>)> instance at
>>> _b0a44c08_p_itk__SmartPointerTitk__MeshTdouble_3_itk__DefaultStaticMeshT
>>> raitsTdouble_3_3_double_float_double_t_t_t>
>>> ------------------------------------------------------------------------
>>> --
>>>
>>> Except for the fact that the GetOutput() method from the
>>> RegularSphereMeshSource returns a bare pointer to the output mesh
>>> instead of a SmartPointer! I thought that there wouldn't be any swig
>>> %typemaps for the itk::Mesh<...> classes yet, but it seems that all the
>>> necessary typemaps are defined in the WrapItk Base.swg library...
>>>
>>> So, can anyone resolve this problem?
>>> Many thanks!
>>>
>>> Sincerely,
>>>
>>> Toon Huysmans.
>>>
>>> Postal Address:
>>>   Vision Lab, Department of Physics
>>>   University of Antwerp (CDE)
>>>   Universiteitsplein 1 (N1.19)
>>>   B-2610 Antwerp, Belgium
>>> Tel: +32 (0) 3 820 24 72
>>> Fax: +32 (0) 3 820 22 45
>>> Email: toon.huysmans at ua.ac.be
>>> Web: http://webhost.ua.ac.be/visielab/staff/tohu/
>>>
>>>
>>> _______________________________________________
>>> Insight-users mailing list
>>> Insight-users at itk.org
>>> http://www.itk.org/mailman/listinfo/insight-users
>>
>>
>>
>> --
>> 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://voxel.jouy.inra.fr
>> _______________________________________________
>> Insight-users mailing list
>> Insight-users at itk.org
>> http://www.itk.org/mailman/listinfo/insight-users
>
> _________________________________________________________________
> Meer ruimte nodig? Maak nu je eigen Space http://spaces.msn.nl/



-- 
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://voxel.jouy.inra.fr


More information about the Insight-users mailing list