g2o
Loading...
Searching...
No Matches
plane3d.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_PLANE3D_H_
28#define G2O_PLANE3D_H_
29
30#include <Eigen/Core>
31#include <Eigen/Geometry>
32
33#include "g2o/stuff/misc.h"
35
36namespace g2o {
37
39 public:
41
42 friend Plane3D operator*(const Isometry3& t, const Plane3D& plane);
43
44 Plane3D() { fromVector(Vector4(1., 0., 0., -1.)); }
45
46 Plane3D(const Vector4& v) { fromVector(v); }
47
48 inline Vector4 toVector() const { return _coeffs; }
49
50 inline const Vector4& coeffs() const { return _coeffs; }
51
52 inline void fromVector(const Vector4& coeffs_) {
53 _coeffs = coeffs_;
54 normalize(_coeffs);
55 }
56
57 static double azimuth(const Vector3& v) { return std::atan2(v(1), v(0)); }
58
59 static double elevation(const Vector3& v) {
60 return std::atan2(v(2), v.head<2>().norm());
61 }
62
63 double distance() const { return -_coeffs(3); }
64
65 Vector3 normal() const { return _coeffs.head<3>(); }
66
67 static Matrix3 rotation(const Vector3& v) {
68 double _azimuth = azimuth(v);
69 double _elevation = elevation(v);
70 return (AngleAxis(_azimuth, Vector3::UnitZ()) *
71 AngleAxis(-_elevation, Vector3::UnitY()))
72 .toRotationMatrix();
73 }
74
75 inline void oplus(const Vector3& v) {
76 // construct a normal from azimuth and elevation;
77 double _azimuth = v[0];
78 double _elevation = v[1];
79 double s = std::sin(_elevation), c = std::cos(_elevation);
80 Vector3 n(c * std::cos(_azimuth), c * std::sin(_azimuth), s);
81
82 // rotate the normal
83 Matrix3 R = rotation(normal());
84 double d = distance() + v[2];
85 _coeffs.head<3>() = R * n;
86 _coeffs(3) = -d;
87 normalize(_coeffs);
88 }
89
90 inline Vector3 ominus(const Plane3D& plane) {
91 // construct the rotation that would bring the plane normal in (1 0 0)
92 Matrix3 R = rotation(normal()).transpose();
93 Vector3 n = R * plane.normal();
94 double d = distance() - plane.distance();
95 return Vector3(azimuth(n), elevation(n), d);
96 }
97
98 protected:
99 static inline void normalize(Vector4& coeffs) {
100 double n = coeffs.head<3>().norm();
101 coeffs = coeffs * (1. / n);
102 }
103
105};
106
107inline Plane3D operator*(const Isometry3& t, const Plane3D& plane) {
108 Vector4 v = plane._coeffs;
109 Vector4 v2;
110 Matrix3 R = t.rotation();
111 v2.head<3>() = R * v.head<3>();
112 v2(3) = v(3) - t.translation().dot(v2.head<3>());
113 return Plane3D(v2);
114};
115
116} // namespace g2o
117
118#endif
Vector3 ominus(const Plane3D &plane)
Definition plane3d.h:90
Vector4 _coeffs
Definition plane3d.h:104
void fromVector(const Vector4 &coeffs_)
Definition plane3d.h:52
Vector4 toVector() const
Definition plane3d.h:48
Vector3 normal() const
Definition plane3d.h:65
static Matrix3 rotation(const Vector3 &v)
Definition plane3d.h:67
static double elevation(const Vector3 &v)
Definition plane3d.h:59
double distance() const
Definition plane3d.h:63
Plane3D(const Vector4 &v)
Definition plane3d.h:46
const Vector4 & coeffs() const
Definition plane3d.h:50
void oplus(const Vector3 &v)
Definition plane3d.h:75
static double azimuth(const Vector3 &v)
Definition plane3d.h:57
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
Definition plane3d.h:40
static void normalize(Vector4 &coeffs)
Definition plane3d.h:99
#define G2O_TYPES_SLAM3D_ADDONS_API
some general case utility functions
VectorN< 3 > Vector3
Definition eigen_types.h:51
MatrixN< 3 > Matrix3
Definition eigen_types.h:72
VectorN< 4 > Vector4
Definition eigen_types.h:52
Eigen::AngleAxis< double > AngleAxis
Definition eigen_types.h:82
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