From 8939adc7991b90e2e52e33187e02f6162dbe56b1 Mon Sep 17 00:00:00 2001 From: dellaert Date: Mon, 25 May 2015 23:49:41 -0700 Subject: [PATCH] Moved ProductLieGroup to its own header --- gtsam/base/ProductLieGroup.h | 115 +++++++++++++++++++++++++++++++++++ tests/testLie.cpp | 95 +---------------------------- 2 files changed, 116 insertions(+), 94 deletions(-) create mode 100644 gtsam/base/ProductLieGroup.h diff --git a/gtsam/base/ProductLieGroup.h b/gtsam/base/ProductLieGroup.h new file mode 100644 index 000000000..2bcb49dba --- /dev/null +++ b/gtsam/base/ProductLieGroup.h @@ -0,0 +1,115 @@ +/* ---------------------------------------------------------------------------- + + * GTSAM Copyright 2010, Georgia Tech Research Corporation, + * Atlanta, Georgia 30332-0415 + * All Rights Reserved + * Authors: Frank Dellaert, et al. (see THANKS for the full author list) + + * See LICENSE for the license information + + * -------------------------------1------------------------------------------- */ + +/** + * @file ProductLieGroup.h + * @date May, 2015 + * @author Frank Dellaert + * @brief Group product of two Lie Groups + */ + +#pragma once + +#include +#include // pair + +namespace gtsam { + +/// Template to construct the product Lie group of two other Lie groups, G and H +/// Assumes manifold structure from G and H, and binary constructor +template +class ProductLieGroup: public std::pair, public LieGroup< + ProductLieGroup, traits::dimension + traits::dimension> { + BOOST_CONCEPT_ASSERT((IsLieGroup)); + BOOST_CONCEPT_ASSERT((IsLieGroup)); + typedef std::pair Base; + +protected: + enum {dimension1 = traits::dimension}; + enum {dimension2 = traits::dimension}; + +public: + /// Default constructor yields identity + ProductLieGroup():Base(traits::Identity(),traits::Identity()) {} + + // Construct from two subgroup elements + ProductLieGroup(const G& g, const H& h):Base(g,h) {} + + // Construct from base + ProductLieGroup(const Base& base):Base(base) {} + + /// @name Group + /// @{ + typedef multiplicative_group_tag group_flavor; + static ProductLieGroup identity() {return ProductLieGroup();} + + ProductLieGroup operator*(const ProductLieGroup& other) const { + return ProductLieGroup(traits::Compose(this->first,other.first), + traits::Compose(this->second,other.second)); + } + ProductLieGroup inverse() const { + return ProductLieGroup(this->first.inverse(), this->second.inverse()); + } + /// @} + + /// @name Manifold (but with derivatives) + /// @{ + enum {dimension = dimension1 + dimension2}; + inline static size_t Dim() {return dimension;} + inline size_t dim() const {return dimension;} + + typedef Eigen::Matrix TangentVector; + typedef OptionalJacobian ChartJacobian; + /// @} + + /// @name Lie Group + /// @{ + Eigen::Matrix AdjointMap() const { + Eigen::Matrix A; + A.setIdentity(); + throw std::runtime_error("ProductLieGroup::derivatives not implemented yet"); + // A.template topLeftCorner() = this->first.AdjointMap(); + // A.template bottomRightCorner() = this->second.AdjointMap(); + return A; + } + static ProductLieGroup Expmap(const TangentVector& v, ChartJacobian Hv = boost::none) { + if (Hv) throw std::runtime_error("ProductLieGroup::derivatives not implemented yet"); + G g = traits::Expmap(v.template head()); + H h = traits::Expmap(v.template tail()); + return ProductLieGroup(g,h); + } + static TangentVector Logmap(const ProductLieGroup& p, ChartJacobian Hp = boost::none) { + if (Hp) throw std::runtime_error("ProductLieGroup::derivatives not implemented yet"); + typename traits::TangentVector v1 = traits::Logmap(p.first); + typename traits::TangentVector v2 = traits::Logmap(p.second); + TangentVector v; + v << v1, v2; + return v; + } + struct ChartAtOrigin { + static TangentVector Local(const ProductLieGroup& m, ChartJacobian Hm = boost::none) { + return Logmap(m, Hm); + } + static ProductLieGroup Retract(const TangentVector& v, ChartJacobian Hv = boost::none) { + return Expmap(v, Hv); + } + }; + using LieGroup::inverse; // with derivative + /// @} +}; + +// Define any direct product group to be a model of the multiplicative Group concept +template +struct traits > : internal::LieGroupTraits< + ProductLieGroup > { +}; +} // namespace gtsam + diff --git a/tests/testLie.cpp b/tests/testLie.cpp index 99337230b..f004dcc0f 100644 --- a/tests/testLie.cpp +++ b/tests/testLie.cpp @@ -16,104 +16,11 @@ * @brief unit tests for Lie group type machinery */ -#include -#include +#include -namespace gtsam { - -/// Template to construct the product Lie group of two other Lie groups, G and H -/// Assumes manifold structure from G and H, and binary constructor -template -class ProductLieGroup: public std::pair, public LieGroup< - ProductLieGroup, traits::dimension + traits::dimension> { - BOOST_CONCEPT_ASSERT((IsLieGroup)); - BOOST_CONCEPT_ASSERT((IsLieGroup)); - typedef std::pair Base; - -protected: - enum {dimension1 = traits::dimension}; - enum {dimension2 = traits::dimension}; - -public: - /// Default constructor yields identity - ProductLieGroup():Base(traits::Identity(),traits::Identity()) {} - - // Construct from two subgroup elements - ProductLieGroup(const G& g, const H& h):Base(g,h) {} - - // Construct from base - ProductLieGroup(const Base& base):Base(base) {} - - /// @name Group - /// @{ - typedef multiplicative_group_tag group_flavor; - static ProductLieGroup identity() {return ProductLieGroup();} - - ProductLieGroup operator*(const ProductLieGroup& other) const { - return ProductLieGroup(traits::Compose(this->first,other.first), - traits::Compose(this->second,other.second)); - } - ProductLieGroup inverse() const { - return ProductLieGroup(this->first.inverse(), this->second.inverse()); - } - /// @} - - /// @name Manifold (but with derivatives) - /// @{ - enum {dimension = dimension1 + dimension2}; - inline static size_t Dim() {return dimension;} - inline size_t dim() const {return dimension;} - - typedef Eigen::Matrix TangentVector; - typedef OptionalJacobian ChartJacobian; - /// @} - - /// @name Lie Group - /// @{ - Eigen::Matrix AdjointMap() const { - Eigen::Matrix A; - A.setIdentity(); - throw std::runtime_error("ProductLieGroup::derivatives not implemented yet"); -// A.template topLeftCorner() = this->first.AdjointMap(); -// A.template bottomRightCorner() = this->second.AdjointMap(); - return A; - } - static ProductLieGroup Expmap(const TangentVector& v, ChartJacobian Hv = boost::none) { - if (Hv) throw std::runtime_error("ProductLieGroup::derivatives not implemented yet"); - G g = traits::Expmap(v.template head()); - H h = traits::Expmap(v.template tail()); - return ProductLieGroup(g,h); - } - static TangentVector Logmap(const ProductLieGroup& p, ChartJacobian Hp = boost::none) { - if (Hp) throw std::runtime_error("ProductLieGroup::derivatives not implemented yet"); - typename traits::TangentVector v1 = traits::Logmap(p.first); - typename traits::TangentVector v2 = traits::Logmap(p.second); - TangentVector v; - v << v1, v2; - return v; - } - struct ChartAtOrigin { - static TangentVector Local(const ProductLieGroup& m, ChartJacobian Hm = boost::none) { - return Logmap(m, Hm); - } - static ProductLieGroup Retract(const TangentVector& v, ChartJacobian Hv = boost::none) { - return Expmap(v, Hv); - } - }; - using LieGroup::inverse; // with derivative - /// @} -}; - -// Define any direct product group to be a model of the multiplicative Group concept -template -struct traits > : internal::LieGroupTraits< - ProductLieGroup > { -}; -} #include #include -#undef CHECK #include using namespace std;