GridMap#

#include "navground/core/states/gridmap.h"
struct GridMap#

A grid map discretizes a portion of space, holding values in an Eigen matrix.

Public Types

using Map = Eigen::Array<uint8_t, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>#

An Eigen array, holding the grid map values.

using ExternalMap = Eigen::Map<Map, Eigen::RowMajor>#

An Eigen map, holding the grid map values.

using Cell = Eigen::Vector2<int>#

The indices of a cell

using ActionType = std::function<void(const Cell&)>#

An action to be applied to a cell during raytracing.

Public Functions

inline GridMap(unsigned width, unsigned height, double resolution, const Vector2 &origin = Vector2::Zero())#

Construct a grid map, storing values locally.

Parameters:
  • width[in] The width of the map in number of cells

  • height[in] The height of the map in number of cells

  • resolution[in] The resolution: size of one cell in meters.

  • origin[in] The position of the left-bottom corner of the map in meters.

inline GridMap(uint8_t *data, unsigned width, unsigned height, ng_float_t resolution, const Vector2 &origin = Vector2::Zero())#

Construct a grid map, linking external values.

Parameters:
  • data[in] A valid pointer to at least at least width x height values.

  • width[in] The width of the map in number of cells

  • height[in] The height of the map in number of cells

  • resolution[in] The resolution: size of one cell in meters.

  • origin[in] The position of the left-bottom corner of the map in meters.

inline Vector2 get_origin() const#

Gets the position of the bottom-left corner of the map in meters.

Returns:

The left-bottom position.

inline void set_origin(const Vector2 &value)#

Sets the the position of the bottom-left corner of the map in meters.

Parameters:

value[in] The desired value

inline Vector2 get_top_right() const#

Gets the position of the top-right corner of the map in meters.

Returns:

The top-right position.

inline Vector2 get_bottom_left() const#

Gets the position of the bottom-left corner of the map in meters.

Returns:

The left-bottom position.

inline Vector2 get_center() const#

Gets the position of the center of the map in meters.

Returns:

The center.

inline void set_center(const Vector2 &value)#

Sets the position of the center of the map in meters.

Parameters:

value[in] The desired value

inline ng_float_t get_resolution() const#

Gets the size of one cell in meters.

Returns:

The resolution.

inline void set_resolution(ng_float_t value)#

Sets the size of one cell in meters.

Parameters:

value[in] The desired positive value

inline unsigned get_width() const#

Gets the number of columns.

Returns:

The width.

inline void set_width(unsigned &value)#

Sets the number of columns.

Will resize the map if needed.

Parameters:

value – A positive value

inline unsigned get_height() const#

Gets the number of rows.

Returns:

The height.

inline void set_height(unsigned &value)#

Sets the number of rows.

Will resize the map if needed.

Parameters:

value – A positive value

inline const Eigen::Ref<const Map> get_map() const#

Returns a constant reference to the map.

Returns:

The map.

inline Eigen::Ref<Map> get_map()#

Returns a reference to the map.

Returns:

The map.

Vector2 get_position_of_cell(const Cell &cell) const#

Gets the position of a the center of a cell.

Does not check whether the cell is contained or not in the map.

Parameters:

cell[in] The cell indices

Returns:

The position in meters

std::optional<Cell> get_possible_cell_at_position(const Vector2 &position) const#

Gets the indices corresponding to a cell at a given position.

Parameters:

position[in] The position

Returns:

The cell or null if the cell lies outside of the map.

Cell get_cell_at_position(const Vector2 &position, bool clamp) const#

Gets the indices corresponding to a cell at a given position.

When the cell lies outside of the map, it either returns unbounded indices (clamp=false) or clamp them (clamp=false).

Parameters:
  • position[in] The position

  • clamp[in] Whether to clamp

Returns:

The cell.

bool contains_point(const Vector2 &point) const#

Checks whether the map contains a point.

Parameters:

point[in] The point

Returns:

True if the point is covered by the map.

void move_center(const Vector2 &position, uint8_t value = 128, bool snap = true)#

Moves the center of the map.

When snap is enabled, it constraints moves by multiple of the cell size.

Parameters:
  • position[in] The desired center position

  • value[in] The cell value set in regions not previously covered by the map.

  • snap[in] Whether to snap movements to the grid.

void move_origin(const Vector2 &position, uint8_t value = 128, bool snap = true)#

Moves the origin of the map.

When snap is enabled, it constraints moves by multiple of the cell size.

Parameters:
  • position[in] The desired origin (bottom-left corner) position

  • value[in] The cell value set in regions not previously covered by the map.

  • snap[in] Whether to snap movements to the grid.

void set_value(uint8_t value)#

Sets the value of all cells.

Parameters:

value[in] The value

void set_value_of_cell(const Cell &cell, uint8_t value)#

Sets the value of a single cell.

Parameters:
  • cell[in] The cell

  • value[in] The value

void set_value_at_point(const Vector2 &point, uint8_t value)#

Sets the value of the cell at a location.

Parameters:
  • point[in] The cell location in meters

  • value[in] The value

void set_value_in_rectangle(const Vector2 &bottom_left, ng_float_t width, ng_float_t height, uint8_t value)#

Sets the value of all cells in a spatial rectangle.

Parameters:
  • bottom_left[in] The bottom-left corner in meters

  • width[in] The rectangle width in meters

  • height[in] The rectangle height in meters

  • value[in] The value

void set_value_in_disc(const Vector2 &center, ng_float_t radius, uint8_t value)#

Sets the value of all cells in a disc.

Parameters:
  • center[in] The center of the disc in meters

  • radius[in] The radius of the disc in meters

  • value[in] The value

void set_value_on_line(const Vector2 &p1, const Vector2 &p2, uint8_t value)#

Sets the value of all cells along a line between to points.

Parameters:
  • p1[in] The line vertex in meters

  • p2[in] The other line vertex in meters

  • value[in] The value

void set_value_between_cells(const Cell &c1, const Cell &c2, uint8_t value)#

Sets the value of all cells along a line between two cells.

Parameters:
  • c1[in] The cell at one vertex

  • c2[in] The cell at the other vertex

  • value[in] The value

void raytrace_between_cells(ActionType at, Cell c1, Cell c2, unsigned int max_length = std::numeric_limits<unsigned int>::max(), unsigned int min_length = 0)#

Applies a function for each cell along a line between two cells using Bresenham’s line algorithms.

If the line has less than min_length cells, it will be ignored. If the line has more than max_length cells, it will be clipped.

Parameters:
  • at[in] The function

  • c1[in] The cell at one vertex

  • c2[in] The cell at the other vertex

  • max_length[in] The maximum number of cells

  • min_length[in] The minimum number of cells