diff --git a/gtsam/base/Group.h b/gtsam/base/Group.h index aec4b5f1c..f97be5376 100644 --- a/gtsam/base/Group.h +++ b/gtsam/base/Group.h @@ -13,8 +13,9 @@ * @file Group.h * * @brief Concept check class for variable types with Group properties - * @date Nov 5, 2011 + * @date November, 2011 * @author Alex Cunningham + * @author Frank Dellaert */ #pragma once @@ -83,21 +84,34 @@ check_group_invariants(const G& a, const G& b, double tol = 1e-9) { && traits::Equals(traits::Compose(a, traits::Between(a, b)), b, tol); } -/// Macro to add group traits, additive flavor -#define GTSAM_ADDITIVE_GROUP(GROUP) \ - typedef additive_group_tag group_flavor; \ - static GROUP Compose(const GROUP &g, const GROUP & h) { return g + h;} \ - static GROUP Between(const GROUP &g, const GROUP & h) { return h - g;} \ - static GROUP Inverse(const GROUP &g) { return -g;} +namespace internal { -/// Macro to add group traits, multiplicative flavor -#define GTSAM_MULTIPLICATIVE_GROUP(GROUP) \ - typedef additive_group_tag group_flavor; \ - static GROUP Compose(const GROUP &g, const GROUP & h) { return g * h;} \ - static GROUP Between(const GROUP &g, const GROUP & h) { return g.inverse() * h;} \ - static GROUP Inverse(const GROUP &g) { return g.inverse();} +/// A helper class that implements the traits interface for groups. +template +struct GroupTraits { + typedef group_tag structure_category; + static Class Identity() { return Class::Identity(); } +}; -} // \ namespace gtsam +/// A helper class that implements the traits interface for additive groups. +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;} +}; + +/// A helper class that implements the traits interface for multiplicative groups. +template +struct MultiplicativeGroupTraits : 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 g.inverse() * h;} \ + static Class Inverse(const Class &g) { return g.inverse();} +}; +} // namespace internal +} // namespace gtsam /** * Macros for using the IsGroup diff --git a/gtsam/geometry/Cyclic.h b/gtsam/geometry/Cyclic.h index 2c883707f..8aa205aa3 100644 --- a/gtsam/geometry/Cyclic.h +++ b/gtsam/geometry/Cyclic.h @@ -16,10 +16,8 @@ **/ #include -#include -#include -#include -#include +#include +#include // for cout :-( namespace gtsam { @@ -33,7 +31,7 @@ public: i_(i) { assert(i < N); } - /// Idenity element + /// Identity element static Cyclic Identity() { return Cyclic(0); } @@ -63,20 +61,10 @@ public: } }; -/// Define cyclic group traits to be a model of the Group concept +/// Define cyclic group traits to be a model of the Additive Group concept template -struct traits > { - typedef group_tag structure_category;GTSAM_ADDITIVE_GROUP(Cyclic) - static Cyclic Identity() { - return Cyclic::Identity(); - } - static bool Equals(const Cyclic& a, const Cyclic& b, - double tol = 1e-9) { - return a.equals(b, tol); - } - static void Print(const Cyclic& c, const std::string &s = "") { - c.print(s); - } +struct traits > : internal::AdditiveGroupTraits >, // + Testable > { }; } // \namespace gtsam