g2o
Loading...
Searching...
No Matches
line3d.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_LINE3D_H_
28#define G2O_LINE3D_H_
29
30#include <Eigen/Core>
31
34
35namespace g2o {
36
37typedef Eigen::Matrix<double, 6, 1> Vector6;
38typedef Eigen::Matrix<double, 6, 6> Matrix6;
39typedef Eigen::Matrix<double, 6, 4> Matrix6x4;
40
45
47 W = Matrix2::Identity();
48 U = Matrix3::Identity();
49 }
50};
52
53class Line3D : public Vector6 {
54 public:
56
58 const Line3D& line);
59
61 *this << 0.0, 0.0, 0.0, 1.0, 0.0, 0.0;
62 }
63
65
67
68 G2O_TYPES_SLAM3D_ADDONS_API inline Vector3 w() const { return head<3>(); }
69
70 G2O_TYPES_SLAM3D_ADDONS_API inline Vector3 d() const { return tail<3>(); }
71
72 G2O_TYPES_SLAM3D_ADDONS_API inline void setW(const Vector3& w_) {
73 head<3>() = w_;
74 }
75
76 G2O_TYPES_SLAM3D_ADDONS_API inline void setD(const Vector3& d_) {
77 tail<3>() = d_;
78 }
79
81 const Vector6& cart) {
82 Line3D l;
83 Vector3 _p = cart.head<3>();
84 Vector3 _d = cart.tail<3>() * 1.0 / cart.tail<3>().norm();
85 _p -= _d * (_d.dot(_p));
86 l.setW(_p.cross(_p + _d));
87 l.setD(_d);
88 return l;
89 }
90
92 const OrthonormalLine3D& ortho) {
93 Vector3 w;
94 w.x() = ortho.U(0, 0) * ortho.W(0, 0);
95 w.y() = ortho.U(1, 0) * ortho.W(0, 0);
96 w.z() = ortho.U(2, 0) * ortho.W(0, 0);
97
98 Vector3 d;
99 d.x() = ortho.U(0, 1) * ortho.W(1, 0);
100 d.y() = ortho.U(1, 1) * ortho.W(1, 0);
101 d.z() = ortho.U(2, 1) * ortho.W(1, 0);
102
103 Line3D l;
104 l.setW(w);
105 l.setD(d);
106 l.normalize();
107
108 return l;
109 }
110
112 const Line3D& line) {
113 OrthonormalLine3D ortho;
114
115 Vector2 mags;
116 mags << line.d().norm(), line.w().norm();
117
118 double wn = 1.0 / mags.norm();
119 ortho.W << mags.y() * wn, -mags.x() * wn, mags.x() * wn, mags.y() * wn;
120
121 double mn = 1.0 / mags.y();
122 double dn = 1.0 / mags.x();
123 Vector3 mdcross;
124 mdcross = line.w().cross(line.d());
125 double mdcrossn = 1.0 / mdcross.norm();
126 ortho.U << line.w().x() * mn, line.d().x() * dn, mdcross.x() * mdcrossn,
127 line.w().y() * mn, line.d().y() * dn, mdcross.y() * mdcrossn,
128 line.w().z() * mn, line.d().z() * dn, mdcross.z() * mdcrossn;
129
130 return ortho;
131 }
132
134 double n = 1.0 / d().norm();
135 (*this) *= n;
136 }
137
139 return Line3D((Vector6)(*this) * (1.0 / d().norm()));
140 }
141
143 OrthonormalLine3D ortho_estimate = toOrthonormal(*this);
144 OrthonormalLine3D ortho_update;
145 ortho_update.W << std::cos(v[3]), -std::sin(v[3]), std::sin(v[3]),
146 std::cos(v[3]);
147 Quaternion quat(std::sqrt(1 - v.head<3>().squaredNorm()), v[0], v[1], v[2]);
148 quat.normalize();
149 ortho_update.U = quat.toRotationMatrix();
150
151 ortho_estimate.U = ortho_estimate.U * ortho_update.U;
152 ortho_estimate.W = ortho_estimate.W * ortho_update.W;
153
154 *this = fromOrthonormal(ortho_estimate);
155 this->normalize();
156 }
157
159 OrthonormalLine3D ortho_estimate = toOrthonormal(*this);
160 OrthonormalLine3D ortho_line = toOrthonormal(line);
161
162 Matrix2 W_delta = ortho_estimate.W.transpose() * ortho_line.W;
163 Matrix3 U_delta = ortho_estimate.U.transpose() * ortho_line.U;
164
165 Vector4 delta;
166 Quaternion q(U_delta);
167 q.normalize();
168 delta[0] = q.x();
169 delta[1] = q.y();
170 delta[2] = q.z();
171 delta[3] = std::atan2(W_delta(1, 0), W_delta(0, 0));
172
173 return delta;
174 }
175};
176
178 const Line3D& line);
179
180namespace internal {
181
183 const Vector6& line);
184
186
187static inline double mline_elevation(const double v[3]) {
188 return std::atan2(v[2], sqrt(v[0] * v[0] + v[1] * v[1]));
189}
190
191G2O_TYPES_SLAM3D_ADDONS_API inline double getAzimuth(const Vector3& direction) {
192 return std::atan2(direction.y(), direction.x());
193}
194
196 const Vector3& direction) {
197 return std::atan2(direction.z(), direction.head<2>().norm());
198}
199
200} // namespace internal
201
202} // namespace g2o
203
204#endif
G2O_TYPES_SLAM3D_ADDONS_API void setW(const Vector3 &w_)
Definition line3d.h:72
G2O_TYPES_SLAM3D_ADDONS_API Line3D(const Vector6 &v)
Definition line3d.h:64
G2O_TYPES_SLAM3D_ADDONS_API friend Line3D operator*(const Isometry3 &t, const Line3D &line)
Definition line3d.cpp:51
static G2O_TYPES_SLAM3D_ADDONS_API Line3D fromCartesian(const Vector6 &cart)
Definition line3d.h:80
static G2O_TYPES_SLAM3D_ADDONS_API OrthonormalLine3D toOrthonormal(const Line3D &line)
Definition line3d.h:111
G2O_TYPES_SLAM3D_ADDONS_API void oplus(const Vector4 &v)
Definition line3d.h:142
G2O_TYPES_SLAM3D_ADDONS_API void normalize()
Definition line3d.h:133
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
Definition line3d.h:55
G2O_TYPES_SLAM3D_ADDONS_API Line3D normalized() const
Definition line3d.h:138
G2O_TYPES_SLAM3D_ADDONS_API Vector3 w() const
Definition line3d.h:68
G2O_TYPES_SLAM3D_ADDONS_API Line3D()
Definition line3d.h:60
G2O_TYPES_SLAM3D_ADDONS_API Vector4 ominus(const Line3D &line)
Definition line3d.h:158
static G2O_TYPES_SLAM3D_ADDONS_API Line3D fromOrthonormal(const OrthonormalLine3D &ortho)
Definition line3d.h:91
G2O_TYPES_SLAM3D_ADDONS_API Vector3 d() const
Definition line3d.h:70
G2O_TYPES_SLAM3D_ADDONS_API Vector6 toCartesian() const
Definition line3d.cpp:41
G2O_TYPES_SLAM3D_ADDONS_API void setD(const Vector3 &d_)
Definition line3d.h:76
#define G2O_TYPES_SLAM3D_ADDONS_API
G2O_TYPES_SLAM3D_ADDONS_API double getElevation(const Vector3 &direction)
Definition line3d.h:195
Vector6 transformCartesianLine(const Isometry3 &t, const Vector6 &line)
Definition line3d.cpp:61
Vector6 normalizeCartesianLine(const Vector6 &line)
Definition line3d.cpp:68
G2O_TYPES_SLAM3D_ADDONS_API double getAzimuth(const Vector3 &direction)
Definition line3d.h:191
static double mline_elevation(const double v[3])
Definition line3d.h:187
VectorN< 3 > Vector3
Definition eigen_types.h:51
Eigen::Matrix< double, 6, 6 > Matrix6
Definition line3d.h:38
MatrixN< 3 > Matrix3
Definition eigen_types.h:72
VectorN< 4 > Vector4
Definition eigen_types.h:52
Line2D operator*(const SE2 &t, const Line2D &l)
Definition line_2d.h:47
Eigen::Transform< double, 3, Eigen::Isometry, Eigen::ColMajor > Isometry3
Definition eigen_types.h:77
VectorN< 6 > Vector6
Definition eigen_types.h:53
MatrixN< 2 > Matrix2
Definition eigen_types.h:71
VectorN< 2 > Vector2
Definition eigen_types.h:50
Eigen::Matrix< double, 6, 4 > Matrix6x4
Definition line3d.h:39
Eigen::Quaternion< double > Quaternion
Definition eigen_types.h:81