gtsam  4.0.0
gtsam
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 
17 // \callgraph
18 #pragma once
19 
20 #include <gtsam/config.h>
21 
23 #include <gtsam/geometry/Point3.h>
24 #include <gtsam/geometry/Rot3.h>
25 #include <gtsam/base/Lie.h>
26 
27 namespace gtsam {
28 
29 class Pose2;
30 // forward declare
31 
37 class GTSAM_EXPORT Pose3: public LieGroup<Pose3, 6> {
38 public:
39 
41  typedef Rot3 Rotation;
42  typedef Point3 Translation;
43 
44 private:
45 
46  Rot3 R_;
47  Point3 t_;
48 
49 public:
50 
53 
55  Pose3() : R_(traits<Rot3>::Identity()), t_(traits<Point3>::Identity()) {}
56 
58  Pose3(const Pose3& pose) :
59  R_(pose.R_), t_(pose.t_) {
60  }
61 
63  Pose3(const Rot3& R, const Point3& t) :
64  R_(R), t_(t) {
65  }
66 
68  explicit Pose3(const Pose2& pose2);
69 
71  Pose3(const Matrix &T) :
72  R_(T(0, 0), T(0, 1), T(0, 2), T(1, 0), T(1, 1), T(1, 2), T(2, 0), T(2, 1),
73  T(2, 2)), t_(T(0, 3), T(1, 3), T(2, 3)) {
74  }
75 
77  static Pose3 Create(const Rot3& R, const Point3& t,
78  OptionalJacobian<6, 3> H1 = boost::none,
79  OptionalJacobian<6, 3> H2 = boost::none);
80 
87  static boost::optional<Pose3> Align(const std::vector<Point3Pair>& abPointPairs);
88 
92 
94  void print(const std::string& s = "") const;
95 
97  bool equals(const Pose3& pose, double tol = 1e-9) const;
98 
102 
104  static Pose3 identity() {
105  return Pose3();
106  }
107 
109  Pose3 inverse() const;
110 
112  Pose3 operator*(const Pose3& T) const {
113  return Pose3(R_ * T.R_, t_ + R_ * T.t_);
114  }
115 
119 
121  static Pose3 Expmap(const Vector6& xi, OptionalJacobian<6, 6> H = boost::none);
122 
124  static Vector6 Logmap(const Pose3& p, OptionalJacobian<6, 6> H = boost::none);
125 
130  Matrix6 AdjointMap() const;
131 
136  Vector6 Adjoint(const Vector6& xi_b) const {
137  return AdjointMap() * xi_b;
138  }
139 
155  static Matrix6 adjointMap(const Vector6 &xi);
156 
160  static Vector6 adjoint(const Vector6 &xi, const Vector6 &y,
161  OptionalJacobian<6, 6> = boost::none);
162 
166  static Vector6 adjointTranspose(const Vector6& xi, const Vector6& y,
167  OptionalJacobian<6, 6> H = boost::none);
168 
170  static Matrix6 ExpmapDerivative(const Vector6& xi);
171 
173  static Matrix6 LogmapDerivative(const Pose3& xi);
174 
175  // Chart at origin, depends on compile-time flag GTSAM_POSE3_EXPMAP
176  struct ChartAtOrigin {
177  static Pose3 Retract(const Vector6& v, ChartJacobian H = boost::none);
178  static Vector6 Local(const Pose3& r, ChartJacobian H = boost::none);
179  };
180 
181  using LieGroup<Pose3, 6>::inverse; // version with derivative
182 
190  static Matrix wedge(double wx, double wy, double wz, double vx, double vy,
191  double vz) {
192  return (Matrix(4, 4) << 0., -wz, wy, vx, wz, 0., -wx, vy, -wy, wx, 0., vz, 0., 0., 0., 0.).finished();
193  }
194 
198 
206  Point3 transform_from(const Point3& p, OptionalJacobian<3, 6> Dpose =
207  boost::none, OptionalJacobian<3, 3> Dpoint = boost::none) const;
208 
210  inline Point3 operator*(const Point3& p) const {
211  return transform_from(p);
212  }
213 
221  Point3 transform_to(const Point3& p, OptionalJacobian<3, 6> Dpose =
222  boost::none, OptionalJacobian<3, 3> Dpoint = boost::none) const;
223 
227 
229  const Rot3& rotation(OptionalJacobian<3, 6> H = boost::none) const;
230 
232  const Point3& translation(OptionalJacobian<3, 6> H = boost::none) const;
233 
235  double x() const {
236  return t_.x();
237  }
238 
240  double y() const {
241  return t_.y();
242  }
243 
245  double z() const {
246  return t_.z();
247  }
248 
250  Matrix4 matrix() const;
251 
255  Pose3 transform_to(const Pose3& pose) const;
256 
258  Pose3 transform_pose_to(const Pose3& pose, OptionalJacobian<6, 6> H1 = boost::none,
259  OptionalJacobian<6, 6> H2 = boost::none) const;
260 
266  double range(const Point3& point, OptionalJacobian<1, 6> H1 = boost::none,
267  OptionalJacobian<1, 3> H2 = boost::none) const;
268 
274  double range(const Pose3& pose, OptionalJacobian<1, 6> H1 = boost::none,
275  OptionalJacobian<1, 6> H2 = boost::none) const;
276 
282  Unit3 bearing(const Point3& point, OptionalJacobian<2, 6> H1 = boost::none,
283  OptionalJacobian<2, 3> H2 = boost::none) const;
284 
288 
294  inline static std::pair<size_t, size_t> translationInterval() {
295  return std::make_pair(3, 5);
296  }
297 
303  static std::pair<size_t, size_t> rotationInterval() {
304  return std::make_pair(0, 2);
305  }
306 
308  GTSAM_EXPORT
309  friend std::ostream &operator<<(std::ostream &os, const Pose3& p);
310 
311  private:
313  friend class boost::serialization::access;
314  template<class Archive>
315  void serialize(Archive & ar, const unsigned int /*version*/) {
316  ar & BOOST_SERIALIZATION_NVP(R_);
317  ar & BOOST_SERIALIZATION_NVP(t_);
318  }
320 
321 };
322 // Pose3 class
323 
331 template<>
332 inline Matrix wedge<Pose3>(const Vector& xi) {
333  return Pose3::wedge(xi(0), xi(1), xi(2), xi(3), xi(4), xi(5));
334 }
335 
341 GTSAM_EXPORT boost::optional<Pose3> align(const std::vector<Point3Pair>& baPointPairs);
342 
343 // For MATLAB wrapper
344 typedef std::vector<Pose3> Pose3Vector;
345 
346 template <>
347 struct traits<Pose3> : public internal::LieGroup<Pose3> {};
348 
349 template <>
350 struct traits<const Pose3> : public internal::LieGroup<Pose3> {};
351 
352 // bearing and range traits, used in RangeFactor
353 template <>
354 struct Bearing<Pose3, Point3> : HasBearing<Pose3, Point3, Unit3> {};
355 
356 template <typename T>
357 struct Range<Pose3, T> : HasRange<Pose3, T, double> {};
358 
359 } // namespace gtsam
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:303
Base class and basic functions for Lie types.
Represents a 3D point on a unit sphere.
Definition: Unit3.h:42
Definition: BearingRange.h:38
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:140
static Matrix wedge(double wx, double wy, double wz, double vx, double vy, double vz)
wedge for Pose3:
Definition: Pose3.h:190
double y() const
get y
Definition: Point3.h:111
Pose3()
Default constructor is origin.
Definition: Pose3.h:55
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition: OptionalJacobian.h:39
Definition: BearingRange.h:32
static Pose3 identity()
identity for group operation
Definition: Pose3.h:104
Definition: Pose3.h:37
Definition: Point3.h:45
Point3 operator*(const Point3 &p) const
syntactic sugar for transform_from
Definition: Pose3.h:210
A CRTP helper class that implements Lie group methods Prerequisites: methods operator*, inverse, and AdjointMap, as well as a ChartAtOrigin struct that will be used to define the manifold Chart To use, simply derive, but also say "using LieGroup<Class,N>::inverse" For derivative math, see doc/math.pdf.
Definition: Lie.h:36
double z() const
get z
Definition: Pose3.h:245
Vector6 Adjoint(const Vector6 &xi_b) const
FIXME Not tested - marked as incorrect.
Definition: Pose3.h:136
Rot3 Rotation
Pose Concept requirements.
Definition: Pose3.h:41
double y() const
get y
Definition: Pose3.h:240
Template to create a binary predicate.
Definition: Testable.h:110
double x() const
get x
Definition: Pose3.h:235
Definition: Pose2.h:36
Pose3(const Pose3 &pose)
Copy constructor.
Definition: Pose3.h:58
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:294
Pose3(const Rot3 &R, const Point3 &t)
Construct from R,t.
Definition: Pose3.h:63
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
3D rotation represented as a rotation matrix or quaternion
Definition: Rot3.h:56
Pose3 operator*(const Pose3 &T) const
compose syntactic sugar
Definition: Pose3.h:112
Bearing-Range product.
double z() const
get z
Definition: Point3.h:114
3D Point
double x() const
get x
Definition: Point3.h:108
Definition: BearingRange.h:123
Definition: BearingRange.h:109
Pose3(const Matrix &T)
Constructor from 4*4 matrix.
Definition: Pose3.h:71
Definition: Pose3.h:176
Matrix wedge< Pose3 >(const Vector &xi)
wedge for Pose3:
Definition: Pose3.h:332
Both LieGroupTraits and Testable.
Definition: Lie.h:237
Global functions in a separate testing namespace.
Definition: chartTesting.h:28