NDEVR
API Documentation
G2oTypes.h
1#pragma once
2#include "GraphOptimization/Headers/base_vertex.h"
3#include "GraphOptimization/Headers/base_binary_edge.h"
4#include "GraphOptimization/Headers/types_sba.h"
5#include "GraphOptimization/Headers/base_multi_edge.h"
6#include "GraphOptimization/Headers/base_unary_edge.h"
7
8#include <opencv2/core/core.hpp>
9
10#include <Eigen/Core>
11#include <Eigen/Geometry>
12#include <Eigen/Dense>
13
14#include "OrbSLAM/Headers/Frame.h"
15#include "OrbSLAM/Headers/KeyFrame.h"
16
17namespace NDEVR
18{
19
20 class KeyFrame;
21 class Frame;
22 class GeometricCamera;
23
24 typedef Eigen::Matrix<g_type, 6, 1> vector6d;
25 typedef Eigen::Matrix<g_type, 9, 1> vector9d;
26 typedef Eigen::Matrix<g_type, 12, 1> vector12d;
27 typedef Eigen::Matrix<g_type, 15, 1> vector15d;
28 typedef Eigen::Matrix<g_type, 12, 12> Matrix12d;
29 typedef Eigen::Matrix<g_type, 15, 15> Matrix15d;
30 typedef Eigen::Matrix<g_type, 9, 9> Matrix9d;
31
38 Eigen::Matrix3<g_type> ExpSO3(const g_type x, const g_type y, const g_type z);
43 Eigen::Matrix3<g_type> ExpSO3(const Eigen::Vector3<g_type>& w);
44
49 Eigen::Vector3<g_type> LogSO3(const Eigen::Matrix3<g_type>& R);
50
55 Eigen::Matrix3<g_type> InverseRightJacobianSO3(const Eigen::Vector3<g_type>& v);
60 Eigen::Matrix3<g_type> RightJacobianSO3(const Eigen::Vector3<g_type>& v);
67 Eigen::Matrix3<g_type> RightJacobianSO3(g_type x, g_type y, g_type z);
68
73 Eigen::Matrix3<g_type> Skew(const Eigen::Vector3<g_type>& w);
80 Eigen::Matrix3<g_type> InverseRightJacobianSO3(g_type x, g_type y, g_type z);
81
86 template<typename T = g_type>
87 Eigen::Matrix<T, 3, 3> NormalizeRotation(const Eigen::Matrix<T, 3, 3>& R) {
88 Eigen::JacobiSVD<Eigen::Matrix<T, 3, 3>> svd(R, Eigen::ComputeFullU | Eigen::ComputeFullV);
89 return svd.matrixU() * svd.matrixV().transpose();
90 }
91
92
99 {
100 public:
112 ImuCamPose(Eigen::Matrix3<g_type>& _Rwc, Eigen::Vector3<g_type>& _twc, KeyFrame* pKF);
113
121 void SetParam(const Buffer<Eigen::Matrix3<g_type>>& _Rcw, const Buffer<Eigen::Vector3<g_type>>& _tcw, const Buffer<Eigen::Matrix3<g_type>>& _Rbc,
122 const Buffer<Eigen::Vector3<g_type>>& _tbc, const g_type& _bf);
123
127 void Update(const g_type* pu);
131 void UpdateW(const g_type* pu);
137 Eigen::Vector2<g_type> Project(const Eigen::Vector3<g_type>& Xw, int cam_idx = 0) const;
143 Eigen::Vector3<g_type> ProjectStereo(const Eigen::Vector3<g_type>& Xw, int cam_idx = 0) const;
149 bool isDepthPositive(const Eigen::Vector3<g_type>& Xw, int cam_idx = 0) const;
150
151 public:
152 Eigen::Matrix3<g_type> Rwb;
153 Eigen::Vector3<g_type> twb;
154
159 g_type bf;
161
162 Eigen::Matrix3<g_type> Rwb0;
163 Eigen::Matrix3<g_type> DR;
164
165 int its;
166 };
167
170 {
171 public:
180 InvDepthPoint(g_type _rho, g_type _u, g_type _v, KeyFrame* pHostKF);
181
185 void Update(const g_type* pu);
186
187 g_type rho;
188 g_type u, v;
189 g_type fx, fy, cx, cy, bf;
190 int its;
191 };
192
194 class VertexPose : public BaseVertex<6, ImuCamPose>
195 {
196 public:
197 VertexPose() {}
198 VertexPose(Frame& pF) {
200 }
201 virtual void oplusImpl(const g_type* update_) final override
202 {
203 _estimate.Update(update_);
204 }
205 };
206
208 class VertexPose4DoF : public BaseVertex<4, ImuCamPose>
209 {
210 public:
211 VertexPose4DoF() {}
212 VertexPose4DoF(Frame& pF) {
214 }
215 VertexPose4DoF(Eigen::Matrix3<g_type>& _Rwc, Eigen::Vector3<g_type>& _twc, KeyFrame* pKF) {
216
217 setEstimate(ImuCamPose(_Rwc, _twc, pKF));
218 }
219 virtual void oplusImpl(const g_type* update_) override {
220 g_type update6DoF[6];
221 update6DoF[0] = 0;
222 update6DoF[1] = 0;
223 update6DoF[2] = update_[0];
224 update6DoF[3] = update_[1];
225 update6DoF[4] = update_[2];
226 update6DoF[5] = update_[3];
227 _estimate.UpdateW(update6DoF);
228 }
229 };
230
232 class VertexVelocity : public BaseVertex<3, Eigen::Vector3<g_type>>
233 {
234 public:
235 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
236 VertexVelocity() {}
237 VertexVelocity(Frame& pF);
238
239 virtual void oplusImpl(const g_type* update_) final override
240 {
241 Eigen::Vector3<g_type> uv;
242 uv << update_[0], update_[1], update_[2];
243 setEstimate(estimate() + uv);
244 lib_assert(abs(_estimate.x()) < 10.0, "Bad speed");
245 lib_assert(abs(_estimate.y()) < 10.0, "Bad speed");
246 lib_assert(abs(_estimate.z()) < 10.0, "Bad speed");
247 }
248 };
249
251 class VertexGyroBias : public BaseVertex<3, Eigen::Vector3<g_type>>
252 {
253 public:
254 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
255 VertexGyroBias() {}
256 VertexGyroBias(Frame& pF);
257
258 virtual void oplusImpl(const g_type* update_) final override
259 {
260 Eigen::Vector3<g_type> ubg;
261 ubg << update_[0], update_[1], update_[2];
262 setEstimate(estimate() + ubg);
263 }
264 };
265
266
268 class VertexAccBias : public BaseVertex<3, Eigen::Vector3<g_type>>
269 {
270 public:
271 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
272 VertexAccBias() {}
273 VertexAccBias(Frame& pF);
274
275 virtual void oplusImpl(const g_type* update_) final override
276 {
277 Eigen::Vector3<g_type> uba;
278 uba << update_[0], update_[1], update_[2];
279 setEstimate(estimate() + uba);
280 }
281 };
282
283
285 class GDirection
286 {
287 public:
288 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
289 GDirection() {}
290 GDirection(Eigen::Matrix3<g_type> pRwg) : Rwg(pRwg) {}
291
292 void Update(const g_type* pu)
293 {
294 Rwg = Rwg * ExpSO3(pu[0], pu[1], 0.0);
295 }
296
297 Eigen::Matrix3<g_type> Rwg, Rgw;
298
299 int its;
300 };
301
303 class VertexGDir : public BaseVertex<2, GDirection>
304 {
305 public:
306 VertexGDir() {}
307 VertexGDir(Eigen::Matrix3<g_type> pRwg) {
308 setEstimate(GDirection(pRwg));
309 }
310 virtual void oplusImpl(const g_type* update_) final override {
311 _estimate.Update(update_);
312 }
313 };
314
316 class VertexScale : public BaseVertex<1, g_type>
317 {
318 public:
319 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
320 VertexScale() {
321 setEstimate(1.0);
322 }
323 VertexScale(g_type ps) {
324 setEstimate(ps);
325 }
326
327 virtual void oplusImpl(const g_type* update_) final override {
328 setEstimate(estimate() * exp(*update_));
329 }
330 };
331
332
334 class VertexInvDepth : public BaseVertex<1, InvDepthPoint>
335 {
336 public:
337 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
338 VertexInvDepth() {}
339 VertexInvDepth(g_type invDepth, g_type u, g_type v, KeyFrame* pHostKF) {
340 setEstimate(InvDepthPoint(invDepth, u, v, pHostKF));
341 }
342 virtual void oplusImpl(const g_type* update_) final override {
343 _estimate.Update(update_);
344 }
345 };
346
348 class EdgeMono : public BaseBinaryEdge<2, Eigen::Vector2<g_type>, VertexSBAPointXYZ, VertexPose>
349 {
350 public:
351 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
352
353 EdgeMono(int cam_idx_ = 0)
354 : cam_idx(cam_idx_)
355 {}
357 _error = _measurement - m_b->estimate().Project(m_a->estimate(), cam_idx);
358 //if (!_error.array().isFinite().all())
359 //throw "error";
360 }
361
362
363 virtual void linearizeOplus();
364
365 bool isDepthPositive()
366 {
367 return m_b->estimate().isDepthPositive(m_a->estimate(), cam_idx);
368 }
369
370 Eigen::Matrix<g_type, 2, 9> GetJacobian() {
372 Eigen::Matrix<g_type, 2, 9> J;
373 J.block<2, 3>(0, 0) = _jacobianOplusXi;
374 J.block<2, 6>(0, 3) = _jacobianOplusXj;
375 return J;
376 }
377
378 Eigen::Matrix<g_type, 9, 9> GetHessian()
379 {
381 Eigen::Matrix<g_type, 2, 9> J;
382 J.block<2, 3>(0, 0) = _jacobianOplusXi;
383 J.block<2, 6>(0, 3) = _jacobianOplusXj;
384 return J.transpose() * information() * J;
385
386 }
387
388 public:
389 const int cam_idx;
390 };
391
393 class EdgeMonoOnlyPose : public BaseUnaryEdge<2, Eigen::Vector2<g_type>, VertexPose>
394 {
395 public:
396 EdgeMonoOnlyPose(const Eigen::Vector3<g_type>& Xw_, int cam_idx_ = 0)
397 : Xw(Xw_)
398 , cam_idx(cam_idx_)
399 {}
401 {
402 _error = _measurement - m_vertex->estimate().Project(Xw, cam_idx);
403 //if (!_error.array().isFinite().all())
404 //throw "error";
405 }
406
407 virtual void linearizeOplus();
408
409 bool isDepthPositive()
410 {
411 return m_vertex->estimate().isDepthPositive(Xw, cam_idx);
412 }
413
414 Eigen::Matrix<g_type, 6, 6> GetHessian() {
416 return _jacobianOplusXi.transpose() * information() * _jacobianOplusXi;
417 }
418
419 public:
420 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
421 const Eigen::Vector3<g_type> Xw;
422 const int cam_idx;
423 };
424
426 class EdgeStereo : public BaseBinaryEdge<3, Eigen::Vector3<g_type>, VertexSBAPointXYZ, VertexPose>
427 {
428 public:
429 EdgeStereo(int cam_idx_ = 0)
430 : cam_idx(cam_idx_)
431 {}
432 bool isDepthPositive()
433 {
434 return true;
435 }
437 {
438 _error = _measurement - m_b->estimate().ProjectStereo(m_a->estimate(), cam_idx);
439 //if (!_error.array().isFinite().all())
440 //throw "error";
441 }
442
443
444 virtual void linearizeOplus();
445
446 Eigen::Matrix<g_type, 3, 9> GetJacobian()
447 {
449 Eigen::Matrix<g_type, 3, 9> J;
450 J.block<3, 3>(0, 0) = _jacobianOplusXi;
451 J.block<3, 6>(0, 3) = _jacobianOplusXj;
452 return J;
453 }
454
455 Eigen::Matrix<g_type, 9, 9> GetHessian()
456 {
458 Eigen::Matrix<g_type, 3, 9> J;
459 J.block<3, 3>(0, 0) = _jacobianOplusXi;
460 J.block<3, 6>(0, 3) = _jacobianOplusXj;
461 return J.transpose() * information() * J;
462 }
463 public:
464 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
465 const int cam_idx;
466 };
467
468
470 class EdgeStereoOnlyPose : public BaseUnaryEdge<3, Eigen::Vector3<g_type>, VertexPose>
471 {
472 public:
473 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
474
475 EdgeStereoOnlyPose(const Eigen::Vector3f& Xw_, int cam_idx_ = 0) :
476 Xw(Xw_.cast<g_type>()), cam_idx(cam_idx_) {}
478 _error = _measurement - m_vertex->estimate().ProjectStereo(Xw, cam_idx);
479 //if (!_error.array().isFinite().all())
480 //throw "error";
481 }
482
483 virtual void linearizeOplus();
484
485 Eigen::Matrix<g_type, 6, 6> GetHessian() {
487 return _jacobianOplusXi.transpose() * information() * _jacobianOplusXi;
488 }
489
490 public:
491 const Eigen::Vector3<g_type> Xw; // 3D point coordinates
492 const int cam_idx;
493 };
494
496 class EdgeInertial : public BaseMultiEdge<9, vector9d>
497 {
498 public:
499 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
500
501 EdgeInertial(IMU::Preintegrated* pInt);
503 virtual void linearizeOplus();
504
505 Eigen::Matrix<g_type, 24, 24> GetHessian() {
506 linearizeOplus();
507 Eigen::Matrix<g_type, 9, 24> J;
508 J.block<9, 6>(0, 0) = _jacobianOplus[0];
509 J.block<9, 3>(0, 6) = _jacobianOplus[1];
510 J.block<9, 3>(0, 9) = _jacobianOplus[2];
511 J.block<9, 3>(0, 12) = _jacobianOplus[3];
512 J.block<9, 6>(0, 15) = _jacobianOplus[4];
513 J.block<9, 3>(0, 21) = _jacobianOplus[5];
514 return J.transpose() * information() * J;
515 }
516
517 Eigen::Matrix<g_type, 18, 18> GetHessianNoPose1() {
518 linearizeOplus();
519 Eigen::Matrix<g_type, 9, 18> J;
520 J.block<9, 3>(0, 0) = _jacobianOplus[1];
521 J.block<9, 3>(0, 3) = _jacobianOplus[2];
522 J.block<9, 3>(0, 6) = _jacobianOplus[3];
523 J.block<9, 6>(0, 9) = _jacobianOplus[4];
524 J.block<9, 3>(0, 15) = _jacobianOplus[5];
525 return J.transpose() * information() * J;
526 }
527
528 Eigen::Matrix<g_type, 9, 9> GetHessian2() {
529 linearizeOplus();
530 Eigen::Matrix<g_type, 9, 9> J;
531 J.block<9, 6>(0, 0) = _jacobianOplus[4];
532 J.block<9, 3>(0, 6) = _jacobianOplus[5];
533 return J.transpose() * information() * J;
534 }
535
536 const Eigen::Matrix3<g_type> JRg, JVg, JPg;
537 const Eigen::Matrix3<g_type> JVa, JPa;
538 IMU::Preintegrated* mpInt;
539 const g_type dt;
540 Eigen::Vector3<g_type> g;
541 };
542
543
545 class EdgeInertialGS : public BaseMultiEdge<9, vector9d>
546 {
547 public:
548 EdgeInertialGS(IMU::Preintegrated* pInt);
549 void computeError() final override;
550 virtual void linearizeOplus() final override;
551
552 const Eigen::Matrix3<g_type> JRg, JVg, JPg;
553 const Eigen::Matrix3<g_type> JVa, JPa;
554 IMU::Preintegrated* mpInt;
555 const g_type dt;
556 Eigen::Vector3<g_type> g, gI;
557 Eigen::Matrix<g_type, 27, 27> GetHessian()
558 {
559 linearizeOplus();
560 Eigen::Matrix<g_type, 9, 27> J;
561 J.block<9, 6>(0, 0) = _jacobianOplus[0];
562 J.block<9, 3>(0, 6) = _jacobianOplus[1];
563 J.block<9, 3>(0, 9) = _jacobianOplus[2];
564 J.block<9, 3>(0, 12) = _jacobianOplus[3];
565 J.block<9, 6>(0, 15) = _jacobianOplus[4];
566 J.block<9, 3>(0, 21) = _jacobianOplus[5];
567 J.block<9, 2>(0, 24) = _jacobianOplus[6];
568 J.block<9, 1>(0, 26) = _jacobianOplus[7];
569 return J.transpose() * information() * J;
570 }
571
572 Eigen::Matrix<g_type, 27, 27> GetHessian2() {
573 linearizeOplus();
574 Eigen::Matrix<g_type, 9, 27> J;
575 J.block<9, 3>(0, 0) = _jacobianOplus[2];
576 J.block<9, 3>(0, 3) = _jacobianOplus[3];
577 J.block<9, 2>(0, 6) = _jacobianOplus[6];
578 J.block<9, 1>(0, 8) = _jacobianOplus[7];
579 J.block<9, 3>(0, 9) = _jacobianOplus[1];
580 J.block<9, 3>(0, 12) = _jacobianOplus[5];
581 J.block<9, 6>(0, 15) = _jacobianOplus[0];
582 J.block<9, 6>(0, 21) = _jacobianOplus[4];
583 return J.transpose() * information() * J;
584 }
585
586 Eigen::Matrix<g_type, 9, 9> GetHessian3() {
587 linearizeOplus();
588 Eigen::Matrix<g_type, 9, 9> J;
589 J.block<9, 3>(0, 0) = _jacobianOplus[2];
590 J.block<9, 3>(0, 3) = _jacobianOplus[3];
591 J.block<9, 2>(0, 6) = _jacobianOplus[6];
592 J.block<9, 1>(0, 8) = _jacobianOplus[7];
593 return J.transpose() * information() * J;
594 }
595
596
597
598 Eigen::Matrix<g_type, 1, 1> GetHessianScale() {
599 linearizeOplus();
600 Eigen::Matrix<g_type, 9, 1> J = _jacobianOplus[7];
601 return J.transpose() * information() * J;
602 }
603
604 Eigen::Matrix<g_type, 3, 3> GetHessianBiasGyro() {
605 linearizeOplus();
606 Eigen::Matrix<g_type, 9, 3> J = _jacobianOplus[2];
607 return J.transpose() * information() * J;
608 }
609
610 Eigen::Matrix<g_type, 3, 3> GetHessianBiasAcc() {
611 linearizeOplus();
612 Eigen::Matrix<g_type, 9, 3> J = _jacobianOplus[3];
613 return J.transpose() * information() * J;
614 }
615
616 Eigen::Matrix<g_type, 2, 2> GetHessianGDir() {
617 linearizeOplus();
618 Eigen::Matrix<g_type, 9, 2> J = _jacobianOplus[6];
619 return J.transpose() * information() * J;
620 }
621 };
622
623
624
626 class EdgeGyroRW : public BaseBinaryEdge<3, Eigen::Vector3<g_type>, VertexGyroBias, VertexGyroBias>
627 {
628 public:
629 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
630
631 EdgeGyroRW() {}
632 void computeError() final override {
633 _error = m_b->estimate() - m_a->estimate();
634 //if (!_error.array().isFinite().all())
635 //throw "error";
636 }
637
638 virtual void linearizeOplus() final override
639 {
640 _jacobianOplusXi = -Eigen::Matrix3<g_type>::Identity();
641 _jacobianOplusXj.setIdentity();
642 }
643
644 Eigen::Matrix<g_type, 6, 6> GetHessian() {
646 Eigen::Matrix<g_type, 3, 6> J;
647 J.block<3, 3>(0, 0) = _jacobianOplusXi;
648 J.block<3, 3>(0, 3) = _jacobianOplusXj;
649 return J.transpose() * information() * J;
650 }
651
652 Eigen::Matrix3<g_type> GetHessian2() {
654 return _jacobianOplusXj.transpose() * information() * _jacobianOplusXj;
655 }
656 };
657
658
660 class EdgeAccRW : public BaseBinaryEdge<3, Eigen::Vector3<g_type>, VertexAccBias, VertexAccBias>
661 {
662 public:
663 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
664
665 EdgeAccRW() {}
666 void computeError() final override
667 {
668 _error = m_b->estimate() - m_a->estimate();
669 //if (!_error.array().isFinite().all())
670 //throw "error";
671 }
672
673 virtual void linearizeOplus() final override
674 {
675 _jacobianOplusXi = -Eigen::Matrix3<g_type>::Identity();
676 _jacobianOplusXj.setIdentity();
677 }
678
679 Eigen::Matrix<g_type, 6, 6> GetHessian() {
681 Eigen::Matrix<g_type, 3, 6> J;
682 J.block<3, 3>(0, 0) = _jacobianOplusXi;
683 J.block<3, 3>(0, 3) = _jacobianOplusXj;
684 return J.transpose() * information() * J;
685 }
686
687 Eigen::Matrix3<g_type> GetHessian2() {
689 return _jacobianOplusXj.transpose() * information() * _jacobianOplusXj;
690 }
691 };
692
694 class ConstraintPoseImu
695 {
696 public:
697 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
698 ConstraintPoseImu(const Eigen::Matrix3<g_type>& Rwb_
699 , const Eigen::Vector3<g_type>& twb_
700 , const Eigen::Vector3<g_type>& vwb_
701 , const Eigen::Vector3<g_type>& bg_
702 , const Eigen::Vector3<g_type>& ba_
703 , const Matrix15d& H_)
704 : Rwb(Rwb_)
705 , twb(twb_)
706 , vwb(vwb_)
707 , bg(bg_)
708 , ba(ba_)
709 , H(H_)
710 {
711 H = (H + H) / 2;
712 Eigen::SelfAdjointEigenSolver<Eigen::Matrix<g_type, 15, 15> > es(H);
713 Eigen::Matrix<g_type, 15, 1> eigs = es.eigenvalues();
714 for (int i = 0; i < 15; i++)
715 if (eigs[i] < 1e-12)
716 eigs[i] = 0;
717 H = es.eigenvectors() * eigs.asDiagonal() * es.eigenvectors().transpose();
718 }
719
720 Eigen::Matrix3<g_type> Rwb;
721 Eigen::Vector3<g_type> twb;
722 Eigen::Vector3<g_type> vwb;
723 Eigen::Vector3<g_type> bg;
724 Eigen::Vector3<g_type> ba;
726 };
727
729 class EdgePriorPoseImu : public BaseMultiEdge<15, vector15d>
730 {
731 public:
732 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
733 EdgePriorPoseImu(ConstraintPoseImu* c);
734 void computeError() override;
735 virtual void linearizeOplus() override;
736
737 Eigen::Matrix<g_type, 15, 15> GetHessian()
738 {
739 linearizeOplus();
740 Eigen::Matrix<g_type, 15, 15> J;
741 J.block<15, 6>(0, 0) = _jacobianOplus[0];
742 J.block<15, 3>(0, 6) = _jacobianOplus[1];
743 J.block<15, 3>(0, 9) = _jacobianOplus[2];
744 J.block<15, 3>(0, 12) = _jacobianOplus[3];
745 return J.transpose() * information() * J;
746 }
747
748 Eigen::Matrix<g_type, 9, 9> GetHessianNoPose()
749 {
750 linearizeOplus();
751 Eigen::Matrix<g_type, 15, 9> J;
752 J.block<15, 3>(0, 0) = _jacobianOplus[1];
753 J.block<15, 3>(0, 3) = _jacobianOplus[2];
754 J.block<15, 3>(0, 6) = _jacobianOplus[3];
755 return J.transpose() * information() * J;
756 }
757 Eigen::Matrix3<g_type> Rwb;
758 Eigen::Vector3<g_type> twb, vwb;
759 Eigen::Vector3<g_type> bg, ba;
760 };
761
763 class EdgePriorAcc : public BaseUnaryEdge<3, Eigen::Vector3<g_type>, VertexAccBias>
764 {
765 public:
766 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
767
768 EdgePriorAcc(const Eigen::Vector3f& bprior_)
769 : bprior(bprior_.cast<g_type>())
770 {}
771
772 void computeError() final override
773 {
774 _error = bprior - m_vertex->estimate();
775 //if (!_error.array().isFinite().all())
776 //throw "error";
777 }
778 virtual void linearizeOplus() final override;
779
780 Eigen::Matrix<g_type, 3, 3> GetHessian()
781 {
783 return _jacobianOplusXi.transpose() * information() * _jacobianOplusXi;
784 }
785
786 const Eigen::Vector3<g_type> bprior;
787 };
788
790 class EdgePriorGyro : public BaseUnaryEdge<3, Eigen::Vector3<g_type>, VertexGyroBias>
791 {
792 public:
793 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
794
795 EdgePriorGyro(const Eigen::Vector3f& bprior_) :bprior(bprior_.cast<g_type>()) {}
796
797 void computeError() final override
798 {
799 _error = bprior - m_vertex->estimate();
800 //if (!_error.array().isFinite().all())
801 //throw "error";
802 }
803 virtual void linearizeOplus() final override;
804
805 Eigen::Matrix<g_type, 3, 3> GetHessian()
806 {
808 return _jacobianOplusXi.transpose() * information() * _jacobianOplusXi;
809 }
810
811 const Eigen::Vector3<g_type> bprior;
812 };
813
814
816 class Edge4DoF : public BaseBinaryEdge<6, vector6d, VertexPose4DoF, VertexPose4DoF>
817 {
818 public:
819 Edge4DoF(const Eigen::Matrix4<g_type>& deltaT) {
820 dTij = deltaT;
821 dRij = deltaT.block<3, 3>(0, 0);
822 dtij = deltaT.block<3, 1>(0, 3);
823 }
824
826 {
827 _error << LogSO3(m_a->estimate().Rcw[0] * m_a->estimate().Rcw[0].transpose() * dRij.transpose()),
828 m_a->estimate().Rcw[0] * (-m_a->estimate().Rcw[0].transpose() * m_a->estimate().tcw[0])
829 + m_a->estimate().tcw[0] - dtij;
830 //if (!_error.array().isFinite().all())
831 //throw "error";
832 }
833
834 // virtual void linearizeOplus(); // numerical implementation
835
836 Eigen::Matrix4<g_type> dTij;
837 Eigen::Matrix3<g_type> dRij;
838 Eigen::Vector3<g_type> dtij;
839 };
840
841}
const InformationType & information() const
Definition base_edge.h:50
Buffer< JacobianType > _jacobianOplus
const EstimateType & estimate() const
void setEstimate(const EstimateType &et)
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
Stores a prior constraint on an IMU pose with its information matrix.
Definition G2oTypes.h:695
Eigen::Matrix3< g_type > Rwb
Body-to-world rotation.
Definition G2oTypes.h:720
Eigen::Vector3< g_type > ba
Accelerometer bias.
Definition G2oTypes.h:724
Matrix15d H
15x15 information matrix.
Definition G2oTypes.h:725
Eigen::Vector3< g_type > twb
Body-to-world translation.
Definition G2oTypes.h:721
Eigen::Vector3< g_type > bg
Gyroscope bias.
Definition G2oTypes.h:723
Eigen::Vector3< g_type > vwb
Body velocity in world frame.
Definition G2oTypes.h:722
void computeError()
Computes the error of the edge and stores it internally.
Definition G2oTypes.h:825
void computeError() final override
Computes the error of the edge and stores it internally.
Definition G2oTypes.h:666
void computeError() final override
Computes the error of the edge and stores it internally.
Definition G2oTypes.h:632
void computeError() final override
Computes the error of the edge and stores it internally.
void computeError()
Computes the error of the edge and stores it internally.
void computeError()
Computes the error of the edge and stores it internally.
Definition G2oTypes.h:400
void computeError()
Computes the error of the edge and stores it internally.
Definition G2oTypes.h:356
void computeError() final override
Computes the error of the edge and stores it internally.
Definition G2oTypes.h:772
void computeError() final override
Computes the error of the edge and stores it internally.
Definition G2oTypes.h:797
void computeError() override
Computes the error of the edge and stores it internally.
void computeError()
Computes the error of the edge and stores it internally.
Definition G2oTypes.h:477
void computeError()
Computes the error of the edge and stores it internally.
Definition G2oTypes.h:436
Represents a single image frame with extracted features and pose information.
Definition Frame.h:111
Represents the gravity direction as a rotation for optimization.
Definition G2oTypes.h:286
Eigen::Matrix3< g_type > Rgw
World-to-gravity and gravity-to-world rotations.
Definition G2oTypes.h:297
int its
Iteration counter.
Definition G2oTypes.h:299
Abstract interface for geometric camera models (pinhole, fisheye, etc.).
Represents a combined IMU and camera pose for graph optimization.
Definition G2oTypes.h:99
Eigen::Vector3< g_type > twb
IMU body-to-world translation.
Definition G2oTypes.h:153
int its
Iteration counter.
Definition G2oTypes.h:165
Buffer< Eigen::Vector3< g_type > > tbc
Camera-body and body-camera translations.
Definition G2oTypes.h:158
void UpdateW(const g_type *pu)
Updates the pose in the world reference frame.
ImuCamPose()
Default constructor.
Definition G2oTypes.h:102
Eigen::Matrix3< g_type > Rwb0
Initial body-to-world rotation for 4DoF pose graph.
Definition G2oTypes.h:162
ImuCamPose(Frame &pF)
Constructs from a Frame.
void Update(const g_type *pu)
Updates the pose in the IMU body reference frame.
Eigen::Vector3< g_type > ProjectStereo(const Eigen::Vector3< g_type > &Xw, int cam_idx=0) const
Projects a 3D world point to stereo coordinates.
bool isDepthPositive(const Eigen::Vector3< g_type > &Xw, int cam_idx=0) const
Checks whether a 3D point has positive depth in the given camera.
Eigen::Vector2< g_type > Project(const Eigen::Vector3< g_type > &Xw, int cam_idx=0) const
Projects a 3D world point to 2D (monocular).
void SetParam(const Buffer< Eigen::Matrix3< g_type > > &_Rcw, const Buffer< Eigen::Vector3< g_type > > &_tcw, const Buffer< Eigen::Matrix3< g_type > > &_Rbc, const Buffer< Eigen::Vector3< g_type > > &_tbc, const g_type &_bf)
Sets camera and IMU extrinsic parameters.
Eigen::Matrix3< g_type > DR
Delta rotation for 4DoF optimization.
Definition G2oTypes.h:163
Buffer< Eigen::Matrix3< g_type > > Rcw
Camera-to-world rotations per camera.
Definition G2oTypes.h:155
Buffer< Eigen::Matrix3< g_type > > Rbc
Camera-body and body-camera rotations.
Definition G2oTypes.h:157
g_type bf
Stereo baseline times focal length.
Definition G2oTypes.h:159
ImuCamPose(Eigen::Matrix3< g_type > &_Rwc, Eigen::Vector3< g_type > &_twc, KeyFrame *pKF)
Constructs from a rotation, translation, and keyframe.
Eigen::Matrix3< g_type > Rwb
IMU body-to-world rotation.
Definition G2oTypes.h:152
Buffer< GeometricCamera * > pCamera
Camera models.
Definition G2oTypes.h:160
Buffer< Eigen::Vector3< g_type > > tcw
Camera-to-world translations per camera.
Definition G2oTypes.h:156
Represents a 3D point parameterized by inverse depth in the host frame.
Definition G2oTypes.h:170
int its
Iteration counter.
Definition G2oTypes.h:190
InvDepthPoint(g_type _rho, g_type _u, g_type _v, KeyFrame *pHostKF)
Constructs from inverse depth and pixel coordinates.
g_type bf
Intrinsic parameters from the host frame.
Definition G2oTypes.h:189
void Update(const g_type *pu)
Updates the inverse depth from the optimization delta.
g_type v
Pixel observation coordinates in the host frame.
Definition G2oTypes.h:188
g_type rho
Inverse depth value.
Definition G2oTypes.h:187
InvDepthPoint()
Default constructor.
Definition G2oTypes.h:173
A keyframe in the SLAM map, derived from Frame.
Definition KeyFrame.h:31
Templated logic for doing matrix multiplication.
Definition Matrix.hpp:182
virtual void oplusImpl(const g_type *update_) final override
update the position of the node from the parameters in v.
Definition G2oTypes.h:275
virtual void oplusImpl(const g_type *update_) final override
update the position of the node from the parameters in v.
Definition G2oTypes.h:310
virtual void oplusImpl(const g_type *update_) final override
update the position of the node from the parameters in v.
Definition G2oTypes.h:258
virtual void oplusImpl(const g_type *update_) final override
update the position of the node from the parameters in v.
Definition G2oTypes.h:342
virtual void oplusImpl(const g_type *update_) override
update the position of the node from the parameters in v.
Definition G2oTypes.h:219
virtual void oplusImpl(const g_type *update_) final override
update the position of the node from the parameters in v.
Definition G2oTypes.h:201
virtual void oplusImpl(const g_type *update_) final override
update the position of the node from the parameters in v.
Definition G2oTypes.h:327
virtual void oplusImpl(const g_type *update_) final override
update the position of the node from the parameters in v.
Definition G2oTypes.h:239
The primary namespace for the NDEVR SDK.
Eigen::Matrix3< g_type > ExpSO3(const g_type x, const g_type y, const g_type z)
Computes the SO3 exponential map from axis components.
Eigen::Matrix< g_type, 15, 15 > Matrix15d
15x15 matrix type.
Definition G2oTypes.h:29
Eigen::Matrix< g_type, 12, 12 > Matrix12d
12x12 matrix type.
Definition G2oTypes.h:28
Eigen::Matrix< T, 3, 3 > NormalizeRotation(const Eigen::Matrix< T, 3, 3 > &R)
Normalizes a rotation matrix using SVD decomposition.
Definition G2oTypes.h:87
Eigen::Matrix< g_type, 12, 1 > vector12d
12-element vector type.
Definition G2oTypes.h:26
constexpr Angle< t_angle_type > abs(const Angle< t_angle_type > &value)
Changes an input with a negative sign, to a positive sign.
Eigen::Vector3< g_type > LogSO3(const Eigen::Matrix3< g_type > &R)
Computes the SO3 logarithm map.
Eigen::Matrix3< g_type > InverseRightJacobianSO3(const Eigen::Vector3< g_type > &v)
Computes the inverse right Jacobian of SO3.
Eigen::Matrix3< g_type > RightJacobianSO3(const Eigen::Vector3< g_type > &v)
Computes the right Jacobian of SO3.
Eigen::Matrix< g_type, 15, 1 > vector15d
15-element vector type.
Definition G2oTypes.h:27
Eigen::Matrix< g_type, 9, 9 > Matrix9d
9x9 matrix type.
Definition G2oTypes.h:30
Eigen::Matrix< g_type, 9, 1 > vector9d
9-element vector type.
Definition G2oTypes.h:25
Eigen::Matrix3< g_type > Skew(const Eigen::Vector3< g_type > &w)
Computes the skew-symmetric matrix of a 3D vector.
Eigen::Matrix< g_type, 6, 1 > vector6d
6-element vector type.
Definition G2oTypes.h:24