[Insight-users] how to wrap std::vector?

Mario Ceresa mario.ceresa at torrescalla.it
Thu Sep 10 08:32:18 EDT 2009


Hello everybody,
I stumbled upon a fascinating problem while using wrap_itk and I
thought that maybe someone here could help me :)

I have a method called GetAlives which returns me a collection of
points as a std::vector<itk::Point>. How can I use it from python? So
far I only managed to get a SwigPointer to the collection, not the
collection itself:

(Pdb) print alives
<Swig Object of type 'std::vector< itk::Point< unsigned short,3u
>,std::allocator< itk::Point< unsigned short,3u > > > *' at 0x3f18870>
(Pdb) print dir(alives)
['__class__', '__cmp__', '__delattr__', '__doc__', '__eq__', '__ge__',
'__getattribute__', '__gt__', '__hash__', '__hex__', '__init__',
'__int__', '__le__', '__long__', '__lt__', '__ne__', '__new__',
'__oct__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
'__str__', 'acquire', 'append', 'disown', 'next', 'own']

Is there a way to get access to the collection using wrap_itk?

You can see all the details in the attached cmake project.

Thanks for any help or suggestion you could provide!

Cheers

Mario
-------------- next part --------------
#ifndef _itkSpeedups_h
#define _itkSpeedups_h

// The python header defines _POSIX_C_SOURCE without a preceding #undef
#undef _POSIX_C_SOURCE

#include "itkFastMarchingImageFilter.h"
#include "itkPoint.h"

#include <vector>

namespace itk
{

template <typename TImage>
class Speedups
{
public:
  ///! Standard "Self" typedef.
  typedef Speedups         Self;

  /// Type of the image from where the buffer will be converted
  typedef TImage                              ImageType;

   
// Image dimension.
  itkStaticConstMacro(ImageDimension, unsigned int,
                      ImageType::ImageDimension);
 
  
  typedef Point< unsigned short, 3 > PointType;

  typedef FastMarchingImageFilter< ImageType, ImageType> FastMarchingFilterType;
  
  typedef typename FastMarchingFilterType::Pointer FastMarchingFilterPointer;
  typedef typename FastMarchingFilterType::LabelImageType LabelImageType;
  typedef typename LabelImageType::Pointer LabelImagePointer;
  typedef typename FastMarchingFilterType::NodeContainer NodeContainerType;
  typedef typename NodeContainerType::Pointer NodeContainerPointer;
  typedef typename FastMarchingFilterType::NodeType NodeType;
  typedef typename LabelImageType::IndexType IndexType;
  
  std::vector<PointType> GetAlives(LabelImageType * label_image,NodeContainerType * ppoints) ;
 
};


} // namespace itk

#ifndef ITK_MANUAL_INSTANTIATION
#include "itkSpeedups.txx"
#endif

#endif 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: itkSpeedups.txx
Type: application/octet-stream
Size: 1043 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090910/045ea1be/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wrap_itkSpeedups.cmake
Type: application/octet-stream
Size: 118 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090910/045ea1be/attachment-0003.obj>
-------------- next part --------------
PROJECT(Speedups)
INCLUDE(CPack)
CMAKE_MINIMUM_REQUIRED(VERSION 2.4.2 FATAL_ERROR)

FIND_PACKAGE(WrapITK REQUIRED)

# Deal with numarray package  Options
SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}")

WRAP_LIBRARY("Speedups" Python)

  SET(WRAPPER_LIBRARY_DEPENDS Base)
  SET(WRAPPER_LIBRARY_LINK_LIBRARIES ITKCommon)
  SET(WRAPPER_SWIG_LIBRARY_FILES ${WRAPPER_SWIG_LIBRARY_FILES})

  WRAPPER_LIBRARY_CREATE_WRAP_FILES()
END_WRAP_LIBRARY()


More information about the Insight-users mailing list