12个版本 (4个重大变更)

0.5.3 2021年7月23日
0.5.2 2021年7月23日
0.4.1 2021年6月30日
0.3.2 2021年6月28日
0.1.0 2021年5月8日

#1635算法

每月28次下载

自定义许可证

125KB
2K SLoC

cell-map: 多层2D细胞地图

Crates.io docs.rs

此crate提供了CellMap类型,它是一个由细胞组成的多层2D地图,可以存储任意数据。它基于ANYbotics/grid_map,一个C++ ROS包,它提供相同类型的数据结构。

CellMap使用ndarray::Array2以高效和可扩展的格式存储其数据。它还使用nalgebra类型来表示向量和点。

入门指南

细胞地图的每一层都由其自己的ndarray::Array2数组表示。地图通过实现Layer trait的枚举来索引每一层。提供衍生宏来简化此过程,例如

use cell_map::Layer;

#[derive(Layer, Clone, Debug)]
enum MyLayer {
    Height,
    Gradient,
    Roughness
}

Layer trait需要是Clone,并建议是Debug

创建CellMap

要创建一个新的地图

use cell_map::{CellMap, CellMapParams, Layer};
use nalgebra::Vector2;

// Creates a new 5x5 map where each cell is 1.0 units wide, which is centred on (0, 0), with
// all elements initialised to 1.0.
let my_map = CellMap::<MyLayer, f64>::new_from_elem(
    CellMapParams {
        cell_size: Vector2::new(1.0, 1.0),
        cell_bounds: Bounds::new((0, 5), (0, 5)).unwrap(),
        centre: Vector2::new(0.0, 0.0),
    },
    1.0,
);

遍历细胞

CellMap提供了遍历其数据的方法

  • CellMap::iter()提供对地图每一层的所有细胞的迭代器
  • CellMap::window_iter()提供对地图中矩形窗口的迭代器
  • CellMap::line_iter()提供两个世界点之间的细胞迭代器

所有迭代器还提供了一个可变版本,未来还将计划更多迭代器!

您可以根据需要修改迭代器,使它们生成它们的索引,以及控制数据来自哪些层。有关更多信息,请参阅iterators

// Check all the cells in our map are 1, this will be true
assert!(my_map.iter().all(|&v| v == 1.0));

// Use a window iterator to change all cells not on the border of the map to 2
my_map.window_iter_mut(Vector2::new(1, 1)).unwrap().for_each(|mut v| {
    v[(1, 1)] = 2.0;
});

// Overwrite all values on the Roughness layer to be zero
my_map.iter_mut().layer(MyLayer::Roughness).for_each(|v| *v = 0.0);

// Check that our map is how we expect it
for ((layer, cell), &value) in my_map.iter().indexed() {
    if matches!(layer, MyLayer::Roughness) {
        assert_eq!(value, 0.0);
    }
    else if cell.x == 0 || cell.x == 4 || cell.y == 0 || cell.y == 4 {
        assert_eq!(value, 1.0);
    }
    else {
        assert_eq!(value, 2.0);
    }
}

依赖关系

~6MB
~122K SLoC