Now all Eigen::Quaternion flavors are certified as IsGroup

release/4.3a0
dellaert 2014-12-07 10:19:38 +01:00
parent 06640cc414
commit 3a6b89e840
1 changed files with 41 additions and 27 deletions

View File

@ -19,47 +19,54 @@
namespace gtsam { namespace gtsam {
/// Typedef to an Eigen Quaternion<double>, we disable alignment because
/// geometry objects are stored in boost pool allocators, in Values
/// containers, and and these pool allocators do not support alignment.
typedef Eigen::Quaternion<double, Eigen::DontAlign> Quaternion;
namespace traits { namespace traits {
/// Define Quaternion to be a model of the Group concept /// Define Eigen::Quaternion to be a model of the Group concept
template<> template<typename _Scalar, int _Options>
struct structure_category<Quaternion> { struct structure_category<Eigen::Quaternion<_Scalar, _Options> > {
typedef group_tag type; typedef group_tag type;
}; };
} // \namespace gtsam::traits } // \namespace gtsam::traits
namespace group { namespace group {
Quaternion compose(const Quaternion&g, const Quaternion& h) { template<typename _Scalar, int _Options>
Eigen::Quaternion<_Scalar, _Options> compose(
const Eigen::Quaternion<_Scalar, _Options> &g,
const Eigen::Quaternion<_Scalar, _Options> & h) {
return g * h; return g * h;
} }
Quaternion between(const Quaternion&g, const Quaternion& h) { template<typename _Scalar, int _Options>
Eigen::Quaternion<_Scalar, _Options> between(
const Eigen::Quaternion<_Scalar, _Options> &g,
const Eigen::Quaternion<_Scalar, _Options> & h) {
return g.inverse() * h; return g.inverse() * h;
} }
Quaternion inverse(const Quaternion&g) { template<typename _Scalar, int _Options>
Eigen::Quaternion<_Scalar, _Options> inverse(
const Eigen::Quaternion<_Scalar, _Options> &g) {
return g.inverse(); return g.inverse();
} }
namespace traits { namespace traits {
/// Define the trait that specifies Quaternion's identity element /// Declare the trait that specifies a quaternion's identity element
template<> template<typename _Scalar, int _Options>
struct identity<Quaternion> { struct identity<Eigen::Quaternion<_Scalar, _Options> > {
static const Quaternion value; static const Eigen::Quaternion<_Scalar, _Options> value;
typedef Quaternion value_type; typedef Eigen::Quaternion<_Scalar, _Options> value_type;
}; };
const Quaternion identity<Quaternion>::value = Quaternion::Identity(); /// Out of line definition of identity
template<typename _Scalar, int _Options>
const Eigen::Quaternion<_Scalar, _Options> identity<
Eigen::Quaternion<_Scalar, _Options> >::value = Eigen::Quaternion<_Scalar,
_Options>::Identity();
/// Define the trait that asserts Quaternion is an additive group /// Define the trait that asserts quaternions are a multiplicative group
template<> template<typename _Scalar, int _Options>
struct flavor<Quaternion> { struct flavor<Eigen::Quaternion<_Scalar, _Options> > {
typedef multiplicative_tag type; typedef multiplicative_tag type;
}; };
@ -67,6 +74,13 @@ struct flavor<Quaternion> {
} // \namespace gtsam::group } // \namespace gtsam::group
} // \namespace gtsam } // \namespace gtsam
/**
* GSAM typedef to an Eigen::Quaternion<double>, we disable alignment because
* geometry objects are stored in boost pool allocators, in Values containers,
* and and these pool allocators do not support alignment.
*/
typedef Eigen::Quaternion<double, Eigen::DontAlign> Quaternion;
/** /**
* @file testCyclic.cpp * @file testCyclic.cpp
* @brief Unit tests for cyclic group * @brief Unit tests for cyclic group