g2o
Loading...
Searching...
No Matches
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 <Eigen/Core>
31#include <Eigen/Geometry>
32#include <cassert>
33
34#include "g2o/stuff/macros.h"
35#include "g2o/stuff/misc.h"
37
38namespace g2o {
39
40namespace 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) return _t(i);
87 return _R.angle();
88 }
89
90 double& operator[](int i) {
91 assert(i >= 0 && i < 3);
92 if (i < 2) return _t(i);
93 return _R.angle();
94 }
95
96 void fromVector(const Eigen::Vector3d& v) { *this = SE2(v[0], v[1], v[2]); }
97
98 Eigen::Vector3d toVector() const {
99 Eigen::Vector3d ret;
100 for (int i = 0; i < 3; i++) {
101 ret(i) = (*this)[i];
102 }
103 return ret;
104 }
105
106 protected:
107 Eigen::Rotation2Dd _R;
108 Eigen::Vector2d _t;
109};
110
111} // namespace tutorial
112} // namespace g2o
113
114#endif
SE2 operator*(const SE2 &tr2) const
Definition se2.h:57
Eigen::Vector2d _t
Definition se2.h:108
Eigen::Rotation2Dd _R
Definition se2.h:107
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
Definition se2.h:44
SE2 & operator*=(const SE2 &tr2)
Definition se2.h:65
SE2(double x, double y, double theta)
Definition se2.h:47
const Eigen::Vector2d & translation() const
Definition se2.h:49
Eigen::Vector2d operator*(const Eigen::Vector2d &v) const
Definition se2.h:72
double & operator[](int i)
Definition se2.h:90
SE2 inverse() const
Definition se2.h:76
const Eigen::Rotation2Dd & rotation() const
Definition se2.h:53
double operator[](int i) const
Definition se2.h:84
Eigen::Rotation2Dd & rotation()
Definition se2.h:55
Eigen::Vector3d toVector() const
Definition se2.h:98
Eigen::Vector2d & translation()
Definition se2.h:51
void fromVector(const Eigen::Vector3d &v)
Definition se2.h:96
#define G2O_TUTORIAL_SLAM2D_API
some general case utility functions
double normalize_theta(double theta)
Definition misc.h:103