LocalMapping.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /**
  2. * This file is part of ORB-SLAM3
  3. *
  4. * Copyright (C) 2017-2020 Carlos Campos, Richard Elvira, Juan J. Gómez Rodríguez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
  5. * Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
  6. *
  7. * ORB-SLAM3 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
  8. * License as published by the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * ORB-SLAM3 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
  12. * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with ORB-SLAM3.
  16. * If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef LOCALMAPPING_H
  19. #define LOCALMAPPING_H
  20. #include "KeyFrame.h"
  21. #include "Atlas.h"
  22. #include "LoopClosing.h"
  23. #include "Tracking.h"
  24. #include "KeyFrameDatabase.h"
  25. #include "Initializer.h"
  26. #include <mutex>
  27. namespace ORB_SLAM3
  28. {
  29. class System;
  30. class Tracking;
  31. class LoopClosing;
  32. class Atlas;
  33. class LocalMapping
  34. {
  35. public:
  36. LocalMapping(System* pSys, Atlas* pAtlas, const float bMonocular, bool bInertial, const string &_strSeqName=std::string());
  37. void SetLoopCloser(LoopClosing* pLoopCloser);
  38. void SetTracker(Tracking* pTracker);
  39. // Main function
  40. void Run();
  41. void InsertKeyFrame(KeyFrame* pKF);
  42. void EmptyQueue();
  43. // Thread Synch
  44. void RequestStop();
  45. void RequestReset();
  46. void RequestResetActiveMap(Map* pMap);
  47. bool Stop();
  48. void Release();
  49. bool isStopped();
  50. bool stopRequested();
  51. bool AcceptKeyFrames();
  52. void SetAcceptKeyFrames(bool flag);
  53. bool SetNotStop(bool flag);
  54. void InterruptBA();
  55. void RequestFinish();
  56. bool isFinished();
  57. int KeyframesInQueue(){
  58. unique_lock<std::mutex> lock(mMutexNewKFs);
  59. return mlNewKeyFrames.size();
  60. }
  61. bool IsInitializing();
  62. double GetCurrKFTime();
  63. KeyFrame* GetCurrKF();
  64. std::mutex mMutexImuInit;
  65. Eigen::MatrixXd mcovInertial;
  66. Eigen::Matrix3d mRwg;
  67. Eigen::Vector3d mbg;
  68. Eigen::Vector3d mba;
  69. double mScale;
  70. double mInitTime;
  71. double mCostTime;
  72. bool mbNewInit;
  73. unsigned int mInitSect;
  74. unsigned int mIdxInit;
  75. unsigned int mnKFs;
  76. double mFirstTs;
  77. int mnMatchesInliers;
  78. bool mbNotBA1;
  79. bool mbNotBA2;
  80. bool mbBadImu;
  81. bool mbWriteStats;
  82. // not consider far points (clouds)
  83. bool mbFarPoints;
  84. float mThFarPoints;
  85. #ifdef REGISTER_TIMES
  86. vector<double> vdKFInsert_ms;
  87. vector<double> vdMPCulling_ms;
  88. vector<double> vdMPCreation_ms;
  89. vector<double> vdLBA_ms;
  90. vector<double> vdKFCulling_ms;
  91. vector<double> vdLMTotal_ms;
  92. vector<double> vdLBASync_ms;
  93. vector<double> vdKFCullingSync_ms;
  94. vector<int> vnLBA_edges;
  95. vector<int> vnLBA_KFopt;
  96. vector<int> vnLBA_KFfixed;
  97. vector<int> vnLBA_MPs;
  98. int nLBA_exec;
  99. int nLBA_abort;
  100. #endif
  101. protected:
  102. bool CheckNewKeyFrames();
  103. void ProcessNewKeyFrame();
  104. void CreateNewMapPoints();
  105. void MapPointCulling();
  106. void SearchInNeighbors();
  107. void KeyFrameCulling();
  108. cv::Mat ComputeF12(KeyFrame* &pKF1, KeyFrame* &pKF2);
  109. cv::Matx33f ComputeF12_(KeyFrame* &pKF1, KeyFrame* &pKF2);
  110. cv::Mat SkewSymmetricMatrix(const cv::Mat &v);
  111. cv::Matx33f SkewSymmetricMatrix_(const cv::Matx31f &v);
  112. System *mpSystem;
  113. bool mbMonocular;
  114. bool mbInertial;
  115. void ResetIfRequested();
  116. bool mbResetRequested;
  117. bool mbResetRequestedActiveMap;
  118. Map* mpMapToReset;
  119. std::mutex mMutexReset;
  120. bool CheckFinish();
  121. void SetFinish();
  122. bool mbFinishRequested;
  123. bool mbFinished;
  124. std::mutex mMutexFinish;
  125. Atlas* mpAtlas;
  126. LoopClosing* mpLoopCloser;
  127. Tracking* mpTracker;
  128. std::list<KeyFrame*> mlNewKeyFrames;
  129. KeyFrame* mpCurrentKeyFrame;
  130. std::list<MapPoint*> mlpRecentAddedMapPoints;
  131. std::mutex mMutexNewKFs;
  132. bool mbAbortBA;
  133. bool mbStopped;
  134. bool mbStopRequested;
  135. bool mbNotStop;
  136. std::mutex mMutexStop;
  137. bool mbAcceptKeyFrames;
  138. std::mutex mMutexAccept;
  139. void InitializeIMU(float priorG = 1e2, float priorA = 1e6, bool bFirst = false);
  140. void ScaleRefinement();
  141. bool bInitializing;
  142. Eigen::MatrixXd infoInertial;
  143. int mNumLM;
  144. int mNumKFCulling;
  145. float mTinit;
  146. int countRefinement;
  147. //DEBUG
  148. ofstream f_lm;
  149. };
  150. } //namespace ORB_SLAM
  151. #endif // LOCALMAPPING_H