Class SimpleMap
Defined in File SimpleMap.hpp
Class Documentation
Simple 2D uint8_t grid using basic C++ types, with full metric conversion support.
Supports arbitrary metric origins, allowing negative coordinates.
Public Functions
Default constructor.
Creates an empty (0x0) SimpleMap with 1.0 meter resolution and origin (0.0, 0.0).
Initialize the map to new dimensions, resolution, and origin.
- Parameters:
width – Number of columns.
height – Number of rows.
resolution – Size of each cell in meters.
origin_x – Metric X coordinate corresponding to cell (0,0).
origin_y – Metric Y coordinate corresponding to cell (0,0).
initial_value – Value to initialize all cells.
Returns the width (number of columns) of the map.
Returns the height (number of rows) of the map.
Returns the resolution (cell size in meters).
Returns the metric origin x coordinate.
Returns the metric origin y coordinate.
Access a cell (const) at (x, y).
- Throws:
std::out_of_range – if (x,y) is out of bounds.
Access a cell (non-const) at (x, y).
- Throws:
std::out_of_range – if (x,y) is out of bounds.
Set all cells to a given value.
- Parameters:
value – Value to fill the map with.
Performs a deep copy from another SimpleMap.
Copies width, height, resolution, origin, and all grid data.
- Parameters:
other – The SimpleMap to copy from.
Checks if given metric coordinates are within the map bounds.
- Parameters:
mx – Metric x coordinate.
my – Metric y coordinate.
- Returns:
true if inside the map bounds, false otherwise.
Converts a cell index (x, y) to real-world metric coordinates (meters).
- Parameters:
x – Cell column index.
y – Cell row index.
- Returns:
Pair (meters_x, meters_y).
Converts real-world metric coordinates (meters) to a cell index (x, y).
- Parameters:
mx – Metric x coordinate.
my – Metric y coordinate.
- Throws:
std::out_of_range – if resulting indices are out of map bounds.
- Returns:
Pair (x, y) cell indices.
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_msg – The occupancy grid message to fill or update.
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_msg – The occupancy grid message to load from.
Saves the map to a file, including metadata and cell data.
- Parameters:
path – Path to the output file.
- Returns:
true if the file was written successfully, false otherwise.
Loads the map from a file, reading metadata and cell data.
- Parameters:
path – Path to the input file.
- Returns:
true if the file was read successfully and is valid, false otherwise.
Prints metadata and optionally all map cell values with coordinates.
- Parameters:
view_data – If true, prints cell-by-cell content with coordinates. Default is false.
Creates a downsampled version of the map by an integer factor.
- Parameters:
factor – Integer factor (>1) to reduce resolution.
- Returns:
A shared pointer to the new downsampled SimpleMap.
Creates a downsampled version of the map to match a target resolution.
- Parameters:
new_resolution – New desired resolution (must be a multiple of current).
- Returns:
A shared pointer to the new downsampled SimpleMap.