[Insight-users] WrapItk: How to enable the typemap for itk::Mesh in external projects?

Toon Huysmans denhuys at hotmail.com
Mon Mar 12 10:38:11 EST 2007


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/	




More information about the Insight-users mailing list