NavMap
Loading...
Searching...
No Matches
test_conversions.cpp File Reference
#include <gtest/gtest.h>
#include <nav_msgs/msg/occupancy_grid.hpp>
#include "navmap_ros_interfaces/msg/nav_map_layer.hpp"
#include "navmap_ros_interfaces/msg/nav_map.hpp"
#include "navmap_ros/conversions.hpp"
#include "navmap_core/NavMap.hpp"
Include dependency graph for test_conversions.cpp:

Functions

navmap::NavMap from_occupancy_grid (const nav_msgs::msg::OccupancyGrid &grid)
 Build a navmap::NavMap from a nav_msgs::msg::OccupancyGrid using a regular triangular surface with shared vertices.
 
 TEST (NavMap_FullConversions, EmptyMap_RoundTrip)
 
 TEST (NavMap_FullConversions, RoundTrip_All)
 
 TEST (NavMap_LayerConversions, F32_RoundTrip)
 
 TEST (NavMap_LayerConversions, F64_RoundTrip)
 
 TEST (NavMap_LayerConversions, ToMsg_Throws_OnMissingLayer)
 
 TEST (NavMap_LayerConversions, U8_RoundTrip)
 
 TEST (TestConversions, RoundTrip_ExactEquality_4m_0p1)
 
 TEST (TestConversions, TriangleIndicesFollowPattern0)
 
nav_msgs::msg::OccupancyGrid to_occupancy_grid (const navmap::NavMap &nm)
 Convert a navmap::NavMap back to nav_msgs::msg::OccupancyGrid.
 

Function Documentation

◆ from_occupancy_grid()

navmap::NavMap from_occupancy_grid ( const nav_msgs::msg::OccupancyGrid & grid)

Build a navmap::NavMap from a nav_msgs::msg::OccupancyGrid using a regular triangular surface with shared vertices.

Parameters
[in]gridInput ROS OccupancyGrid (row-major, width×height, resolution and origin).
Returns
A core navmap::NavMap with:
  • Vertices: (W+1) * (H+1) laid on the grid plane, with Z = grid.info.origin.position.z.
  • Triangles: 2 * W * H (two per cell), using diagonal pattern = 0.
  • One surface whose frame matches grid.header.frame_id, and grid metadata filled.
  • A per-NavCel layer named "occupancy" of type uint8, with values mapped as: -1 → 255 (unknown), 0..100 → 0..254 (linear scaling).
  • Vertex layout follows the grid indexation with shared vertices across adjacent cells.
  • Triangle winding and diagonal split are deterministic (pattern = 0).
  • If width == 0 or height == 0, the returned map contains no triangles.
Note
The grid origin pose may contain a rotation. The vertex Z is taken from the origin Z; handling of non-zero yaw/roll/pitch (if any) is implementation-defined in the builder.

◆ TEST() [1/8]

TEST ( NavMap_FullConversions ,
EmptyMap_RoundTrip  )

◆ TEST() [2/8]

TEST ( NavMap_FullConversions ,
RoundTrip_All  )

◆ TEST() [3/8]

TEST ( NavMap_LayerConversions ,
F32_RoundTrip  )

◆ TEST() [4/8]

TEST ( NavMap_LayerConversions ,
F64_RoundTrip  )

◆ TEST() [5/8]

TEST ( NavMap_LayerConversions ,
ToMsg_Throws_OnMissingLayer  )

◆ TEST() [6/8]

TEST ( NavMap_LayerConversions ,
U8_RoundTrip  )

◆ TEST() [7/8]

TEST ( TestConversions ,
RoundTrip_ExactEquality_4m_0p1  )

◆ TEST() [8/8]

TEST ( TestConversions ,
TriangleIndicesFollowPattern0  )

◆ to_occupancy_grid()

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

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

Parameters
[in]nmCore NavMap to be rasterized as an occupancy grid.
Returns
A ROS OccupancyGrid populated from nm.

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.