types_six_dof_expmap.h
Go to the documentation of this file.
1 // g2o - General Graph Optimization
2 // Copyright (C) 2011 H. Strasdat
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 // Modified by Raúl Mur Artal (2014)
28 // Added EdgeSE3ProjectXYZ (project using focal_length in x,y directions)
29 // Modified by Raúl Mur Artal (2016)
30 // Added EdgeStereoSE3ProjectXYZ (project using focal_length in x,y directions)
31 // Added EdgeSE3ProjectXYZOnlyPose (unary edge to optimize only the camera pose)
32 // Added EdgeStereoSE3ProjectXYZOnlyPose (unary edge to optimize only the camera pose)
33 
34 #ifndef G2O_SIX_DOF_TYPES_EXPMAP
35 #define G2O_SIX_DOF_TYPES_EXPMAP
36 
37 #include "../core/base_vertex.h"
38 #include "../core/base_binary_edge.h"
39 #include "../core/base_unary_edge.h"
40 #include "se3_ops.h"
41 #include "se3quat.h"
42 #include "types_sba.h"
43 #include <Eigen/Geometry>
44 
45 namespace g2o {
46 namespace types_six_dof_expmap {
47 void init();
48 }
49 
50 using namespace Eigen;
51 
52 typedef Matrix<double, 6, 6> Matrix6d;
53 
54 
59 class VertexSE3Expmap : public BaseVertex<6, SE3Quat>{
60 public:
61  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
62 
64 
65  bool read(std::istream& is);
66 
67  bool write(std::ostream& os) const;
68 
69  virtual void setToOriginImpl() {
70  _estimate = SE3Quat();
71  }
72 
73  virtual void oplusImpl(const double* update_) {
74  Eigen::Map<const Vector6d> update(update_);
75  setEstimate(SE3Quat::exp(update)*estimate());
76  }
77 };
78 
79 
80 class EdgeSE3ProjectXYZ: public BaseBinaryEdge<2, Vector2d, VertexSBAPointXYZ, VertexSE3Expmap>{
81 public:
82  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
83 
85 
86  bool read(std::istream& is);
87 
88  bool write(std::ostream& os) const;
89 
90  void computeError() {
91  const VertexSE3Expmap* v1 = static_cast<const VertexSE3Expmap*>(_vertices[1]);
92  const VertexSBAPointXYZ* v2 = static_cast<const VertexSBAPointXYZ*>(_vertices[0]);
93  Vector2d obs(_measurement);
94  _error = obs-cam_project(v1->estimate().map(v2->estimate()));
95  }
96 
97  bool isDepthPositive() {
98  const VertexSE3Expmap* v1 = static_cast<const VertexSE3Expmap*>(_vertices[1]);
99  const VertexSBAPointXYZ* v2 = static_cast<const VertexSBAPointXYZ*>(_vertices[0]);
100  return (v1->estimate().map(v2->estimate()))(2)>0.0;
101  }
102 
103 
104  virtual void linearizeOplus();
105 
106  Vector2d cam_project(const Vector3d & trans_xyz) const;
107 
108  double fx, fy, cx, cy;
109 };
110 
111 
112 class EdgeStereoSE3ProjectXYZ: public BaseBinaryEdge<3, Vector3d, VertexSBAPointXYZ, VertexSE3Expmap>{
113 public:
114  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
115 
117 
118  bool read(std::istream& is);
119 
120  bool write(std::ostream& os) const;
121 
122  void computeError() {
123  const VertexSE3Expmap* v1 = static_cast<const VertexSE3Expmap*>(_vertices[1]);
124  const VertexSBAPointXYZ* v2 = static_cast<const VertexSBAPointXYZ*>(_vertices[0]);
125  Vector3d obs(_measurement);
126  _error = obs - cam_project(v1->estimate().map(v2->estimate()),bf);
127  }
128 
130  const VertexSE3Expmap* v1 = static_cast<const VertexSE3Expmap*>(_vertices[1]);
131  const VertexSBAPointXYZ* v2 = static_cast<const VertexSBAPointXYZ*>(_vertices[0]);
132  return (v1->estimate().map(v2->estimate()))(2)>0.0;
133  }
134 
135 
136  virtual void linearizeOplus();
137 
138  Vector3d cam_project(const Vector3d & trans_xyz, const float &bf) const;
139 
140  double fx, fy, cx, cy, bf;
141 };
142 
143 class EdgeSE3ProjectXYZOnlyPose: public BaseUnaryEdge<2, Vector2d, VertexSE3Expmap>{
144 public:
145  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
146 
148 
149  bool read(std::istream& is);
150 
151  bool write(std::ostream& os) const;
152 
153  void computeError() {
154  const VertexSE3Expmap* v1 = static_cast<const VertexSE3Expmap*>(_vertices[0]);
155  Vector2d obs(_measurement);
156  _error = obs-cam_project(v1->estimate().map(Xw));
157  }
158 
160  const VertexSE3Expmap* v1 = static_cast<const VertexSE3Expmap*>(_vertices[0]);
161  return (v1->estimate().map(Xw))(2)>0.0;
162  }
163 
164 
165  virtual void linearizeOplus();
166 
167  Vector2d cam_project(const Vector3d & trans_xyz) const;
168 
169  Vector3d Xw;
170  double fx, fy, cx, cy;
171 };
172 
173 
174 class EdgeStereoSE3ProjectXYZOnlyPose: public BaseUnaryEdge<3, Vector3d, VertexSE3Expmap>{
175 public:
176  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
177 
179 
180  bool read(std::istream& is);
181 
182  bool write(std::ostream& os) const;
183 
184  void computeError() {
185  const VertexSE3Expmap* v1 = static_cast<const VertexSE3Expmap*>(_vertices[0]);
186  Vector3d obs(_measurement);
187  _error = obs - cam_project(v1->estimate().map(Xw));
188  }
189 
191  const VertexSE3Expmap* v1 = static_cast<const VertexSE3Expmap*>(_vertices[0]);
192  return (v1->estimate().map(Xw))(2)>0.0;
193  }
194 
195 
196  virtual void linearizeOplus();
197 
198  Vector3d cam_project(const Vector3d & trans_xyz) const;
199 
200  Vector3d Xw;
201  double fx, fy, cx, cy, bf;
202 };
203 
204 
205 
206 } // end namespace
207 
208 #endif
virtual void setToOriginImpl()
sets the node to the origin (used in the multilevel stuff)
virtual void oplusImpl(const double *update_)
Templatized BaseVertex.
Definition: base_vertex.h:53
Point vertex, XYZ.
Definition: types_sba.h:40
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
SE3 Vertex parameterized internally with a transformation matrix and externally with its exponential ...
EIGEN_MAKE_ALIGNED_OPERATOR_NEW EdgeStereoSE3ProjectXYZOnlyPose()
static SE3Quat exp(const Vector6d &update)
Definition: se3quat.h:223
Matrix< double, 6, 6 > Matrix6d
const EstimateType & estimate() const
return the current estimate of the vertex
Definition: base_vertex.h:102
Vector3d map(const Vector3d &xyz) const
Definition: se3quat.h:217
EIGEN_MAKE_ALIGNED_OPERATOR_NEW EdgeSE3ProjectXYZOnlyPose()


orb_slam2_ros
Author(s):
autogenerated on Wed Apr 21 2021 02:53:05