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 
86  static boost::optional<Pose3> Align(const std::vector<Point3Pair>& abPointPairs);
87 
91 
93  void print(const std::string& s = "") const;
94 
96  bool equals(const Pose3& pose, double tol = 1e-9) const;
97 
101 
103  static Pose3 identity() {
104  return Pose3();
105  }
106 
108  Pose3 inverse() const;
109 
111  Pose3 operator*(const Pose3& T) const {
112  return Pose3(R_ * T.R_, t_ + R_ * T.t_);
113  }
114 
118 
120  static Pose3 Expmap(const Vector6& xi, OptionalJacobian<6, 6> H = boost::none);
121 
123  static Vector6 Logmap(const Pose3& p, OptionalJacobian<6, 6> H = boost::none);
124 
129  Matrix6 AdjointMap() const;
130 
135  Vector6 Adjoint(const Vector6& xi_b) const {
136  return AdjointMap() * xi_b;
137  }
138 
154  static Matrix6 adjointMap(const Vector6 &xi);
155 
159  static Vector6 adjoint(const Vector6 &xi, const Vector6 &y,
160  OptionalJacobian<6, 6> = boost::none);
161 
162  // temporary fix for wrappers until case issue is resolved
163  static Matrix6 adjointMap_(const Vector6 &xi) { return adjointMap(xi);}
164  static Vector6 adjoint_(const Vector6 &xi, const Vector6 &y) { return adjoint(xi, y);}
165 
169  static Vector6 adjointTranspose(const Vector6& xi, const Vector6& y,
170  OptionalJacobian<6, 6> H = boost::none);
171 
173  static Matrix6 ExpmapDerivative(const Vector6& xi);
174 
176  static Matrix6 LogmapDerivative(const Pose3& xi);
177 
178  // Chart at origin, depends on compile-time flag GTSAM_POSE3_EXPMAP
179  struct ChartAtOrigin {
180  static Pose3 Retract(const Vector6& v, ChartJacobian H = boost::none);
181  static Vector6 Local(const Pose3& r, ChartJacobian H = boost::none);
182  };
183 
184  using LieGroup<Pose3, 6>::inverse; // version with derivative
185 
193  static Matrix wedge(double wx, double wy, double wz, double vx, double vy,
194  double vz) {
195  return (Matrix(4, 4) << 0., -wz, wy, vx, wz, 0., -wx, vy, -wy, wx, 0., vz, 0., 0., 0., 0.).finished();
196  }
197 
201 
209  Point3 transformFrom(const Point3& p, OptionalJacobian<3, 6> Dpose =
210  boost::none, OptionalJacobian<3, 3> Dpoint = boost::none) const;
211 
213  inline Point3 operator*(const Point3& p) const {
214  return transformFrom(p);
215  }
216 
224  Point3 transformTo(const Point3& p, OptionalJacobian<3, 6> Dpose =
225  boost::none, OptionalJacobian<3, 3> Dpoint = boost::none) const;
226 
230 
232  const Rot3& rotation(OptionalJacobian<3, 6> H = boost::none) const;
233 
235  const Point3& translation(OptionalJacobian<3, 6> H = boost::none) const;
236 
238  double x() const {
239  return t_.x();
240  }
241 
243  double y() const {
244  return t_.y();
245  }
246 
248  double z() const {
249  return t_.z();
250  }
251 
253  Matrix4 matrix() const;
254 
256  Pose3 transformPoseFrom(const Pose3& pose) const;
257 
259  Pose3 transformPoseTo(const Pose3& pose, OptionalJacobian<6, 6> H1 = boost::none,
260  OptionalJacobian<6, 6> H2 = boost::none) const;
261 
267  double range(const Point3& point, OptionalJacobian<1, 6> H1 = boost::none,
268  OptionalJacobian<1, 3> H2 = boost::none) const;
269 
275  double range(const Pose3& pose, OptionalJacobian<1, 6> H1 = boost::none,
276  OptionalJacobian<1, 6> H2 = boost::none) const;
277 
283  Unit3 bearing(const Point3& point, OptionalJacobian<2, 6> H1 = boost::none,
284  OptionalJacobian<2, 3> H2 = boost::none) const;
285 
292  Unit3 bearing(const Pose3& pose, OptionalJacobian<2, 6> H1 = boost::none,
293  OptionalJacobian<2, 6> H2 = boost::none) const;
294 
298 
304  inline static std::pair<size_t, size_t> translationInterval() {
305  return std::make_pair(3, 5);
306  }
307 
313  static std::pair<size_t, size_t> rotationInterval() {
314  return std::make_pair(0, 2);
315  }
316 
318  GTSAM_EXPORT
319  friend std::ostream &operator<<(std::ostream &os, const Pose3& p);
320 
321 #ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V4
322  Point3 transform_from(const Point3& p,
325  OptionalJacobian<3, 6> Dpose = boost::none,
326  OptionalJacobian<3, 3> Dpoint = boost::none) const {
327  return transformFrom(p, Dpose, Dpoint);
328  }
329  Point3 transform_to(const Point3& p,
330  OptionalJacobian<3, 6> Dpose = boost::none,
331  OptionalJacobian<3, 3> Dpoint = boost::none) const {
332  return transformTo(p, Dpose, Dpoint);
333  }
334  Pose3 transform_pose_to(const Pose3& pose,
335  OptionalJacobian<6, 6> H1 = boost::none,
336  OptionalJacobian<6, 6> H2 = boost::none) const {
337  return transformPoseTo(pose, H1, H2);
338  }
341  Pose3 transform_to(const Pose3& pose) const;
343 #endif
344 
345  private:
347  friend class boost::serialization::access;
348  template<class Archive>
349  void serialize(Archive & ar, const unsigned int /*version*/) {
350  ar & BOOST_SERIALIZATION_NVP(R_);
351  ar & BOOST_SERIALIZATION_NVP(t_);
352  }
354 
355 #ifdef GTSAM_USE_QUATERNIONS
356  // Align if we are using Quaternions
357  public:
358  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
359 #endif
360 };
361 // Pose3 class
362 
370 template<>
371 inline Matrix wedge<Pose3>(const Vector& xi) {
372  return Pose3::wedge(xi(0), xi(1), xi(2), xi(3), xi(4), xi(5));
373 }
374 
375 #ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V4
376 // deprecated: use Pose3::Align with point pairs ordered the opposite way
377 GTSAM_EXPORT boost::optional<Pose3> align(const std::vector<Point3Pair>& baPointPairs);
378 #endif
379 
380 // For MATLAB wrapper
381 typedef std::vector<Pose3> Pose3Vector;
382 
383 template <>
384 struct traits<Pose3> : public internal::LieGroup<Pose3> {};
385 
386 template <>
387 struct traits<const Pose3> : public internal::LieGroup<Pose3> {};
388 
389 // bearing and range traits, used in RangeFactor
390 template <>
391 struct Bearing<Pose3, Point3> : HasBearing<Pose3, Point3, Unit3> {};
392 
393 template<>
394 struct Bearing<Pose3, Pose3> : HasBearing<Pose3, Pose3, Unit3> {};
395 
396 template <typename T>
397 struct Range<Pose3, T> : HasRange<Pose3, T, double> {};
398 
399 } // namespace gtsam
Pose3(const Matrix &T)
Constructor from 4*4 matrix.
Definition: Pose3.h:71
double x() const
get x
Definition: Point3.h:108
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:141
Definition: Point3.h:45
Both LieGroupTraits and Testable.
Definition: Lie.h:237
Template to create a binary predicate.
Definition: Testable.h:110
Bearing-Range product.
Definition: Pose3.h:179
Definition: BearingRange.h:33
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition: OptionalJacobian.h:39
Definition: Rot3.h:56
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:304
A CRTP helper class that implements Lie group methods Prerequisites: methods operator*,...
Definition: Lie.h:36
Definition: BearingRange.h:193
Represents a 3D point on a unit sphere.
Definition: Unit3.h:42
double z() const
get z
Definition: Pose3.h:248
static Matrix wedge(double wx, double wy, double wz, double vx, double vy, double vz)
wedge for Pose3:
Definition: Pose3.h:193
double x() const
get x
Definition: Pose3.h:238
static Pose3 identity()
identity for group operation
Definition: Pose3.h:103
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
Vector6 Adjoint(const Vector6 &xi_b) const
FIXME Not tested - marked as incorrect.
Definition: Pose3.h:135
Definition: Pose2.h:36
Matrix wedge< Pose3 >(const Vector &xi)
wedge for Pose3:
Definition: Pose3.h:371
Definition: BearingRange.h:179
3D Point
Definition: BearingRange.h:39
3D rotation represented as a rotation matrix or quaternion
Rot3 Rotation
Pose Concept requirements.
Definition: Pose3.h:41
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
double y() const
get y
Definition: Point3.h:111
Definition: Pose3.h:37
Base class and basic functions for Lie types.
Pose3(const Rot3 &R, const Point3 &t)
Construct from R,t.
Definition: Pose3.h:63
double y() const
get y
Definition: Pose3.h:243
Pose3(const Pose3 &pose)
Copy constructor.
Definition: Pose3.h:58
Point2 operator *(double s, const Point2 &p)
multiply with scalar
Definition: Point2.h:170
double z() const
get z
Definition: Point3.h:114
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:313
Pose3()
Default constructor is origin.
Definition: Pose3.h:55