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>
30  return SOn::Hat(xi);
31 }
32 
33 // Implementation for N>=5 just uses dynamic version
34 template <int N>
36  return SOn::Vee(X);
37 }
38 
39 template <int N>
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>
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>
68  throw std::runtime_error("SO<N>::Expmap only implemented for SO3 and SO4.");
69 }
70 
71 template <int N>
73  throw std::runtime_error("SO<N>::ExpmapDerivative only implemented for SO3.");
74 }
75 
76 template <int N>
78  throw std::runtime_error("SO<N>::Logmap only implemented for SO3.");
79 }
80 
81 template <int N>
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>
90  // Vectorize
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?
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
#define I
Definition: main.h:112
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
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar * data() const
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:94
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
int n
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
Rot2 R(Rot2::fromAngle(0.1))
static Matrix VectorizedGenerators()
Calculate N^2 x dim matrix of vectorized Lie algebra generators for SO(N)
Definition: SOn.h:302
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate set rrange [*:*] noreverse nowriteback set trange [*:*] noreverse nowriteback set urange [*:*] noreverse nowriteback set vrange [*:*] noreverse nowriteback set xlabel matrix size set x2label set timefmt d m y n H
#define N
Definition: gksort.c:12
Definition: SOn.h:54
constexpr int NSquaredSO(int N)
Definition: SOn.h:46
MatrixNN matrix_
Rotation matrix.
Definition: SOn.h:64
static size_t AmbientDim(size_t d)
Definition: SOn.h:212
Vector::Scalar omega(const Vector &t, const Vector &s, RealScalar angle)
Definition: IDRS.h:36
RealScalar s
SO()
Construct SO<N> identity for N >= 2.
Definition: SOn.h:81
Vector xi
Definition: testPose2.cpp:148
traits
Definition: chartTesting.h:28
static TangentVector Logmap(const SO &R, ChartJacobian H={})
Definition: SOn-inl.h:77
MatrixDD AdjointMap() const
Adjoint map.
Definition: SO4.cpp:159
static TangentVector Local(const SO &R, ChartJacobian H={})
Definition: SOn-inl.h:50
void print(const std::string &s=std::string()) const
Definition: SOn-inl.h:108
size_t rows() const
Definition: SOn.h:159
#define X
Definition: icosphere.cpp:20
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


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:35:53