gtsam
Loading...
Searching...
No Matches
ExtendedPose3.h
Go to the documentation of this file.
1/* ----------------------------------------------------------------------------
2
3 * GTSAM Copyright 2010, 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
17
18#pragma once
19
23#include <gtsam/geometry/Rot3.h>
24
25#include <cassert>
26#include <iostream>
27#include <string>
28#include <type_traits>
29
30#if GTSAM_ENABLE_BOOST_SERIALIZATION
31#include <boost/serialization/nvp.hpp>
32#endif
33
34namespace gtsam {
35
36template <int K, class Derived = void>
37class ExtendedPose3;
38
47template <int K_, class Derived>
49 std::conditional_t<std::is_void_v<Derived>,
50 ExtendedPose3<K_, void>, Derived>,
51 (K_ == Eigen::Dynamic) ? Eigen::Dynamic : 3 + 3 * K_,
52 (K_ == Eigen::Dynamic) ? Eigen::Dynamic : 3 + K_> {
53 public:
54 static constexpr int K = K_;
55 using This = std::conditional_t<std::is_void_v<Derived>,
56 ExtendedPose3<K, void>, Derived>;
57 inline constexpr static int dimension =
58 (K == Eigen::Dynamic) ? Eigen::Dynamic : 3 + 3 * K;
59 inline constexpr static int matrixDim =
60 (K == Eigen::Dynamic) ? Eigen::Dynamic : 3 + K;
61
63 using TangentVector = typename Base::TangentVector;
64 using Jacobian = typename Base::Jacobian;
65 using ChartJacobian = typename Base::ChartJacobian;
66 using ComponentJacobian =
67 std::conditional_t<dimension == Eigen::Dynamic,
71 using MatrixRep = Eigen::Matrix<double, matrixDim, matrixDim>;
73 using LieAlgebra = Eigen::Matrix<double, matrixDim, matrixDim>;
74 using Matrix3K = Eigen::Matrix<double, 3, K>;
75
76 static_assert(K == Eigen::Dynamic || K >= 1,
77 "ExtendedPose3<K>: K should be >= 1 or Eigen::Dynamic.");
78
79 protected:
81 Matrix3K t_;
82
83 template <int K__>
84 using IsDynamic = typename std::enable_if<K__ == Eigen::Dynamic, void>::type;
85 template <int K__>
86 using IsFixed = typename std::enable_if<K__ >= 1, void>::type;
87
88 public:
91
98 template <int K__ = K_, typename = IsFixed<K__>>
99 ExtendedPose3() : R_(Rot3::Identity()), t_(Matrix3K::Zero()) {}
100
108 template <int K__ = K_, typename = IsDynamic<K__>>
109 explicit ExtendedPose3(size_t k = 0)
110 : R_(Rot3::Identity()), t_(3, static_cast<Eigen::Index>(k)) {
111 t_.setZero();
112 }
113
115 ExtendedPose3(const ExtendedPose3&) = default;
116
119
126 ExtendedPose3(const Rot3& R, const Matrix3K& x);
127
136 template <int FixedK = K, typename = IsFixed<FixedK>, typename... Vecs,
137 typename = std::enable_if_t<
138 sizeof...(Vecs) == FixedK &&
139 (std::is_constructible_v<Point3, Vecs> && ...)>>
140 ExtendedPose3(const Rot3& R, const Vecs&... xs);
141
148 explicit ExtendedPose3(const MatrixRep& T);
149
153
160 static size_t Dimension(size_t k) { return 3 + 3 * k; }
161
163 size_t k() const { return static_cast<size_t>(t_.cols()); }
164
166 size_t dim() const { return Dimension(k()); }
167
174 const Rot3& rotation(ComponentJacobian H = {}) const;
175
183 Point3 x(size_t i, ComponentJacobian H = {}) const;
184
190 const Matrix3K& xMatrix() const;
191
197 Matrix3K& xMatrix();
198
202
208 void print(const std::string& s = "") const;
209
217 bool equals(const ExtendedPose3& other, double tol = 1e-9) const;
218
222
228 template <int K__ = K_, typename = IsFixed<K__>>
229 static This Identity() {
230 return MakeReturn(ExtendedPose3());
231 }
232
239 template <int K__ = K_, typename = IsDynamic<K__>>
240 static This Identity(size_t k = 0) {
241 return MakeReturn(ExtendedPose3(k));
242 }
243
249 This inverse() const;
250
257 This operator*(const This& other) const;
258
262
270 static This Expmap(const TangentVector& xi, ChartJacobian Hxi = {});
271
279 static TangentVector Logmap(const This& pose, ChartJacobian Hpose = {});
280
286 Jacobian AdjointMap() const;
287
294 static Jacobian adjointMap(const TangentVector& xi);
295
302 static Jacobian ExpmapDerivative(const TangentVector& xi);
303
310 static Jacobian LogmapDerivative(const TangentVector& xi);
311
318 static Jacobian LogmapDerivative(const This& pose);
319
329 static This Retract(const TangentVector& xi, ChartJacobian Hxi = {});
330
338 static TangentVector Local(const This& pose, ChartJacobian Hpose = {});
339 };
340
341 using LieGroup<This, dimension>::inverse;
342
346
353
360 static LieAlgebra Hat(const TangentVector& xi);
361
368 static TangentVector Vee(const LieAlgebra& X);
369
371
372 friend std::ostream& operator<<(std::ostream& os, const ExtendedPose3& p) {
373 os << "R: " << p.R_ << "\n";
374 os << "x: " << p.t_;
375 return os;
376 }
377
378 protected:
379 static This MakeReturn(const ExtendedPose3& value) {
380 if constexpr (std::is_void_v<Derived>) {
381 return value;
382 } else {
383 return This(value);
384 }
385 }
386
387 static const ExtendedPose3& AsBase(const This& value) {
388 if constexpr (std::is_void_v<Derived>) {
389 return value;
390 } else {
391 return static_cast<const ExtendedPose3&>(value);
392 }
393 }
394
395 static size_t RuntimeK(const TangentVector& xi);
396 static void ZeroJacobian(ChartJacobian H, Eigen::Index d);
397
398 private:
399#if GTSAM_ENABLE_BOOST_SERIALIZATION
400 friend class boost::serialization::access;
401 template <class Archive>
402 void serialize(Archive& ar, const unsigned int /*version*/) {
403 ar& BOOST_SERIALIZATION_NVP(R_);
404 ar& BOOST_SERIALIZATION_NVP(t_);
405 }
406#endif
407};
408
411using ExtendedPose3d = ExtendedPose3<Eigen::Dynamic>;
412
413template <int K, class Derived>
414struct traits<ExtendedPose3<K, Derived>>
415 : public internal::MatrixLieGroup<ExtendedPose3<K, Derived>,
416 ExtendedPose3<K, Derived>::matrixDim> {};
417
418template <int K, class Derived>
419struct traits<const ExtendedPose3<K, Derived>>
420 : public internal::MatrixLieGroup<ExtendedPose3<K, Derived>,
421 ExtendedPose3<K, Derived>::matrixDim> {};
422
423} // namespace gtsam
424
425#include "ExtendedPose3-inl.h"
Base class and basic functions for Matrix Lie groups.
Macros for Matrix constants to avoid excessive template instantiation.
Template implementations for ExtendedPose3<K, Derived>.
3D Point
3D rotation represented as a rotation matrix or quaternion
Global functions in a separate testing namespace.
Definition chartTesting.h:28
Vector3 Point3
As of GTSAM 4, in order to make GTSAM more lean, it is now possible to just typedef Point3 to Vector3...
Definition Point3.h:38
ExtendedPose3< 2 > Se23
Convenience typedef for dynamic-k ExtendedPose3.
Definition ExtendedPose3.h:410
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
A CRTP helper class that implements Lie group methods Prerequisites: methods operator*,...
Definition Lie.h:114
A CRTP helper class that implements matrix Lie group methods.
Definition MatrixLieGroup.h:51
Both LieGroupTraits and Testable.
Definition MatrixLieGroup.h:350
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition OptionalJacobian.h:40
Lie group SE_k(3): semidirect product of SO(3) with k copies of R^3.
Definition ExtendedPose3.h:52
MatrixRep matrix() const
Homogeneous matrix representation.
Definition ExtendedPose3-inl.h:340
static Jacobian adjointMap(const TangentVector &xi)
Lie algebra adjoint map.
Definition ExtendedPose3-inl.h:256
size_t dim() const
Definition ExtendedPose3.h:166
ExtendedPose3 & operator=(const ExtendedPose3 &)=default
Copy assignment.
static LieAlgebra Hat(const TangentVector &xi)
Hat operator from tangent to Lie algebra.
Definition ExtendedPose3-inl.h:355
ExtendedPose3(const Rot3 &R, const Vecs &... xs)
Construct a fixed-size state from rotation and K 3-vectors.
Definition ExtendedPose3-inl.h:49
static This Expmap(const TangentVector &xi, ChartJacobian Hxi={})
Exponential map from tangent to group.
Definition ExtendedPose3-inl.h:152
ExtendedPose3(const Rot3 &R, const Matrix3K &x)
Construct from rotation and 3xk block.
Definition ExtendedPose3-inl.h:44
static This Identity()
Definition ExtendedPose3.h:229
Point3 x(size_t i, ComponentJacobian H={}) const
void print(const std::string &s="") const
Print this state.
Definition ExtendedPose3-inl.h:116
static TangentVector Logmap(const This &pose, ChartJacobian Hpose={})
Logarithm map from group to tangent.
Definition ExtendedPose3-inl.h:210
static Jacobian ExpmapDerivative(const TangentVector &xi)
Jacobian of Expmap.
Definition ExtendedPose3-inl.h:280
static This Identity(size_t k=0)
Identity element for dynamic-size K.
Definition ExtendedPose3.h:240
This operator*(const This &other) const
Group composition.
Definition ExtendedPose3-inl.h:135
ExtendedPose3(size_t k=0)
Construct a dynamic-size identity element.
Definition ExtendedPose3.h:109
Eigen::Matrix< double, matrixDim, matrixDim > MatrixRep
Homogeneous matrix representation in the group.
Definition ExtendedPose3.h:71
Rot3 R_
Definition ExtendedPose3.h:80
size_t k() const
Definition ExtendedPose3.h:163
static TangentVector Vee(const LieAlgebra &X)
Vee operator from Lie algebra to tangent.
Definition ExtendedPose3-inl.h:375
This inverse() const
Group inverse.
Definition ExtendedPose3-inl.h:127
bool equals(const ExtendedPose3 &other, double tol=1e-9) const
Equality check with tolerance.
Definition ExtendedPose3-inl.h:121
Matrix3K t_
Definition ExtendedPose3.h:81
ExtendedPose3()
Construct a fixed-size identity element.
Definition ExtendedPose3.h:99
Eigen::Matrix< double, matrixDim, matrixDim > LieAlgebra
Lie algebra matrix type used by Hat/Vee.
Definition ExtendedPose3.h:73
static Jacobian LogmapDerivative(const TangentVector &xi)
Jacobian of Logmap evaluated from tangent coordinates.
Definition ExtendedPose3-inl.h:288
const Rot3 & rotation(ComponentJacobian H={}) const
Rotation component.
Definition ExtendedPose3-inl.h:76
ExtendedPose3(const ExtendedPose3 &)=default
Copy constructor.
const Matrix3K & xMatrix() const
Access all x_i blocks.
Definition ExtendedPose3-inl.h:105
Matrix3K & xMatrix()
Mutable access to all x_i blocks.
Definition ExtendedPose3-inl.h:111
static size_t Dimension(size_t k)
Runtime manifold dimension helper.
Definition ExtendedPose3.h:160
static Jacobian LogmapDerivative(const This &pose)
Jacobian of Logmap evaluated at a group element.
Definition ExtendedPose3-inl.h:320
ExtendedPose3(const MatrixRep &T)
Construct from homogeneous matrix representation.
Definition ExtendedPose3-inl.h:58
Jacobian AdjointMap() const
Adjoint map.
Definition ExtendedPose3-inl.h:234
Chart operations at identity for LieGroup/Manifold compatibility.
Definition ExtendedPose3.h:321
static This Retract(const TangentVector &xi, ChartJacobian Hxi={})
Retract at identity.
Definition ExtendedPose3-inl.h:326
static TangentVector Local(const This &pose, ChartJacobian Hpose={})
Local coordinates at identity.
Definition ExtendedPose3-inl.h:333
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
Definition Rot3.h:65