Map.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 MAP_H
  19. #define MAP_H
  20. #include "MapPoint.h"
  21. #include "KeyFrame.h"
  22. #include <set>
  23. #include <pangolin/pangolin.h>
  24. #include <mutex>
  25. #include <boost/serialization/base_object.hpp>
  26. namespace ORB_SLAM3
  27. {
  28. class MapPoint;
  29. class KeyFrame;
  30. class Atlas;
  31. class KeyFrameDatabase;
  32. class Map
  33. {
  34. friend class boost::serialization::access;
  35. template<class Archive>
  36. void serialize(Archive &ar, const unsigned int version)
  37. {
  38. ar & mnId;
  39. ar & mnInitKFid;
  40. ar & mnMaxKFid;
  41. ar & mnBigChangeIdx;
  42. // Save/load a set structure, the set structure is broken in libboost 1.58 for ubuntu 16.04, a vector is serializated
  43. //ar & mspKeyFrames;
  44. //ar & mspMapPoints;
  45. ar & mvpBackupKeyFrames;
  46. ar & mvpBackupMapPoints;
  47. ar & mvBackupKeyFrameOriginsId;
  48. ar & mnBackupKFinitialID;
  49. ar & mnBackupKFlowerID;
  50. ar & mbImuInitialized;
  51. ar & mbIsInertial;
  52. ar & mbIMU_BA1;
  53. ar & mbIMU_BA2;
  54. }
  55. public:
  56. EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  57. Map();
  58. Map(int initKFid);
  59. ~Map();
  60. void AddKeyFrame(KeyFrame* pKF);
  61. void AddMapPoint(MapPoint* pMP);
  62. void EraseMapPoint(MapPoint* pMP);
  63. void EraseKeyFrame(KeyFrame* pKF);
  64. void SetReferenceMapPoints(const std::vector<MapPoint*> &vpMPs);
  65. void InformNewBigChange();
  66. int GetLastBigChangeIdx();
  67. std::vector<KeyFrame*> GetAllKeyFrames();
  68. std::vector<MapPoint*> GetAllMapPoints();
  69. std::vector<MapPoint*> GetReferenceMapPoints();
  70. long unsigned int MapPointsInMap();
  71. long unsigned KeyFramesInMap();
  72. long unsigned int GetId();
  73. long unsigned int GetInitKFid();
  74. void SetInitKFid(long unsigned int initKFif);
  75. long unsigned int GetMaxKFid();
  76. KeyFrame* GetOriginKF();
  77. void SetCurrentMap();
  78. void SetStoredMap();
  79. bool HasThumbnail();
  80. bool IsInUse();
  81. void SetBad();
  82. bool IsBad();
  83. void clear();
  84. int GetMapChangeIndex();
  85. void IncreaseChangeIndex();
  86. int GetLastMapChange();
  87. void SetLastMapChange(int currentChangeId);
  88. void SetImuInitialized();
  89. bool isImuInitialized();
  90. void ApplyScaledRotation(const Sophus::SE3f &T, const float s, const bool bScaledVel=false);
  91. void SetInertialSensor();
  92. bool IsInertial();
  93. void SetIniertialBA1();
  94. void SetIniertialBA2();
  95. bool GetIniertialBA1();
  96. bool GetIniertialBA2();
  97. void PrintEssentialGraph();
  98. bool CheckEssentialGraph();
  99. void ChangeId(long unsigned int nId);
  100. unsigned int GetLowerKFID();
  101. void PreSave(std::set<GeometricCamera*> &spCams);
  102. void PostLoad(KeyFrameDatabase* pKFDB, ORBVocabulary* pORBVoc/*, map<long unsigned int, KeyFrame*>& mpKeyFrameId*/, map<unsigned int, GeometricCamera*> &mpCams);
  103. void printReprojectionError(list<KeyFrame*> &lpLocalWindowKFs, KeyFrame* mpCurrentKF, string &name, string &name_folder);
  104. vector<KeyFrame*> mvpKeyFrameOrigins;
  105. vector<unsigned long int> mvBackupKeyFrameOriginsId;
  106. KeyFrame* mpFirstRegionKF;
  107. std::mutex mMutexMapUpdate;
  108. // This avoid that two points are created simultaneously in separate threads (id conflict)
  109. std::mutex mMutexPointCreation;
  110. bool mbFail;
  111. // Size of the thumbnail (always in power of 2)
  112. static const int THUMB_WIDTH = 512;
  113. static const int THUMB_HEIGHT = 512;
  114. static long unsigned int nNextId;
  115. // DEBUG: show KFs which are used in LBA
  116. std::set<long unsigned int> msOptKFs;
  117. std::set<long unsigned int> msFixedKFs;
  118. protected:
  119. long unsigned int mnId;
  120. std::set<MapPoint*> mspMapPoints;
  121. std::set<KeyFrame*> mspKeyFrames;
  122. // Save/load, the set structure is broken in libboost 1.58 for ubuntu 16.04, a vector is serializated
  123. std::vector<MapPoint*> mvpBackupMapPoints;
  124. std::vector<KeyFrame*> mvpBackupKeyFrames;
  125. KeyFrame* mpKFinitial;
  126. KeyFrame* mpKFlowerID;
  127. unsigned long int mnBackupKFinitialID;
  128. unsigned long int mnBackupKFlowerID;
  129. std::vector<MapPoint*> mvpReferenceMapPoints;
  130. bool mbImuInitialized;
  131. int mnMapChange;
  132. int mnMapChangeNotified;
  133. long unsigned int mnInitKFid;
  134. long unsigned int mnMaxKFid;
  135. //long unsigned int mnLastLoopKFid;
  136. // Index related to a big change in the map (loop closure, global BA)
  137. int mnBigChangeIdx;
  138. // View of the map in aerial sight (for the AtlasViewer)
  139. GLubyte* mThumbnail;
  140. bool mIsInUse;
  141. bool mHasTumbnail;
  142. bool mbBad = false;
  143. bool mbIsInertial;
  144. bool mbIMU_BA1;
  145. bool mbIMU_BA2;
  146. // Mutex
  147. std::mutex mMutexMap;
  148. };
  149. } //namespace ORB_SLAM3
  150. #endif // MAP_H