cell-map: many-layer 2D cellular maps
This crate provides the CellMap type, a 2D map with many layers comprised of
cells that can store arbitrary data. It is based on
ANYbotics/grid_map, a C++ ROS package
which provides the same type of data structre.
CellMap uses ndarray::Array2 to store its data in an efficient and
scalable format. It also uses nalgebra types for expressing vectors and
points.
Getting Started
Add cell-map to your dependencies:
[]
= "0.2"
Layers
Each layer of the cell map is represented by its own ndarray::Array2 array.
The map indexes each layer by an enum implementing the Layer trait. A derive
macro is provided to simplify this, for example:
use Layer;
The Layer trait is required to be Clone, and is recommended to be Debug.
Creating a CellMap
To create a new map:
use ;
use Vector2;
// Creates a new 5x5 map where each cell is 1.0 units wide, which is centred on (0, 0).
let my_map = new_from_elem;
Iterating Over Cells
CellMap provides the following iteration types over its cells:
CellIter- iterate each cell in the mapWindowIter- iterate a window through the map
All iterators also provide a mutable variant, and more iterators are planned in the future!
You can modify iterators so they produce Layered or Indexed iterators as
well.
// Check all the cells in our map are 1, this will be true
assert!;
// Use a window iterator to change all cells not on the border of the map to 2
my_map.window_iter_mut.unwrap.for_each;
// Overwrite all values on the Roughness layer to be zero
my_map.iter_mut.layer.for_each;
// Check that our map is how we expect it
for in my_map.iter.indexed