g2o
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 
31 #include "g2o/stuff/misc.h"
32 #include <Eigen/Core>
33 #include <Eigen/Geometry>
34 
35 namespace g2o {
36 
37  typedef Eigen::Matrix<double, 7, 6, Eigen::ColMajor> Matrix7x6d;
38 
39  typedef Eigen::Matrix<double, 6, 1, Eigen::ColMajor> Vector6d;
40 
41  typedef Eigen::Matrix<double, 6, 6, Eigen::ColMajor> Matrix6d;
42 
43  /*Using G2O_TYPES_SLAM3D_ADDONS_API here causes Compiler Error C2487 on MSVC*/
44  class Line3D : public Vector6d{
45  public:
47  G2O_TYPES_SLAM3D_ADDONS_API friend Line3D operator*(const Isometry3D& t, const Line3D& line);
48  Line3D(){
49  *this << 0., 0., 0., 1., 0., 0.;
50  }
51 
52  G2O_TYPES_SLAM3D_ADDONS_API Line3D(const Vector6d& v){
53  (Vector6d&)*this = v;
54  }
55 
57 
59  return head<3>();
60  }
61 
63  return tail<3>();
64  }
65 
66  G2O_TYPES_SLAM3D_ADDONS_API inline void setW(const Vector3D& w_) {
67  head<3>()=w_;
68  }
69 
70  G2O_TYPES_SLAM3D_ADDONS_API inline void setD(const Vector3D& d_) {
71  tail<3>()=d_;
72  }
73 
74  G2O_TYPES_SLAM3D_ADDONS_API static inline Line3D fromCartesian(const Vector6d& cart) {
75  Line3D l;
76  Vector3D _d= cart.tail<3>() * 1./cart.tail<3>().norm();
77  Vector3D _p= cart.head<3>();
78  _p -= _d*(_d.dot(_p));
79  l.setW(_p.cross(_p+_d));
80  l.setD(_d);
81  return l;
82  }
83 
85  double n = 1./d().norm();
86  (*this)*=n;
87  }
88 
90  return Line3D((Vector6d)(*this)*(1./d().norm()));
91  }
92 
93  G2O_TYPES_SLAM3D_ADDONS_API inline void oplus(const Vector6d& v){
94  *this+=v;
95  normalize();
96  }
97 
98  G2O_TYPES_SLAM3D_ADDONS_API inline Vector6d ominus(const Line3D& line){
99  return (Vector6d)(*this)-line;
100  }
101 
102  G2O_TYPES_SLAM3D_ADDONS_API static void jacobian(Matrix7x6d& Jp, Matrix7x6d& Jl, const Isometry3D& x, const Line3D& l);
103  };
104 
105 
106 
108 
109  namespace internal {
110  G2O_TYPES_SLAM3D_ADDONS_API Vector6d transformCartesianLine(const Isometry3D& t, const Vector6d& line);
111  G2O_TYPES_SLAM3D_ADDONS_API Vector6d normalizeCartesianLine(const Vector6d& line);
112  }
113 
114 }
115 
116 #endif
G2O_TYPES_SLAM3D_ADDONS_API Vector3D w() const
Definition: line3d.h:58
G2O_TYPES_SLAM3D_ADDONS_API Vector6d ominus(const Line3D &line)
Definition: line3d.h:98
some general case utility functions
Eigen::Matrix< double, 6, 6, Eigen::ColMajor > Matrix6d
Eigen::Matrix< double, 3, 1, Eigen::ColMajor > Vector3D
Definition: eigen_types.h:46
G2O_TYPES_SLAM3D_ADDONS_API Vector3D d() const
Definition: line3d.h:62
static G2O_TYPES_SLAM3D_ADDONS_API void jacobian(Matrix7x6d &Jp, Matrix7x6d &Jl, const Isometry3D &x, const Line3D &l)
Definition: line3d.cpp:61
Vector6d transformCartesianLine(const Isometry3D &t, const Vector6d &line)
Definition: line3d.cpp:108
G2O_TYPES_SLAM3D_ADDONS_API void oplus(const Vector6d &v)
Definition: line3d.h:93
G2O_TYPES_SLAM3D_ADDONS_API Line3D(const Vector6d &v)
Definition: line3d.h:52
G2O_TYPES_SLAM3D_ADDONS_API Line3D normalized() const
Definition: line3d.h:89
Eigen::Matrix< double, 7, 6, Eigen::ColMajor > Matrix7x6d
Definition: line3d.h:37
G2O_TYPES_SLAM3D_ADDONS_API void normalize()
Definition: line3d.h:84
Eigen::Transform< double, 3, Eigen::Isometry, Eigen::ColMajor > Isometry3D
Definition: eigen_types.h:66
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
Definition: line3d.h:46
G2O_TYPES_SLAM3D_ADDONS_API Vector6d toCartesian() const
Definition: line3d.cpp:51
static G2O_TYPES_SLAM3D_ADDONS_API Line3D fromCartesian(const Vector6d &cart)
Definition: line3d.h:74
Line3D()
Definition: line3d.h:48
#define G2O_TYPES_SLAM3D_ADDONS_API
G2O_TYPES_SLAM3D_ADDONS_API void setD(const Vector3D &d_)
Definition: line3d.h:70
G2O_TYPES_SLAM3D_ADDONS_API friend Line3D operator*(const Isometry3D &t, const Line3D &line)
Definition: line3d.cpp:94
G2O_TYPES_SLAM3D_ADDONS_API void setW(const Vector3D &w_)
Definition: line3d.h:66
Vector6d normalizeCartesianLine(const Vector6d &line)
Definition: line3d.cpp:115
Matrix< double, 6, 1, Eigen::ColMajor > Vector6d
Definition: types_icp.cpp:75