gtsam  3.2.1
gtsam
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
23 #include <boost/optional.hpp>
24 #include <gtsam/base/Matrix.h>
25 #include <gtsam/base/DerivedValue.h>
26 #include <gtsam/geometry/Point2.h>
27 #include <gtsam/geometry/Rot2.h>
28 
29 namespace gtsam {
30 
36 class GTSAM_EXPORT Pose2 : public DerivedValue<Pose2> {
37 
38 public:
39  static const size_t dimension = 3;
40 
42  typedef Rot2 Rotation;
43  typedef Point2 Translation;
44 
45 private:
46  Rot2 r_;
47  Point2 t_;
48 
49 public:
50 
53 
55  Pose2() {} // default is origin
56 
58  Pose2(const Pose2& pose) : r_(pose.r_), t_(pose.t_) {}
59 
66  Pose2(double x, double y, double theta) :
67  r_(Rot2::fromAngle(theta)), t_(x, y) {
68  }
69 
71  Pose2(double theta, const Point2& t) :
72  r_(Rot2::fromAngle(theta)), t_(t) {
73  }
74 
76  Pose2(const Rot2& r, const Point2& t) : r_(r), t_(t) {}
77 
79  Pose2(const Matrix &T) :
80  r_(Rot2::atan2(T(1, 0), T(0, 0))), t_(T(0, 2), T(1, 2)) {
81  assert(T.rows() == 3 && T.cols() == 3);
82  }
83 
87 
89  Pose2(const Vector& v) {
90  *this = Expmap(v);
91  }
92 
96 
98  void print(const std::string& s = "") const;
99 
101  bool equals(const Pose2& pose, double tol = 1e-9) const;
102 
106 
108  inline static Pose2 identity() { return Pose2(); }
109 
111  Pose2 inverse(boost::optional<Matrix&> H1=boost::none) const;
112 
114  Pose2 compose(const Pose2& p2,
115  boost::optional<Matrix&> H1 = boost::none,
116  boost::optional<Matrix&> H2 = boost::none) const;
117 
119  inline Pose2 operator*(const Pose2& p2) const {
120  return Pose2(r_*p2.r(), t_ + r_*p2.t());
121  }
122 
126  Pose2 between(const Pose2& p2,
127  boost::optional<Matrix&> H1=boost::none,
128  boost::optional<Matrix&> H2=boost::none) const;
129 
130 
134 
136  inline static size_t Dim() { return dimension; }
137 
139  inline size_t dim() const { return dimension; }
140 
142  Pose2 retract(const Vector& v) const;
143 
145  Vector localCoordinates(const Pose2& p2) const;
146 
150 
152  static Pose2 Expmap(const Vector& xi);
153 
155  static Vector Logmap(const Pose2& p);
156 
161  Matrix AdjointMap() const;
162  inline Vector Adjoint(const Vector& xi) const {
163  assert(xi.size() == 3);
164  return AdjointMap()*xi;
165  }
166 
174  static inline Matrix wedge(double vx, double vy, double w) {
175  return (Matrix(3,3) <<
176  0.,-w, vx,
177  w, 0., vy,
178  0., 0., 0.);
179  }
180 
184 
186  Point2 transform_to(const Point2& point,
187  boost::optional<Matrix&> H1=boost::none,
188  boost::optional<Matrix&> H2=boost::none) const;
189 
191  Point2 transform_from(const Point2& point,
192  boost::optional<Matrix&> H1=boost::none,
193  boost::optional<Matrix&> H2=boost::none) const;
194 
196  inline Point2 operator*(const Point2& point) const { return transform_from(point);}
197 
201 
203  inline double x() const { return t_.x(); }
204 
206  inline double y() const { return t_.y(); }
207 
209  inline double theta() const { return r_.theta(); }
210 
212  inline const Point2& t() const { return t_; }
213 
215  inline const Rot2& r() const { return r_; }
216 
218  inline const Point2& translation() const { return t_; }
219 
221  inline const Rot2& rotation() const { return r_; }
222 
224  Matrix matrix() const;
225 
231  Rot2 bearing(const Point2& point,
232  boost::optional<Matrix&> H1=boost::none,
233  boost::optional<Matrix&> H2=boost::none) const;
234 
240  Rot2 bearing(const Pose2& point,
241  boost::optional<Matrix&> H1=boost::none,
242  boost::optional<Matrix&> H2=boost::none) const;
243 
249  double range(const Point2& point,
250  boost::optional<Matrix&> H1=boost::none,
251  boost::optional<Matrix&> H2=boost::none) const;
252 
258  double range(const Pose2& point,
259  boost::optional<Matrix&> H1=boost::none,
260  boost::optional<Matrix&> H2=boost::none) const;
261 
265 
271  inline static std::pair<size_t, size_t> translationInterval() { return std::make_pair(0, 1); }
272 
278  static std::pair<size_t, size_t> rotationInterval() { return std::make_pair(2, 2); }
279 
280 private:
281 
282  // Serialization function
283  friend class boost::serialization::access;
284  template<class Archive>
285  void serialize(Archive & ar, const unsigned int version) {
286  ar & boost::serialization::make_nvp("Pose2",
287  boost::serialization::base_object<Value>(*this));
288  ar & BOOST_SERIALIZATION_NVP(t_);
289  ar & BOOST_SERIALIZATION_NVP(r_);
290  }
291 }; // Pose2
292 
294 template <>
295 inline Matrix wedge<Pose2>(const Vector& xi) {
296  return Pose2::wedge(xi(0),xi(1),xi(2));
297 }
298 
303 typedef std::pair<Point2,Point2> Point2Pair;
304 GTSAM_EXPORT boost::optional<Pose2> align(const std::vector<Point2Pair>& pairs);
305 
307 
308 } // namespace gtsam
309 
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:271
Pose2(const Matrix &T)
Constructor from 3*3 matrix.
Definition: Pose2.h:79
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:278
static Matrix wedge(double vx, double vy, double w)
wedge for SE(2):
Definition: Pose2.h:174
Matrix inverse(const Matrix &A)
invert A
Definition: Matrix.cpp:289
static Pose2 identity()
identity for group operation
Definition: Pose2.h:108
Pose2(double theta, const Point2 &t)
construct from rotation and translation
Definition: Pose2.h:71
Definition: Point2.h:35
Matrix wedge< Pose2 >(const Vector &xi)
specialization for pose2 wedge function (generic template in Lie.h)
Definition: Pose2.h:295
2D Point
const Point2 & translation() const
translation
Definition: Pose2.h:218
Rot2 Rotation
Pose Concept requirements.
Definition: Pose2.h:42
void print(const Matrix &A, const string &s, ostream &stream)
print a matrix
Definition: Matrix.cpp:183
const Rot2 & rotation() const
rotation
Definition: Pose2.h:221
Template to create a binary predicate.
Definition: Testable.h:102
std::pair< Point2, Point2 > Point2Pair
Calculate pose between a vector of 2D point correspondences (p,q) where q = Pose2::transform_from(p) ...
Definition: Pose2.h:303
const Point2 & t() const
translation
Definition: Pose2.h:212
double x() const
get x
Definition: Pose2.h:203
double y() const
get y
Definition: Pose2.h:206
Point2 operator*(const Point2 &point) const
syntactic sugar for transform_from
Definition: Pose2.h:196
static size_t Dim()
Dimensionality of tangent space = 3 DOF - used to autodetect sizes.
Definition: Pose2.h:136
typedef and functions to augment Eigen's MatrixXd
Definition: Pose2.h:36
Pose2(const Pose2 &pose)
copy constructor
Definition: Pose2.h:58
Pose2 operator*(const Pose2 &p2) const
compose syntactic sugar
Definition: Pose2.h:119
double theta() const
get theta
Definition: Pose2.h:209
Pose2(double x, double y, double theta)
construct from (x,y,theta)
Definition: Pose2.h:66
Pose2(const Vector &v)
Construct from canonical coordinates (Lie algebra)
Definition: Pose2.h:89
const Rot2 & r() const
rotation
Definition: Pose2.h:215
Pose2(const Rot2 &r, const Point2 &t)
construct from r,t
Definition: Pose2.h:76
Pose2()
default constructor = origin
Definition: Pose2.h:55
Definition: DerivedValue.h:44
Definition: Rot2.h:34
size_t dim() const
Dimensionality of tangent space = 3 DOF.
Definition: Pose2.h:139
2D rotation