From 07ef30039a5363fe43a617f9a36b18a4bab85d3f Mon Sep 17 00:00:00 2001 From: dellaert Date: Sat, 6 Dec 2014 11:17:54 +0100 Subject: [PATCH] structure_tag works --- gtsam/base/concepts.h | 55 +++++++++++++++++------------ gtsam/geometry/tests/testCyclic.cpp | 13 ++++--- 2 files changed, 38 insertions(+), 30 deletions(-) diff --git a/gtsam/base/concepts.h b/gtsam/base/concepts.h index 967a91707..393bb69b1 100644 --- a/gtsam/base/concepts.h +++ b/gtsam/base/concepts.h @@ -24,7 +24,7 @@ namespace traits { */ //@{ template -struct structure_category {}; // specializations should be derived from one of the following tags +struct structure_category; // specializations should be derived from one of the following tags //@} /** @@ -92,8 +92,8 @@ namespace traits { /** @name Group Traits */ //@{ -template struct identity {}; -template struct group_flavor {}; +template struct identity; +template struct group_flavor; //@} /** @name Group Flavor Tags */ @@ -104,41 +104,50 @@ struct multiplicative_group_tag {}; } // namespace traits +/** + * Group Concept + */ template -class GroupConcept { - public: - typedef G Group; - static const Group identity = traits::identity::value; +class Group { +public: - BOOST_CONCEPT_USAGE(GroupConcept) { - BOOST_STATIC_ASSERT(boost::is_base_of::type>::value ); - Group ip = inverse(p); - Group pq = compose(p, q); - Group d = between(p, q); - test = equal(p, q); - test2 = operator_usage(p, q, traits::group_flavor::type); + typedef typename traits::identity::value_type identity_value_type; + typedef typename traits::group_flavor::type group_flavor_tag; + typedef typename traits::structure_category::type structure_category_tag; + + BOOST_CONCEPT_USAGE(Group) { + e = traits::identity::value; +// BOOST_STATIC_ASSERT(boost::is_base_of::type>::value ); +// G ip = inverse(p); +// G pq = compose(p, q); +// G d = between(p, q); +// test = equal(p, q); +// test2 = operator_usage(p, q, traits::group_flavor::type); } - bool check_invariants(const Group& a, const Group& b) { - return (equal(compose(a, inverse(a)), identity)) + bool check_invariants(const G& a, const G& b) { + group_flavor_tag group_flavor; + return (equal(compose(a, inverse(a)), e)) && (equal(between(a, b), compose(inverse(a), b))) && (equal(compose(a, between(a, b)), b)) - && operator_usage(a, b, traits::group_flavor::type); + && operator_usage(a, b, group_flavor); } - private: - Group p,q; +private: + G p, q, e; bool test, test2; - bool operator_usage(const Group& a, const Group& b, const traits::multiplicative_group_tag&) { - return equal(compose(a, b), a*b); + bool operator_usage(const G& a, const G& b, + traits::multiplicative_group_tag) { + return equal(compose(a, b), a * b); } - bool operator_usage(const Group& a, const Group& b, const traits::additive_group_tag&) { - return equal(compose(a, b), a+b); + bool operator_usage(const G& a, const G& b, traits::additive_group_tag) { + return equal(compose(a, b), a + b); } }; + /* template class LieGroupConcept : public GroupConcept, public ManifoldConcept { diff --git a/gtsam/geometry/tests/testCyclic.cpp b/gtsam/geometry/tests/testCyclic.cpp index bdf0c3e98..8ea678a0f 100644 --- a/gtsam/geometry/tests/testCyclic.cpp +++ b/gtsam/geometry/tests/testCyclic.cpp @@ -11,7 +11,7 @@ /** * @file Cyclic.h - * @brief Cyclic group, can act on 2D vector spaces + * @brief Cyclic group, i.e., the integers modulo N * @author Frank Dellaert **/ @@ -35,6 +35,9 @@ public: }; namespace traits { +template struct structure_category > { + typedef group_tag type; +}; template struct identity > { static const Cyclic value; typedef Cyclic value_type; @@ -74,21 +77,17 @@ const Cyclic identity >::value = Cyclic(0); using namespace std; using namespace gtsam; -typedef Cyclic<6> G; +typedef Cyclic<6> G; // Let's use the cyclic group of order 6 //****************************************************************************** TEST(Cyclic, Concept) { EXPECT_LONGS_EQUAL(0,traits::identity::value); - //BOOST_CONCEPT_ASSERT((GroupConcept >)); -// EXPECT(assert_equal(p1, p2)); -// EXPECT_LONGS_EQUAL(2,offset2.size()); + BOOST_CONCEPT_ASSERT((Group)); } //****************************************************************************** TEST(Cyclic, Constructor) { G g(0); -// EXPECT(assert_equal(p1, p2)); -// EXPECT_LONGS_EQUAL(2,offset2.size()); } //******************************************************************************