Got rid of CRTP

release/4.3a0
dellaert 2015-05-25 20:51:50 -07:00
parent 1bbbb7ad56
commit 111d0d39dd
6 changed files with 48 additions and 51 deletions

View File

@ -128,7 +128,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
template<class Derived, typename G, typename H>
template<typename G, typename H>
class DirectProduct: public std::pair<G, H> {
BOOST_CONCEPT_ASSERT((IsGroup<G>));
BOOST_CONCEPT_ASSERT((IsGroup<H>));
@ -140,23 +140,23 @@ public:
// Construct from two subgroup elements
DirectProduct(const G& g, const H& h):std::pair<G,H>(g,h) {}
Derived operator*(const Derived& other) const {
return Derived(traits<G>::Compose(this->first, other.first),
DirectProduct operator*(const DirectProduct& other) const {
return DirectProduct(traits<G>::Compose(this->first, other.first),
traits<H>::Compose(this->second, other.second));
}
Derived inverse() const {
return Derived(this->first.inverse(), this->second.inverse());
DirectProduct inverse() const {
return DirectProduct(this->first.inverse(), this->second.inverse());
}
};
// Define any direct product group to be a model of the multiplicative Group concept
template<class Derived, typename G, typename H>
struct traits<DirectProduct<Derived, G, H> > :
internal::MultiplicativeGroupTraits<DirectProduct<Derived, G, H> > {};
template<typename G, typename H>
struct traits<DirectProduct<G, H> > :
internal::MultiplicativeGroupTraits<DirectProduct<G, H> > {};
/// Template to construct the direct sum of two additive groups
/// Assumes existence of three additive operators for both groups
template<class Derived, typename G, typename H>
template<typename G, typename H>
class DirectSum: public std::pair<G, H> {
BOOST_CONCEPT_ASSERT((IsGroup<G>)); // TODO(frank): check additive
BOOST_CONCEPT_ASSERT((IsGroup<H>)); // TODO(frank): check additive
@ -171,21 +171,21 @@ public:
// Construct from two subgroup elements
DirectSum(const G& g, const H& h):std::pair<G,H>(g,h) {}
Derived operator+(const Derived& other) const {
DirectSum operator+(const DirectSum& other) const {
return DirectSum(g()+other.g(), h()+other.h());
}
Derived operator-(const Derived& other) const {
return Derived(g()-other.g(), h()-other.h());
DirectSum operator-(const DirectSum& other) const {
return DirectSum(g()-other.g(), h()-other.h());
}
Derived operator-() const {
return Derived(- g(), - h());
DirectSum operator-() const {
return DirectSum(- g(), - h());
}
};
// Define direct sums to be a model of the Additive Group concept
template<class Derived, typename G, typename H>
struct traits<DirectSum<Derived, G, H> > :
internal::AdditiveGroupTraits<DirectSum<Derived, G, H> > {};
template<typename G, typename H>
struct traits<DirectSum<G, H> > :
internal::AdditiveGroupTraits<DirectSum<G, H> > {};
} // namespace gtsam

View File

@ -170,14 +170,14 @@ struct FixedDimension {
"FixedDimension instantiated for dymanically-sized type.");
};
/// CRTP to construct the product manifold of two other manifolds, M1 and M2
/// Assumes manifold structure from M1 and M2, and binary constructor
template<class Derived, typename M1, typename M2>
/// Helper class to construct the product manifold of two other manifolds, M1 and M2
/// Assumes nothing except manifold structure from M1 and M2
template<typename M1, typename M2>
class ProductManifold: public std::pair<M1, M2> {
BOOST_CONCEPT_ASSERT((IsManifold<M1>));
BOOST_CONCEPT_ASSERT((IsManifold<M2>));
private:
protected:
enum { dimension1 = traits<M1>::dimension };
enum { dimension2 = traits<M2>::dimension };
@ -196,14 +196,14 @@ public:
ProductManifold(const M1& m1, const M2& m2):std::pair<M1,M2>(m1,m2) {}
/// Retract delta to manifold
Derived retract(const TangentVector& xi) const {
ProductManifold retract(const TangentVector& xi) const {
M1 m1 = traits<M1>::Retract(this->first, xi.template head<dimension1>());
M2 m2 = traits<M2>::Retract(this->second, xi.template tail<dimension2>());
return Derived(m1,m2);
return ProductManifold(m1,m2);
}
/// Compute the coordinates in the tangent space
TangentVector localCoordinates(const Derived& other) const {
TangentVector localCoordinates(const ProductManifold& other) const {
typename traits<M1>::TangentVector v1 = traits<M1>::Local(this->first, other.first);
typename traits<M2>::TangentVector v2 = traits<M2>::Local(this->second, other.second);
TangentVector v;
@ -213,9 +213,8 @@ public:
};
// Define any direct product group to be a model of the multiplicative Group concept
template<class Derived, typename M1, typename M2>
struct traits<ProductManifold<Derived, M1, M2> > : internal::Manifold<
ProductManifold<Derived, M1, M2> > {
template<typename M1, typename M2>
struct traits<ProductManifold<M1, M2> > : internal::Manifold<ProductManifold<M1, M2> > {
};
} // \ namespace gtsam

View File

@ -103,11 +103,7 @@ TEST(Group, S3) {
//******************************************************************************
// The direct product of S2=Z2 and S3 is the symmetry group of a hexagon,
// i.e., the dihedral group of order 12 (denoted Dih6 because 6-sided polygon)
struct Dih6 : DirectProduct<Dih6, S2, S3> {
typedef DirectProduct<Dih6, S2, S3> Base;
Dih6(const S2& g, const S3& h):Base(g,h) {}
Dih6() {}
};
typedef DirectProduct<S2, S3> Dih6;
std::ostream &operator<<(std::ostream &os, const Dih6& m) {
os << "( " << m.first << ", " << m.second << ")";

View File

@ -21,13 +21,17 @@ namespace gtsam {
* but here we choose instead to parameterize it as a (Rot3,Unit3) pair.
* We can then non-linearly optimize immediately on this 5-dimensional manifold.
*/
class GTSAM_EXPORT EssentialMatrix : private ProductManifold<EssentialMatrix, Rot3, Unit3> {
class GTSAM_EXPORT EssentialMatrix : private ProductManifold<Rot3, Unit3> {
private:
friend class ProductManifold<EssentialMatrix, Rot3, Unit3>;
typedef ProductManifold<EssentialMatrix, Rot3, Unit3> Base;
typedef ProductManifold<Rot3, Unit3> Base;
Matrix3 E_; ///< Essential matrix
/// Construct from Base
EssentialMatrix(const Base& base) :
Base(base), E_(direction().skew() * rotation().matrix()) {
}
public:
/// Static function to convert Point2 to homogeneous coordinates
@ -82,9 +86,16 @@ public:
using Base::dimension;
using Base::dim;
using Base::Dim;
using Base::retract;
using Base::localCoordinates;
/// Retract delta to manifold
EssentialMatrix retract(const TangentVector& v) const {
return Base::retract(v);
}
/// Compute the coordinates in the tangent space
TangentVector localCoordinates(const EssentialMatrix& other) const {
return Base::localCoordinates(other);
}
/// @}
/// @name Essential matrix methods

View File

@ -87,12 +87,7 @@ TEST(Cyclic , Invariants) {
//******************************************************************************
// The Direct sum of Z2 and Z2 is *not* Cyclic<4>, but the
// smallest non-cyclic group called the Klein four-group:
struct K4: DirectSum<K4, Z2, Z2> {
typedef DirectSum<K4, Z2, Z2> Base;
K4(const Z2& g, const Z2& h):Base(g,h) {}
K4(const Base& base):Base(base) {}
K4() {}
};
typedef DirectSum<Z2, Z2> K4;
namespace gtsam {

View File

@ -10,13 +10,14 @@
* -------------------------------1------------------------------------------- */
/**
* @file testExpression.cpp
* @file testManifold.cpp
* @date September 18, 2014
* @author Frank Dellaert
* @author Paul Furgale
* @brief unit tests for Block Automatic Differentiation
* @brief unit tests for Manifold type machinery
*/
#include <gtsam/base/Manifold.h>
#include <gtsam/geometry/PinholeCamera.h>
#include <gtsam/geometry/Pose2.h>
#include <gtsam/geometry/Cal3_S2.h>
@ -149,12 +150,7 @@ TEST(Manifold, DefaultChart) {
}
//******************************************************************************
struct MyPoint2Pair : public ProductManifold<MyPoint2Pair,Point2,Point2> {
typedef ProductManifold<MyPoint2Pair,Point2,Point2> Base;
MyPoint2Pair(const Point2& p1, const Point2& p2):Base(p1,p2) {}
MyPoint2Pair(const Base& base):Base(base) {}
MyPoint2Pair() {}
};
typedef ProductManifold<Point2,Point2> MyPoint2Pair;
// Define any direct product group to be a model of the multiplicative Group concept
namespace gtsam {