Map.cc
Go to the documentation of this file.
1 
21 #include "Map.h"
22 
23 #include<mutex>
24 
25 namespace ORB_SLAM2
26 {
27 
28 Map::Map():mnMaxKFid(0),mnBigChangeIdx(0)
29 {
30 }
31 
33 {
34  unique_lock<mutex> lock(mMutexMap);
35  mspKeyFrames.insert(pKF);
36  if(pKF->mnId>mnMaxKFid)
37  mnMaxKFid=pKF->mnId;
38 }
39 
41 {
42  unique_lock<mutex> lock(mMutexMap);
43  mspMapPoints.insert(pMP);
44 }
45 
47 {
48  unique_lock<mutex> lock(mMutexMap);
49  mspMapPoints.erase(pMP);
50 
51  // TODO: This only erase the pointer.
52  // Delete the MapPoint
53 }
54 
56 {
57  unique_lock<mutex> lock(mMutexMap);
58  mspKeyFrames.erase(pKF);
59 
60  // TODO: This only erase the pointer.
61  // Delete the MapPoint
62 }
63 
64 void Map::SetReferenceMapPoints(const vector<MapPoint *> &vpMPs)
65 {
66  unique_lock<mutex> lock(mMutexMap);
67  mvpReferenceMapPoints = vpMPs;
68 }
69 
71 {
72  unique_lock<mutex> lock(mMutexMap);
74 }
75 
77 {
78  unique_lock<mutex> lock(mMutexMap);
79  return mnBigChangeIdx;
80 }
81 
82 vector<KeyFrame*> Map::GetAllKeyFrames()
83 {
84  unique_lock<mutex> lock(mMutexMap);
85  return vector<KeyFrame*>(mspKeyFrames.begin(),mspKeyFrames.end());
86 }
87 
88 vector<MapPoint*> Map::GetAllMapPoints()
89 {
90  unique_lock<mutex> lock(mMutexMap);
91  return vector<MapPoint*>(mspMapPoints.begin(),mspMapPoints.end());
92 }
93 
94 long unsigned int Map::MapPointsInMap()
95 {
96  unique_lock<mutex> lock(mMutexMap);
97  return mspMapPoints.size();
98 }
99 
100 long unsigned int Map::KeyFramesInMap()
101 {
102  unique_lock<mutex> lock(mMutexMap);
103  return mspKeyFrames.size();
104 }
105 
106 vector<MapPoint*> Map::GetReferenceMapPoints()
107 {
108  unique_lock<mutex> lock(mMutexMap);
109  return mvpReferenceMapPoints;
110 }
111 
112 long unsigned int Map::GetMaxKFid()
113 {
114  unique_lock<mutex> lock(mMutexMap);
115  return mnMaxKFid;
116 }
117 
119 {
120  for(set<MapPoint*>::iterator sit=mspMapPoints.begin(), send=mspMapPoints.end(); sit!=send; sit++)
121  delete *sit;
122 
123  for(set<KeyFrame*>::iterator sit=mspKeyFrames.begin(), send=mspKeyFrames.end(); sit!=send; sit++)
124  delete *sit;
125 
126  mspMapPoints.clear();
127  mspKeyFrames.clear();
128  mnMaxKFid = 0;
129  mvpReferenceMapPoints.clear();
130  mvpKeyFrameOrigins.clear();
131 }
132 
133 // map serialization addition
134 template<class Archive>
135 void Map::serialize(Archive &ar, const unsigned int version)
136 {
137  // don't save mutex
138  unique_lock<mutex> lock_MapUpdate(mMutexMapUpdate);
139  unique_lock<mutex> lock_Map(mMutexMap);
140  ar & mspMapPoints;
141  ar & mvpKeyFrameOrigins;
142  ar & mspKeyFrames;
144  ar & mnMaxKFid & mnBigChangeIdx;
145 }
146 template void Map::serialize(boost::archive::binary_iarchive&, const unsigned int);
147 template void Map::serialize(boost::archive::binary_oarchive&, const unsigned int);
148 
149 } //namespace ORB_SLAM
long unsigned int GetMaxKFid()
Definition: Map.cc:112
void EraseMapPoint(MapPoint *pMP)
Definition: Map.cc:46
void InformNewBigChange()
Definition: Map.cc:70
std::mutex mMutexMap
Definition: Map.h:81
std::vector< MapPoint * > mvpReferenceMapPoints
Definition: Map.h:74
std::vector< KeyFrame * > GetAllKeyFrames()
Definition: Map.cc:82
std::mutex mMutexMapUpdate
Definition: Map.h:65
std::vector< MapPoint * > GetReferenceMapPoints()
Definition: Map.cc:106
void AddMapPoint(MapPoint *pMP)
Definition: Map.cc:40
std::vector< MapPoint * > GetAllMapPoints()
Definition: Map.cc:88
long unsigned int mnMaxKFid
Definition: Map.h:76
vector< KeyFrame * > mvpKeyFrameOrigins
Definition: Map.h:63
int mnBigChangeIdx
Definition: Map.h:79
long unsigned KeyFramesInMap()
Definition: Map.cc:100
void clear()
Definition: Map.cc:118
long unsigned int MapPointsInMap()
Definition: Map.cc:94
void EraseKeyFrame(KeyFrame *pKF)
Definition: Map.cc:55
std::set< MapPoint * > mspMapPoints
Definition: Map.h:71
void serialize(Archive &ar, const unsigned int version)
Definition: Map.cc:135
void SetReferenceMapPoints(const std::vector< MapPoint * > &vpMPs)
Definition: Map.cc:64
void AddKeyFrame(KeyFrame *pKF)
Definition: Map.cc:32
int GetLastBigChangeIdx()
Definition: Map.cc:76
long unsigned int mnId
Definition: KeyFrame.h:125
std::set< KeyFrame * > mspKeyFrames
Definition: Map.h:72


orb_slam2_ros
Author(s):
autogenerated on Wed Apr 21 2021 02:53:05