gtsam  3.2.1
gtsam
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
22 #ifndef GTSAM_POSE3_EXPMAP
23 #define POSE3_DEFAULT_COORDINATES_MODE Pose3::FIRST_ORDER
24 #else
25 #define POSE3_DEFAULT_COORDINATES_MODE Pose3::EXPMAP
26 #endif
27 
28 #include <gtsam/base/DerivedValue.h>
29 #include <gtsam/geometry/Point3.h>
30 #include <gtsam/geometry/Rot3.h>
31 
32 namespace gtsam {
33 
34 class Pose2;
35 // forward declare
36 
42 class GTSAM_EXPORT Pose3: public DerivedValue<Pose3> {
43 public:
44  static const size_t dimension = 6;
45 
47  typedef Rot3 Rotation;
48  typedef Point3 Translation;
49 
50 private:
51 
52  Rot3 R_;
53  Point3 t_;
54 
55 public:
56 
59 
61  Pose3() {
62  }
63 
65  Pose3(const Pose3& pose) :
66  R_(pose.R_), t_(pose.t_) {
67  }
68 
70  Pose3(const Rot3& R, const Point3& t) :
71  R_(R), t_(t) {
72  }
73 
75  explicit Pose3(const Pose2& pose2);
76 
78  Pose3(const Matrix &T) :
79  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),
80  T(2, 2)), t_(T(0, 3), T(1, 3), T(2, 3)) {
81  }
82 
86 
88  void print(const std::string& s = "") const;
89 
91  bool equals(const Pose3& pose, double tol = 1e-9) const;
92 
96 
98  static Pose3 identity() {
99  return Pose3();
100  }
101 
103  Pose3 inverse(boost::optional<Matrix&> H1 = boost::none) const;
104 
106  Pose3 compose(const Pose3& p2, boost::optional<Matrix&> H1 = boost::none,
107  boost::optional<Matrix&> H2 = boost::none) const;
108 
110  Pose3 operator*(const Pose3& T) const {
111  return Pose3(R_ * T.R_, t_ + R_ * T.t_);
112  }
113 
118  Pose3 between(const Pose3& p2, boost::optional<Matrix&> H1 = boost::none,
119  boost::optional<Matrix&> H2 = boost::none) const;
120 
124 
130  FIRST_ORDER
131  };
132 
134  static size_t Dim() {
135  return dimension;
136  }
137 
139  size_t dim() const {
140  return dimension;
141  }
142 
144  Pose3 retractFirstOrder(const Vector& d) const;
145 
147  Pose3 retract(const Vector& d, Pose3::CoordinatesMode mode =
148  POSE3_DEFAULT_COORDINATES_MODE) const;
149 
151  Vector6 localCoordinates(const Pose3& T2, Pose3::CoordinatesMode mode =POSE3_DEFAULT_COORDINATES_MODE) const;
152 
156 
158  static Pose3 Expmap(const Vector& xi);
159 
161  static Vector6 Logmap(const Pose3& p);
162 
167  Matrix6 AdjointMap() const;
168 
173  Vector Adjoint(const Vector& xi_b) const {return AdjointMap()*xi_b; }
174 
190  static Matrix6 adjointMap(const Vector& xi);
191 
195  static Vector adjoint(const Vector& xi, const Vector& y, boost::optional<Matrix&> H = boost::none);
196 
200  static Vector adjointTranspose(const Vector& xi, const Vector& y, boost::optional<Matrix&> H = boost::none);
201 
212  static Matrix6 dExpInv_exp(const Vector& xi);
213 
221  static Matrix wedge(double wx, double wy, double wz, double vx, double vy, double vz) {
222  return (Matrix(4,4) <<
223  0.,-wz, wy, vx,
224  wz, 0.,-wx, vy,
225  -wy, wx, 0., vz,
226  0., 0., 0., 0.);
227  }
228 
232 
240  Point3 transform_from(const Point3& p,
241  boost::optional<Matrix&> Dpose=boost::none, boost::optional<Matrix&> Dpoint=boost::none) const;
242 
244  inline Point3 operator*(const Point3& p) const { return transform_from(p); }
245 
253  Point3 transform_to(const Point3& p,
254  boost::optional<Matrix&> Dpose=boost::none, boost::optional<Matrix&> Dpoint=boost::none) const;
255 
259 
261  const Rot3& rotation() const { return R_; }
262 
264  const Point3& translation() const { return t_; }
265 
267  double x() const { return t_.x(); }
268 
270  double y() const { return t_.y(); }
271 
273  double z() const { return t_.z(); }
274 
276  Matrix4 matrix() const;
277 
279  Pose3 transform_to(const Pose3& pose) const;
280 
286  double range(const Point3& point,
287  boost::optional<Matrix&> H1=boost::none,
288  boost::optional<Matrix&> H2=boost::none) const;
289 
295  double range(const Pose3& pose,
296  boost::optional<Matrix&> H1=boost::none,
297  boost::optional<Matrix&> H2=boost::none) const;
298 
302 
308  inline static std::pair<size_t, size_t> translationInterval() { return std::make_pair(3, 5); }
309 
315  static std::pair<size_t, size_t> rotationInterval() { return std::make_pair(0, 2); }
316 
318  GTSAM_EXPORT friend std::ostream &operator<<(std::ostream &os, const Pose3& p);
319 
320  private:
322  friend class boost::serialization::access;
323  template<class Archive>
324  void serialize(Archive & ar, const unsigned int version) {
325  ar & boost::serialization::make_nvp("Pose3",
326  boost::serialization::base_object<Value>(*this));
327  ar & BOOST_SERIALIZATION_NVP(R_);
328  ar & BOOST_SERIALIZATION_NVP(t_);
329  }
331 
332  };// Pose3 class
333 
341 template<>
342 inline Matrix wedge<Pose3>(const Vector& xi) {
343  return Pose3::wedge(xi(0), xi(1), xi(2), xi(3), xi(4), xi(5));
344 }
345 
350 typedef std::pair<Point3, Point3> Point3Pair;
351 GTSAM_EXPORT boost::optional<Pose3> align(const std::vector<Point3Pair>& pairs);
352 
353 } // namespace gtsam
const Rot3 & rotation() const
get rotation
Definition: Pose3.h:261
Pose3()
Default constructor is origin.
Definition: Pose3.h:61
double y() const
get y
Definition: Pose3.h:270
Pose3 operator*(const Pose3 &T) const
compose syntactic sugar
Definition: Pose3.h:110
Pose3(const Matrix &T)
Constructor from 4*4 matrix.
Definition: Pose3.h:78
Matrix inverse(const Matrix &A)
invert A
Definition: Matrix.cpp:289
double z() const
get z
Definition: Pose3.h:273
const Point3 & translation() const
get translation
Definition: Pose3.h:264
Pose3(const Pose3 &pose)
Copy constructor.
Definition: Pose3.h:65
CoordinatesMode
Enum to indicate which method should be used in Pose3::retract() and Pose3::localCoordinates() ...
Definition: Pose3.h:128
Matrix wedge< Pose3 >(const Vector &xi)
wedge for Pose3:
Definition: Pose3.h:342
Definition: Pose3.h:42
Point3 operator*(const Point3 &p) const
syntactic sugar for transform_from
Definition: Pose3.h:244
void print(const Matrix &A, const string &s, ostream &stream)
print a matrix
Definition: Matrix.cpp:183
Definition: Rot3.h:61
static Matrix wedge(double wx, double wy, double wz, double vx, double vy, double vz)
wedge for Pose3:
Definition: Pose3.h:221
The correct exponential map, computationally expensive.
Definition: Pose3.h:129
Template to create a binary predicate.
Definition: Testable.h:102
Rot3 Rotation
Pose Concept requirements.
Definition: Pose3.h:47
Pose3(const Rot3 &R, const Point3 &t)
Construct from R,t.
Definition: Pose3.h:70
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:315
Definition: Pose2.h:36
double x() const
get x
Definition: Pose3.h:267
static Pose3 identity()
identity for group operation
Definition: Pose3.h:98
static size_t Dim()
Dimensionality of tangent space = 6 DOF - used to autodetect sizes.
Definition: Pose3.h:134
3D Point
std::pair< Point3, Point3 > Point3Pair
Calculate pose between a vector of 3D point correspondences (p,q) where q = Pose3::transform_from(p) ...
Definition: Pose3.h:350
Definition: DerivedValue.h:44
size_t dim() const
Dimensionality of the tangent space = 6 DOF.
Definition: Pose3.h:139
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:308
Definition: Point3.h:39
3D rotation represented as a rotation matrix or quaternion
Vector Adjoint(const Vector &xi_b) const
FIXME Not tested - marked as incorrect.
Definition: Pose3.h:173