diff --git a/gtsam/base/Manifold.h b/gtsam/base/Manifold.h index 783605b33..22315bf15 100644 --- a/gtsam/base/Manifold.h +++ b/gtsam/base/Manifold.h @@ -23,347 +23,347 @@ #include #include #include - -namespace gtsam { - -/** - * A manifold defines a space in which there is a notion of a linear tangent space - * that can be centered around a given point on the manifold. These nonlinear - * spaces may have such properties as wrapping around (as is the case with rotations), - * which might make linear operations on parameters not return a viable element of - * the manifold. - * - * We perform optimization by computing a linear delta in the tangent space of the - * current estimate, and then apply this change using a retraction operation, which - * maps the change in tangent space back to the manifold itself. - * - * There may be multiple possible retractions for a given manifold, which can be chosen - * between depending on the computational complexity. The important criteria for - * the creation for the retract and localCoordinates functions is that they be - * inverse operations. The new notion of a Chart guarantees that. - * - */ - -// Traits, same style as Boost.TypeTraits -// All meta-functions below ever only declare a single type -// or a type/value/value_type -namespace traits { - -// is group, by default this is false -template -struct is_group: public boost::false_type { -}; - -// identity, no default provided, by default given by default constructor -template -struct identity { - static T value() { - return T(); - } -}; - -// is manifold, by default this is false -template -struct is_manifold: public boost::false_type { -}; - -// dimension, can return Eigen::Dynamic (-1) if not known at compile time -// defaults to dynamic, TODO makes sense ? -typedef boost::integral_constant Dynamic; +// +//namespace gtsam { +// +///** +// * A manifold defines a space in which there is a notion of a linear tangent space +// * that can be centered around a given point on the manifold. These nonlinear +// * spaces may have such properties as wrapping around (as is the case with rotations), +// * which might make linear operations on parameters not return a viable element of +// * the manifold. +// * +// * We perform optimization by computing a linear delta in the tangent space of the +// * current estimate, and then apply this change using a retraction operation, which +// * maps the change in tangent space back to the manifold itself. +// * +// * There may be multiple possible retractions for a given manifold, which can be chosen +// * between depending on the computational complexity. The important criteria for +// * the creation for the retract and localCoordinates functions is that they be +// * inverse operations. The new notion of a Chart guarantees that. +// * +// */ +// +//// Traits, same style as Boost.TypeTraits +//// All meta-functions below ever only declare a single type +//// or a type/value/value_type +//namespace traits { +// +//// is group, by default this is false //template -//struct dimension: public Dynamic { -//struct dimension : public boost::integral_constant { // just temporary fix to minimize compiler errors while refactoring +//struct is_group: public boost::false_type { //}; - -/** - * zero::value is intended to be the origin of a canonical coordinate system - * with canonical(t) == DefaultChart::local(zero::value, t) - * Below we provide the group identity as zero *in case* it is a group - */ -template struct zero: public identity { - BOOST_STATIC_ASSERT(is_group::value); -}; - -// double - -template<> -struct is_group : public boost::true_type { -}; - -template<> -struct is_manifold : public boost::true_type { -}; - -template<> -struct dimension : public boost::integral_constant { -}; - -template<> -struct zero { - static double value() { - return 0; - } -}; - -// Fixed size Eigen::Matrix type - -template -struct is_group > : public boost::true_type { -}; - -template -struct is_manifold > : public boost::true_type { -}; - -template -struct dimension > : public boost::integral_constant< - int, - M == Eigen::Dynamic ? Eigen::Dynamic : - (N == Eigen::Dynamic ? Eigen::Dynamic : M * N)> { - //TODO after switch to c++11 : the above should should be extracted to a constexpr function - // for readability and to reduce code duplication -}; - -template -struct zero > { - BOOST_STATIC_ASSERT_MSG((M!=Eigen::Dynamic && N!=Eigen::Dynamic), - "traits::zero is only supported for fixed-size matrices"); - static Eigen::Matrix value() { - return Eigen::Matrix::Zero(); - } -}; - -template -struct identity > : public zero< - Eigen::Matrix > { -}; - -template struct is_chart: public boost::false_type { -}; - -} // \ namespace traits - -// Chart is a map from T -> vector, retract is its inverse -template -struct DefaultChart { - //BOOST_STATIC_ASSERT(traits::is_manifold::value); - typedef T type; - typedef Eigen::Matrix::dimension, 1> vector; - - static vector local(const T& origin, const T& other) { - return origin.localCoordinates(other); - } - static T retract(const T& origin, const vector& d) { - return origin.retract(d); - } - static int getDimension(const T& origin) { - return origin.dim(); - } -}; - -namespace traits { -// populate default traits -template struct is_chart > : public boost::true_type { -}; -template struct dimension > : public dimension { -}; -} - -template -struct ChartConcept { -public: - typedef typename C::type type; - typedef typename C::vector vector; - - BOOST_CONCEPT_USAGE(ChartConcept) { - // is_chart trait should be true - BOOST_STATIC_ASSERT((traits::is_chart::value)); - - /** - * Returns Retraction update of val_ - */ - type retract_ret = C::retract(val_, vec_); - - /** - * Returns local coordinates of another object - */ - vec_ = C::local(val_, retract_ret); - - // a way to get the dimension that is compatible with dynamically sized types - dim_ = C::getDimension(val_); - } - -private: - type val_; - vector vec_; - int dim_; -}; - -/** - * CanonicalChart > is a chart around zero::value - * Canonical is CanonicalChart > - * An example is Canonical - */ -template struct CanonicalChart { - BOOST_CONCEPT_ASSERT((ChartConcept)); - - typedef C Chart; - typedef typename Chart::type type; - typedef typename Chart::vector vector; - - // Convert t of type T into canonical coordinates - vector local(const type& t) { - return Chart::local(traits::zero::value(), t); - } - // Convert back from canonical coordinates to T - type retract(const vector& v) { - return Chart::retract(traits::zero::value(), v); - } -}; -template struct Canonical: public CanonicalChart > { -}; - -// double - -template<> -struct DefaultChart { - typedef double type; - typedef Eigen::Matrix vector; - - static vector local(double origin, double other) { - vector d; - d << other - origin; - return d; - } - static double retract(double origin, const vector& d) { - return origin + d[0]; - } - static int getDimension(double) { - return 1; - } -}; - -// Fixed size Eigen::Matrix type - -template -struct DefaultChart > { - /** - * This chart for the vector space of M x N matrices (represented by Eigen matrices) chooses as basis the one with respect to which the coordinates are exactly the matrix entries as laid out in memory (as determined by Options). - * Computing coordinates for a matrix is then simply a reshape to the row vector of appropriate size. - */ - typedef Eigen::Matrix type; - typedef type T; - typedef Eigen::Matrix::value, 1> vector; - - BOOST_STATIC_ASSERT_MSG((M!=Eigen::Dynamic && N!=Eigen::Dynamic), - "Internal error: DefaultChart for Dynamic should be handled by template below"); - - static vector local(const T& origin, const T& other) { - return reshape(other) - - reshape(origin); - } - static T retract(const T& origin, const vector& d) { - return origin + reshape(d); - } - static int getDimension(const T&origin) { - return origin.rows() * origin.cols(); - } -}; - -// Dynamically sized Vector -template<> -struct DefaultChart { - typedef Vector type; - typedef Vector vector; - static vector local(const Vector& origin, const Vector& other) { - return other - origin; - } - static Vector retract(const Vector& origin, const vector& d) { - return origin + d; - } - static int getDimension(const Vector& origin) { - return origin.size(); - } -}; - -// Dynamically sized Matrix -template<> -struct DefaultChart { - typedef Matrix type; - typedef Vector vector; - static vector local(const Matrix& origin, const Matrix& other) { - Matrix d = other - origin; - return Eigen::Map(d.data(),getDimension(d)); - } - static Matrix retract(const Matrix& origin, const vector& d) { - return origin + Eigen::Map(d.data(),origin.rows(),origin.cols()); - } - static int getDimension(const Matrix& m) { - return m.size(); - } -}; - -/** - * Old Concept check class for Manifold types - * Requires a mapping between a linear tangent space and the underlying - * manifold, of which Lie is a specialization. - * - * The necessary functions to implement for Manifold are defined - * below with additional details as to the interface. The - * concept checking function in class Manifold will check whether or not - * the function exists and throw compile-time errors. - * - * Returns dimensionality of the tangent space, which may be smaller than the number - * of nonlinear parameters. - * size_t dim() const; - * - * Returns a new T that is a result of updating *this with the delta v after pulling - * the updated value back to the manifold T. - * T retract(const Vector& v) const; - * - * Returns the linear coordinates of lp in the tangent space centered around *this. - * Vector localCoordinates(const T& lp) const; - * - * By convention, we use capital letters to designate a static function - * @tparam T is a Lie type, like Point2, Pose3, etc. - */ -template -class ManifoldConcept { -private: - /** concept checking function - implement the functions this demands */ - static T concept_check(const T& t) { - - /** assignment */ - T t2 = t; - - /** - * Returns dimensionality of the tangent space - */ - size_t dim_ret = t.dim(); - - /** - * Returns Retraction update of T - */ - T retract_ret = t.retract(gtsam::zero(dim_ret)); - - /** - * Returns local coordinates of another object - */ - Vector localCoords_ret = t.localCoordinates(t2); - - return retract_ret; - } -}; - -} // \ namespace gtsam - -/** - * Macros for using the ManifoldConcept - * - An instantiation for use inside unit tests - * - A typedef for use inside generic algorithms - * - * NOTE: intentionally not in the gtsam namespace to allow for classes not in - * the gtsam namespace to be more easily enforced as testable - */ -#define GTSAM_CONCEPT_MANIFOLD_INST(T) template class gtsam::ManifoldConcept; -#define GTSAM_CONCEPT_MANIFOLD_TYPE(T) typedef gtsam::ManifoldConcept _gtsam_ManifoldConcept_##T; +// +//// identity, no default provided, by default given by default constructor +//template +//struct identity { +// static T value() { +// return T(); +// } +//}; +// +//// is manifold, by default this is false +//template +//struct is_manifold: public boost::false_type { +//}; +// +//// dimension, can return Eigen::Dynamic (-1) if not known at compile time +//// defaults to dynamic, TODO makes sense ? +//typedef boost::integral_constant Dynamic; +////template +////struct dimension: public Dynamic { +////struct dimension : public boost::integral_constant { // just temporary fix to minimize compiler errors while refactoring +////}; +// +///** +// * zero::value is intended to be the origin of a canonical coordinate system +// * with canonical(t) == DefaultChart::local(zero::value, t) +// * Below we provide the group identity as zero *in case* it is a group +// */ +//template struct zero: public identity { +// BOOST_STATIC_ASSERT(is_group::value); +//}; +// +//// double +// +//template<> +//struct is_group : public boost::true_type { +//}; +// +//template<> +//struct is_manifold : public boost::true_type { +//}; +// +//template<> +//struct dimension : public boost::integral_constant { +//}; +// +//template<> +//struct zero { +// static double value() { +// return 0; +// } +//}; +// +//// Fixed size Eigen::Matrix type +// +//template +//struct is_group > : public boost::true_type { +//}; +// +//template +//struct is_manifold > : public boost::true_type { +//}; +// +//template +//struct dimension > : public boost::integral_constant< +// int, +// M == Eigen::Dynamic ? Eigen::Dynamic : +// (N == Eigen::Dynamic ? Eigen::Dynamic : M * N)> { +// //TODO after switch to c++11 : the above should should be extracted to a constexpr function +// // for readability and to reduce code duplication +//}; +// +//template +//struct zero > { +// BOOST_STATIC_ASSERT_MSG((M!=Eigen::Dynamic && N!=Eigen::Dynamic), +// "traits::zero is only supported for fixed-size matrices"); +// static Eigen::Matrix value() { +// return Eigen::Matrix::Zero(); +// } +//}; +// +//template +//struct identity > : public zero< +// Eigen::Matrix > { +//}; +// +//template struct is_chart: public boost::false_type { +//}; +// +//} // \ namespace traits +// +//// Chart is a map from T -> vector, retract is its inverse +//template +//struct DefaultChart { +// //BOOST_STATIC_ASSERT(traits::is_manifold::value); +// typedef T type; +// typedef Eigen::Matrix::dimension, 1> vector; +// +// static vector local(const T& origin, const T& other) { +// return origin.localCoordinates(other); +// } +// static T retract(const T& origin, const vector& d) { +// return origin.retract(d); +// } +// static int getDimension(const T& origin) { +// return origin.dim(); +// } +//}; +// +//namespace traits { +//// populate default traits +//template struct is_chart > : public boost::true_type { +//}; +//template struct dimension > : public dimension { +//}; +//} +// +//template +//struct ChartConcept { +//public: +// typedef typename C::type type; +// typedef typename C::vector vector; +// +// BOOST_CONCEPT_USAGE(ChartConcept) { +// // is_chart trait should be true +// BOOST_STATIC_ASSERT((traits::is_chart::value)); +// +// /** +// * Returns Retraction update of val_ +// */ +// type retract_ret = C::retract(val_, vec_); +// +// /** +// * Returns local coordinates of another object +// */ +// vec_ = C::local(val_, retract_ret); +// +// // a way to get the dimension that is compatible with dynamically sized types +// dim_ = C::getDimension(val_); +// } +// +//private: +// type val_; +// vector vec_; +// int dim_; +//}; +// +///** +// * CanonicalChart > is a chart around zero::value +// * Canonical is CanonicalChart > +// * An example is Canonical +// */ +//template struct CanonicalChart { +// BOOST_CONCEPT_ASSERT((ChartConcept)); +// +// typedef C Chart; +// typedef typename Chart::type type; +// typedef typename Chart::vector vector; +// +// // Convert t of type T into canonical coordinates +// vector local(const type& t) { +// return Chart::local(traits::zero::value(), t); +// } +// // Convert back from canonical coordinates to T +// type retract(const vector& v) { +// return Chart::retract(traits::zero::value(), v); +// } +//}; +//template struct Canonical: public CanonicalChart > { +//}; +// +//// double +// +//template<> +//struct DefaultChart { +// typedef double type; +// typedef Eigen::Matrix vector; +// +// static vector local(double origin, double other) { +// vector d; +// d << other - origin; +// return d; +// } +// static double retract(double origin, const vector& d) { +// return origin + d[0]; +// } +// static int getDimension(double) { +// return 1; +// } +//}; +// +//// Fixed size Eigen::Matrix type +// +//template +//struct DefaultChart > { +// /** +// * This chart for the vector space of M x N matrices (represented by Eigen matrices) chooses as basis the one with respect to which the coordinates are exactly the matrix entries as laid out in memory (as determined by Options). +// * Computing coordinates for a matrix is then simply a reshape to the row vector of appropriate size. +// */ +// typedef Eigen::Matrix type; +// typedef type T; +// typedef Eigen::Matrix::value, 1> vector; +// +// BOOST_STATIC_ASSERT_MSG((M!=Eigen::Dynamic && N!=Eigen::Dynamic), +// "Internal error: DefaultChart for Dynamic should be handled by template below"); +// +// static vector local(const T& origin, const T& other) { +// return reshape(other) +// - reshape(origin); +// } +// static T retract(const T& origin, const vector& d) { +// return origin + reshape(d); +// } +// static int getDimension(const T&origin) { +// return origin.rows() * origin.cols(); +// } +//}; +// +//// Dynamically sized Vector +//template<> +//struct DefaultChart { +// typedef Vector type; +// typedef Vector vector; +// static vector local(const Vector& origin, const Vector& other) { +// return other - origin; +// } +// static Vector retract(const Vector& origin, const vector& d) { +// return origin + d; +// } +// static int getDimension(const Vector& origin) { +// return origin.size(); +// } +//}; +// +//// Dynamically sized Matrix +//template<> +//struct DefaultChart { +// typedef Matrix type; +// typedef Vector vector; +// static vector local(const Matrix& origin, const Matrix& other) { +// Matrix d = other - origin; +// return Eigen::Map(d.data(),getDimension(d)); +// } +// static Matrix retract(const Matrix& origin, const vector& d) { +// return origin + Eigen::Map(d.data(),origin.rows(),origin.cols()); +// } +// static int getDimension(const Matrix& m) { +// return m.size(); +// } +//}; +// +///** +// * Old Concept check class for Manifold types +// * Requires a mapping between a linear tangent space and the underlying +// * manifold, of which Lie is a specialization. +// * +// * The necessary functions to implement for Manifold are defined +// * below with additional details as to the interface. The +// * concept checking function in class Manifold will check whether or not +// * the function exists and throw compile-time errors. +// * +// * Returns dimensionality of the tangent space, which may be smaller than the number +// * of nonlinear parameters. +// * size_t dim() const; +// * +// * Returns a new T that is a result of updating *this with the delta v after pulling +// * the updated value back to the manifold T. +// * T retract(const Vector& v) const; +// * +// * Returns the linear coordinates of lp in the tangent space centered around *this. +// * Vector localCoordinates(const T& lp) const; +// * +// * By convention, we use capital letters to designate a static function +// * @tparam T is a Lie type, like Point2, Pose3, etc. +// */ +//template +//class ManifoldConcept { +//private: +// /** concept checking function - implement the functions this demands */ +// static T concept_check(const T& t) { +// +// /** assignment */ +// T t2 = t; +// +// /** +// * Returns dimensionality of the tangent space +// */ +// size_t dim_ret = t.dim(); +// +// /** +// * Returns Retraction update of T +// */ +// T retract_ret = t.retract(gtsam::zero(dim_ret)); +// +// /** +// * Returns local coordinates of another object +// */ +// Vector localCoords_ret = t.localCoordinates(t2); +// +// return retract_ret; +// } +//}; +// +//} // \ namespace gtsam +// +///** +// * Macros for using the ManifoldConcept +// * - An instantiation for use inside unit tests +// * - A typedef for use inside generic algorithms +// * +// * NOTE: intentionally not in the gtsam namespace to allow for classes not in +// * the gtsam namespace to be more easily enforced as testable +// */ +#define GTSAM_CONCEPT_MANIFOLD_INST(T) +#define GTSAM_CONCEPT_MANIFOLD_TYPE(T) diff --git a/gtsam/base/concepts.h b/gtsam/base/concepts.h index 8dac2d55d..4667e87fc 100644 --- a/gtsam/base/concepts.h +++ b/gtsam/base/concepts.h @@ -206,6 +206,36 @@ struct LieGroup { } // namespace internal +template +struct Canonical { + BOOST_STATIC_ASSERT_MSG( + (boost::is_base_of::structure_category_tag>::value), + "This type's trait does not assert it is a group (or derived)"); + typedef traits_x Traits; + typedef typename Traits::TangentVector TangentVector; + enum { dimension = Traits::dimension }; + typedef OptionalJacobian ChartJacobian; + + static TangentVector Local(const ManifoldType& other) { + return Traits::Local(Traits::Identity(), other); + } + + static ManifoldType Retract(const TangentVector& v) { + return Traits::Retract(Traits::Identity(), v); + } + + static TangentVector Local(const ManifoldType& other, + ChartJacobian Hother) { + return Traits::Local(Traits::Identity(), other, boost::none, Hother); + } + + static ManifoldType Retract(const ManifoldType& origin, + const TangentVector& v, + ChartJacobian Horigin, + ChartJacobian Hv) { + return Traits::Retract(Traits::Identity(), v, boost::none, Hv); + } +}; /// Check invariants for Manifold type template diff --git a/gtsam/geometry/Cal3Bundler.h b/gtsam/geometry/Cal3Bundler.h index fc1d63e10..8adbce06c 100644 --- a/gtsam/geometry/Cal3Bundler.h +++ b/gtsam/geometry/Cal3Bundler.h @@ -37,6 +37,8 @@ private: public: + enum { dimension = 3 }; + /// @name Standard Constructors /// @{ @@ -169,24 +171,7 @@ private: }; -// Define GTSAM traits -namespace traits { - template<> -struct GTSAM_EXPORT is_manifold : public boost::true_type{ -}; - -template<> -struct GTSAM_EXPORT dimension : public boost::integral_constant{ -}; - -template<> -struct GTSAM_EXPORT zero { - static Cal3Bundler value() { - return Cal3Bundler(0, 0, 0); - } -}; - -} +struct traits_x : public internal::Manifold {}; } // namespace gtsam diff --git a/gtsam/geometry/Cal3DS2.h b/gtsam/geometry/Cal3DS2.h index fb338431a..6ad9706de 100644 --- a/gtsam/geometry/Cal3DS2.h +++ b/gtsam/geometry/Cal3DS2.h @@ -43,6 +43,8 @@ class GTSAM_EXPORT Cal3DS2 : public Cal3DS2_Base { public: + enum { dimension = 9 }; + /// @name Standard Constructors /// @{ @@ -107,18 +109,8 @@ private: }; -// Define GTSAM traits -namespace traits { - template<> -struct GTSAM_EXPORT is_manifold : public boost::true_type{ -}; - -template<> -struct GTSAM_EXPORT dimension : public boost::integral_constant{ -}; - -} +struct traits_x : public internal::Manifold {}; } diff --git a/gtsam/geometry/Cal3Unified.h b/gtsam/geometry/Cal3Unified.h index 133e330ba..4513346d8 100644 --- a/gtsam/geometry/Cal3Unified.h +++ b/gtsam/geometry/Cal3Unified.h @@ -50,6 +50,7 @@ private: double xi_; // mirror parameter public: + enum { dimension = 10 }; Vector vector() const ; @@ -138,23 +139,8 @@ private: }; -// Define GTSAM traits -namespace traits { - template<> -struct GTSAM_EXPORT is_manifold : public boost::true_type{ -}; - -template<> -struct GTSAM_EXPORT dimension : public boost::integral_constant{ -}; - -template<> -struct GTSAM_EXPORT zero { - static Cal3Unified value() { return Cal3Unified();} -}; - -} +struct traits_x : public internal::Manifold {}; } diff --git a/gtsam/geometry/Cal3_S2.h b/gtsam/geometry/Cal3_S2.h index cf358d0b2..aacb5e84c 100644 --- a/gtsam/geometry/Cal3_S2.h +++ b/gtsam/geometry/Cal3_S2.h @@ -36,7 +36,7 @@ private: double fx_, fy_, s_, u0_, v0_; public: - + enum { dimension = 5 }; typedef boost::shared_ptr shared_ptr; ///< shared pointer to calibration object /// @name Standard Constructors @@ -224,22 +224,7 @@ private: }; -// Define GTSAM traits -namespace traits { - template<> -struct GTSAM_EXPORT is_manifold : public boost::true_type{ -}; - -template<> -struct GTSAM_EXPORT dimension : public boost::integral_constant{ -}; - -template<> -struct GTSAM_EXPORT zero { - static Cal3_S2 value() { return Cal3_S2();} -}; - -} +struct traits_x : public internal::Manifold {}; } // \ namespace gtsam diff --git a/gtsam/geometry/CalibratedCamera.h b/gtsam/geometry/CalibratedCamera.h index f5a8b4469..bac0ac0e8 100644 --- a/gtsam/geometry/CalibratedCamera.h +++ b/gtsam/geometry/CalibratedCamera.h @@ -44,6 +44,8 @@ private: public: + enum { dimension = 6 }; + /// @name Standard Constructors /// @{ @@ -199,23 +201,8 @@ private: /// @} }; -// Define GTSAM traits -namespace traits { - template<> -struct GTSAM_EXPORT is_group : public boost::true_type { -}; - -template<> -struct GTSAM_EXPORT is_manifold : public boost::true_type { -}; - -template<> -struct GTSAM_EXPORT dimension : public boost::integral_constant< - int, 6> { -}; - -} +struct traits_x : public internal::LieGroup {}; } diff --git a/gtsam/geometry/EssentialMatrix.h b/gtsam/geometry/EssentialMatrix.h index b25286412..107ddb3fb 100644 --- a/gtsam/geometry/EssentialMatrix.h +++ b/gtsam/geometry/EssentialMatrix.h @@ -30,6 +30,8 @@ private: public: + enum { dimension = 5 }; + /// Static function to convert Point2 to homogeneous coordinates static Vector Homogeneous(const Point2& p) { return (Vector(3) << p.x(), p.y(), 1).finished(); @@ -196,23 +198,8 @@ private: }; -// Define GTSAM traits -namespace traits { - template<> -struct GTSAM_EXPORT is_manifold : public boost::true_type{ -}; - -template<> -struct GTSAM_EXPORT dimension : public boost::integral_constant{ -}; - -template<> -struct GTSAM_EXPORT zero { - static EssentialMatrix value() { return EssentialMatrix();} -}; - -} +struct traits_x : public internal::LieGroup {}; } // gtsam diff --git a/gtsam/geometry/Point2.h b/gtsam/geometry/Point2.h index 8c8e03db4..618d2ed94 100644 --- a/gtsam/geometry/Point2.h +++ b/gtsam/geometry/Point2.h @@ -39,7 +39,7 @@ private: double x_, y_; public: - + enum { dimension = 3 }; /// @name Standard Constructors /// @{ @@ -245,22 +245,8 @@ private: /// multiply with scalar inline Point2 operator*(double s, const Point2& p) {return p*s;} -// Define GTSAM traits -namespace traits { - template<> -struct GTSAM_EXPORT is_group : public boost::true_type{ -}; - -template<> -struct GTSAM_EXPORT is_manifold : public boost::true_type{ -}; - -template<> -struct GTSAM_EXPORT dimension : public boost::integral_constant{ -}; - -} +struct traits_x : public internal::LieGroup {}; } diff --git a/gtsam/geometry/Point3.h b/gtsam/geometry/Point3.h index 56d9b8bef..b256fa9f3 100644 --- a/gtsam/geometry/Point3.h +++ b/gtsam/geometry/Point3.h @@ -43,6 +43,7 @@ namespace gtsam { double x_, y_, z_; public: + enum { dimension = 3 }; /// @name Standard Constructors /// @{ @@ -248,20 +249,6 @@ namespace gtsam { /// Syntactic sugar for multiplying coordinates by a scalar s*p inline Point3 operator*(double s, const Point3& p) { return p*s;} - // Define GTSAM traits - namespace traits { - template<> - struct GTSAM_EXPORT is_group : public boost::true_type{ - }; - - template<> - struct GTSAM_EXPORT is_manifold : public boost::true_type{ - }; - - template<> - struct GTSAM_EXPORT dimension : public boost::integral_constant{ - }; - - } + struct traits_x : public internal::LieGroup {}; } diff --git a/gtsam/geometry/Pose2.h b/gtsam/geometry/Pose2.h index 49eb444b2..33782fdb4 100644 --- a/gtsam/geometry/Pose2.h +++ b/gtsam/geometry/Pose2.h @@ -47,6 +47,8 @@ private: public: + enum { dimension = 3 }; + /// @name Standard Constructors /// @{ @@ -298,18 +300,8 @@ inline Matrix wedge(const Vector& xi) { typedef std::pair Point2Pair; GTSAM_EXPORT boost::optional align(const std::vector& pairs); -// Define GTSAM traits -namespace traits { - template<> -struct GTSAM_EXPORT is_manifold : public boost::true_type{ -}; - -template<> -struct GTSAM_EXPORT dimension : public boost::integral_constant{ -}; - -} +struct traits_x : public internal::LieGroup {}; } // namespace gtsam diff --git a/gtsam/geometry/Pose3.h b/gtsam/geometry/Pose3.h index 6a7ed8456..140db7b41 100644 --- a/gtsam/geometry/Pose3.h +++ b/gtsam/geometry/Pose3.h @@ -53,6 +53,8 @@ private: public: + enum { dimension = 3 }; + /// @name Standard Constructors /// @{ @@ -354,21 +356,7 @@ inline Matrix wedge(const Vector& xi) { typedef std::pair Point3Pair; GTSAM_EXPORT boost::optional align(const std::vector& pairs); -// Define GTSAM traits -namespace traits { - template<> -struct GTSAM_EXPORT is_group : public boost::true_type{ -}; - -template<> -struct GTSAM_EXPORT is_manifold : public boost::true_type{ -}; - -template<> -struct GTSAM_EXPORT dimension : public boost::integral_constant{ -}; - -} +struct traits_x : public internal::LieGroup {}; } // namespace gtsam diff --git a/gtsam/geometry/Rot2.h b/gtsam/geometry/Rot2.h index 744e246b3..4ede4326f 100644 --- a/gtsam/geometry/Rot2.h +++ b/gtsam/geometry/Rot2.h @@ -241,20 +241,7 @@ namespace gtsam { }; - // Define GTSAM traits - namespace traits { - template<> - struct GTSAM_EXPORT is_group : public boost::true_type{ - }; + struct traits_x : public internal::LieGroup {}; - template<> - struct GTSAM_EXPORT is_manifold : public boost::true_type{ - }; - - template<> - struct GTSAM_EXPORT dimension : public boost::integral_constant{ - }; - - } } // gtsam diff --git a/gtsam/geometry/StereoCamera.h b/gtsam/geometry/StereoCamera.h index b69da71bd..1d03352da 100644 --- a/gtsam/geometry/StereoCamera.h +++ b/gtsam/geometry/StereoCamera.h @@ -44,6 +44,8 @@ private: public: + enum { dimension = 6 }; + /// @name Standard Constructors /// @{ @@ -150,22 +152,7 @@ private: }; -// Define GTSAM traits -namespace traits { - template<> -struct GTSAM_EXPORT is_manifold : public boost::true_type{ -}; - -template<> -struct GTSAM_EXPORT dimension : public boost::integral_constant{ -}; - -template<> -struct GTSAM_EXPORT zero { - static StereoCamera value() { return StereoCamera();} -}; - -} +struct traits_x : public internal::LieGroup {}; } diff --git a/gtsam/geometry/StereoPoint2.h b/gtsam/geometry/StereoPoint2.h index 694bf525b..fcd37c5d8 100644 --- a/gtsam/geometry/StereoPoint2.h +++ b/gtsam/geometry/StereoPoint2.h @@ -174,20 +174,6 @@ namespace gtsam { }; - // Define GTSAM traits - namespace traits { - template<> - struct is_group : public boost::true_type { - }; - - template<> - struct is_manifold : public boost::true_type { - }; - - template<> - struct dimension : public boost::integral_constant { - }; - - } + struct traits_x : public internal::LieGroup {}; } diff --git a/gtsam/nonlinear/AdaptAutoDiff.h b/gtsam/nonlinear/AdaptAutoDiff.h index 5118426b4..9ba59d977 100644 --- a/gtsam/nonlinear/AdaptAutoDiff.h +++ b/gtsam/nonlinear/AdaptAutoDiff.h @@ -28,9 +28,9 @@ namespace gtsam { template class AdaptAutoDiff { - static const int N = traits::dimension::value; - static const int M1 = traits::dimension::value; - static const int M2 = traits::dimension::value; + static const int N = traits:_x:dimension; + static const int M1 = traits_x::dimension; + static const int M2 = traits_x::dimension; typedef Eigen::Matrix RowMajor1; typedef Eigen::Matrix RowMajor2;