33 #ifndef GSLAM_CORE_HASHMAP_H_ 34 #define GSLAM_CORE_HASHMAP_H_ 36 #include <unordered_map> 42 typedef std::unordered_map<PointID, PointPtr> PointMap;
43 typedef std::unordered_map<FrameID, FramePtr> FrameMap;
44 typedef PointMap::iterator PointIt;
45 typedef FrameMap::iterator FrameIt;
46 typedef PointMap::const_iterator ConstPointIt;
47 typedef FrameMap::const_iterator ConstFrameIt;
55 virtual std::string type()
const {
return "HashMap"; }
59 virtual bool insertMapFrame(
const FramePtr& frame);
60 virtual bool eraseMapPoint(
const PointID& pointId);
61 virtual bool eraseMapFrame(
const FrameID& frameId);
64 virtual std::size_t frameNum()
const;
65 virtual std::size_t pointNum()
const;
67 virtual FramePtr getFrame(
const FrameID&
id)
const;
68 virtual PointPtr getPoint(
const PointID&
id)
const;
69 virtual bool getFrames(FrameArray& frames)
const;
70 virtual bool getPoints(PointArray& points)
const;
73 virtual bool save(std::string path)
const;
74 virtual bool load(std::string path);
79 mutable MutexRW _mutexPoints, _mutexFrames;
83 WriteMutex lock(_mutexPoints);
84 PointIt it = _points.find(point->id());
85 if (it != _points.end())
return false;
86 _points.insert(make_pair(point->id(), point));
90 inline bool HashMap::insertMapFrame(
const FramePtr& frame) {
91 WriteMutex lock(_mutexFrames);
92 FrameIt it = _frames.find(frame->id());
93 if (it != _frames.end())
return false;
94 _frames.insert(make_pair(frame->id(), frame));
98 inline bool HashMap::eraseMapPoint(
const PointID& pointId) {
99 WriteMutex lock(_mutexPoints);
100 return _points.erase(pointId) != 0;
103 inline bool HashMap::eraseMapFrame(
const FrameID& frameId) {
104 WriteMutex lock(_mutexFrames);
105 return _frames.erase(frameId) != 0;
108 inline void HashMap::clear() {
109 WriteMutex lock1(_mutexFrames);
110 WriteMutex lock2(_mutexPoints);
115 inline std::size_t HashMap::frameNum()
const {
116 ReadMutex lock(_mutexFrames);
117 return _frames.size();
120 inline std::size_t HashMap::pointNum()
const {
121 ReadMutex lock(_mutexPoints);
122 return _points.size();
125 inline FramePtr HashMap::getFrame(
const FrameID&
id)
const {
126 ReadMutex lock(_mutexFrames);
127 ConstFrameIt it = _frames.find(
id);
128 if (it != _frames.end())
134 inline PointPtr HashMap::getPoint(
const PointID&
id)
const {
135 ReadMutex lock(_mutexPoints);
136 ConstPointIt it = _points.find(
id);
137 if (it != _points.end())
143 inline bool HashMap::getFrames(FrameArray& frames)
const {
144 ReadMutex lock(_mutexFrames);
146 frames.reserve(_frames.size());
147 for (
const std::pair<FrameID, FramePtr>& fr : _frames)
148 frames.push_back(fr.second);
152 inline bool HashMap::getPoints(PointArray& points)
const {
153 ReadMutex lock(_mutexPoints);
155 points.reserve(_points.size());
156 for (
const std::pair<PointID, PointPtr>& pt : _points)
157 points.push_back(pt.second);
164 inline bool HashMap::load(std::string path) {
return false; }
166 #endif // GSLAM_CORE_HASHMAP_H_
virtual bool save(std::string path) const
Save or load the map from/to the file.
Definition: HashMap.h:162
virtual bool insertMapPoint(const PointPtr &point)
MapFrame & MapPoint interface.
Definition: HashMap.h:82