[Insight-users] Python Wrapping: A lonely journey
Brad King
brad.king at kitware.com
Mon, 09 Feb 2004 17:07:50 -0500
Carlos Phillips wrote:
> Hi,
> Over a month ago I set out to use ITK through python by wrapping custom
> subclasses of ITK. I wrote most of the relevant ITK c++ code and
> constructed vtk-python based visualization classes. During this time, I
> posted several messages on this list asking for help in creating python
> wrappers for custom subclasses of ITK. I was assured that this would not
> be too hard, but I have yet to manage to do this. Also, no one seems to
> have any working examples of wrapping custom classes.
Support for wrapping classes outside the tree is still under
development. Pleast send me links to the mailing list archive for the
messages that told you it wouldn't be too hard. I will try to clarify
or correct what was said.
> I have managed to
> create wrappers for templated functions which access ITK data structures
> as is done in ConnectVTKITK. I have also managed to create wrappers for
> classes which do not subclass ITK classes. I have not managed to create
> a wrapper for even the simplest ITK subclass:
>
> template<typename TPixel>
> class Image2D : public itk::Image< TPixel, 2 >
> {
> public:
> typedef Image2D Self;
> typedef itk::Image Superclass;
> typedef itk::SmartPointer<Self> Pointer;
> typedef itk::SmartPointer<const Self> ConstPointer;
> itkNewMacro( Self );
> itkTypeMacro( Image2D, Image );
> }
>
> I tried using the following cable config file:
>
> %module TestPython
> %{
> #include "itkImage.h"
> #include "Test.h"
> %}
> %include "Test.h"
> %template(classNameUS2) className<itk::Image<short unsigned int, 2> >;
This is a SWIG configuration file, not a CableSwig configuration file.
It will not work for ITK classes because the level of C++ templates
involved it too hard for SWIG.
>
> I can't seem to get this to be processed. Is there anyone out there who
> could help me. I have invested considerable time in understanding ITK
> and would hate to have to start looking for a new framework.
>
> Any help would be greatly appreciated.
Hopefully we will have support within a couple of months (it actually
should work now, but the amount of code required is pretty large). For
now, you can try putting your class inside Insight/Code/Algorithms and
looking at the CMakeLists.txt file there and in
Insight/Wrapping/CSwig/Algorithms to see how the classes are registered
for the build and for wrapping.
-Brad