EasyNav Simple Stack
Loading...
Searching...
No Matches
SimpleMap Class Reference

Simple 2D uint8_t grid using basic C++ types, with full metric conversion support. More...

#include <SimpleMap.hpp>

Public Member Functions

uint8_t & at (int x, int y)
 Access a cell (non-const) at (x, y).
 
uint8_t at (int x, int y) const
 Access a cell (const) at (x, y).
 
std::pair< double, double > cell_to_metric (int x, int y) const
 Converts a cell index (x, y) to real-world metric coordinates (meters).
 
bool check_bounds_metric (double mx, double my) const
 Checks if given metric coordinates are within the map bounds.
 
void deep_copy (const SimpleMap &other)
 Performs a deep copy from another SimpleMap.
 
std::shared_ptr< SimpleMapdownsample (double new_resolution) const
 Creates a downsampled version of the map to match a target resolution.
 
std::shared_ptr< SimpleMapdownsample_factor (int factor) const
 Creates a downsampled version of the map by an integer factor.
 
void fill (uint8_t value)
 Set all cells to a given value.
 
void from_occupancy_grid (const nav_msgs::msg::OccupancyGrid &grid_msg)
 Load map data and metadata from a nav_msgs::msg::OccupancyGrid message.
 
size_t height () const
 Returns the height (number of rows) of the map.
 
void initialize (int width, int height, double resolution, double origin_x, double origin_y, bool initial_value=false)
 Initialize the map to new dimensions, resolution, and origin.
 
bool load_from_file (const std::string &path)
 Loads the map from a file, reading metadata and cell data.
 
std::pair< int, int > metric_to_cell (double mx, double my) const
 Converts real-world metric coordinates (meters) to a cell index (x, y).
 
double origin_x () const
 Returns the metric origin x coordinate.
 
double origin_y () const
 Returns the metric origin y coordinate.
 
void print (bool view_data=false) const
 Prints metadata and optionally all map cell values with coordinates.
 
double resolution () const
 Returns the resolution (cell size in meters).
 
bool save_to_file (const std::string &path) const
 Saves the map to a file, including metadata and cell data.
 
 SimpleMap ()
 Default constructor.
 
void to_occupancy_grid (nav_msgs::msg::OccupancyGrid &grid_msg) const
 Updates a nav_msgs::msg::OccupancyGrid message from the SimpleMap contents.
 
size_t width () const
 Returns the width (number of columns) of the map.
 

Detailed Description

Simple 2D uint8_t grid using basic C++ types, with full metric conversion support.

Supports arbitrary metric origins, allowing negative coordinates.

Constructor & Destructor Documentation

◆ SimpleMap()

SimpleMap ( )

Default constructor.

Creates an empty (0x0) SimpleMap with 1.0 meter resolution and origin (0.0, 0.0).

Member Function Documentation

◆ at() [1/2]

uint8_t & at ( int x,
int y )

Access a cell (non-const) at (x, y).

Exceptions
std::out_of_rangeif (x,y) is out of bounds.

◆ at() [2/2]

uint8_t at ( int x,
int y ) const

Access a cell (const) at (x, y).

Exceptions
std::out_of_rangeif (x,y) is out of bounds.

◆ cell_to_metric()

std::pair< double, double > cell_to_metric ( int x,
int y ) const

Converts a cell index (x, y) to real-world metric coordinates (meters).

Parameters
xCell column index.
yCell row index.
Returns
Pair (meters_x, meters_y).

◆ check_bounds_metric()

bool check_bounds_metric ( double mx,
double my ) const

Checks if given metric coordinates are within the map bounds.

Parameters
mxMetric x coordinate.
myMetric y coordinate.
Returns
true if inside the map bounds, false otherwise.

◆ deep_copy()

void deep_copy ( const SimpleMap & other)

Performs a deep copy from another SimpleMap.

Copies width, height, resolution, origin, and all grid data.

Parameters
otherThe SimpleMap to copy from.

◆ downsample()

std::shared_ptr< SimpleMap > downsample ( double new_resolution) const

Creates a downsampled version of the map to match a target resolution.

Parameters
new_resolutionNew desired resolution (must be a multiple of current).
Returns
A shared pointer to the new downsampled SimpleMap.

◆ downsample_factor()

std::shared_ptr< SimpleMap > downsample_factor ( int factor) const

Creates a downsampled version of the map by an integer factor.

Parameters
factorInteger factor (>1) to reduce resolution.
Returns
A shared pointer to the new downsampled SimpleMap.

◆ fill()

void fill ( uint8_t value)

Set all cells to a given value.

Parameters
valueValue to fill the map with.

◆ from_occupancy_grid()

void from_occupancy_grid ( const nav_msgs::msg::OccupancyGrid & grid_msg)

Load map data and metadata from a nav_msgs::msg::OccupancyGrid message.

This function resizes the internal grid to match the occupancy grid dimensions, sets the resolution and origin, and copies the data.

Parameters
grid_msgThe occupancy grid message to load from.

◆ height()

size_t height ( ) const

Returns the height (number of rows) of the map.

◆ initialize()

void initialize ( int width,
int height,
double resolution,
double origin_x,
double origin_y,
bool initial_value = false )

Initialize the map to new dimensions, resolution, and origin.

Parameters
widthNumber of columns.
heightNumber of rows.
resolutionSize of each cell in meters.
origin_xMetric X coordinate corresponding to cell (0,0).
origin_yMetric Y coordinate corresponding to cell (0,0).
initial_valueValue to initialize all cells.

◆ load_from_file()

bool load_from_file ( const std::string & path)

Loads the map from a file, reading metadata and cell data.

Parameters
pathPath to the input file.
Returns
true if the file was read successfully and is valid, false otherwise.

◆ metric_to_cell()

std::pair< int, int > metric_to_cell ( double mx,
double my ) const

Converts real-world metric coordinates (meters) to a cell index (x, y).

Parameters
mxMetric x coordinate.
myMetric y coordinate.
Returns
Pair (x, y) cell indices.
Exceptions
std::out_of_rangeif resulting indices are out of map bounds.

◆ origin_x()

double origin_x ( ) const

Returns the metric origin x coordinate.

◆ origin_y()

double origin_y ( ) const

Returns the metric origin y coordinate.

◆ print()

void print ( bool view_data = false) const

Prints metadata and optionally all map cell values with coordinates.

Parameters
view_dataIf true, prints cell-by-cell content with coordinates. Default is false.

◆ resolution()

double resolution ( ) const

Returns the resolution (cell size in meters).

◆ save_to_file()

bool save_to_file ( const std::string & path) const

Saves the map to a file, including metadata and cell data.

Parameters
pathPath to the output file.
Returns
true if the file was written successfully, false otherwise.

◆ to_occupancy_grid()

void to_occupancy_grid ( nav_msgs::msg::OccupancyGrid & grid_msg) const

Updates a nav_msgs::msg::OccupancyGrid message from the SimpleMap contents.

Cells are mapped as follows:

  • true -> 100 (occupied)
  • false -> 0 (free)

If the grid dimensions do not match, the message is rdata_esized automatically.

Parameters
grid_msgThe occupancy grid message to fill or update.

◆ width()

size_t width ( ) const

Returns the width (number of columns) of the map.


The documentation for this class was generated from the following files: