Function navmap_ros::to_occupancy_grid

Function Documentation

nav_msgs::msg::OccupancyGrid navmap_ros::to_occupancy_grid(const navmap::NavMap &nm)

Convert a navmap::NavMap back to nav_msgs::msg::OccupancyGrid.

Two paths are considered:

  • Fast exact path: If the first surface encodes valid grid metadata (GridMeta) and there is a per-NavCel "occupancy" layer of type U8 with size 2 * W * H, the function reconstructs an OccupancyGrid exactly (linear inverse mapping 0..254 0..100, 255 -1).

  • Generic fallback: If the exact path is not applicable, the function samples cell centers via a navcel-locator (e.g., locate_navcel) and reads "occupancy" values to populate the grid.

Note

The fallback path assumes the presence of an "occupancy" layer. The precise sampling strategy (bounds, resolution, and handling of cells without a containing navcel) is implementation-defined.

Warning

If the map does not carry grid metadata or the "occupancy" layer is missing, the result may be incomplete or implementation-defined.

Parameters:

nm[in] Core NavMap to be rasterized as an occupancy grid.

Returns:

A ROS OccupancyGrid populated from nm.