NavMap
Loading...
Searching...
No Matches
conversions.hpp
Go to the documentation of this file.
1// Copyright 2025 Intelligent Robotics Lab
2//
3// This file is part of the project Easy Navigation (EasyNav in short)
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16
17#ifndef NAVMAP_ROS__CONVERSIONS_HPP_
18#define NAVMAP_ROS__CONVERSIONS_HPP_
19
38
39#include <string>
40
41#include "Eigen/Core"
42#include "pcl/point_cloud.h"
43#include "pcl/point_types.h"
44#include "std_msgs/msg/header.hpp"
45#include "sensor_msgs/msg/point_cloud2.hpp"
46#include "navmap_ros_interfaces/msg/nav_map.hpp"
47#include "navmap_ros_interfaces/msg/nav_map_layer.hpp"
48#include "nav_msgs/msg/occupancy_grid.hpp"
49#include "navmap_core/Costs.hpp"
51
56namespace navmap_ros
57{
58
59// Cost values (costmap_2d convention), defined in navmap_core/Costs.hpp
65
66// --------- NavMap <-> ROS message ---------
67
82navmap_ros_interfaces::msg::NavMap to_msg(
83 const navmap::NavMap & nm, const std_msgs::msg::Header & header);
84
90navmap_ros_interfaces::msg::NavMap to_msg(const navmap::NavMap & nm);
91
106 const navmap_ros_interfaces::msg::NavMap & msg,
107 std_msgs::msg::Header & header);
108
112navmap::NavMap from_msg(const navmap_ros_interfaces::msg::NavMap & msg);
113
129navmap_ros_interfaces::msg::NavMapLayer to_msg(
130 const navmap::NavMap & nm,
131 const std::string & layer,
132 const std_msgs::msg::Header & header);
133
137navmap_ros_interfaces::msg::NavMapLayer to_msg(
138 const navmap::NavMap & nm,
139 const std::string & layer);
140
150navmap_ros_interfaces::msg::NavMapLayer to_layer_update_msg(
151 const navmap::NavMap & nm, const std::string & layer,
152 const std_msgs::msg::Header & header = std_msgs::msg::Header(),
153 float max_sparse_fraction = 0.25f);
154
174void from_msg(
175 const navmap_ros_interfaces::msg::NavMapLayer & msg,
176 navmap::NavMap & nm,
177 std_msgs::msg::Header & header);
178
182void from_msg(
183 const navmap_ros_interfaces::msg::NavMapLayer & msg,
184 navmap::NavMap & nm);
185
186// --------- OccupancyGrid <-> NavMap (shared vertices, per-NavCel layer) ---------
187
210 const nav_msgs::msg::OccupancyGrid & grid,
211 std_msgs::msg::Header & header);
212
216navmap::NavMap from_occupancy_grid(const nav_msgs::msg::OccupancyGrid & grid);
217
241nav_msgs::msg::OccupancyGrid to_occupancy_grid(
242 const navmap::NavMap & nm,
243 const std_msgs::msg::Header & header);
244
248nav_msgs::msg::OccupancyGrid to_occupancy_grid(const navmap::NavMap & nm);
249
259{
261 float resolution = 1.0;
262
264 float max_edge_len = 2.0;
265
267 float max_dz = 0.25f;
268
270 float max_slope_deg = 30.0f; // maximum slope w.r.t. vertical
271
273 float neighbor_radius = 2.0f; // search radius
274
276 int k_neighbors = 20; // k-NN alternative to radius
277
279 float min_area = 1e-6f; // minimum triangle area to avoid degenerates
280
282 bool use_radius = true;
283
285 float min_angle_deg = 20.0f; // minimum interior angle (deg) to avoid sliver triangles
286
288 float min_clearance = 1.0f;
289
292
294 float min_surface_area = 0.0f;
295
297 float max_hole_area = 1.0f;
298
300 bool carve_free_space = true;
301
304
306 float carve_voxel = 0.0f;
307
309 float carve_max_range = 20.0f;
310
312 float carve_ratio = 1.0f;
313};
314
317{
318 std::size_t input = 0;
319 std::size_t carved = 0; // in space that rays went through
320 std::size_t seen_from_below = 0;
321};
322
350 const pcl::PointCloud<pcl::PointXYZ> & input_points,
351 navmap_ros_interfaces::msg::NavMap & out_msg,
352 BuildParams params);
353
372pcl::PointCloud<pcl::PointXYZ> filter_with_viewpoints(
373 const pcl::PointCloud<pcl::PointWithViewpoint> & input_points,
374 const BuildParams & params,
375 ViewpointFilterStats * stats = nullptr);
376
383 const pcl::PointCloud<pcl::PointWithViewpoint> & input_points,
384 navmap_ros_interfaces::msg::NavMap & out_msg,
385 BuildParams params);
386
404 const sensor_msgs::msg::PointCloud2 & pc2,
405 navmap_ros_interfaces::msg::NavMap & out_msg,
406 BuildParams params);
407
436 const pcl::PointCloud<pcl::PointXYZ> & grid_points,
437 navmap_ros_interfaces::msg::NavMap & out_msg,
438 BuildParams params);
439
440} // namespace navmap_ros
441
442#endif // NAVMAP_ROS__CONVERSIONS_HPP_
Values of a U8 cost layer, as in costmap_2d / Nav2 (so that bridging to them is a copy).
Core container and data structures for EasyNav navigable meshes.
Definition NavMap.hpp:561
Conversions between core NavMap and ROS-level structures.
nav_msgs::msg::OccupancyGrid to_occupancy_grid(const navmap::NavMap &nm, const std_msgs::msg::Header &header)
Convert a navmap::NavMap back to nav_msgs::msg::OccupancyGrid.
Definition conversions.cpp:498
navmap::NavMap from_msg(const navmap_ros_interfaces::msg::NavMap &msg, std_msgs::msg::Header &header)
Reconstruct a core navmap::NavMap from the ROS transport message.
navmap_ros_interfaces::msg::NavMapLayer to_layer_update_msg(const navmap::NavMap &nm, const std::string &layer, const std_msgs::msg::Header &header=std_msgs::msg::Header(), float max_sparse_fraction=0.25f)
Layer update with only what changed since the layer's last clear_changes().
Definition conversions.cpp:349
navmap_ros_interfaces::msg::NavMap to_msg(const navmap::NavMap &nm, const std_msgs::msg::Header &header)
Convert a core navmap::NavMap into its compact ROS transport message.
Definition conversions.cpp:184
pcl::PointCloud< pcl::PointXYZ > filter_with_viewpoints(const pcl::PointCloud< pcl::PointWithViewpoint > &input_points, const BuildParams &params, ViewpointFilterStats *stats=nullptr)
Clean a cloud with the sensor position of each point (vp_x, vp_y, vp_z).
Definition conversions.cpp:1873
navmap::NavMap from_points(const pcl::PointCloud< pcl::PointXYZ > &input_points, navmap_ros_interfaces::msg::NavMap &out_msg, BuildParams params)
Build a NavMap from an unorganized point cloud (multi-level grid triangulation).
Definition conversions.cpp:1026
navmap::NavMap from_regular_grid(const pcl::PointCloud< pcl::PointXYZ > &grid_points, navmap_ros_interfaces::msg::NavMap &out_msg, BuildParams params)
Build a NavMap surface from an organized (grid-shaped) PCL point cloud.
Definition conversions.cpp:1444
navmap::NavMap from_pointcloud2(const sensor_msgs::msg::PointCloud2 &pc2, navmap_ros_interfaces::msg::NavMap &out_msg, BuildParams params)
Build a NavMap surface from a ROS sensor_msgs::msg::PointCloud2.
Definition conversions.cpp:1909
navmap::NavMap from_occupancy_grid(const nav_msgs::msg::OccupancyGrid &grid, std_msgs::msg::Header &header)
Build a navmap::NavMap from a nav_msgs::msg::OccupancyGrid using a regular triangular surface with sh...
Definition conversions.cpp:417
constexpr std::uint8_t MAX_NON_OBSTACLE
Highest traversable cost.
Definition Costs.hpp:32
constexpr std::uint8_t NO_INFORMATION
Unknown, not observed.
Definition Costs.hpp:29
constexpr std::uint8_t FREE_SPACE
Known free.
Definition Costs.hpp:33
constexpr std::uint8_t LETHAL_OBSTACLE
Obstacle.
Definition Costs.hpp:30
constexpr std::uint8_t INSCRIBED_INFLATED_OBSTACLE
The robot would touch an obstacle.
Definition Costs.hpp:31
Parameters controlling NavMap construction from point clouds.
Definition conversions.hpp:259
float max_slope_deg
Maximum slope with respect to the vertical axis (degrees).
Definition conversions.hpp:270
bool carve_free_space
With viewpoints: drop the points in space that rays went through (people, noise).
Definition conversions.hpp:300
float carve_ratio
A voxel is carved when rays went through it more than carve_ratio times its hits.
Definition conversions.hpp:312
float resolution
Target in-plane sampling resolution (meters) used by voxelization or gridding.
Definition conversions.hpp:261
int max_surfaces
Maximum number of surfaces to keep, largest first (0 = all).
Definition conversions.hpp:291
int k_neighbors
Alternative to radius: number of nearest neighbors (k-NN).
Definition conversions.hpp:276
float max_hole_area
Enclosed empty regions up to this area (square meters) are filled (0 = none).
Definition conversions.hpp:297
float min_angle_deg
Minimum interior angle (degrees) to avoid sliver triangles.
Definition conversions.hpp:285
float max_dz
Maximum allowed vertical jump (meters) between vertices of a triangle.
Definition conversions.hpp:267
float min_clearance
Vertical free space (meters) that separates two stacked surfaces in a cell.
Definition conversions.hpp:288
float min_area
Minimum triangle area (square meters) to reject degenerate faces.
Definition conversions.hpp:279
float neighbor_radius
Neighborhood radius (meters) for candidate connectivity.
Definition conversions.hpp:273
bool use_radius
If true, use radius-based neighborhoods; otherwise use k-NN.
Definition conversions.hpp:282
float max_edge_len
Maximum allowed edge length (meters) when forming triangles.
Definition conversions.hpp:264
float carve_voxel
Voxel size (meters) of the free-space carving (0 = max(0.1, resolution / 2)).
Definition conversions.hpp:306
float carve_max_range
Rays carve only their first carve_max_range meters.
Definition conversions.hpp:309
float min_surface_area
Surfaces smaller than this area (square meters) are dropped (0 = keep all).
Definition conversions.hpp:294
bool drop_seen_from_below
With viewpoints: drop the faces only seen from below (ceilings, slab undersides).
Definition conversions.hpp:303
Points removed by filter_with_viewpoints().
Definition conversions.hpp:317
std::size_t seen_from_below
Definition conversions.hpp:320
std::size_t carved
Definition conversions.hpp:319
std::size_t input
Definition conversions.hpp:318