/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 <beluga_ros/messages.hpp>
19 
20 #include <Eigen/Core>
21 #include <beluga/eigen_compatibility.hpp>
22 
23 #include <range/v3/view/enumerate.hpp>
24 
25 #include <beluga/sensor/data/ndt_cell.hpp>
27 
33 namespace beluga_ros {
34 
35 namespace detail {
36 
38 
46  Eigen::SelfAdjointEigenSolver<Eigen::Matrix<double, 3, 3>>& eigen_solver,
47  beluga::NDTCell<3> cell,
48  beluga_ros::msg::Marker& marker);
49 
51 
56 void use_cell_size(const Eigen::Vector<int, 3>& position, double size, beluga_ros::msg::Marker& marker);
57 
58 } // namespace detail
59 
62 
71 template <typename MapType, int NDim>
72 std::pair<beluga_ros::msg::MarkerArray, bool> assign_obstacle_map(
74  beluga_ros::msg::MarkerArray& message) {
75  bool cubes_generated = false;
76  // Get data from the grid
77  auto& map = grid.data();
78 
79  // Clean up the message
80  beluga_ros::msg::Marker marker;
81  marker.ns = "obstacles";
82  marker.action = beluga_ros::msg::Marker::DELETEALL;
83  message.markers.push_back(marker);
84 
85  // Add the markers
86  Eigen::SelfAdjointEigenSolver<Eigen::Matrix<double, 3, 3>> eigen_solver;
87  for (auto [index, entry] : ranges::views::enumerate(map)) {
88  const auto& [cell_center, cell] = entry;
89  beluga_ros::msg::Marker marker;
90  marker.header.frame_id = "map";
91  marker.id = index + 1;
92  marker.ns = "obstacles";
93 
94  // Try to create an ellipsoid with values of the cell
95  if (!beluga_ros::detail::use_mean_covariance(eigen_solver, cell, marker)) {
96  // Create a cube based on the resolution of the grid
97  cubes_generated = true;
98  beluga_ros::detail::use_cell_size(cell_center, grid.resolution(), marker);
99  }
100 
101  // Add the marker
102  message.markers.push_back(marker);
103  }
104 
105  return {message, cubes_generated};
106 }
107 
108 } // namespace beluga_ros
109 
110 #endif // BELUGA_ROS_NDT_ELLIPSOID_HPP
double resolution() const
const map_type & data() const
The main Beluga ROS namespace.
Definition: amcl.hpp:44
std::pair< beluga_ros::msg::MarkerArray, bool > assign_obstacle_map(const beluga::SparseValueGrid< MapType, NDim > &grid, beluga_ros::msg::MarkerArray &message)
Definition: ndt_ellipsoid.hpp:72
bool use_mean_covariance(Eigen::SelfAdjointEigenSolver< Eigen::Matrix< double, 3, 3 >> &eigen_solver, beluga::NDTCell< 3 > cell, beluga_ros::msg::Marker &marker)
Create an ellipoid based on NDT cell data (eigenvalues and eigenvectors) contained in the received ma...
void use_cell_size(const Eigen::Vector< int, 3 > &position, double size, beluga_ros::msg::Marker &marker)
Create a cube contained in the received marker.