载入中...
搜索中...
未找到
map.h
浏览该文件的文档.
1
12#pragma once
13
14#include "camera.h"
15#include "common_include.h"
16#include "config.h"
17
19struct MapPoint;
20
26struct Feature {
27 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
28 typedef std::shared_ptr<Feature> Ptr;
29
35 static Ptr create() {
36 Ptr feature(new Feature);
37 return feature;
38 }
39
40 std::weak_ptr<MapPoint> m_mapPoint;
42};
43
49struct MapPoint {
50 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
51 typedef std::shared_ptr<MapPoint> Ptr;
52
59 static Ptr create() {
60 static std::size_t pointNum = 0;
61 Ptr point(new MapPoint);
62 point->m_id = pointNum++;
63 return point;
64 }
65
66 bool m_isOutlier = false;
67 int m_featureNum = 0;
68 std::size_t m_id;
70};
71
76class Frame {
77public:
78 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
79 typedef std::shared_ptr<Frame> Ptr;
80
87 Frame(cv::Mat leftIMG, cv::Mat rightIMG)
88 : m_leftIMG(std::move(leftIMG))
89 , m_rightIMG(std::move(rightIMG)) {
90 static std::size_t frameNum = 0;
91 m_id = frameNum++;
92 }
93
94 std::vector<Feature::Ptr> &getLeftFeatures() { return m_leftFeatures; }
95 std::vector<Feature::Ptr> &getRightFeatures() { return m_rightFeatures; }
96
97 int initKeyFrame(const Camera::Ptr &camera);
98
99 static double distance(const Frame &left, const Frame &right);
100
101 SE3d &pose() { return m_pose; }
102 const SE3d &pose() const { return m_pose; }
103
104private:
105 std::vector<Feature::Ptr> m_leftFeatures;
106 std::vector<Feature::Ptr> m_rightFeatures;
108
109public:
110 std::size_t m_keyID = -1;
111 std::size_t m_id;
112 cv::Mat m_leftIMG;
113 cv::Mat m_rightIMG;
114 bool m_isKeyFrame = false;
115};
116
121class Map {
122public:
123 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
124
125 typedef std::shared_ptr<Map> Ptr;
126 typedef std::unordered_map<std::size_t, Frame::Ptr> FramesType;
127 typedef std::unordered_map<std::size_t, MapPoint::Ptr> PointsType;
128
129 Map(const Map &other) = delete;
130 Map &operator=(const Map &other) = delete;
131
132 void insertMapPoints(const std::vector<MapPoint::Ptr> &mapPoints) {
133 for (auto &point : mapPoints)
134 m_points.insert(std::make_pair(point->m_id, point));
135 }
136
144 void insertKeyFrame(const Frame::Ptr &keyFrame);
145
146 static Ptr getInstance() {
147 static Ptr map(new Map);
148 return map;
149 }
150
153
156
159
162
164 void removeOldFrame(const Frame::Ptr &keyFrame);
165
167 void cleanMap();
168
169private:
170 Map() = default;
175
176public:
177 std::mutex m_mutex;
178 std::condition_variable m_cond;
179 bool m_isReady = false;
180};
181
定义Camera相机类
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef std::shared_ptr< Camera > Ptr
Definition camera.h:27
Frame维护了一帧内的信息
Definition map.h:76
SE3d m_pose
Frame的位姿Tcw
Definition map.h:107
SE3d & pose()
Definition map.h:101
int initKeyFrame(const Camera::Ptr &camera)
设定关键帧,并进行特征检测、匹配
Definition map.cc:14
std::size_t m_keyID
关键帧id,如果fram是关键帧
Definition map.h:110
std::size_t m_id
索引(唯一)
Definition map.h:111
static double distance(const Frame &left, const Frame &right)
计算两个位姿之间的距离,以left为参考
Definition map.cc:89
std::vector< Feature::Ptr > m_leftFeatures
左图特征点
Definition map.h:105
std::vector< Feature::Ptr > & getLeftFeatures()
Definition map.h:94
std::vector< Feature::Ptr > & getRightFeatures()
Definition map.h:95
const SE3d & pose() const
Definition map.h:102
bool m_isKeyFrame
关键帧标识
Definition map.h:114
cv::Mat m_leftIMG
左图
Definition map.h:112
std::vector< Feature::Ptr > m_rightFeatures
右图特征点(不关联MapPoint)
Definition map.h:106
cv::Mat m_rightIMG
右图
Definition map.h:113
Frame(cv::Mat leftIMG, cv::Mat rightIMG)
Frame只提供左右图的构造方式
Definition map.h:87
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef std::shared_ptr< Frame > Ptr
Definition map.h:79
Map用作前端、展示和后端的交互中心(单例设计模式)
Definition map.h:121
void cleanMap()
在后端优化后,移除无用地图点
Definition map.cc:131
Map()=default
FramesType & getActiveFrames()
获取激活关键帧
Definition map.h:152
std::unordered_map< std::size_t, Frame::Ptr > FramesType
Definition map.h:126
std::condition_variable m_cond
条件变量,保证后端优化效率
Definition map.h:178
std::mutex m_mutex
地图锁,保证后端、前端和Viewer的线程安全
Definition map.h:177
Map(const Map &other)=delete
FramesType m_frames
存储slam过程中的关键帧
Definition map.h:171
PointsType m_points
存储slam过程中的地图点MapPoints
Definition map.h:172
void removeOldFrame(const Frame::Ptr &keyFrame)
移除关键帧(满足时间连续,空间展开原则)
Definition map.cc:95
bool m_isReady
搭配条件变量一起使 用
Definition map.h:179
Map & operator=(const Map &other)=delete
static Ptr getInstance()
Definition map.h:146
PointsType m_activePoints
存储待后端优化的points
Definition map.h:174
FramesType & getAllFrames()
获取地图中所有关键帧
Definition map.h:158
void insertMapPoints(const std::vector< MapPoint::Ptr > &mapPoints)
Definition map.h:132
PointsType & getActivePoints()
获取激活地图点
Definition map.h:155
FramesType m_activeFrames
存储待后端优化的frames
Definition map.h:173
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef std::shared_ptr< Map > Ptr
Definition map.h:125
std::unordered_map< std::size_t, MapPoint::Ptr > PointsType
Definition map.h:127
PointsType & getAllPoints()
获取地图中所有地图点
Definition map.h:161
void insertKeyFrame(const Frame::Ptr &keyFrame)
添加关键帧到Map中
Definition map.cc:146
引入所有所需头文件,定义所有所需超参数
#define NAMESPACE_END
Definition common_include.h:41
#define NAMESPACE_BEGIN
Definition common_include.h:40
NAMESPACE_BEGIN typedef Eigen::Vector2d Vec2d
Definition common_include.h:46
Sophus::SE3d SE3d
Definition common_include.h:57
Eigen::Vector3d Vec3d
Definition common_include.h:47
编写slam系统的超参数信息类
Feature维护了帧的特征点信息
Definition map.h:26
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef std::shared_ptr< Feature > Ptr
Definition map.h:28
std::weak_ptr< MapPoint > m_mapPoint
维护的MapPoint的weak_ptr
Definition map.h:40
static Ptr create()
Frame的简单工厂设计模式
Definition map.h:35
Vec2d m_position
维护了像素坐标系下的位置信息
Definition map.h:41
MapPoint为地图点
Definition map.h:49
static Ptr create()
MapPoint的简单工厂设计模式
Definition map.h:59
Vec3d m_position
世界坐标系上位置信息
Definition map.h:69
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef std::shared_ptr< MapPoint > Ptr
Definition map.h:51
bool m_isOutlier
outlier标识
Definition map.h:66
std::size_t m_id
唯一的id信息
Definition map.h:68
int m_featureNum
维护由**关键帧**指向地图点的Feature
Definition map.h:67