4141#include < pcl/point_cloud.h>
4242#include < pcl/point_types.h>
4343
44+ #include " std_msgs/msg/header.hpp"
4445#include " sensor_msgs/msg/point_cloud2.hpp"
4546#include " navmap_ros_interfaces/msg/nav_map.hpp"
4647#include " navmap_ros_interfaces/msg/nav_map_layer.hpp"
@@ -81,6 +82,7 @@ constexpr uint8_t FREE_SPACE = 0;
8182 * @brief Convert a core `navmap::NavMap` into its compact ROS transport message.
8283 *
8384 * @param[in] nm Core NavMap to be serialized into a ROS message.
85+ * @param[in] header Header to assign to the resulting message.
8486 * @return A `navmap_ros_interfaces::msg::NavMap` containing geometry (vertices, triangles),
8587 * surfaces metadata and user-defined layers.
8688 *
@@ -91,12 +93,20 @@ constexpr uint8_t FREE_SPACE = 0;
9193 * @note This function does not perform IO; it only builds the message in-memory.
9294 */
9395navmap_ros_interfaces::msg::NavMap to_msg (
94- const navmap::NavMap & nm);
96+ const navmap::NavMap & nm, const std_msgs::msg::Header & header);
97+
98+ /* *
99+ * @brief Backward-compatible overload (no header provided).
100+ *
101+ * The returned message header will be default-constructed.
102+ */
103+ navmap_ros_interfaces::msg::NavMap to_msg (const navmap::NavMap & nm);
95104
96105/* *
97106 * @brief Reconstruct a core `navmap::NavMap` from the ROS transport message.
98107 *
99108 * @param[in] msg Input `navmap_ros_interfaces::msg::NavMap` message.
109+ * @param[out] header Header extracted from the message.
100110 * @return A core `navmap::NavMap` equivalent to the content of @p msg.
101111 *
102112 * @details
@@ -105,13 +115,21 @@ navmap_ros_interfaces::msg::NavMap to_msg(
105115 *
106116 * @throw std::runtime_error If the message describes inconsistent geometry or layer sizes.
107117 */
118+ navmap::NavMap from_msg (
119+ const navmap_ros_interfaces::msg::NavMap & msg,
120+ std_msgs::msg::Header & header);
121+
122+ /* *
123+ * @brief Backward-compatible overload (ignores message header).
124+ */
108125navmap::NavMap from_msg (const navmap_ros_interfaces::msg::NavMap & msg);
109126
110127/* *
111128 * @brief Convert a single layer from a NavMap into a ROS message.
112129 *
113130 * @param[in] nm Input NavMap.
114131 * @param[in] layer Name of the layer to export.
132+ * @param[in] header Header to assign to the resulting message.
115133 * @return A NavMapLayer message containing the layer values and metadata.
116134 *
117135 * @details
@@ -121,6 +139,14 @@ navmap::NavMap from_msg(const navmap_ros_interfaces::msg::NavMap & msg);
121139 *
122140 * @throw std::runtime_error If the layer does not exist or has an unsupported type.
123141 */
142+ navmap_ros_interfaces::msg::NavMapLayer to_msg (
143+ const navmap::NavMap & nm,
144+ const std::string & layer,
145+ const std_msgs::msg::Header & header);
146+
147+ /* *
148+ * @brief Backward-compatible overload (no header provided).
149+ */
124150navmap_ros_interfaces::msg::NavMapLayer to_msg (
125151 const navmap::NavMap & nm,
126152 const std::string & layer);
@@ -133,6 +159,7 @@ navmap_ros_interfaces::msg::NavMapLayer to_msg(
133159 *
134160 * @param[in] msg Input NavMapLayer message.
135161 * @param[in,out] nm Destination NavMap (must already have navcels sized correctly).
162+ * @param[out] header Header extracted from the message.
136163 *
137164 * @details
138165 * - The function verifies that the length of the populated data array matches
@@ -141,6 +168,14 @@ navmap_ros_interfaces::msg::NavMapLayer to_msg(
141168 *
142169 * @throw std::runtime_error If sizes are inconsistent or the message is ill-formed.
143170 */
171+ void from_msg (
172+ const navmap_ros_interfaces::msg::NavMapLayer & msg,
173+ navmap::NavMap & nm,
174+ std_msgs::msg::Header & header);
175+
176+ /* *
177+ * @brief Backward-compatible overload (ignores message header).
178+ */
144179void from_msg (
145180 const navmap_ros_interfaces::msg::NavMapLayer & msg,
146181 navmap::NavMap & nm);
@@ -152,6 +187,7 @@ void from_msg(
152187 * using a regular triangular surface with shared vertices.
153188 *
154189 * @param[in] grid Input ROS OccupancyGrid (row-major, width×height, resolution and origin).
190+ * @param[out] header Header to assign to the resulting message.
155191 * @return A core `navmap::NavMap` with:
156192 * - Vertices: `(W+1) * (H+1)` laid on the grid plane, with `Z = grid.info.origin.position.z`.
157193 * - Triangles: `2 * W * H` (two per cell), using diagonal pattern = 0.
@@ -167,6 +203,13 @@ void from_msg(
167203 * @note The grid origin pose may contain a rotation. The vertex Z is taken from the origin Z;
168204 * handling of non-zero yaw/roll/pitch (if any) is implementation-defined in the builder.
169205 */
206+ navmap::NavMap from_occupancy_grid (
207+ const nav_msgs::msg::OccupancyGrid & grid,
208+ std_msgs::msg::Header & header);
209+
210+ /* *
211+ * @brief Backward-compatible overload (ignores grid header).
212+ */
170213navmap::NavMap from_occupancy_grid (const nav_msgs::msg::OccupancyGrid & grid);
171214
172215/* *
@@ -192,6 +235,13 @@ navmap::NavMap from_occupancy_grid(const nav_msgs::msg::OccupancyGrid & grid);
192235 * @warning If the map does not carry grid metadata or the `"occupancy"` layer is missing,
193236 * the result may be incomplete or implementation-defined.
194237 */
238+ nav_msgs::msg::OccupancyGrid to_occupancy_grid (
239+ const navmap::NavMap & nm,
240+ const std_msgs::msg::Header & header);
241+
242+ /* *
243+ * @brief Backward-compatible overload.
244+ */
195245nav_msgs::msg::OccupancyGrid to_occupancy_grid (const navmap::NavMap & nm);
196246
197247/* *
0 commit comments