LocalMapping.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /**
  2. * This file is part of ORB-SLAM3
  3. *
  4. * Copyright (C) 2017-2021 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 "Settings.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. EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  37. LocalMapping(System* pSys, Atlas* pAtlas, const float bMonocular, bool bInertial, const string &_strSeqName=std::string());
  38. void SetLoopCloser(LoopClosing* pLoopCloser);
  39. void SetTracker(Tracking* pTracker);
  40. // Main function
  41. void Run();
  42. void InsertKeyFrame(KeyFrame* pKF);
  43. void EmptyQueue();
  44. // Thread Synch
  45. void RequestStop();
  46. void RequestReset();
  47. void RequestResetActiveMap(Map* pMap);
  48. bool Stop();
  49. void Release();
  50. bool isStopped();
  51. bool stopRequested();
  52. bool AcceptKeyFrames();
  53. void SetAcceptKeyFrames(bool flag);
  54. bool SetNotStop(bool flag);
  55. void InterruptBA();
  56. void RequestFinish();
  57. bool isFinished();
  58. int KeyframesInQueue(){
  59. unique_lock<std::mutex> lock(mMutexNewKFs);
  60. return mlNewKeyFrames.size();
  61. }
  62. bool IsInitializing();
  63. double GetCurrKFTime();
  64. KeyFrame* GetCurrKF();
  65. std::mutex mMutexImuInit;
  66. Eigen::MatrixXd mcovInertial;
  67. Eigen::Matrix3d mRwg;
  68. Eigen::Vector3d mbg;
  69. Eigen::Vector3d mba;
  70. double mScale;
  71. double mInitTime;
  72. double mCostTime;
  73. unsigned int mInitSect;
  74. unsigned int mIdxInit;
  75. unsigned int mnKFs;
  76. double mFirstTs;
  77. int mnMatchesInliers;
  78. // For debugging (erase in normal mode)
  79. int mInitFr;
  80. int mIdxIteration;
  81. string strSequence;
  82. bool mbNotBA1;
  83. bool mbNotBA2;
  84. bool mbBadImu;
  85. bool mbWriteStats;
  86. // not consider far points (clouds)
  87. bool mbFarPoints;
  88. float mThFarPoints;
  89. #ifdef REGISTER_TIMES
  90. vector<double> vdKFInsert_ms;
  91. vector<double> vdMPCulling_ms;
  92. vector<double> vdMPCreation_ms;
  93. vector<double> vdLBA_ms;
  94. vector<double> vdKFCulling_ms;
  95. vector<double> vdLMTotal_ms;
  96. vector<double> vdLBASync_ms;
  97. vector<double> vdKFCullingSync_ms;
  98. vector<int> vnLBA_edges;
  99. vector<int> vnLBA_KFopt;
  100. vector<int> vnLBA_KFfixed;
  101. vector<int> vnLBA_MPs;
  102. int nLBA_exec;
  103. int nLBA_abort;
  104. #endif
  105. protected:
  106. bool CheckNewKeyFrames();
  107. void ProcessNewKeyFrame();
  108. void CreateNewMapPoints();
  109. void MapPointCulling();
  110. void SearchInNeighbors();
  111. void KeyFrameCulling();
  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