NDEVR
API Documentation
OptimizableTypes.h
1#pragma once
2#include "base_unary_edge.h"
3#include "types_six_dof_expmap.h"
4#include "sim3.h"
5#include "GraphOptimization/Headers/GeometricCamera.h"
6#include <Eigen/Geometry>
7
8
9namespace NDEVR
10{
11 class GeometricCamera;
13 class EdgeSE3ProjectXYZOnlyPose : public BaseUnaryEdge<2, Eigen::Vector2<g_type>, VertexSE3Expmap>
14 {
15 public:
19
20 void computeError() final override
21 {
22 _error = _measurement - pCamera->project(m_vertex->estimate().map(Xw));
23 //if (!_error.array().isFinite().all())
24 //throw "error";
25 }
26
27 bool isDepthPositive()
28 {
29 return (m_vertex->estimate().map(Xw))(2) > g_type(0.0);
30 }
31 void linearizeOplus() final override
32 {
33 Eigen::Vector3<g_type> xyz_trans = m_vertex->estimate().map(Xw);
34
35 g_type x = xyz_trans[0];
36 g_type y = xyz_trans[1];
37 g_type z = xyz_trans[2];
38
39 Eigen::Matrix<g_type, 3, 6> SE3deriv;
40 SE3deriv << 0.f, z, -y, 1.f, 0.f, 0.f,
41 -z, 0.f, x, 0.f, 1.f, 0.f,
42 y, -x, 0.f, 0.f, 0.f, 1.f;
43
44 _jacobianOplusXi = -pCamera->projectJac(xyz_trans) * SE3deriv;
45 }
46
47
48 Eigen::Vector3<g_type> Xw;
49 GeometricCamera* pCamera = nullptr;
50 public:
51 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
52 };
53
55 class EdgeSE3ProjectXYZOnlyPoseToBody : public BaseUnaryEdge<2, Eigen::Vector2<g_type>, VertexSE3Expmap>
56 {
57 public:
58 EdgeSE3ProjectXYZOnlyPoseToBody()
59 {}
60
61 bool isDepthPositive()
62 {
63 return ((mTrl * m_vertex->estimate()).map(Xw))(2) > 0.0;
64 }
65 void computeError() final override
66 {
67 _error = _measurement - pCamera->project((mTrl * m_vertex->estimate()).map(Xw));
68 //if (!_error.array().isFinite().all())
69 //throw "error";
70 }
71
72 void linearizeOplus() final override
73 {
74 SE3Quat T_lw(m_vertex->estimate());
75 Eigen::Vector3<g_type> X_l = T_lw.map(Xw);
76 Eigen::Vector3<g_type> X_r = mTrl.map(T_lw.map(Xw));
77
78 g_type x_w = X_l[0];
79 g_type y_w = X_l[1];
80 g_type z_w = X_l[2];
81
82 Eigen::Matrix<g_type, 3, 6> SE3deriv;
83 SE3deriv << 0.f, z_w, -y_w, 1.f, 0.f, 0.f,
84 -z_w, 0.f, x_w, 0.f, 1.f, 0.f,
85 y_w, -x_w, 0.f, 0.f, 0.f, 1.f;
86
87 _jacobianOplusXi = -pCamera->projectJac(X_r) * mTrl.rotation().toRotationMatrix() * SE3deriv;
88 }
89 Eigen::Vector3<g_type> Xw;
92 public:
93 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
94 };
95
97 class EdgeSE3ProjectXYZ : public BaseBinaryEdge<2, Eigen::Vector2<g_type>, VertexSBAPointXYZ, VertexSE3Expmap>
98 {
99 public:
100 EdgeSE3ProjectXYZ()
102 {}
103 bool isDepthPositive()
104 {
105 return (m_b->estimate().map(m_a->estimate()))(2) > 0.0;
106 }
107 void computeError() final override
108 {
109 Eigen::Vector2<g_type> obs(_measurement);
110 _error = obs - pCamera->project(m_b->estimate().map(m_a->estimate()));
111 //if (!_error.array().isFinite().all())
112 //throw "error";
113 }
114 void linearizeOplus() final override
115 {
116 SE3Quat T(m_b->estimate());
117 Eigen::Vector3<g_type> xyz = m_a->estimate();
118 Eigen::Vector3<g_type> xyz_trans = T.map(xyz);
119
120 g_type x = xyz_trans[0];
121 g_type y = xyz_trans[1];
122 g_type z = xyz_trans[2];
123
124 auto projectJac = -pCamera->projectJac(xyz_trans);
125
126 _jacobianOplusXi = projectJac * T.rotation().toRotationMatrix();
127
128 Eigen::Matrix<g_type, 3, 6> SE3deriv;
129 SE3deriv << 0.f, z, -y, 1.f, 0.f, 0.f,
130 -z, 0.f, x, 0.f, 1.f, 0.f,
131 y, -x, 0.f, 0.f, 0.f, 1.f;
132
133 _jacobianOplusXj = projectJac * SE3deriv;
134 }
136 public:
137 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
138 };
139
141 class EdgeSE3ProjectXYZToBody : public BaseBinaryEdge<2, Eigen::Vector2<g_type>, VertexSBAPointXYZ, VertexSE3Expmap> {
142 public:
143 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
144 EdgeSE3ProjectXYZToBody()
146 {}
147
148 void computeError() final override
149 {
150 _error = _measurement - pCamera->project((mTrl * m_b->estimate()).map(m_a->estimate()));
151 //if (!_error.array().isFinite().all())
152 //throw "error";
153 }
154 void linearizeOplus() final override
155 {
156 SE3Quat T_lw(m_b->estimate());
157 SE3Quat T_rw = mTrl * T_lw;
158 Eigen::Vector3<g_type> X_w = m_a->estimate();
159 Eigen::Vector3<g_type> X_l = T_lw.map(X_w);
160 Eigen::Vector3<g_type> X_r = mTrl.map(T_lw.map(X_w));
161
162 _jacobianOplusXi = -pCamera->projectJac(X_r) * T_rw.rotation().toRotationMatrix();
163
164 g_type x = X_l[0];
165 g_type y = X_l[1];
166 g_type z = X_l[2];
167
168 Eigen::Matrix<g_type, 3, 6> SE3deriv;
169 SE3deriv << 0.f, z, -y, 1.f, 0.f, 0.f,
170 -z, 0.f, x, 0.f, 1.f, 0.f,
171 y, -x, 0.f, 0.f, 0.f, 1.f;
172
173 _jacobianOplusXj = -pCamera->projectJac(X_r) * mTrl.rotation().toRotationMatrix() * SE3deriv;
174 }
175 bool isDepthPositive() {
176 return ((mTrl * m_b->estimate()).map(m_a->estimate()))(2) > 0.0;
177 }
180 };
181
183 class VertexSim3Expmap : public BaseVertex<7, Sim3>
184 {
185 public:
186 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
187
188 VertexSim3Expmap()
190 , pCamera1(nullptr)
191 , pCamera2(nullptr)
192 {
193 _marginalized = false;
194 _fix_scale = false;
195 }
196
197
198 virtual void setToOriginImpl()
199 {
200 _estimate = Sim3();
201 }
202
203 virtual void oplusImpl(const g_type* update_)
204 {
205 Vector7d update(update_);
206 Sim3 s(update, _fix_scale);
207 setEstimate(s * estimate());
208 }
209
210
211
214 };
215
216
218 class EdgeSim3ProjectXYZ : public BaseBinaryEdge<2, Eigen::Vector2<g_type>, VertexSBAPointXYZ, VertexSim3Expmap>
219 {
220 public:
221 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
222 EdgeSim3ProjectXYZ()
224 {
225 }
226 void computeError() final override
227 {
228 _error = _measurement - m_b->pCamera1->project(m_b->estimate().map(m_a->estimate()));
229 //if (!_error.array().isFinite().all())
230 //throw "error";
231 }
232
233 // virtual void linearizeOplus();
234
235 };
236
238 class EdgeInverseSim3ProjectXYZ : public BaseBinaryEdge<2, Eigen::Vector2<g_type>, VertexSBAPointXYZ, VertexSim3Expmap>
239 {
240 public:
241 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
242 EdgeInverseSim3ProjectXYZ()
244 {
245 }
246 void computeError() final override
247 {
248 _error = _measurement - m_b->pCamera2->project((m_b->estimate().inverse().map(m_a->estimate())));
249 //if (!_error.array().isFinite().all())
250 //throw "error";
251 }
252 // virtual void linearizeOplus();
253
254 };
255
256}
const EstimateType & estimate() const
return the current estimate of the vertex
EstimateType _estimate
void setEstimate(const EstimateType &et)
void computeError() final override
Computes the error of the edge and stores it internally.
GeometricCamera * pCamera
Pointer to the camera model.
SE3Quat mTrl
Transform from the left (reference) to the right (body) camera.
Eigen::Vector3< g_type > Xw
3D world point coordinate.
void computeError() final override
Computes the error of the edge and stores it internally.
EdgeSE3ProjectXYZOnlyPose()
Default constructor.
void computeError() final override
Computes the reprojection error using the camera model.
SE3Quat mTrl
Transform from left (reference) to right (body) camera.
void computeError() final override
Computes the error of the edge and stores it internally.
GeometricCamera * pCamera
Pointer to the camera model.
GeometricCamera * pCamera
Pointer to the camera model used for projection.
void computeError() final override
Computes the error of the edge and stores it internally.
void computeError() final override
Computes the error of the edge and stores it internally.
Abstract interface for geometric camera models (pinhole, fisheye, etc.).
virtual Eigen::Matrix< g_type, 2, 3 > projectJac(const Eigen::Vector3< g_type > &v3D)=0
Computes the 2x3 Jacobian of the projection function.
bool _marginalized
Whether this vertex is marginalized (Schur complement).
SE(3) rigid body transformation represented by a unit quaternion and translation vector.
Definition se3quat.h:42
const Quaternion< g_type > & rotation() const
Returns a const reference to the rotation quaternion.
Definition se3quat.h:116
Vector3< g_type > map(const Vector3< g_type > &xyz) const
Transforms a 3D point: R*xyz + t.
Definition se3quat.h:263
Point vertex, XYZ.
Definition types_sba.h:41
SE3 Vertex parameterized internally with a transformation matrix and externally with its exponential ...
Vertex for Sim3 similarity transformations (7-DoF: rotation, translation, scale).
virtual void oplusImpl(const g_type *update_)
update the position of the node from the parameters in v.
bool _fix_scale
Whether to fix the scale during optimization.
GeometricCamera * pCamera2
Camera models for the two views.
The primary namespace for the NDEVR SDK.
Eigen::Matrix< g_type, 7, 1 > Vector7d
7D vector for quaternion + translation representation.
Definition se3quat.h:39
Similarity transformation in 3D (rotation + translation + scale).
Definition sim3.h:13