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_TUTORIAL_SE2_H
28 #define G2O_TUTORIAL_SE2_H
29 
30 #include "g2o/stuff/misc.h"
31 #include "g2o/stuff/macros.h"
32 
34 
35 #include <Eigen/Core>
36 #include <Eigen/Geometry>
37 
38 namespace g2o {
39 
40  namespace tutorial {
41 
43  public:
45  SE2():_R(0),_t(0,0){}
46 
47  SE2(double x, double y, double theta):_R(theta),_t(x,y){}
48 
49  const Eigen::Vector2d& translation() const {return _t;}
50 
51  Eigen::Vector2d& translation() {return _t;}
52 
53  const Eigen::Rotation2Dd& rotation() const {return _R;}
54 
55  Eigen::Rotation2Dd& rotation() {return _R;}
56 
57  SE2 operator * (const SE2& tr2) const{
58  SE2 result(*this);
59  result._t += _R*tr2._t;
60  result._R.angle()+= tr2._R.angle();
61  result._R.angle()=normalize_theta(result._R.angle());
62  return result;
63  }
64 
65  SE2& operator *= (const SE2& tr2){
66  _t+=_R*tr2._t;
67  _R.angle()+=tr2._R.angle();
68  _R.angle()=normalize_theta(_R.angle());
69  return *this;
70  }
71 
72  Eigen::Vector2d operator * (const Eigen::Vector2d& v) const {
73  return _t+_R*v;
74  }
75 
76  SE2 inverse() const{
77  SE2 ret;
78  ret._R=_R.inverse();
79  ret._R.angle()=normalize_theta(ret._R.angle());
80  ret._t=ret._R*(Eigen::Vector2d(-1 * _t));
81  return ret;
82  }
83 
84  double operator [](int i) const {
85  assert (i>=0 && i<3);
86  if (i<2)
87  return _t(i);
88  return _R.angle();
89  }
90 
91  double& operator [](int i) {
92  assert (i>=0 && i<3);
93  if (i<2)
94  return _t(i);
95  return _R.angle();
96  }
97 
98  void fromVector (const Eigen::Vector3d& v){
99  *this=SE2(v[0], v[1], v[2]);
100  }
101 
102  Eigen::Vector3d toVector() const {
103  Eigen::Vector3d ret;
104  for (int i=0; i<3; i++){
105  ret(i)=(*this)[i];
106  }
107  return ret;
108  }
109 
110  protected:
111  Eigen::Rotation2Dd _R;
112  Eigen::Vector2d _t;
113  };
114 
115  } // end namespace
116 } // end namespace
117 
118 #endif
Eigen::Vector2d & translation()
Definition: se2.h:51
SE2(double x, double y, double theta)
Definition: se2.h:47
some general case utility functions
const Eigen::Rotation2Dd & rotation() const
Definition: se2.h:53
Line2D operator*(const SE2 &t, const Line2D &l)
Definition: line_2d.h:48
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
Definition: se2.h:44
Eigen::Vector3d toVector() const
Definition: se2.h:102
void fromVector(const Eigen::Vector3d &v)
Definition: se2.h:98
Eigen::Rotation2Dd & rotation()
Definition: se2.h:55
SE2 inverse() const
Definition: se2.h:76
const Eigen::Vector2d & translation() const
Definition: se2.h:49
#define G2O_TUTORIAL_SLAM2D_API
double normalize_theta(double theta)
Definition: misc.h:94
Eigen::Vector2d _t
Definition: se2.h:112
Eigen::Rotation2Dd _R
Definition: se2.h:111