diff --git a/gtsam/base/Group.h b/gtsam/base/Group.h index f35091757..39541416e 100644 --- a/gtsam/base/Group.h +++ b/gtsam/base/Group.h @@ -20,6 +20,8 @@ #pragma once +#include + #include #include #include @@ -87,34 +89,38 @@ check_group_invariants(const G& a, const G& b, double tol = 1e-9) { namespace internal { -/// A helper class that implements the traits interface for groups. -/// Assumes that constructor yields identity +/// A helper class that implements the traits interface for multiplicative groups. +/// Assumes existence of identity, operator* and inverse method template -struct GroupTraits { +struct MultiplicativeGroupTraits { typedef group_tag structure_category; - static Class Identity() { return Class(); } + typedef multiplicative_group_tag group_flavor; + static Class Identity() { return Class::identity(); } + static Class Compose(const Class &g, const Class & h) { return g * h;} + static Class Between(const Class &g, const Class & h) { return g.inverse() * h;} + static Class Inverse(const Class &g) { return g.inverse();} }; -/// A helper class that implements the traits interface for multiplicative groups. -/// Assumes existence of operator* and inverse method +/// Both multiplicative group traits and Testable template -struct MultiplicativeGroupTraits : GroupTraits { - typedef multiplicative_group_tag group_flavor; \ - static Class Compose(const Class &g, const Class & h) { return g * h;} \ - static Class Between(const Class &g, const Class & h) { return g.inverse() * h;} \ - static Class Inverse(const Class &g) { return g.inverse();} -}; +struct MultiplicativeGroup : MultiplicativeGroupTraits, Testable {}; /// A helper class that implements the traits interface for additive groups. -/// Assumes existence of three additive operators +/// Assumes existence of identity and three additive operators template -struct AdditiveGroupTraits : GroupTraits { - typedef additive_group_tag group_flavor; \ - static Class Compose(const Class &g, const Class & h) { return g + h;} \ - static Class Between(const Class &g, const Class & h) { return h - g;} \ - static Class Inverse(const Class &g) { return -g;} +struct AdditiveGroupTraits { + typedef group_tag structure_category; + typedef additive_group_tag group_flavor; + static Class Identity() { return Class::identity(); } + static Class Compose(const Class &g, const Class & h) { return g + h;} + static Class Between(const Class &g, const Class & h) { return h - g;} + static Class Inverse(const Class &g) { return -g;} }; +/// Both additive group traits and Testable +template +struct AdditiveGroup : AdditiveGroupTraits, Testable {}; + } // namespace internal /// compose multiple times @@ -127,7 +133,7 @@ compose_pow(const G& g, size_t n) { } /// Template to construct the direct product of two arbitrary groups -/// Assumes nothing except group structure from G and H +/// Assumes nothing except group structure and Testable from G and H template class DirectProduct: public std::pair { BOOST_CONCEPT_ASSERT((IsGroup)); @@ -140,6 +146,9 @@ public: // Construct from two subgroup elements DirectProduct(const G& g, const H& h):std::pair(g,h) {} + // identity + static DirectProduct identity() { return DirectProduct(); } + DirectProduct operator*(const DirectProduct& other) const { return DirectProduct(traits::Compose(this->first, other.first), traits::Compose(this->second, other.second)); @@ -171,6 +180,9 @@ public: // Construct from two subgroup elements DirectSum(const G& g, const H& h):std::pair(g,h) {} + // identity + static DirectSum identity() { return DirectSum(); } + DirectSum operator+(const DirectSum& other) const { return DirectSum(g()+other.g(), h()+other.h()); } diff --git a/gtsam/base/Lie.h b/gtsam/base/Lie.h index c9f788992..05c7bc20f 100644 --- a/gtsam/base/Lie.h +++ b/gtsam/base/Lie.h @@ -136,8 +136,10 @@ namespace internal { /// A helper class that implements the traits interface for GTSAM lie groups. /// To use this for your gtsam type, define: /// template<> struct traits : public internal::LieGroupTraits {}; +/// Assumes existence of: identity, dimension, localCoordinates, retract, +/// and additionally Logmap, Expmap, compose, between, and inverse template -struct LieGroupTraits : Testable { +struct LieGroupTraits { typedef lie_group_tag structure_category; /// @name Group @@ -167,12 +169,10 @@ struct LieGroupTraits : Testable { ChartJacobian Horigin = boost::none, ChartJacobian Hv = boost::none) { return origin.retract(v, Horigin, Hv); } - /// @} /// @name Lie Group /// @{ - static TangentVector Logmap(const Class& m, ChartJacobian Hm = boost::none) { return Class::Logmap(m, Hm); } @@ -195,11 +195,12 @@ struct LieGroupTraits : Testable { ChartJacobian H = boost::none) { return m.inverse(H); } - /// @} - }; +/// Both LieGroupTraits and Testable +template struct LieGroup: LieGroupTraits, Testable {}; + } // \ namepsace internal /** diff --git a/gtsam/base/Manifold.h b/gtsam/base/Manifold.h index 12df84819..b20c60822 100644 --- a/gtsam/base/Manifold.h +++ b/gtsam/base/Manifold.h @@ -116,10 +116,8 @@ struct ManifoldTraits: ManifoldImpl { } }; -/// Implement both manifold and testable traits at the same time -template -struct Manifold: Testable, ManifoldTraits { -}; +/// Both ManifoldTraits and Testable +template struct Manifold: ManifoldTraits, Testable {}; } // \ namespace internal diff --git a/gtsam/base/VectorSpace.h b/gtsam/base/VectorSpace.h index 558fe52c9..c356dcc07 100644 --- a/gtsam/base/VectorSpace.h +++ b/gtsam/base/VectorSpace.h @@ -20,7 +20,7 @@ template struct traits; namespace internal { -/// VectorSpace Implementation for Fixed sizes +/// VectorSpaceTraits Implementation for Fixed sizes template struct VectorSpaceImpl { @@ -83,7 +83,7 @@ struct VectorSpaceImpl { /// @} }; -/// VectorSpace implementation for dynamic types. +/// VectorSpaceTraits implementation for dynamic types. template struct VectorSpaceImpl { @@ -159,11 +159,11 @@ struct VectorSpaceImpl { /// @} }; -/// A helper that implements the traits interface for GTSAM lie groups. +/// A helper that implements the traits interface for GTSAM vector space types. /// To use this for your gtsam type, define: -/// template<> struct traits : public VectorSpace { }; +/// template<> struct traits : public VectorSpaceTraits { }; template -struct VectorSpace: Testable, VectorSpaceImpl { +struct VectorSpaceTraits: VectorSpaceImpl { typedef vector_space_tag structure_category; @@ -178,9 +178,12 @@ struct VectorSpace: Testable, VectorSpaceImpl { enum { dimension = Class::dimension}; typedef Class ManifoldType; /// @} - }; +/// Both VectorSpaceTRaits and Testable +template +struct VectorSpace: Testable, VectorSpaceTraits {}; + /// A helper that implements the traits interface for GTSAM lie groups. /// To use this for your gtsam type, define: /// template<> struct traits : public ScalarTraits { };