Atlas.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 ATLAS_H
  19. #define ATLAS_H
  20. #include "Map.h"
  21. #include "MapPoint.h"
  22. #include "KeyFrame.h"
  23. #include "GeometricCamera.h"
  24. #include "Pinhole.h"
  25. #include "KannalaBrandt8.h"
  26. #include <set>
  27. #include <mutex>
  28. #include <boost/serialization/vector.hpp>
  29. #include <boost/serialization/export.hpp>
  30. namespace ORB_SLAM3
  31. {
  32. class Viewer;
  33. class Map;
  34. class MapPoint;
  35. class KeyFrame;
  36. class KeyFrameDatabase;
  37. class Frame;
  38. class KannalaBrandt8;
  39. class Pinhole;
  40. //BOOST_CLASS_EXPORT_GUID(Pinhole, "Pinhole")
  41. //BOOST_CLASS_EXPORT_GUID(KannalaBrandt8, "KannalaBrandt8")
  42. class Atlas
  43. {
  44. friend class boost::serialization::access;
  45. template<class Archive>
  46. void serialize(Archive &ar, const unsigned int version)
  47. {
  48. ar.template register_type<Pinhole>();
  49. ar.template register_type<KannalaBrandt8>();
  50. // Save/load a set structure, the set structure is broken in libboost 1.58 for ubuntu 16.04, a vector is serializated
  51. //ar & mspMaps;
  52. ar & mvpBackupMaps;
  53. ar & mvpCameras;
  54. // Need to save/load the static Id from Frame, KeyFrame, MapPoint and Map
  55. ar & Map::nNextId;
  56. ar & Frame::nNextId;
  57. ar & KeyFrame::nNextId;
  58. ar & MapPoint::nNextId;
  59. ar & GeometricCamera::nNextId;
  60. ar & mnLastInitKFidMap;
  61. }
  62. public:
  63. EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  64. Atlas();
  65. Atlas(int initKFid); // When its initialization the first map is created
  66. ~Atlas();
  67. void CreateNewMap();
  68. void ChangeMap(Map* pMap);
  69. unsigned long int GetLastInitKFid();
  70. void SetViewer(Viewer* pViewer);
  71. // Method for change components in the current map
  72. void AddKeyFrame(KeyFrame* pKF);
  73. void AddMapPoint(MapPoint* pMP);
  74. //void EraseMapPoint(MapPoint* pMP);
  75. //void EraseKeyFrame(KeyFrame* pKF);
  76. GeometricCamera* AddCamera(GeometricCamera* pCam);
  77. std::vector<GeometricCamera*> GetAllCameras();
  78. /* All methods without Map pointer work on current map */
  79. void SetReferenceMapPoints(const std::vector<MapPoint*> &vpMPs);
  80. void InformNewBigChange();
  81. int GetLastBigChangeIdx();
  82. long unsigned int MapPointsInMap();
  83. long unsigned KeyFramesInMap();
  84. // Method for get data in current map
  85. std::vector<KeyFrame*> GetAllKeyFrames();
  86. std::vector<MapPoint*> GetAllMapPoints();
  87. std::vector<MapPoint*> GetReferenceMapPoints();
  88. vector<Map*> GetAllMaps();
  89. int CountMaps();
  90. void clearMap();
  91. void clearAtlas();
  92. Map* GetCurrentMap();
  93. void SetMapBad(Map* pMap);
  94. void RemoveBadMaps();
  95. bool isInertial();
  96. void SetInertialSensor();
  97. void SetImuInitialized();
  98. bool isImuInitialized();
  99. // Function for garantee the correction of serialization of this object
  100. void PreSave();
  101. void PostLoad();
  102. map<long unsigned int, KeyFrame*> GetAtlasKeyframes();
  103. void SetKeyFrameDababase(KeyFrameDatabase* pKFDB);
  104. KeyFrameDatabase* GetKeyFrameDatabase();
  105. void SetORBVocabulary(ORBVocabulary* pORBVoc);
  106. ORBVocabulary* GetORBVocabulary();
  107. long unsigned int GetNumLivedKF();
  108. long unsigned int GetNumLivedMP();
  109. protected:
  110. std::set<Map*> mspMaps;
  111. std::set<Map*> mspBadMaps;
  112. // Its necessary change the container from set to vector because libboost 1.58 and Ubuntu 16.04 have an error with this cointainer
  113. std::vector<Map*> mvpBackupMaps;
  114. Map* mpCurrentMap;
  115. std::vector<GeometricCamera*> mvpCameras;
  116. unsigned long int mnLastInitKFidMap;
  117. Viewer* mpViewer;
  118. bool mHasViewer;
  119. // Class references for the map reconstruction from the save file
  120. KeyFrameDatabase* mpKeyFrameDB;
  121. ORBVocabulary* mpORBVocabulary;
  122. // Mutex
  123. std::mutex mMutexAtlas;
  124. }; // class Atlas
  125. } // namespace ORB_SLAM3
  126. #endif // ATLAS_H