Modernized group traits
parent
283faba562
commit
8d97415239
|
|
@ -13,8 +13,9 @@
|
||||||
* @file Group.h
|
* @file Group.h
|
||||||
*
|
*
|
||||||
* @brief Concept check class for variable types with Group properties
|
* @brief Concept check class for variable types with Group properties
|
||||||
* @date Nov 5, 2011
|
* @date November, 2011
|
||||||
* @author Alex Cunningham
|
* @author Alex Cunningham
|
||||||
|
* @author Frank Dellaert
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#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);
|
&& traits<G>::Equals(traits<G>::Compose(a, traits<G>::Between(a, b)), b, tol);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Macro to add group traits, additive flavor
|
namespace internal {
|
||||||
#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;}
|
|
||||||
|
|
||||||
/// Macro to add group traits, multiplicative flavor
|
/// A helper class that implements the traits interface for groups.
|
||||||
#define GTSAM_MULTIPLICATIVE_GROUP(GROUP) \
|
template<class Class>
|
||||||
typedef additive_group_tag group_flavor; \
|
struct GroupTraits {
|
||||||
static GROUP Compose(const GROUP &g, const GROUP & h) { return g * h;} \
|
typedef group_tag structure_category;
|
||||||
static GROUP Between(const GROUP &g, const GROUP & h) { return g.inverse() * h;} \
|
static Class Identity() { return Class::Identity(); }
|
||||||
static GROUP Inverse(const GROUP &g) { return g.inverse();}
|
};
|
||||||
|
|
||||||
} // \ 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
|
* Macros for using the IsGroup
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,8 @@
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#include <gtsam/base/Group.h>
|
#include <gtsam/base/Group.h>
|
||||||
#include <cstddef>
|
#include <gtsam/base/Testable.h>
|
||||||
#include <string>
|
#include <iostream> // for cout :-(
|
||||||
#include <iostream>
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
|
|
@ -33,7 +31,7 @@ public:
|
||||||
i_(i) {
|
i_(i) {
|
||||||
assert(i < N);
|
assert(i < N);
|
||||||
}
|
}
|
||||||
/// Idenity element
|
/// Identity element
|
||||||
static Cyclic Identity() {
|
static Cyclic Identity() {
|
||||||
return Cyclic(0);
|
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>
|
template<size_t N>
|
||||||
struct traits<Cyclic<N> > {
|
struct traits<Cyclic<N> > : internal::AdditiveGroupTraits<Cyclic<N> >, //
|
||||||
typedef group_tag structure_category;GTSAM_ADDITIVE_GROUP(Cyclic<N>)
|
Testable<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);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // \namespace gtsam
|
} // \namespace gtsam
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue