处理子图 4. 结束子图

void Submap2D::Finish()

1
2
3
4
CHECK(grid_);
CHECK(!insertion_finished());
grid_ = grid_->ComputeCroppedGrid();
set_insertion_finished(true);

这里的set_insertion_finished(true);就是子图结束建图了,可以添加函数isFinished判断,其实就是判断insertion_finished_是否true。 子图建完才会进入后端

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
std::unique_ptr<Grid2D> ProbabilityGrid::ComputeCroppedGrid() const
{
Eigen::Array2i offset;
CellLimits cell_limits;
ComputeCroppedLimits(&offset, &cell_limits);
const double resolution = limits().resolution();
const Eigen::Vector2d max =
limits().max() - resolution * Eigen::Vector2d(offset.y(), offset.x());
// conversion_tables_ 是两个表
std::unique_ptr<ProbabilityGrid> cropped_grid =
absl::make_unique<ProbabilityGrid>(
MapLimits(resolution, max, cell_limits), conversion_tables_);
// 对应的cell设置概率,在SetProbability里又转成了空闲概率
for (const Eigen::Array2i& xy_index : XYIndexRangeIterator(cell_limits))
{
if (!IsKnown(xy_index + offset)) continue;
cropped_grid->SetProbability(xy_index, GetProbability(xy_index + offset) );
}
return std::unique_ptr<Grid2D>(cropped_grid.release());
}
1
2
3
4
void set_insertion_finished(bool insertion_finished)
{
insertion_finished_ = insertion_finished;
}