farm-ng-core
manifold.h
Go to the documentation of this file.
1 // Copyright (c) 2011, Hauke Strasdat
2 // Copyright (c) 2012, Steven Lovegrove
3 // Copyright (c) 2021, farm-ng, inc.
4 //
5 // Use of this source code is governed by an MIT-style
6 // license that can be found in the LICENSE file or at
7 // https://opensource.org/licenses/MIT.
8 
9 #pragma once
10 
12 
13 namespace sophus::ceres {
14 
15 /// Templated local parameterization for LieGroup [with implemented
16 /// LieGroup::Dx_this_mul_exp_x_at_0() ]
17 template <template <class> class TLieGroup>
18 class Manifold : public ::ceres::Manifold {
19  public:
20  using LieGroupF64 = TLieGroup<double>;
21  static int constexpr kDof = LieGroupF64::kDof;
22  static int constexpr kNumParams = LieGroupF64::kNumParams;
23 
24  using Tangent = Eigen::Vector<double, kDof>;
25  using Params = Eigen::Vector<double, kNumParams>;
26 
27  /// LieGroup plus operation for Ceres
28  ///
29  /// T * exp(x)
30  ///
31  bool Plus(
32  double const* t_raw,
33  double const* delta_raw,
34  double* t_plus_delta_raw) const override {
35  LieGroupF64 t = LieGroupF64::fromParams(Eigen::Map<Params const>(t_raw));
36  Eigen::Map<Tangent const> delta(delta_raw);
37 
38  Eigen::Map<Params> out_params(t_plus_delta_raw);
39  LieGroupF64 t_plus_delta = t * LieGroupF64::exp(delta);
40  out_params = t_plus_delta.params();
41  return true;
42  }
43 
44  /// Jacobian of LieGroup plus operation for Ceres
45  ///
46  /// Dx T * exp(x) with x=0
47  ///
48  bool PlusJacobian(double const* t_raw, double* jacobian_raw) const override {
49  LieGroupF64 t = LieGroupF64::fromParams(Eigen::Map<Params const>(t_raw));
50  Eigen::Map<Eigen::Matrix<
51  double,
52  kNumParams,
53  kDof,
54  kDof == 1 ? Eigen::ColMajor : Eigen::RowMajor>>
55  jacobian(jacobian_raw);
56  jacobian = t.dxThisMulExpXAt0();
57  return true;
58  }
59 
60  bool Minus(double const* y_raw, double const* x_raw, double* y_minus_x_raw)
61  const override {
62  LieGroupF64 y = LieGroupF64::fromParams(Eigen::Map<Params const>(y_raw));
63  LieGroupF64 x = LieGroupF64::fromParams(Eigen::Map<Params const>(x_raw));
64  Eigen::Map<Tangent> out_params(y_minus_x_raw);
65  out_params = (x.inverse() * y).log();
66  return true;
67  }
68 
69  bool MinusJacobian(double const* x_raw, double* jacobian_raw) const override {
70  LieGroupF64 x = LieGroupF64::fromParams(Eigen::Map<Params const>(x_raw));
71  Eigen::Map<Eigen::Matrix<double, kDof, kNumParams, Eigen::RowMajor>>
72  jacobian(jacobian_raw);
73  jacobian = x.dxLogThisInvTimesXAtThis();
74  return true;
75  }
76 
77  [[nodiscard]] int AmbientSize() const override {
78  return LieGroupF64::kNumParams;
79  }
80 
81  [[nodiscard]] int TangentSize() const override { return LieGroupF64::kDof; }
82 };
83 
84 } // namespace sophus::ceres
sophus::ceres::Manifold::Minus
bool Minus(double const *y_raw, double const *x_raw, double *y_minus_x_raw) const override
Definition: manifold.h:60
sophus::ceres::Manifold::AmbientSize
int AmbientSize() const override
Definition: manifold.h:77
typetraits.h
sophus::ceres::Manifold::PlusJacobian
bool PlusJacobian(double const *t_raw, double *jacobian_raw) const override
Jacobian of LieGroup plus operation for Ceres.
Definition: manifold.h:48
sophus::ceres::Manifold::Tangent
Eigen::Vector< double, kDof > Tangent
Definition: manifold.h:24
sophus::ceres::Manifold::LieGroupF64
TLieGroup< double > LieGroupF64
Definition: manifold.h:20
sophus::ceres::Manifold::kDof
static constexpr int kDof
Definition: manifold.h:21
sophus::ceres
Definition: manifold.h:13
sophus::ceres::Manifold::Params
Eigen::Vector< double, kNumParams > Params
Definition: manifold.h:25
sophus::ceres::Manifold::kNumParams
static constexpr int kNumParams
Definition: manifold.h:22
sophus::ceres::Manifold
Templated local parameterization for LieGroup [with implemented LieGroup::Dx_this_mul_exp_x_at_0() ].
Definition: manifold.h:18
sophus::ceres::Manifold::MinusJacobian
bool MinusJacobian(double const *x_raw, double *jacobian_raw) const override
Definition: manifold.h:69
sophus::ceres::Manifold::Plus
bool Plus(double const *t_raw, double const *delta_raw, double *t_plus_delta_raw) const override
LieGroup plus operation for Ceres.
Definition: manifold.h:31
sophus::ceres::Manifold::TangentSize
int TangentSize() const override
Definition: manifold.h:81