add Lie group operations

release/4.3a0
Varun Agrawal 2022-04-30 05:12:43 -04:00
parent 9eff71ea8e
commit 7a56473d8f
2 changed files with 49 additions and 2 deletions

View File

@ -12,7 +12,7 @@
/**
* @file Similarity2.cpp
* @brief Implementation of Similarity2 transform
* @author John Lambert
* @author John Lambert, Varun Agrawal
*/
#include <gtsam/base/Manifold.h>
@ -198,6 +198,30 @@ Similarity2 Similarity2::Align(const Pose2Pairs& abPosePairs) {
return internal::AlignGivenR(abPointPairs, aRb_estimate);
}
Vector4 Similarity2::Logmap(const Similarity2& S, //
OptionalJacobian<4, 4> Hm) {
const Vector2 u = S.t_;
const Vector1 w = Rot2::Logmap(S.R_);
const double s = log(S.s_);
Vector4 result;
result << u, w, s;
if (Hm) {
throw std::runtime_error("Similarity2::Logmap: derivative not implemented");
}
return result;
}
Similarity2 Similarity2::Expmap(const Vector4& v, //
OptionalJacobian<4, 4> Hm) {
const Vector2 t = v.head<2>();
const Rot2 R = Rot2::Expmap(v.segment<1>(2));
const double s = v[3];
if (Hm) {
throw std::runtime_error("Similarity2::Expmap: derivative not implemented");
}
return Similarity2(R, t, s);
}
std::ostream& operator<<(std::ostream& os, const Similarity2& p) {
os << "[" << p.rotation().theta() << " " << p.translation().transpose() << " "
<< p.scale() << "]\';";

View File

@ -12,7 +12,7 @@
/**
* @file Similarity2.h
* @brief Implementation of Similarity2 transform
* @author John Lambert
* @author John Lambert, Varun Agrawal
*/
#pragma once
@ -138,6 +138,29 @@ class GTSAM_EXPORT Similarity2 : public LieGroup<Similarity2, 4> {
/// @name Lie Group
/// @{
/**
* Log map at the identity
* \f$ [t_x, t_y, \delta, \lambda] \f$
*/
static Vector4 Logmap(const Similarity2& S, //
OptionalJacobian<4, 4> Hm = boost::none);
/// Exponential map at the identity
static Similarity2 Expmap(const Vector4& v, //
OptionalJacobian<4, 4> Hm = boost::none);
/// Chart at the origin
struct ChartAtOrigin {
static Similarity2 Retract(const Vector4& v,
ChartJacobian H = boost::none) {
return Similarity2::Expmap(v, H);
}
static Vector4 Local(const Similarity2& other,
ChartJacobian H = boost::none) {
return Similarity2::Logmap(other, H);
}
};
using LieGroup<Similarity2, 4>::inverse;
/// @}