commit
5ead98afb7
|
@ -54,44 +54,66 @@ template <typename T> struct traits_x;
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
/// A helper that implements the traits interface for GTSAM manifolds.
|
/// Requirements on type to pass it to Manifold template below
|
||||||
/// To use this for your gtsam type, define:
|
template<class Class>
|
||||||
/// template<> struct traits<Type> : public Manifold<Type> { };
|
struct HasManifoldPrereqs {
|
||||||
template<typename _ManifoldType>
|
|
||||||
struct Manifold : Testable<_ManifoldType> {
|
|
||||||
// Typedefs required by all manifold types.
|
|
||||||
typedef _ManifoldType ManifoldType;
|
|
||||||
typedef manifold_tag structure_category;
|
|
||||||
enum { dimension = ManifoldType::dimension };
|
|
||||||
typedef Eigen::Matrix<double, dimension, 1> TangentVector;
|
|
||||||
typedef OptionalJacobian<dimension, dimension> ChartJacobian;
|
|
||||||
|
|
||||||
static TangentVector Local(const ManifoldType& origin,
|
enum { dim = Class::dimension };
|
||||||
const ManifoldType& other) {
|
|
||||||
|
Class p, q;
|
||||||
|
Eigen::Matrix<double, dim, 1> v;
|
||||||
|
OptionalJacobian<dim, dim> Hp, Hq, Hv;
|
||||||
|
|
||||||
|
BOOST_CONCEPT_USAGE(HasManifoldPrereqs) {
|
||||||
|
v = p.localCoordinates(q);
|
||||||
|
q = p.retract(v);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Extra manifold traits for fixed-dimension types
|
||||||
|
template<class Class, size_t N>
|
||||||
|
struct ManifoldImpl {
|
||||||
|
// Compile-time dimensionality
|
||||||
|
static int GetDimension(const Class&) {
|
||||||
|
return N;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Extra manifold traits for variable-dimension types
|
||||||
|
template<class Class>
|
||||||
|
struct ManifoldImpl<Class, Eigen::Dynamic> {
|
||||||
|
// Run-time dimensionality
|
||||||
|
static int GetDimension(const Class& m) {
|
||||||
|
return m.dim();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/// A helper that implements the traits interface for GTSAM manifolds.
|
||||||
|
/// To use this for your class type, define:
|
||||||
|
/// template<> struct traits<Class> : public Manifold<Class> { };
|
||||||
|
template<class Class>
|
||||||
|
struct Manifold: Testable<Class>, ManifoldImpl<Class, Class::dimension> {
|
||||||
|
|
||||||
|
// Check that Class has the necessary machinery
|
||||||
|
BOOST_CONCEPT_ASSERT((HasManifoldPrereqs<Class>));
|
||||||
|
|
||||||
|
// Dimension of the manifold
|
||||||
|
enum { dimension = Class::dimension };
|
||||||
|
|
||||||
|
// Typedefs required by all manifold types.
|
||||||
|
typedef Class ManifoldType;
|
||||||
|
typedef manifold_tag structure_category;
|
||||||
|
typedef Eigen::Matrix<double, dimension, 1> TangentVector;
|
||||||
|
|
||||||
|
// Local coordinates
|
||||||
|
static TangentVector Local(const Class& origin, const Class& other) {
|
||||||
return origin.localCoordinates(other);
|
return origin.localCoordinates(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ManifoldType Retract(const ManifoldType& origin,
|
// Retraction back to manifold
|
||||||
const TangentVector& v) {
|
static Class Retract(const Class& origin, const TangentVector& v) {
|
||||||
return origin.retract(v);
|
return origin.retract(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
static TangentVector Local(const ManifoldType& origin,
|
|
||||||
const ManifoldType& other,
|
|
||||||
ChartJacobian Horigin,
|
|
||||||
ChartJacobian Hother) {
|
|
||||||
return origin.localCoordinates(other, Horigin, Hother);
|
|
||||||
}
|
|
||||||
|
|
||||||
static ManifoldType Retract(const ManifoldType& origin,
|
|
||||||
const TangentVector& v,
|
|
||||||
ChartJacobian Horigin,
|
|
||||||
ChartJacobian Hv) {
|
|
||||||
return origin.retract(v, Horigin, Hv);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int GetDimension(const ManifoldType& m){ return m.dim(); }
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // \ namespace internal
|
} // \ namespace internal
|
||||||
|
@ -106,35 +128,16 @@ check_manifold_invariants(const T& a, const T& b, double tol=1e-9) {
|
||||||
return v0.norm() < tol && traits_x<T>::Equals(b,c,tol);
|
return v0.norm() < tol && traits_x<T>::Equals(b,c,tol);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define GTSAM_MANIFOLD_DECLARATIONS(MANIFOLD,DIM,TANGENT_VECTOR) \
|
/// Manifold concept
|
||||||
typedef MANIFOLD ManifoldType;\
|
template<typename T>
|
||||||
typedef manifold_tag structure_category; \
|
|
||||||
struct dimension : public boost::integral_constant<int, DIM> {};\
|
|
||||||
typedef TANGENT_VECTOR TangentVector;\
|
|
||||||
typedef OptionalJacobian<dimension, dimension> ChartJacobian; \
|
|
||||||
static TangentVector Local(const ManifoldType& origin, \
|
|
||||||
const ManifoldType& other, \
|
|
||||||
ChartJacobian Horigin=boost::none, \
|
|
||||||
ChartJacobian Hother=boost::none); \
|
|
||||||
static ManifoldType Retract(const ManifoldType& origin, \
|
|
||||||
const TangentVector& v,\
|
|
||||||
ChartJacobian Horigin=boost::none, \
|
|
||||||
ChartJacobian Hv=boost::none); \
|
|
||||||
static int GetDimension(const ManifoldType& m) { return dimension; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Manifold concept
|
|
||||||
*/
|
|
||||||
template<typename M>
|
|
||||||
class IsManifold {
|
class IsManifold {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef typename traits_x<M>::structure_category structure_category_tag;
|
typedef typename traits_x<T>::structure_category structure_category_tag;
|
||||||
static const size_t dim = traits_x<M>::dimension;
|
static const size_t dim = traits_x<T>::dimension;
|
||||||
typedef typename traits_x<M>::ManifoldType ManifoldType;
|
typedef typename traits_x<T>::ManifoldType ManifoldType;
|
||||||
typedef typename traits_x<M>::TangentVector TangentVector;
|
typedef typename traits_x<T>::TangentVector TangentVector;
|
||||||
typedef typename traits_x<M>::ChartJacobian ChartJacobian;
|
|
||||||
|
|
||||||
BOOST_CONCEPT_USAGE(IsManifold) {
|
BOOST_CONCEPT_USAGE(IsManifold) {
|
||||||
BOOST_STATIC_ASSERT_MSG(
|
BOOST_STATIC_ASSERT_MSG(
|
||||||
|
@ -143,26 +146,21 @@ public:
|
||||||
BOOST_STATIC_ASSERT(TangentVector::SizeAtCompileTime == dim);
|
BOOST_STATIC_ASSERT(TangentVector::SizeAtCompileTime == dim);
|
||||||
|
|
||||||
// make sure Chart methods are defined
|
// make sure Chart methods are defined
|
||||||
v = traits_x<M>::Local(p, q);
|
v = traits_x<T>::Local(p, q);
|
||||||
q = traits_x<M>::Retract(p, v);
|
q = traits_x<T>::Retract(p, v);
|
||||||
// and the versions with Jacobians.
|
|
||||||
//v = traits_x<M>::Local(p,q,Hp,Hq);
|
|
||||||
//q = traits_x<M>::Retract(p,v,Hp,Hv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
ManifoldType p, q;
|
|
||||||
ChartJacobian Hp, Hq, Hv;
|
|
||||||
TangentVector v;
|
TangentVector v;
|
||||||
bool b;
|
ManifoldType p, q;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Give fixed size dimension of a type, fails at compile time if dynamic
|
/// Give fixed size dimension of a type, fails at compile time if dynamic
|
||||||
template<typename M>
|
template<typename T>
|
||||||
struct FixedDimension {
|
struct FixedDimension {
|
||||||
typedef const int value_type;
|
typedef const int value_type;
|
||||||
static const int value = traits_x<M>::dimension;
|
static const int value = traits_x<T>::dimension;
|
||||||
BOOST_STATIC_ASSERT_MSG(value != Eigen::Dynamic,
|
BOOST_STATIC_ASSERT_MSG(value != Eigen::Dynamic,
|
||||||
"FixedDimension instantiated for dymanically-sized type.");
|
"FixedDimension instantiated for dymanically-sized type.");
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue