/home/runner/work/beluga/beluga/beluga_ros/include/beluga_ros/ndt_ellipsoid.hpp Source File

/home/runner/work/beluga/beluga/beluga_ros/include/beluga_ros/ndt_ellipsoid.hpp Source File#

Beluga ROS: /home/runner/work/beluga/beluga/beluga_ros/include/beluga_ros/ndt_ellipsoid.hpp Source File
Beluga ROS
ndt_ellipsoid.hpp
Go to the documentation of this file.
1 // Copyright 2025 Ekumen, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef BELUGA_ROS_NDT_ELLIPSOID_HPP
16 #define BELUGA_ROS_NDT_ELLIPSOID_HPP
17 
18 #include <Eigen/Core>
19 #include <beluga/eigen_compatibility.hpp>
20 
21 #include <range/v3/view/enumerate.hpp>
22 
23 #include <beluga/sensor/data/ndt_cell.hpp>
25 
26 #include <visualization_msgs/msg/marker.hpp>
27 #include <visualization_msgs/msg/marker_array.hpp>
28 
34 namespace beluga_ros {
35 
36 namespace detail {
37 
39 
47  Eigen::SelfAdjointEigenSolver<Eigen::Matrix<double, 3, 3>>& eigen_solver,
48  beluga::NDTCell<3> cell,
49  visualization_msgs::msg::Marker& marker);
50 
52 
57 void use_cell_size(const Eigen::Vector<int, 3>& position, double size, visualization_msgs::msg::Marker& marker);
58 
59 } // namespace detail
60 
63 
72 template <typename MapType, int NDim>
73 std::pair<visualization_msgs::msg::MarkerArray, bool> assign_obstacle_map(
75  visualization_msgs::msg::MarkerArray& message) {
76  bool cubes_generated = false;
77  // Get data from the grid
78  auto& map = grid.data();
79 
80  // Clean up the message
81  visualization_msgs::msg::Marker marker;
82  marker.ns = "obstacles";
83  marker.action = visualization_msgs::msg::Marker::DELETEALL;
84  message.markers.push_back(marker);
85 
86  // Add the markers
87  Eigen::SelfAdjointEigenSolver<Eigen::Matrix<double, 3, 3>> eigen_solver;
88  for (auto [index, entry] : ranges::views::enumerate(map)) {
89  const auto& [cell_center, cell] = entry;
90  visualization_msgs::msg::Marker marker;
91  marker.header.frame_id = "map";
92  marker.id = index + 1;
93  marker.ns = "obstacles";
94 
95  // Try to create an ellipsoid with values of the cell
96  if (!beluga_ros::detail::use_mean_covariance(eigen_solver, cell, marker)) {
97  // Create a cube based on the resolution of the grid
98  cubes_generated = true;
99  beluga_ros::detail::use_cell_size(cell_center, grid.resolution(), marker);
100  }
101 
102  // Add the marker
103  message.markers.push_back(marker);
104  }
105 
106  return {message, cubes_generated};
107 }
108 
109 } // namespace beluga_ros
110 
111 #endif // BELUGA_ROS_NDT_ELLIPSOID_HPP
double resolution() const
const map_type & data() const
The main Beluga ROS namespace.
Definition: amcl.hpp:47
std::pair< visualization_msgs::msg::MarkerArray, bool > assign_obstacle_map(const beluga::SparseValueGrid< MapType, NDim > &grid, visualization_msgs::msg::MarkerArray &message)
Definition: ndt_ellipsoid.hpp:73
void use_cell_size(const Eigen::Vector< int, 3 > &position, double size, visualization_msgs::msg::Marker &marker)
Create a cube contained in the received marker.
bool use_mean_covariance(Eigen::SelfAdjointEigenSolver< Eigen::Matrix< double, 3, 3 >> &eigen_solver, beluga::NDTCell< 3 > cell, visualization_msgs::msg::Marker &marker)
Create an ellipoid based on NDT cell data (eigenvalues and eigenvectors) contained in the received ma...