0

I am wrapping a C++ class (PointMatcher.h) for C# using SWIG. I have used the %template directive to concretise a template class as follows:

%include "../pointmatcher/PointMatcher.h"

%template(PointMatcherFloat) PointMatcher<float>;

However, it turns out the template PointMatcher<T> contains typedefs and typenames based on <T> and these are not being included in the SWIG wrapper. (Specifically, I need access to TransformationParameters below.)

//! The scalar type
typedef T ScalarType;
//! A vector over ScalarType
typedef typename Eigen::Matrix<T, Eigen::Dynamic, 1> Vector;
//! A vector of vector over ScalarType, not a matrix
typedef std::vector<Vector, Eigen::aligned_allocator<Vector> > VectorVector;
//! A quaternion over ScalarType
typedef typename Eigen::Quaternion<T> Quaternion;
//! A vector of quaternions over ScalarType
typedef std::vector<Quaternion, Eigen::aligned_allocator<Quaternion> > QuaternionVector;
//! A dense matrix over ScalarType
typedef typename Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> Matrix;
//! A dense integer matrix
typedef typename Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic> IntMatrix;

//! A matrix holding the parameters a transformation.
/**
    The transformation lies in the special Euclidean group of dimension \f$n\f$, \f$SE(n)\f$, implemented as a dense matrix of size \f$n+1 \times n+1\f$ over ScalarType.
*/
typedef Matrix TransformationParameters;

// alias for scope reasons
typedef PointMatcherSupport::Parametrizable Parametrizable; //!< alias
typedef Parametrizable::Parameters Parameters; //!< alias
typedef Parametrizable::ParameterDoc ParameterDoc; //!< alias
typedef Parametrizable::ParametersDoc ParametersDoc; //!< alias
typedef Parametrizable::InvalidParameter InvalidParameter; //!< alias

I have tried duplicating the declarations above as an %inline block, using T and float. (As described in the SWIG 3.0 documentation on typedef.) In both cases the typedefs are simply included in the .cxx file, but no associated classes or methods are generated.

How do I make sure these types are made available in PointMatcherFloat?


Edit note: I previously thought this was about member templates (like How to instantiate a template method of a template class with swig? and How to get SWIG to apply templates when wrapping a template class containing vectors?) but it's actually about typedefs/typenames within a template.

Community
  • 1
  • 1
lofidevops
  • 15,528
  • 14
  • 79
  • 119
  • Addendum: while working on another method I discovered that the typedef I'm interested in (TransformationParameters) is in fact being generated as SWIGTYPE_p_Eigen__MatrixT_float_Eigen__Dynamic_Eigen__Dynamic_t. How can I rename it TransformationParametersFloat and have it appear within the concretised PointMatcherFloat class? – lofidevops Sep 03 '15 at 14:11
  • You can use the `%rename` syntax or explicit instantiate member functions, member types etc, e.g. `%template (SomeClassSomeMemberFunction) SomeClass::SomeMemberFunction` similarly for typedef's within classes. A word of advice though is to create a pure C wrapper of the functions from Eigen that you want to expose - it is so much simpler – Jens Munk Sep 06 '15 at 17:20
  • @JensMunk thanks - what order do I make the rename and/or template calls in (relative to my existing template call) – lofidevops Sep 07 '15 at 14:40
  • As I suggested, I would create a function, which is a non-template function, which requires more simple types on its interface and wrap this instead, e.g. a function with prototype `SomeFunction(T**, size_t, size_t,....)` and wrap the 3 first arguments to a matrix in the target language, e.g. a NumPy matrix in Python. – Jens Munk Sep 07 '15 at 17:57
  • An example of renaming nested templates is given here: http://stackoverflow.com/questions/9757642/wrapping-specialised-c-template-class-with-swig – Jens Munk Sep 07 '15 at 18:05

0 Answers0