Modernized group traits
parent
283faba562
commit
8d97415239
|
|
@ -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<G>::Equals(traits<G>::Compose(a, traits<G>::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<class Class>
|
||||
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<class Class>
|
||||
struct AdditiveGroupTraits : GroupTraits<Class> {
|
||||
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<class Class>
|
||||
struct MultiplicativeGroupTraits : GroupTraits<Class> {
|
||||
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
|
||||
|
|
|
|||
|
|
@ -16,10 +16,8 @@
|
|||
**/
|
||||
|
||||
#include <gtsam/base/Group.h>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <assert.h>
|
||||
#include <gtsam/base/Testable.h>
|
||||
#include <iostream> // 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<size_t N>
|
||||
struct traits<Cyclic<N> > {
|
||||
typedef group_tag structure_category;GTSAM_ADDITIVE_GROUP(Cyclic<N>)
|
||||
static Cyclic<N> Identity() {
|
||||
return Cyclic<N>::Identity();
|
||||
}
|
||||
static bool Equals(const Cyclic<N>& a, const Cyclic<N>& b,
|
||||
double tol = 1e-9) {
|
||||
return a.equals(b, tol);
|
||||
}
|
||||
static void Print(const Cyclic<N>& c, const std::string &s = "") {
|
||||
c.print(s);
|
||||
}
|
||||
struct traits<Cyclic<N> > : internal::AdditiveGroupTraits<Cyclic<N> >, //
|
||||
Testable<Cyclic<N> > {
|
||||
};
|
||||
|
||||
} // \namespace gtsam
|
||||
|
|
|
|||
Loading…
Reference in New Issue