gtsam
Loading...
Searching...
No Matches
Pose3.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
16
17// \callgraph
18#pragma once
19
20#include <gtsam/config.h>
21
25#include <gtsam/geometry/Rot3.h>
26#include <gtsam/base/Lie.h>
27
28#if GTSAM_ENABLE_BOOST_SERIALIZATION
29#include <boost/serialization/base_object.hpp>
30#endif
31
32namespace gtsam {
33
34class Pose2;
35// forward declare
36
42class GTSAM_EXPORT Pose3: public ExtendedPose3<1, Pose3> {
43public:
44 using Base = ExtendedPose3<1, Pose3>;
45
47 typedef Rot3 Rotation;
48 typedef Point3 Translation;
49 inline constexpr static auto dimension = 6;
50
51public:
52 using Vector16 = Eigen::Matrix<double, 16, 1>;
53 using Base::operator*;
54
57
59 Pose3() : Base() {}
60
62 Pose3(const Pose3& pose) = default;
63
64 Pose3& operator=(const Pose3& other) = default;
65
66 Pose3(const Base& other) : Base(other) {}
67
69 Pose3(const Rot3& R, const Point3& t)
70 : Base(R, Vector3(t.x(), t.y(), t.z())) {}
71
73 explicit Pose3(const Pose2& pose2);
74
76 Pose3(const Matrix &T) : Base(Matrix4(T)) {}
77
79 static Pose3 Create(const Rot3& R, const Point3& t,
81 OptionalJacobian<6, 3> Ht = {});
82
84 static Pose3 FromPose2(const Pose2& p, OptionalJacobian<6,3> H = {});
85
91 static std::optional<Pose3> Align(const Point3Pairs& abPointPairs);
92
93 // Version of Pose3::Align that takes 2 matrices.
94 static std::optional<Pose3> Align(ConstMatrixView a, ConstMatrixView b);
95
99
101 void print(const std::string& s = "") const;
102
104 bool equals(const Pose3& pose, double tol = 1e-9) const;
105
109
124 Pose3 interpolateRt(const Pose3& T, double t,
125 OptionalJacobian<6, 6> Hself = {},
126 OptionalJacobian<6, 6> Harg = {},
127 OptionalJacobian<6, 1> Ht = {}) const;
128
130 Pose3 operator*(const Pose3& T) const {
131 return Pose3(R_ * T.R_, t_ + R_ * T.t_);
132 }
133
137
138 using LieAlgebra = Matrix4;
139
141 static Pose3 Expmap(const Vector6& xi, OptionalJacobian<6, 6> Hxi = {});
142
143 // temporary fix for wrappers until case issue is resolved
144 static Matrix6 adjointMap_(const Vector6 &xi) { return adjointMap(xi);}
145 static Vector6 adjoint_(const Vector6 &xi, const Vector6 &y) { return adjoint(xi, y);}
146
147 // Chart at origin, depends on compile-time flag GTSAM_POSE3_EXPMAP
148 struct GTSAM_EXPORT ChartAtOrigin {
149 static Pose3 Retract(const Vector6& xi, ChartJacobian Hxi = {});
150 static Vector6 Local(const Pose3& pose, ChartJacobian Hpose = {});
151 };
152
156
165 {}, OptionalJacobian<3, 3> Hpoint = {}) const;
166
172 Matrix transformFrom(ConstMatrixView points) const;
173
175 inline Point3 operator*(const Point3& point) const {
176 return transformFrom(point);
177 }
178
186 Point3 transformTo(const Point3& point, OptionalJacobian<3, 6> Hself =
187 {}, OptionalJacobian<3, 3> Hpoint = {}) const;
188
194 Matrix transformTo(ConstMatrixView points) const;
195
199
201 const Point3& translation(OptionalJacobian<3, 6> Hself = {}) const;
202
204 double x() const {
205 return translation().x();
206 }
207
209 double y() const {
210 return translation().y();
211 }
212
214 double z() const {
215 return translation().z();
216 }
217
223 Pose3 transformPoseFrom(const Pose3& aTb, OptionalJacobian<6, 6> Hself = {},
224 OptionalJacobian<6, 6> HaTb = {}) const;
225
230 Pose3 transformPoseTo(const Pose3& wTb, OptionalJacobian<6, 6> Hself = {},
231 OptionalJacobian<6, 6> HwTb = {}) const;
232
238 double range(const Point3& point, OptionalJacobian<1, 6> Hself = {},
239 OptionalJacobian<1, 3> Hpoint = {}) const;
240
246 double range(const Pose3& pose, OptionalJacobian<1, 6> Hself = {},
247 OptionalJacobian<1, 6> Hpose = {}) const;
248
254 Unit3 bearing(const Point3& point, OptionalJacobian<2, 6> Hself = {},
255 OptionalJacobian<2, 3> Hpoint = {}) const;
256
263 Unit3 bearing(const Pose3& pose, OptionalJacobian<2, 6> Hself = {},
264 OptionalJacobian<2, 6> Hpose = {}) const;
265
269
275 inline static std::pair<size_t, size_t> translationInterval() {
276 return {3, 5};
277 }
278
284 static std::pair<size_t, size_t> rotationInterval() {
285 return {0, 2};
286 }
287
293 Pose3 slerp(double t, const Pose3& other, OptionalJacobian<6, 6> Hx = {},
294 OptionalJacobian<6, 6> Hy = {}) const;
295
297 GTSAM_EXPORT
298 friend std::ostream &operator<<(std::ostream &os, const Pose3& p);
299
303
304#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
306 static inline LieAlgebra wedge(double wx, double wy, double wz, double vx,
307 double vy, double vz) {
308 return Hat((TangentVector() << wx, wy, wz, vx, vy, vz).finished());
309 }
310#endif
312
313 private:
314#if GTSAM_ENABLE_BOOST_SERIALIZATION
316 friend class boost::serialization::access;
317 template<class Archive>
318 void serialize(Archive & ar, const unsigned int /*version*/) {
319 ar & BOOST_SERIALIZATION_NVP(R_);
320 ar & BOOST_SERIALIZATION_NVP(t_);
321 }
322#endif
324};
325// Pose3 class
326
327#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
329template<>
330inline Matrix wedge<Pose3>(const Vector& xi) {
331 // NOTE(chris): Need eval() as workaround for Apple clang + avx2.
332 return Matrix(Pose3::Hat(xi)).eval();
333}
334#endif
335
336// Convenience typedef
337using Pose3Pair = std::pair<Pose3, Pose3>;
338using Pose3Pairs = std::vector<std::pair<Pose3, Pose3> >;
339
340// For MATLAB wrapper
341typedef std::vector<Pose3> Pose3Vector;
342
364template <>
365struct traits<Pose3> : public internal::MatrixLieGroup<Pose3, 4> {
367 inline constexpr static int QcqpVectorDim = 13;
368
373 template <int D = 1>
374 static Matrix QcqpValue(const Pose3& value) {
375 if constexpr (D == 1) {
376 const Matrix4 T = value.matrix();
377 Eigen::Matrix<double, 13, 1> X;
378 X(0, 0) = 1.0;
379 X.segment<3>(1) = T.col(0).head<3>();
380 X.segment<3>(4) = T.col(1).head<3>();
381 X.segment<3>(7) = T.col(2).head<3>();
382 X.segment<3>(10) = T.col(3).head<3>();
383 return X;
384 } else {
385 throw std::invalid_argument(
386 "traits<Pose3>::QcqpValue only supports D=1.");
387 }
388 }
389
394 template <int D = 1>
395 static std::vector<std::pair<Matrix, double>> QcqpConstraints() {
396 if constexpr (D == 1) {
397 std::vector<std::pair<Matrix, double>> constraints;
398 constraints.reserve(10);
399
400 Matrix A = Matrix::Zero(13, 13);
401
402 // Homogenization.
403 A(0, 0) = 1.0;
404 constraints.emplace_back(A, 1.0);
405
406 // cross(R.col(1), R.col(2)) = x(0) * R.col(0).
407 A.setZero();
408 A(5, 9) = 0.5;
409 A(9, 5) = 0.5;
410 A(6, 8) = -0.5;
411 A(8, 6) = -0.5;
412 A(0, 1) = -0.5;
413 A(1, 0) = -0.5;
414 constraints.emplace_back(A, 0.0);
415
416 A.setZero();
417 A(6, 7) = 0.5;
418 A(7, 6) = 0.5;
419 A(4, 9) = -0.5;
420 A(9, 4) = -0.5;
421 A(0, 2) = -0.5;
422 A(2, 0) = -0.5;
423 constraints.emplace_back(A, 0.0);
424
425 A.setZero();
426 A(4, 8) = 0.5;
427 A(8, 4) = 0.5;
428 A(5, 7) = -0.5;
429 A(7, 5) = -0.5;
430 A(0, 3) = -0.5;
431 A(3, 0) = -0.5;
432 constraints.emplace_back(A, 0.0);
433
434 // RR^T = I.
435 A.setZero();
436 A(1, 1) = 1.0;
437 A(4, 4) = 1.0;
438 A(7, 7) = 1.0;
439 constraints.emplace_back(A, 1.0);
440
441 A.setZero();
442 A(1, 2) = 0.5;
443 A(2, 1) = 0.5;
444 A(4, 5) = 0.5;
445 A(5, 4) = 0.5;
446 A(7, 8) = 0.5;
447 A(8, 7) = 0.5;
448 constraints.emplace_back(A, 0.0);
449
450 A.setZero();
451 A(1, 3) = 0.5;
452 A(3, 1) = 0.5;
453 A(4, 6) = 0.5;
454 A(6, 4) = 0.5;
455 A(7, 9) = 0.5;
456 A(9, 7) = 0.5;
457 constraints.emplace_back(A, 0.0);
458
459 A.setZero();
460 A(2, 2) = 1.0;
461 A(5, 5) = 1.0;
462 A(8, 8) = 1.0;
463 constraints.emplace_back(A, 1.0);
464
465 A.setZero();
466 A(2, 3) = 0.5;
467 A(3, 2) = 0.5;
468 A(5, 6) = 0.5;
469 A(6, 5) = 0.5;
470 A(8, 9) = 0.5;
471 A(9, 8) = 0.5;
472 constraints.emplace_back(A, 0.0);
473
474 A.setZero();
475 A(3, 3) = 1.0;
476 A(6, 6) = 1.0;
477 A(9, 9) = 1.0;
478 constraints.emplace_back(A, 1.0);
479
480 return constraints;
481 } else {
482 throw std::invalid_argument(
483 "traits<Pose3>::QcqpConstraints only supports D=1.");
484 }
485 }
486
488 template <int D>
489 static Pose3 FromQcqpValue(const Matrix& X) {
490 if constexpr (D == 1) {
491 if (X.rows() != QcqpVectorDim || X.cols() != 1 ||
492 std::abs(X(0, 0)) < 1e-9) {
493 throw std::invalid_argument(
494 "traits<Pose3>::FromQcqpValue requires a 13-by-1 vector with a "
495 "nonzero homogenization entry.");
496 }
497 const Vector x = X.col(0) / X(0, 0);
498 Matrix3 R;
499 R.col(0) = x.segment<3>(1);
500 R.col(1) = x.segment<3>(4);
501 R.col(2) = x.segment<3>(7);
502 return Pose3(Rot3::ClosestTo(R), x.segment<3>(10));
503 } else {
504 throw std::invalid_argument(
505 "traits<Pose3>::FromQcqpValue only supports D=1.");
506 }
507 }
508};
509
510template <>
511struct traits<const Pose3> : public traits<Pose3> {};
512
513// bearing and range traits, used in RangeFactor
514template <>
515struct Bearing<Pose3, Point3> : HasBearing<Pose3, Point3, Unit3> {};
516
517template<>
518struct Bearing<Pose3, Pose3> : HasBearing<Pose3, Pose3, Unit3> {};
519
520template <typename T>
521struct Range<Pose3, T> : HasRange<Pose3, T, double> {};
522
523} // namespace gtsam
Base class and basic functions for Lie types.
Extended pose Lie group SE_k(3), with static or dynamic k.
3D Point
Bearing-Range product.
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
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:143
Line3 transformTo(const Pose3 &wTc, const Line3 &wL, OptionalJacobian< 4, 6 > Dpose, OptionalJacobian< 4, 4 > Dline)
Transform a line from world to camera frame.
Definition Line3.cpp:91
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
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
Definition BearingRange.h:36
Definition BearingRange.h:42
Definition BearingRange.h:182
Definition BearingRange.h:196
MatrixRep matrix() const
Homogeneous matrix representation.
Definition ExtendedPose3-inl.h:340
static LieAlgebra Hat(const TangentVector &xi)
Rot3 R_
Definition ExtendedPose3.h:80
Matrix3K t_
Definition ExtendedPose3.h:81
ExtendedPose3()
Definition ExtendedPose3.h:99
A 2D pose (Point2,Rot2).
Definition Pose2.h:39
A 3D pose (R,t) : (Rot3,Point3).
Definition Pose3.h:42
Pose3()
Default constructor is origin.
Definition Pose3.h:59
Pose3(const Rot3 &R, const Point3 &t)
Construct from R,t.
Definition Pose3.h:69
Pose3(const Matrix &T)
Constructor from 4*4 matrix.
Definition Pose3.h:76
double z() const
get z
Definition Pose3.h:214
static std::pair< size_t, size_t > rotationInterval()
Return the start and end indices (inclusive) of the rotation component of the exponential map paramet...
Definition Pose3.h:284
Pose3 operator*(const Pose3 &T) const
Compose syntactic sugar.
Definition Pose3.h:130
Rot3 Rotation
Pose Concept requirements.
Definition Pose3.h:47
Point3 transformFrom(const Point3 &point, OptionalJacobian< 3, 6 > Hself={}, OptionalJacobian< 3, 3 > Hpoint={}) const
takes point in Pose coordinates and transforms it to world coordinates
Definition Pose3.cpp:180
double y() const
get y
Definition Pose3.h:209
const Point3 & translation(OptionalJacobian< 3, 6 > Hself={}) const
get translation
Definition Pose3.cpp:158
static std::pair< size_t, size_t > translationInterval()
Return the start and end indices (inclusive) of the translation component of the exponential map para...
Definition Pose3.h:275
Point3 operator*(const Point3 &point) const
syntactic sugar for transformFrom
Definition Pose3.h:175
double x() const
get x
Definition Pose3.h:204
Pose3(const Pose3 &pose)=default
Copy constructor.
Definition Pose3.h:148
static Matrix QcqpValue(const Pose3 &value)
Return the D=1 homogenized QCQP variable x = [1, vec(R), tx, ty, tz] in column-major order.
Definition Pose3.h:374
static constexpr int QcqpVectorDim
Dimension of the D=1 homogenized QCQP vector.
Definition Pose3.h:367
static std::vector< std::pair< Matrix, double > > QcqpConstraints()
Return the ten D=1 lifted SE(3) manifold constraints A, b such that trace(x' A x) = b.
Definition Pose3.h:395
static Pose3 FromQcqpValue(const Matrix &X)
Project a D=1 homogenized QCQP vector back to Pose3.
Definition Pose3.h:489
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
Definition Rot3.h:65
static Rot3 ClosestTo(const Matrix3 &M)
Static, named constructor that finds Rot3 element closest to M in Frobenius norm.
Definition Rot3.h:287