g2o
se2.h
Go to the documentation of this file.
1 // g2o - General Graph Optimization
2 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27 #ifndef G2O_SE2_H_
28 #define G2O_SE2_H_
29 
30 #include "g2o/stuff/misc.h"
31 #include "g2o_types_slam2d_api.h"
32 #include <Eigen/Core>
33 #include <Eigen/Geometry>
34 
35 namespace g2o {
36 
41  public:
43  SE2():_R(0),_t(0,0){}
44 
45  SE2(const Isometry2D& iso): _R(0), _t(iso.translation()){
46  _R.fromRotationMatrix(iso.linear());
47  }
48 
49  SE2(const Vector3D& v):_R(v[2]),_t(v[0],v[1]){}
50 
51  SE2(double x, double y, double theta):_R(theta),_t(x,y){}
52 
54  inline const Vector2D& translation() const {return _t;}
55  void setTranslation(const Vector2D& t_) {_t=t_;}
56 
58  inline const Eigen::Rotation2Dd& rotation() const {return _R;}
59  void setRotation(const Eigen::Rotation2Dd& R_) {_R=R_;}
60 
62  inline SE2 operator * (const SE2& tr2) const{
63  SE2 result(*this);
64  result *= tr2;
65  return result;
66  }
67 
69  inline SE2& operator *= (const SE2& tr2){
70  _t+=_R*tr2._t;
71  _R.angle()+=tr2._R.angle();
72  _R.angle()=normalize_theta(_R.angle());
73  return *this;
74  }
75 
77  inline Vector2D operator * (const Vector2D& v) const {
78  return _t+_R*v;
79  }
80 
82  inline SE2 inverse() const{
83  SE2 ret;
84  ret._R=_R.inverse();
85  ret._R.angle()=normalize_theta(ret._R.angle());
86 #ifdef _MSC_VER
87  ret._t=ret._R*(Vector2D(_t*-1.));
88 #else
89  ret._t=ret._R*(_t*-1.);
90 #endif
91  return ret;
92  }
93 
94  inline double operator [](int i) const {
95  assert (i>=0 && i<3);
96  if (i<2)
97  return _t(i);
98  return _R.angle();
99  }
100 
101 
103  inline void fromVector (const Vector3D& v){
104  *this=SE2(v[0], v[1], v[2]);
105  }
106 
108  inline Vector3D toVector() const {
109  return Vector3D(_t.x(), _t.y(), _R.angle());
110  }
111 
112  inline Isometry2D toIsometry() const {
113  Isometry2D iso = Isometry2D::Identity();
114  iso.linear() = _R.toRotationMatrix();
115  iso.translation() = _t;
116  return iso;
117  }
118 
119  protected:
120  Eigen::Rotation2Dd _R;
122  };
123 
124 } // end namespace
125 
126 #endif
Eigen::Matrix< double, 2, 1, Eigen::ColMajor > Vector2D
Definition: eigen_types.h:45
some general case utility functions
Vector3D toVector() const
convert to a 3D vector (x, y, theta)
Definition: se2.h:108
Eigen::Matrix< double, 3, 1, Eigen::ColMajor > Vector3D
Definition: eigen_types.h:46
SE2(const Vector3D &v)
Definition: se2.h:49
Eigen::Transform< double, 2, Eigen::Isometry, Eigen::ColMajor > Isometry2D
Definition: eigen_types.h:65
represent SE2
Definition: se2.h:40
Line2D operator*(const SE2 &t, const Line2D &l)
Definition: line_2d.h:48
SE2()
Definition: se2.h:43
#define G2O_TYPES_SLAM2D_API
const Eigen::Rotation2Dd & rotation() const
rotational component
Definition: se2.h:58
void fromVector(const Vector3D &v)
assign from a 3D vector (x, y, theta)
Definition: se2.h:103
double normalize_theta(double theta)
Definition: misc.h:94
SE2(double x, double y, double theta)
Definition: se2.h:51
Eigen::Rotation2Dd _R
Definition: se2.h:120
SE2(const Isometry2D &iso)
Definition: se2.h:45
SE2 inverse() const
invert :-)
Definition: se2.h:82
const Vector2D & translation() const
translational component
Definition: se2.h:54
Isometry2D toIsometry() const
Definition: se2.h:112
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
Definition: se2.h:42
Vector2D _t
Definition: se2.h:121
void setTranslation(const Vector2D &t_)
Definition: se2.h:55
void setRotation(const Eigen::Rotation2Dd &R_)
Definition: se2.h:59