gtsam  4.0.0
gtsam
Pose2.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 
19 // \callgraph
20 
21 #pragma once
22 
24 #include <gtsam/geometry/Point2.h>
25 #include <gtsam/geometry/Rot2.h>
26 #include <gtsam/base/Lie.h>
27 #include <gtsam/dllexport.h>
28 
29 namespace gtsam {
30 
36 class GTSAM_EXPORT Pose2: public LieGroup<Pose2, 3> {
37 
38 public:
39 
41  typedef Rot2 Rotation;
42  typedef Point2 Translation;
43 
44 private:
45 
46  Rot2 r_;
47  Point2 t_;
48 
49 public:
50 
53 
55  Pose2() :
56  r_(traits<Rot2>::Identity()), t_(traits<Point2>::Identity()) {
57  }
58 
60  Pose2(const Pose2& pose) : r_(pose.r_), t_(pose.t_) {}
61 
68  Pose2(double x, double y, double theta) :
69  r_(Rot2::fromAngle(theta)), t_(x, y) {
70  }
71 
73  Pose2(double theta, const Point2& t) :
74  r_(Rot2::fromAngle(theta)), t_(t) {
75  }
76 
78  Pose2(const Rot2& r, const Point2& t) : r_(r), t_(t) {}
79 
81  Pose2(const Matrix &T) :
82  r_(Rot2::atan2(T(1, 0), T(0, 0))), t_(T(0, 2), T(1, 2)) {
83  assert(T.rows() == 3 && T.cols() == 3);
84  }
85 
89 
91  Pose2(const Vector& v) : Pose2() {
92  *this = Expmap(v);
93  }
94 
98 
100  void print(const std::string& s = "") const;
101 
103  bool equals(const Pose2& pose, double tol = 1e-9) const;
104 
108 
110  inline static Pose2 identity() { return Pose2(); }
111 
113  Pose2 inverse() const;
114 
116  inline Pose2 operator*(const Pose2& p2) const {
117  return Pose2(r_*p2.r(), t_ + r_*p2.t());
118  }
119 
123 
125  static Pose2 Expmap(const Vector3& xi, ChartJacobian H = boost::none);
126 
128  static Vector3 Logmap(const Pose2& p, ChartJacobian H = boost::none);
129 
134  Matrix3 AdjointMap() const;
135  inline Vector3 Adjoint(const Vector3& xi) const {
136  return AdjointMap()*xi;
137  }
138 
142  static Matrix3 adjointMap(const Vector3& v);
143 
151  static inline Matrix3 wedge(double vx, double vy, double w) {
152  Matrix3 m;
153  m << 0.,-w, vx,
154  w, 0., vy,
155  0., 0., 0.;
156  return m;
157  }
158 
160  static Matrix3 ExpmapDerivative(const Vector3& v);
161 
163  static Matrix3 LogmapDerivative(const Pose2& v);
164 
165  // Chart at origin, depends on compile-time flag SLOW_BUT_CORRECT_EXPMAP
166  struct ChartAtOrigin {
167  static Pose2 Retract(const Vector3& v, ChartJacobian H = boost::none);
168  static Vector3 Local(const Pose2& r, ChartJacobian H = boost::none);
169  };
170 
171  using LieGroup<Pose2, 3>::inverse; // version with derivative
172 
176 
178  Point2 transform_to(const Point2& point,
179  OptionalJacobian<2, 3> H1 = boost::none,
180  OptionalJacobian<2, 2> H2 = boost::none) const;
181 
183  Point2 transform_from(const Point2& point,
184  OptionalJacobian<2, 3> H1 = boost::none,
185  OptionalJacobian<2, 2> H2 = boost::none) const;
186 
188  inline Point2 operator*(const Point2& point) const { return transform_from(point);}
189 
193 
195  inline double x() const { return t_.x(); }
196 
198  inline double y() const { return t_.y(); }
199 
201  inline double theta() const { return r_.theta(); }
202 
204  inline const Point2& t() const { return t_; }
205 
207  inline const Rot2& r() const { return r_; }
208 
210  inline const Point2& translation() const { return t_; }
211 
213  inline const Rot2& rotation() const { return r_; }
214 
216  Matrix3 matrix() const;
217 
223  Rot2 bearing(const Point2& point,
224  OptionalJacobian<1, 3> H1=boost::none, OptionalJacobian<1, 2> H2=boost::none) const;
225 
231  Rot2 bearing(const Pose2& pose,
232  OptionalJacobian<1, 3> H1=boost::none, OptionalJacobian<1, 3> H2=boost::none) const;
233 
239  double range(const Point2& point,
240  OptionalJacobian<1, 3> H1=boost::none,
241  OptionalJacobian<1, 2> H2=boost::none) const;
242 
248  double range(const Pose2& point,
249  OptionalJacobian<1, 3> H1=boost::none,
250  OptionalJacobian<1, 3> H2=boost::none) const;
251 
255 
261  inline static std::pair<size_t, size_t> translationInterval() { return std::make_pair(0, 1); }
262 
268  static std::pair<size_t, size_t> rotationInterval() { return std::make_pair(2, 2); }
269 
271 
272 private:
273 
274  // Serialization function
275  friend class boost::serialization::access;
276  template<class Archive>
277  void serialize(Archive & ar, const unsigned int /*version*/) {
278  ar & BOOST_SERIALIZATION_NVP(t_);
279  ar & BOOST_SERIALIZATION_NVP(r_);
280  }
281 }; // Pose2
282 
284 template <>
285 inline Matrix wedge<Pose2>(const Vector& xi) {
286  return Pose2::wedge(xi(0),xi(1),xi(2));
287 }
288 
293 typedef std::pair<Point2,Point2> Point2Pair;
294 GTSAM_EXPORT boost::optional<Pose2> align(const std::vector<Point2Pair>& pairs);
295 
296 template <>
297 struct traits<Pose2> : public internal::LieGroup<Pose2> {};
298 
299 template <>
300 struct traits<const Pose2> : public internal::LieGroup<Pose2> {};
301 
302 // bearing and range traits, used in RangeFactor
303 template <typename T>
304 struct Bearing<Pose2, T> : HasBearing<Pose2, T, Rot2> {};
305 
306 template <typename T>
307 struct Range<Pose2, T> : HasRange<Pose2, T, double> {};
308 
309 } // namespace gtsam
310 
Definition: Rot2.h:33
Rot2 Rotation
Pose Concept requirements.
Definition: Pose2.h:41
Pose2(const Rot2 &r, const Point2 &t)
construct from r,t
Definition: Pose2.h:78
Pose2()
default constructor = origin
Definition: Pose2.h:55
Base class and basic functions for Lie types.
Definition: BearingRange.h:38
const Point2 & translation() const
translation
Definition: Pose2.h:210
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: Pose2.h:268
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:140
2D rotation
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition: OptionalJacobian.h:39
Pose2(const Vector &v)
Construct from canonical coordinates (Lie algebra)
Definition: Pose2.h:91
Definition: BearingRange.h:32
Definition: Pose2.h:166
double y() const
get y
Definition: Point2.h:106
std::pair< Point2, Point2 > Point2Pair
Calculate pose between a vector of 2D point correspondences (p,q) where q = Pose2::transform_from(p) ...
Definition: Point2.h:163
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 theta() const
get theta
Definition: Pose2.h:201
2D Point
Template to create a binary predicate.
Definition: Testable.h:110
double x() const
get x
Definition: Pose2.h:195
Definition: Pose2.h:36
Pose2(double theta, const Point2 &t)
construct from rotation and translation
Definition: Pose2.h:73
Definition: Point2.h:40
double y() const
get y
Definition: Pose2.h:198
const Rot2 & rotation() const
rotation
Definition: Pose2.h:213
Pose2 operator*(const Pose2 &p2) const
compose syntactic sugar
Definition: Pose2.h:116
Pose2(const Matrix &T)
Constructor from 3*3 matrix.
Definition: Pose2.h:81
const Rot2 & r() const
rotation
Definition: Pose2.h:207
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
Pose2(double x, double y, double theta)
construct from (x,y,theta)
Definition: Pose2.h:68
const Point2 & t() const
translation
Definition: Pose2.h:204
Matrix wedge< Pose2 >(const Vector &xi)
specialization for pose2 wedge function (generic template in Lie.h)
Definition: Pose2.h:285
Bearing-Range product.
Point2 operator*(const Point2 &point) const
syntactic sugar for transform_from
Definition: Pose2.h:188
double theta() const
return angle (RADIANS)
Definition: Rot2.h:173
Definition: BearingRange.h:123
Pose2(const Pose2 &pose)
copy constructor
Definition: Pose2.h:60
Definition: BearingRange.h:109
static Matrix3 wedge(double vx, double vy, double w)
wedge for SE(2):
Definition: Pose2.h:151
static Pose2 identity()
identity for group operation
Definition: Pose2.h:110
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: Pose2.h:261
double x() const
get x
Definition: Point2.h:103
Both LieGroupTraits and Testable.
Definition: Lie.h:237
Global functions in a separate testing namespace.
Definition: chartTesting.h:28