grid_map::GridMap数据结构
主要的数据如下:
std::string frameId_; 坐标系名称;
std::unordered_map<std::string, Matrix> data_;每一层的地图数据,存放在一个Eigen的二维矩阵中;
Length length_; 将map的二维尺寸存放在一个Eigen二维向量中;
double resolution_; 栅格化表示地图的分辨率;
Position position_; 栅格地图几何中心在坐标系下的值;
Size size_; 栅格地图的x,y尺度(数量);
grid_map::GridMap坐标系
gridmap与cv::Mat坐标系
|<----------- width --------------->|
| |
-------|-----------------------------------|----> cols
^ | ^ |
| | x | |
| | | |
| | y | |
height | <-----------+--------------- |
| | | orig = position |
| | | |
| | | |
v | |
-------|-----------------------------------|
|
v
rows
gridmap-坐标系(x,y) 与 图像cv::Mat的转换:
其中,x,y为国际制单位;
double offset_x_set = img_height/2;
double offset_y_set = img_width/2;
cv::Point2i output;
output.y = -(x - map_center_x_value)/reslution + offset_x;
output.x = -(y - map_center_y_value)/reslution + offset_y;
grid_map::GridMap索引
GridMap二维索引(i,j)与数据存储的关系:
按照二维矩阵的方式存储数据,行为i,列为j,存储数据如下:
------------------------------
|(0,0)|(0,1)| ... |
|-----|----------------------|
|(1,0)|(1,1)| ... |
|-----|-----|----------------|
| | ... |
|-----|----------------------|
| | ... |
------------------------------
GridMap的索引(i,j)与图像cv::Mat所索引的关系:
GridMap与cv::Mat的数据索引顺序一致:
grid_map::Matrix& data = gridMap[layer];
cv::Mat imageMono;
data(i, j) = imageMono.at<Type_>(i, j);
GridMap的索引(i,j)与OccupancyGrid的索引(idx)关系:
OccupancyGrid的参数width,height;
已知(i,j),求取idx:
ix = width - i - 1;
iy = height - j - 1;
idx = ix + iy * width;
已知idx,求取(i,j):
iy = idx / width;
ix = idx % width;
i = width - ix - 1;
j = height - iy - 1;