GTSAM  4.0.2
C++ library for smoothing and mapping (SAM)
SOn-inl.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010-2019, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
12 #pragma once
13 
21 #include <gtsam/base/Matrix.h>
22 
23 #include <iostream>
24 
25 namespace gtsam {
26 
27 // Implementation for N>=5 just uses dynamic version
28 template <int N>
29 typename SO<N>::MatrixNN SO<N>::Hat(const TangentVector& xi) {
30  return SOn::Hat(xi);
31 }
32 
33 // Implementation for N>=5 just uses dynamic version
34 template <int N>
35 typename SO<N>::TangentVector SO<N>::Vee(const MatrixNN& X) {
36  return SOn::Vee(X);
37 }
38 
39 template <int N>
40 SO<N> SO<N>::ChartAtOrigin::Retract(const TangentVector& xi, ChartJacobian H) {
41  if (H) throw std::runtime_error("SO<N>::Retract jacobian not implemented.");
42  const Matrix X = Hat(xi / 2.0);
43  size_t n = AmbientDim(xi.size());
44  const auto I = Eigen::MatrixXd::Identity(n, n);
45  // https://pdfs.semanticscholar.org/6165/0347b2ccac34b5f423081d1ce4dbc4d09475.pdf
46  return SO((I + X) * (I - X).inverse());
47 }
48 
49 template <int N>
50 typename SO<N>::TangentVector SO<N>::ChartAtOrigin::Local(const SO& R,
51  ChartJacobian H) {
52  if (H) throw std::runtime_error("SO<N>::Local jacobian not implemented.");
53  const size_t n = R.rows();
54  const auto I = Eigen::MatrixXd::Identity(n, n);
55  const Matrix X = (I - R.matrix_) * (I + R.matrix_).inverse();
56  return -2 * Vee(X);
57 }
58 
59 template <int N>
60 typename SO<N>::MatrixDD SO<N>::AdjointMap() const {
61  if (N==2) return I_1x1; // SO(2) case
62  throw std::runtime_error(
63  "SO<N>::AdjointMap only implemented for SO2, SO3 and SO4.");
64 }
65 
66 template <int N>
67 SO<N> SO<N>::Expmap(const TangentVector& omega, ChartJacobian H) {
68  throw std::runtime_error("SO<N>::Expmap only implemented for SO3 and SO4.");
69 }
70 
71 template <int N>
72 typename SO<N>::MatrixDD SO<N>::ExpmapDerivative(const TangentVector& omega) {
73  throw std::runtime_error("SO<N>::ExpmapDerivative only implemented for SO3.");
74 }
75 
76 template <int N>
77 typename SO<N>::TangentVector SO<N>::Logmap(const SO& R, ChartJacobian H) {
78  throw std::runtime_error("SO<N>::Logmap only implemented for SO3.");
79 }
80 
81 template <int N>
82 typename SO<N>::MatrixDD SO<N>::LogmapDerivative(const TangentVector& omega) {
83  throw std::runtime_error("O<N>::LogmapDerivative only implemented for SO3.");
84 }
85 
86 // Default fixed size version (but specialized elsewehere for N=2,3,4)
87 template <int N>
88 typename SO<N>::VectorN2 SO<N>::vec(
89  OptionalJacobian<internal::NSquaredSO(N), dimension> H) const {
90  // Vectorize
91  VectorN2 X = Eigen::Map<const VectorN2>(matrix_.data());
92 
93  // If requested, calculate H as (I \oplus Q) * P,
94  // where Q is the N*N rotation matrix, and P is calculated below.
95  if (H) {
96  // Calculate P matrix of vectorized generators
97  // TODO(duy): Should we refactor this as the jacobian of Hat?
98  Matrix P = SO<N>::VectorizedGenerators();
99  for (size_t i = 0; i < N; i++) {
100  H->block(i * N, 0, N, dimension) =
101  matrix_ * P.block(i * N, 0, N, dimension);
102  }
103  }
104  return X;
105 }
106 
107 template <int N>
108 void SO<N>::print(const std::string& s) const {
109  std::cout << s << matrix_ << std::endl;
110 }
111 
112 } // namespace gtsam
static MatrixNN Hat(const TangentVector &xi)
Definition: SOn-inl.h:29
SO inverse() const
inverse of a rotation = transpose
Definition: SOn.h:195
static MatrixDD ExpmapDerivative(const TangentVector &omega)
Derivative of Expmap, currently only defined for SO3.
Definition: SOn-inl.h:72
static SO Expmap(const TangentVector &omega, ChartJacobian H={})
Definition: SOn-inl.h:67
static MatrixDD LogmapDerivative(const TangentVector &omega)
Derivative of Logmap, currently only defined for SO3.
Definition: SOn-inl.h:82
static Matrix VectorizedGenerators()
Calculate N^2 x dim matrix of vectorized Lie algebra generators for SO(N)
Definition: SOn.h:302
Definition: SOn.h:54
MatrixNN matrix_
Rotation matrix.
Definition: SOn.h:64
typedef and functions to augment Eigen&#39;s MatrixXd
SO()
Construct SO<N> identity for N >= 2.
Definition: SOn.h:81
Definition: chartTesting.h:28
Definition: OptionalJacobian.h:38
static TangentVector Logmap(const SO &R, ChartJacobian H={})
Definition: SOn-inl.h:77
MatrixDD AdjointMap() const
Adjoint map.
Definition: SOn-inl.h:60
static TangentVector Local(const SO &R, ChartJacobian H={})
Definition: SOn-inl.h:50
static TangentVector Vee(const MatrixNN &X)
Inverse of Hat. See note about xi element order in Hat.
Definition: SOn-inl.h:35
static SO Retract(const TangentVector &xi, ChartJacobian H={})
Definition: SOn-inl.h:40
VectorN2 vec(OptionalJacobian< internal::NSquaredSO(N), dimension > H={}) const
Definition: SOn-inl.h:88