[Insight-users] python prototyping advice

Carlos Santos csantos.incor at gmail.com
Fri Aug 19 16:15:19 EDT 2005


Hi,

I had the same problem and solved it by inserting the line:
#include <libnumarray.h>
into the file
InsightToolkit-2.0.1/Wrapping/CSwig/Common/itkPyBuffer.h
Some background on the issue:
http://www.itk.org/pipermail/insight-users/2004-August/010256.html
There is an entry at the ITK bug tracker about this, I can't find the
link to it though.

Hope this helps,

Carlos

On 8/18/05, Richard Beare <richard.beare at gmail.com> wrote:
> Hi,
> This looks very interesting. However a stumbling block at the moment
> appears to be the compilation of ITK with numarray support enabled -
> my copy from cvs appears broken.
> 
> Any hints on getting it working?
> Building object file wrap_itkPyBufferPython.o...
> In file included from
> /scratch/richardb/Build/WebCVS/Insight/Wrapping/CSwig/CommonA/itkPyBuffer.h:105,
>                  from
> /scratch/richardb/Build/WebCVS/Insight/Wrapping/CSwig/CommonA/wrap_itkPyBuffer.cxx:17,
>                  from
> /scratch/richardb/Build/WebCVS/ITKBuild/Wrapping/CSwig/CommonA/wrap_itkPyBufferPython.cxx:931:
> /scratch/richardb/Build/WebCVS/Insight/Wrapping/CSwig/CommonA/itkPyBuffer.txx:
> In constructor `itk::PyBuffer<TImage>::PyBuffer()':
> /scratch/richardb/Build/WebCVS/Insight/Wrapping/CSwig/CommonA/itkPyBuffer.txx:32:
> error: there are no arguments to `import_libnumarray' that depend on a
> template parameter, so a declaration of `import_libnumarray' must be
> available
> /scratch/richardb/Build/WebCVS/Insight/Wrapping/CSwig/CommonA/itkPyBuffer.txx:32:
> error: (if you use `-fpermissive', G++ will accept your code, but
> allowing the use of an undeclared name is deprecated)
> /scratch/richardb/Build/WebCVS/Insight/Wrapping/CSwig/CommonA/itkPyBuffer.txx:
> In constructor `itk::PyBuffer<TImage>::PyBuffer() [with TImage =
> itk::Image<unsigned char, 3u>]':
> /scratch/richardb/Build/WebCVS/Insight/Wrapping/CSwig/CommonA/itkPyBuffer.h:57:
>   instantiated from `static itk::SmartPointer<itk::PyBuffer<TImage> >
> itk::PyBuffer<TImage>::New() [with TImage = itk::Image<unsigned char,
> 3u>]'
> /scratch/richardb/Build/WebCVS/ITKBuild/Wrapping/CSwig/CommonA/wrap_itkPyBufferPython.cxx:2388:
>   instantiated from here
> /scratch/richardb/Build/WebCVS/Insight/Wrapping/CSwig/CommonA/itkPyBuffer.txx:32:
> error: `import_libnumarray' undeclared (first use this function)
> /scratch/richardb/Build/WebCVS/Insight/Wrapping/CSwig/CommonA/itkPyBuffer.txx:32:
> error: (Each undeclared identifier is reported only once for each
> function it appears in.)
> /scratch/richardb/Build/WebCVS/Insight/Wrapping/CSwig/CommonA/itkPyBuffer.txx:
> In constructor `itk::PyBuffer<TImage>::PyBuffer() [with TImage =
> itk::Image<short unsigned int, 3u>]':
> /scratch/richardb/Build/WebCVS/Insight/Wrapping/CSwig/CommonA/itkPyBuffer.h:57:
>   instantiated from `static itk::SmartPointer<itk::PyBuffer<TImage> >
> itk::PyBuffer<TImage>::New() [with TImage = itk::Image<short unsigned
> int, 3u>]'
> /scratch/richardb/Build/WebCVS/ITKBuild/Wrapping/CSwig/CommonA/wrap_itkPyBufferPython.cxx:2531:
>   instantiated from here
> /scratch/richardb/Build/WebCVS/Insight/Wrapping/CSwig/CommonA/itkPyBuffer.txx:32:
> error: `import_libnumarray' undeclared (first use this function)
> /scratch/richardb/Build/WebCVS/Insight/Wrapping/CSwig/CommonA/itkPyBuffer.txx:
> In constructor `itk::PyBuffer<TImage>::PyBuffer() [with TImage =
> itk::Image<unsigned char, 2u>]':
> /scratch/richardb/Build/WebCVS/Insight/Wrapping/CSwig/CommonA/itkPyBuffer.h:57:
>   instantiated from `static itk::SmartPointer<itk::PyBuffer<TImage> >
> itk::PyBuffer<TImage>::New() [with TImage = itk::Image<unsigned char,
> 2u>]'
> /scratch/richardb/Build/WebCVS/ITKBuild/Wrapping/CSwig/CommonA/wrap_itkPyBufferPython.cxx:2674:
>   instantiated from here
> /scratch/richardb/Build/WebCVS/Insight/Wrapping/CSwig/CommonA/itkPyBuffer.txx:32:
> error: `import_libnumarray' undeclared (first use this function)
> /scratch/richardb/Build/WebCVS/Insight/Wrapping/CSwig/CommonA/itkPyBuffer.txx:
> In constructor `itk::PyBuffer<TImage>::PyBuffer() [with TImage =
> itk::Image<short unsigned int, 2u>]':
> /scratch/richardb/Build/WebCVS/Insight/Wrapping/CSwig/CommonA/itkPyBuffer.h:57:
>   instantiated from `static itk::SmartPointer<itk::PyBuffer<TImage> >
> itk::PyBuffer<TImage>::New() [with TImage = itk::Image<short unsigned
> int, 2u>]'
> /scratch/richardb/Build/WebCVS/ITKBuild/Wrapping/CSwig/CommonA/wrap_itkPyBufferPython.cxx:2817:
>   instantiated from here
> /scratch/richardb/Build/WebCVS/Insight/Wrapping/CSwig/CommonA/itkPyBuffer.txx:32:
> error: `import_libnumarray' undeclared (first use this function)
> /scratch/richardb/Build/WebCVS/Insight/Wrapping/CSwig/CommonA/itkPyBuffer.txx:
> In constructor `itk::PyBuffer<TImage>::PyBuffer() [with TImage =
> itk::Image<float, 2u>]':
> /scratch/richardb/Build/WebCVS/Insight/Wrapping/CSwig/CommonA/itkPyBuffer.h:57:
>   instantiated from `static itk::SmartPointer<itk::PyBuffer<TImage> >
> itk::PyBuffer<TImage>::New() [with TImage = itk::Image<float, 2u>]'
> /scratch/richardb/Build/WebCVS/ITKBuild/Wrapping/CSwig/CommonA/wrap_itkPyBufferPython.cxx:4150:
>   instantiated from here
> /scratch/richardb/Build/WebCVS/Insight/Wrapping/CSwig/CommonA/itkPyBuffer.txx:32:
> error: `import_libnumarray' undeclared (first use this function)
> /scratch/richardb/Build/WebCVS/Insight/Wrapping/CSwig/CommonA/itkPyBuffer.txx:
> In constructor `itk::PyBuffer<TImage>::PyBuffer() [with TImage =
> itk::Image<float, 3u>]':
> /scratch/richardb/Build/WebCVS/Insight/Wrapping/CSwig/CommonA/itkPyBuffer.h:57:
>   instantiated from `static itk::SmartPointer<itk::PyBuffer<TImage> >
> itk::PyBuffer<TImage>::New() [with TImage = itk::Image<float, 3u>]'
> /scratch/richardb/Build/WebCVS/ITKBuild/Wrapping/CSwig/CommonA/wrap_itkPyBufferPython.cxx:6673:
>   instantiated from here
> /scratch/richardb/Build/WebCVS/Insight/Wrapping/CSwig/CommonA/itkPyBuffer.txx:32:
> error: `import_libnumarray' undeclared (first use this function)
> make[5]: *** [wrap_itkPyBufferPython.o] Error 1
> make[4]: *** [default_target] Error 2
> make[3]: *** [default_target_CommonA] Error 2
> make[2]: *** [default_target] Error 2
> make[1]: *** [default_target_Wrapping_CSwig] Error 2
> make: *** [default_target] Error 2
> On 8/18/05, Gaetan Lehmann <gaetan.lehmann at jouy.inra.fr> wrote:
> > On Wed, 17 Aug 2005 20:46:10 +0200, Einstein, Daniel R
> > <daniel.einstein at pnl.gov> wrote:
> >
> > > Gaetan,
> > >
> > > I am very much interested in prototyping with python as well. I have a
> > > little experience with ITK now, and have worked somewhat with the
> > > InsightToolkit module (unfortunately this is something I must do in my
> > > spare time). I find the wrapping uneven. I was able to do it on one of
> > > my machines but the other is being a bit more difficult.
> > >
> > > Anyway, could you clarify the comment you made to Richard about ipython?
> > > What exactly does the ipython patch allow you to do?
> >
> > Using dir() function on an ITK object to get the list of attributes return
> > a list with attributes names and a non string object. This non string
> > object was breaking completion of attributes in ipython... itk was
> > impossible to use completion on ITK objects.
> > The patch allow to use completion on ITK objects, which is very useful
> > while prototyping with ITK because ITK names are very long.
> >
> > Another great feature of ipython is the -qthread (or -wthread and
> > -gthread) command line option. This option allows to use Qt gui without
> > freezing the interperter. With that option, I have developed a small
> > viewer with Qt and VTK which let me see in 3D the 3D images I have
> > produced... really useful too for prototyping
> >
> > >
> > > Also, in terms of your public directory, I see all of the classes that
> > > you have wrapped. But these won't these need to be re-wrapped on our
> > > local machines? Or am I missing something?
> >
> > There is only sources in public repository, you have to build binaries for
> > your own system, but that build is very simple: you just need to install
> > cableswig and to activate ITK_CSWIG_PYTHON in cmake
> >
> > All comments about wrappers are very welcome :-)
> >
> > Regards,
> >
> > Gaetan
> >
> > >
> > > Thank you for your help
> > >
> > > Best Regards,
> > > Dan
> > >
> > >
> > > Daniel R Einstein, PhD
> > > Biological Monitoring and Modeling
> > > Pacific Northwest National Laboratory
> > > P.O. Box 999; MSIN P7-59
> > > Richland, WA 99352
> > > Tel: 509/ 376-2924
> > > Fax: 509/376-9064
> > > daniel.einstein at pnl.gov
> > >
> > >
> > > -----Original Message-----
> > > From: insight-users-bounces+daniel.einstein=pnl.gov at itk.org
> > > [mailto:insight-users-bounces+daniel.einstein=pnl.gov at itk.org] On Behalf
> > > Of Gaetan Lehmann
> > > Sent: Tuesday, August 16, 2005 11:58 PM
> > > To: Richard.Beare at ieee.org
> > > Cc: insight-users at itk.org
> > > Subject: Re: [Insight-users] python prototyping advice
> > >
> > >
> > > Hi Richard,
> > >
> > > I'm glad to see another ITK user who wants to do prototyping with python.
> > > I'm not the only one ! ;-) Sadely prototyping with python is not a
> > > priority for ITK developers, and there is lot of things which make
> > > prototyping with python difficult (the small number of wrapped class to
> > > begin).
> > >
> > > You may be interested in the work I have already done on wrapper. ITK is
> > > a huge library, and wrapping all classes with a large set of types would
> > > produce too large executables. To increase the number of wrapped
> > > classes, I decided to wrap only unsigned short and float type, in 2 and
> > > 3 dimensions (US2, US3, F2, F3). This way, I have wrapped lots more
> > > filters with only a small increase of executables size.
> > > This work is kept in sync with ITK CVS repository and is available in a
> > > darcs repository at http://voxel.jouy.inra.fr/darcs/itk-mima2/
> > > It also include some work done on mathematical morphology filters, and a
> > > module for python (the module is named itk) which introduce facilities
> > > for prototyping, especially with ipython.
> > > If you are a ipython user, I advise you to checkout a fresh svn version
> > > of
> > > ipython: it contains a patch which allow completion to work with ITK.
> > > That make prototyping really easier. If you're not a ipython user, you
> > > should try it quickly ;-)
> > >
> > > If you're interested in improving ITK, you should consider joining the
> > > developers mailing list which is the right list to talk about that. On
> > > this list, we are also talking with Benoit Regrain of what can be done
> > > to make ITK more usable with python and to improve wrap process. You are
> > > welcome in the discussion if you're interested in :-)
> > >
> > > Gaetan
> > >
> > > On Wed, 17 Aug 2005 08:01:07 +0200, Richard Beare
> > > <richard.beare at gmail.com> wrote:
> > >
> > >> Hi,
> > >>
> > >> I'm trying to stick with prototyping using python for simpler trials.
> > >> At the moment this includes mimicing a few old matlab scripts. This
> > >> brings me to my two questions.
> > >>
> > >> Every time I've attempted to do something in python I've been slowed
> > >> down by missing wrappers. Some of these are easy enough to add (I hope
> > >> this is true - I'm waiting for the build to finish at the moment).
> > >> Assuming I've done this successfully, is there any way I can commit
> > >> these additions back to the repository? What is the protocol for this
> > >> type of thing?
> > >>
> > >> The other question relates to certain types of operations that are
> > >> often done in interactive interpreter environments like matlab or R.
> > >> The particular matlab script I'm porting has a step where every pixel
> > >> in a mask is weighted by the distance to the mask center of gravity.
> > >>
> > >> The approach in matlab is to generate coordinate images and operate on
> > >> them e.g
> > >>
> > >> dist = sqrt((xcoords - xcog).^2 + (ycoords - ycog).^2);
> > >>
> > >> result = mask * dist
> > >>
> > >> How do I do something equivalent in python? Is this where the numarray
> > >> stuff comes in?
> > >>
> > >> Thanks
> > >> _______________________________________________
> > >> Insight-users mailing list
> > >> Insight-users at itk.org
> > >> http://www.itk.org/mailman/listinfo/insight-users
> > >
> > >
> > >
> > > --
> > > Gaetan Lehmann <gaetan.lehmann at jouy.inra.fr>
> > > Tel: +33 1 34 65 29 66
> > > Biologie du D�veloppement et de la Reproduction INRA de Jouy-en-Josas
> > > (France)
> > > Web: http://voxel.jouy.inra.fr
> > > _______________________________________________
> > > Insight-users mailing list
> > > Insight-users at itk.org
> > > http://www.itk.org/mailman/listinfo/insight-users
> > >
> >
> >
> >
> > --
> > Gaetan Lehmann <gaetan.lehmann at jouy.inra.fr>
> > Tel: +33 1 34 65 29 66
> > Biologie du D�veloppement et de la Reproduction
> > INRA de Jouy-en-Josas (France)
> > Web: http://voxel.jouy.inra.fr
> >
> _______________________________________________
> 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