Hat and Vee enforcement

release/4.3a0
Frank Dellaert 2025-03-08 11:39:25 -05:00
parent 51d7483da6
commit 82ec8c03c0
2 changed files with 38 additions and 16 deletions

View File

@ -171,21 +171,22 @@ namespace internal {
/// Assumes existence of: identity, dimension, localCoordinates, retract, /// Assumes existence of: identity, dimension, localCoordinates, retract,
/// and additionally Logmap, Expmap, compose, between, and inverse /// and additionally Logmap, Expmap, compose, between, and inverse
template<class Class> template<class Class>
struct LieGroupTraits: GetDimensionImpl<Class, Class::dimension> { struct LieGroupTraits: public GetDimensionImpl<Class, Class::dimension> {
typedef lie_group_tag structure_category; using structure_category = lie_group_tag;
/// @name Group /// @name Group
/// @{ /// @{
typedef multiplicative_group_tag group_flavor; using group_flavor = multiplicative_group_tag;
static Class Identity() { return Class::Identity();} static Class Identity() { return Class::Identity();}
/// @} /// @}
/// @name Manifold /// @name Manifold
/// @{ /// @{
typedef Class ManifoldType; using ManifoldType = Class;
inline constexpr static auto dimension = Class::dimension; inline constexpr static auto dimension = Class::dimension;
typedef Eigen::Matrix<double, dimension, 1> TangentVector; using LieAlgebra = Class::LieAlgebra;
typedef OptionalJacobian<dimension, dimension> ChartJacobian; using TangentVector = Eigen::Matrix<double, dimension, 1>;
using ChartJacobian = OptionalJacobian<dimension, dimension>;
static TangentVector Local(const Class& origin, const Class& other, static TangentVector Local(const Class& origin, const Class& other,
ChartJacobian Horigin = {}, ChartJacobian Hother = {}) { ChartJacobian Horigin = {}, ChartJacobian Hother = {}) {
@ -222,13 +223,21 @@ struct LieGroupTraits: GetDimensionImpl<Class, Class::dimension> {
ChartJacobian H = {}) { ChartJacobian H = {}) {
return m.inverse(H); return m.inverse(H);
} }
static LieAlgebra Hat(const TangentVector& v) {
return Class::Hat(v);
}
static TangentVector Vee(const LieAlgebra& X) {
return Class::Vee(X);
}
/// @} /// @}
}; };
/// Both LieGroupTraits and Testable /// Both LieGroupTraits and Testable
template<class Class> struct LieGroup: LieGroupTraits<Class>, Testable<Class> {}; template<class Class> struct LieGroup: LieGroupTraits<Class>, Testable<Class> {};
} // \ namepsace internal } // \ namespace internal
/** /**
* These core global functions can be specialized by new Lie types * These core global functions can be specialized by new Lie types
@ -261,6 +270,7 @@ class IsLieGroup: public IsGroup<T>, public IsManifold<T> {
public: public:
typedef typename traits<T>::structure_category structure_category_tag; typedef typename traits<T>::structure_category structure_category_tag;
typedef typename traits<T>::ManifoldType ManifoldType; typedef typename traits<T>::ManifoldType ManifoldType;
typedef typename traits<T>::LieAlgebra LieAlgebra;
typedef typename traits<T>::TangentVector TangentVector; typedef typename traits<T>::TangentVector TangentVector;
typedef typename traits<T>::ChartJacobian ChartJacobian; typedef typename traits<T>::ChartJacobian ChartJacobian;
@ -269,7 +279,7 @@ public:
(std::is_base_of<lie_group_tag, structure_category_tag>::value), (std::is_base_of<lie_group_tag, structure_category_tag>::value),
"This type's trait does not assert it is a Lie group (or derived)"); "This type's trait does not assert it is a Lie group (or derived)");
// group opertations with Jacobians // group operations with Jacobians
g = traits<T>::Compose(g, h, Hg, Hh); g = traits<T>::Compose(g, h, Hg, Hh);
g = traits<T>::Between(g, h, Hg, Hh); g = traits<T>::Between(g, h, Hg, Hh);
g = traits<T>::Inverse(g, Hg); g = traits<T>::Inverse(g, Hg);
@ -279,9 +289,13 @@ public:
// log and exponential map with Jacobians // log and exponential map with Jacobians
g = traits<T>::Expmap(v, Hg); g = traits<T>::Expmap(v, Hg);
v = traits<T>::Logmap(g, Hg); v = traits<T>::Logmap(g, Hg);
// hat and vee
X = traits<T>::Hat(v);
v = traits<T>::Vee(X);
} }
private: private:
T g, h; T g, h;
LieAlgebra X;
TangentVector v; TangentVector v;
ChartJacobian Hg, Hh; ChartJacobian Hg, Hh;
}; };
@ -301,22 +315,21 @@ T BCH(const T& X, const T& Y) {
return T(X + Y + _2 * X_Y + _12 * bracket(X - Y, X_Y) - _24 * bracket(Y, bracket(X, X_Y))); return T(X + Y + _2 * X_Y + _12 * bracket(X - Y, X_Y) - _24 * bracket(Y, bracket(X, X_Y)));
} }
/** #ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
* Declaration of wedge (see Murray94book) used to convert /// @deprecated: use T::Hat
* from n exponential coordinates to n*n element of the Lie algebra
*/
template <class T> Matrix wedge(const Vector& x); template <class T> Matrix wedge(const Vector& x);
#endif
/** /**
* Exponential map given exponential coordinates * Exponential map given exponential coordinates
* class T needs a wedge<> function and a constructor from Matrix * class T needs a constructor from Matrix.
* @param x exponential coordinates, vector of size n * @param x exponential coordinates, vector of size n
* @ return a T * @ return a T
*/ */
template <class T> template <class T>
T expm(const Vector& x, int K=7) { T expm(const Vector& x, int K = 7) {
Matrix xhat = wedge<T>(x); auto xhat = T::Hat(x);
return T(expm(xhat,K)); return T(expm(xhat, K));
} }
/** /**

View File

@ -51,6 +51,8 @@ struct VectorSpaceImpl {
/// @name Lie Group /// @name Lie Group
/// @{ /// @{
typedef Eigen::Matrix<double, N, 1> LieAlgebra;
static TangentVector Logmap(const Class& m, ChartJacobian Hm = {}) { static TangentVector Logmap(const Class& m, ChartJacobian Hm = {}) {
if (Hm) *Hm = Jacobian::Identity(); if (Hm) *Hm = Jacobian::Identity();
return m.vector(); return m.vector();
@ -80,6 +82,13 @@ struct VectorSpaceImpl {
return -v; return -v;
} }
static LieAlgebra Hat(const TangentVector& v) {
return v;
}
static TangentVector Vee(const LieAlgebra& X) {
return X;
}
/// @} /// @}
}; };