Atlas.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 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 the set of maps, the set is broken in libboost 1.58 for ubuntu 16.04
  51. //ar & mspMaps;
  52. ar & mvpBackupMaps;
  53. ar & mvpCameras;
  54. //ar & mvpBackupCamPin;
  55. //ar & mvpBackupCamKan;
  56. // Need to save/load the static Id from Frame, KeyFrame, MapPoint and Map
  57. ar & Map::nNextId;
  58. ar & Frame::nNextId;
  59. ar & KeyFrame::nNextId;
  60. ar & MapPoint::nNextId;
  61. ar & GeometricCamera::nNextId;
  62. ar & mnLastInitKFidMap;
  63. }
  64. public:
  65. Atlas();
  66. Atlas(int initKFid); // When its initialization the first map is created
  67. ~Atlas();
  68. void CreateNewMap();
  69. void ChangeMap(Map* pMap);
  70. unsigned long int GetLastInitKFid();
  71. void SetViewer(Viewer* pViewer);
  72. // Method for change components in the current map
  73. void AddKeyFrame(KeyFrame* pKF);
  74. void AddMapPoint(MapPoint* pMP);
  75. //void EraseMapPoint(MapPoint* pMP);
  76. //void EraseKeyFrame(KeyFrame* pKF);
  77. void AddCamera(GeometricCamera* pCam);
  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. void SetKeyFrameDababase(KeyFrameDatabase* pKFDB);
  103. KeyFrameDatabase* GetKeyFrameDatabase();
  104. void SetORBVocabulary(ORBVocabulary* pORBVoc);
  105. ORBVocabulary* GetORBVocabulary();
  106. long unsigned int GetNumLivedKF();
  107. long unsigned int GetNumLivedMP();
  108. protected:
  109. std::set<Map*> mspMaps;
  110. std::set<Map*> mspBadMaps;
  111. // Its necessary change the container from set to vector because libboost 1.58 and Ubuntu 16.04 have an error with this cointainer
  112. std::vector<Map*> mvpBackupMaps;
  113. Map* mpCurrentMap;
  114. std::vector<GeometricCamera*> mvpCameras;
  115. std::vector<KannalaBrandt8*> mvpBackupCamKan;
  116. std::vector<Pinhole*> mvpBackupCamPin;
  117. //Pinhole testCam;
  118. std::mutex mMutexAtlas;
  119. unsigned long int mnLastInitKFidMap;
  120. Viewer* mpViewer;
  121. bool mHasViewer;
  122. // Class references for the map reconstruction from the save file
  123. KeyFrameDatabase* mpKeyFrameDB;
  124. ORBVocabulary* mpORBVocabulary;
  125. }; // class Atlas
  126. } // namespace ORB_SLAM3
  127. #endif // ATLAS_H