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_SE2_H_
28#define G2O_SE2_H_
29
30#include <Eigen/Core>
31#include <Eigen/Geometry>
32#include <cassert>
33
35#include "g2o/stuff/misc.h"
37
38namespace g2o {
39
44 public:
46 SE2() : _R(0), _t(0, 0) {}
47
48 SE2(const Isometry2& iso) : _R(0), _t(iso.translation()) {
49 _R.fromRotationMatrix(iso.linear());
50 }
51
52 SE2(const Vector3& v) : _R(v[2]), _t(v[0], v[1]) {}
53
54 SE2(double x, double y, double theta) : _R(theta), _t(x, y) {}
55
57 inline const Vector2& translation() const { return _t; }
58 void setTranslation(const Vector2& t_) { _t = t_; }
59
61 inline const Rotation2D& rotation() const { return _R; }
62 void setRotation(const Rotation2D& R_) { _R = R_; }
63
65 inline SE2 operator*(const SE2& tr2) const {
66 SE2 result(*this);
67 result *= tr2;
68 return result;
69 }
70
72 inline SE2& operator*=(const SE2& tr2) {
73 _t += _R * tr2._t;
74 _R.angle() += tr2._R.angle();
75 _R.angle() = normalize_theta(_R.angle());
76 return *this;
77 }
78
80 inline Vector2 operator*(const Vector2& v) const { return _t + _R * v; }
81
83 inline SE2 inverse() const {
84 SE2 ret;
85 ret._R = _R.inverse();
86 ret._R.angle() = normalize_theta(ret._R.angle());
87#ifdef _MSC_VER
88 ret._t = ret._R * (Vector2(_t * -1.));
89#else
90 ret._t = ret._R * (_t * -1.);
91#endif
92 return ret;
93 }
94
95 inline double operator[](int i) const {
96 assert(i >= 0 && i < 3);
97 if (i < 2) return _t(i);
98 return _R.angle();
99 }
100
102 inline void fromVector(const Vector3& v) { *this = SE2(v[0], v[1], v[2]); }
103
105 inline Vector3 toVector() const {
106 return Vector3(_t.x(), _t.y(), _R.angle());
107 }
108
109 inline Isometry2 toIsometry() const {
110 Isometry2 iso = Isometry2::Identity();
111 iso.linear() = _R.toRotationMatrix();
112 iso.translation() = _t;
113 return iso;
114 }
115
116 protected:
119};
120
121} // namespace g2o
122
123#endif
represent SE2
Definition se2.h:43
const Vector2 & translation() const
translational component
Definition se2.h:57
Rotation2D _R
Definition se2.h:117
Vector2 operator*(const Vector2 &v) const
project a 2D vector
Definition se2.h:80
SE2(const Vector3 &v)
Definition se2.h:52
Vector3 toVector() const
convert to a 3D vector (x, y, theta)
Definition se2.h:105
SE2 operator*(const SE2 &tr2) const
concatenate two SE2 elements (motion composition)
Definition se2.h:65
void setRotation(const Rotation2D &R_)
Definition se2.h:62
SE2 inverse() const
invert :-)
Definition se2.h:83
SE2 & operator*=(const SE2 &tr2)
motion composition operator
Definition se2.h:72
void fromVector(const Vector3 &v)
assign from a 3D vector (x, y, theta)
Definition se2.h:102
SE2(const Isometry2 &iso)
Definition se2.h:48
void setTranslation(const Vector2 &t_)
Definition se2.h:58
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
Definition se2.h:45
Vector2 _t
Definition se2.h:118
SE2(double x, double y, double theta)
Definition se2.h:54
SE2()
Definition se2.h:46
double operator[](int i) const
Definition se2.h:95
const Rotation2D & rotation() const
rotational component
Definition se2.h:61
Isometry2 toIsometry() const
Definition se2.h:109
#define G2O_TYPES_SLAM2D_API
some general case utility functions
VectorN< 3 > Vector3
Definition eigen_types.h:51
Eigen::Transform< double, 2, Eigen::Isometry, Eigen::ColMajor > Isometry2
Definition eigen_types.h:76
double normalize_theta(double theta)
Definition misc.h:103
Eigen::Rotation2D< double > Rotation2D
Definition eigen_types.h:80
VectorN< 2 > Vector2
Definition eigen_types.h:50