Go to the documentation of this file.
17 #ifndef NDT__NDT_MAP_HPP_
18 #define NDT__NDT_MAP_HPP_
23 #include <sensor_msgs/point_cloud2_iterator.hpp>
27 #include <unordered_map>
36 namespace localization
47 uint32_t NDT_PUBLIC
validate_pcl_map(
const sensor_msgs::msg::PointCloud2 & msg);
51 template<
typename Derived,
typename VoxelT>
55 using Grid = std::unordered_map<uint64_t, VoxelT>;
58 using TimePoint = std::chrono::system_clock::time_point;
64 : m_config(voxel_grid_config), m_map(m_config.get_capacity())
66 m_output_vector.reserve(1U);
95 m_output_vector.clear();
96 const auto vx_it = m_map.find(m_config.
index(pt));
98 if (vx_it != m_map.end() && vx_it->second.usable()) {
99 m_output_vector.emplace_back(vx_it->second);
101 return m_output_vector;
106 void insert(
const sensor_msgs::msg::PointCloud2 & msg)
109 m_frame_id = msg.header.frame_id;
110 this->
impl().insert_(msg);
130 typename Grid::const_iterator
begin() const noexcept
136 typename Grid::iterator
begin() noexcept
138 return m_map.begin();
142 typename Grid::const_iterator
cbegin() const noexcept
144 return m_map.cbegin();
148 typename Grid::const_iterator
end() const noexcept
154 typename Grid::iterator
end() noexcept
160 typename Grid::const_iterator
cend() const noexcept
191 return m_config.
index(pt);
203 auto emplace(uint64_t key,
const VoxelT && vx)
205 return m_map.emplace(key, std::move(vx));
213 std::string m_frame_id{};
220 :
public NDTMapBase<DynamicNDTMap, DynamicNDTVoxel>
224 using Grid = std::unordered_map<uint64_t, Voxel>;
233 void insert_(
const sensor_msgs::msg::PointCloud2 & msg)
235 sensor_msgs::PointCloud2ConstIterator<float32_t> x_it(msg,
"x");
236 sensor_msgs::PointCloud2ConstIterator<float32_t> y_it(msg,
"y");
237 sensor_msgs::PointCloud2ConstIterator<float32_t> z_it(msg,
"z");
239 while (x_it != x_it.end() &&
240 y_it != y_it.end() &&
243 const auto pt =
Point({*x_it, *y_it, *z_it});
244 const auto voxel_idx = index(pt);
245 voxel(voxel_idx).add_observation(pt);
252 for (
auto & vx_it : *
this) {
253 auto & vx = vx_it.second;
254 (void) vx.try_stabilize();
263 :
public NDTMapBase<StaticNDTMap, StaticNDTVoxel>
277 void insert_(
const sensor_msgs::msg::PointCloud2 & msg)
282 throw std::runtime_error(
283 "Point cloud representing the ndt map is either empty"
284 "or does not have the correct format.");
287 sensor_msgs::PointCloud2ConstIterator<Real> x_it(msg,
"x");
288 sensor_msgs::PointCloud2ConstIterator<Real> y_it(msg,
"y");
289 sensor_msgs::PointCloud2ConstIterator<Real> z_it(msg,
"z");
290 sensor_msgs::PointCloud2ConstIterator<Real> icov_xx_it(msg,
"icov_xx");
291 sensor_msgs::PointCloud2ConstIterator<Real> icov_xy_it(msg,
"icov_xy");
292 sensor_msgs::PointCloud2ConstIterator<Real> icov_xz_it(msg,
"icov_xz");
293 sensor_msgs::PointCloud2ConstIterator<Real> icov_yy_it(msg,
"icov_yy");
294 sensor_msgs::PointCloud2ConstIterator<Real> icov_yz_it(msg,
"icov_yz");
295 sensor_msgs::PointCloud2ConstIterator<Real> icov_zz_it(msg,
"icov_zz");
296 sensor_msgs::PointCloud2ConstIterator<uint32_t> cell_id_it(msg,
"cell_id");
298 while (x_it != x_it.end() &&
299 y_it != y_it.end() &&
300 z_it != z_it.end() &&
301 icov_xx_it != icov_xx_it.end() &&
302 icov_xy_it != icov_xy_it.end() &&
303 icov_xz_it != icov_xz_it.end() &&
304 icov_yy_it != icov_yy_it.end() &&
305 icov_yz_it != icov_yz_it.end() &&
306 icov_zz_it != icov_zz_it.end() &&
307 cell_id_it != cell_id_it.end())
309 const Point centroid{*x_it, *y_it, *z_it};
310 const auto voxel_idx = index(centroid);
315 Grid::key_type received_idx = 0U;
316 std::memcpy(&received_idx, &cell_id_it[0U],
sizeof(received_idx));
320 if (voxel_idx != received_idx) {
321 throw std::domain_error(
322 "NDTVoxelMap: Pointcloud representing the ndt map"
323 "does not have a matching grid configuration with "
324 "the map representation it is being inserted to. The cell IDs do not matchb");
327 Eigen::Matrix3d inv_covariance;
328 inv_covariance << *icov_xx_it, *icov_xy_it, *icov_xz_it,
329 *icov_xy_it, *icov_yy_it, *icov_yz_it,
330 *icov_xz_it, *icov_yz_it, *icov_zz_it;
331 const Voxel vx{centroid, inv_covariance};
333 const auto insert_res = emplace(voxel_idx,
Voxel{centroid, inv_covariance});
334 if (!insert_res.second) {
336 insert_res.first->second = vx;
360 namespace point_adapter
366 inline NDT_PUBLIC
auto x_(
const Eigen::Vector3d & pt)
372 inline NDT_PUBLIC
auto y_(
const Eigen::Vector3d & pt)
378 inline NDT_PUBLIC
auto z_(
const Eigen::Vector3d & pt)
384 inline NDT_PUBLIC
auto &
xr_(Eigen::Vector3d & pt)
390 inline NDT_PUBLIC
auto &
yr_(Eigen::Vector3d & pt)
396 inline NDT_PUBLIC
auto &
zr_(Eigen::Vector3d & pt)
404 #endif // NDT__NDT_MAP_HPP_
Grid::iterator begin() noexcept
Returns an iterator to the first element of the map.
Definition: ndt_map.hpp:136
Grid::const_iterator cend() const noexcept
Returns a const iterator to one past the last element of the map.
Definition: ndt_map.hpp:160
TimePoint stamp() const noexcept
Definition: ndt_map.hpp:173
Eigen::Vector3d Point
Definition: ndt_map.hpp:56
Grid::const_iterator begin() const noexcept
Returns an const iterator to the first element of the map.
Definition: ndt_map.hpp:130
std::chrono::system_clock::time_point TimePoint
Definition: ndt_map.hpp:58
const PointXYZ & get_voxel_size() const
Gets the voxel size of the voxel grid.
Definition: perception/filters/voxel_grid/src/config.cpp:115
auto index(const Point &pt) const
Definition: ndt_map.hpp:189
auto emplace(uint64_t key, const VoxelT &&vx)
Definition: ndt_map.hpp:203
auto x_(const PointT &pt)
Gets the x value for a point.
Definition: common_2d.hpp:47
void insert_(const sensor_msgs::msg::PointCloud2 &msg)
Definition: ndt_map.hpp:233
This file includes common type definition.
DifferentialState y
Definition: kinematic_bicycle.snippet.hpp:28
Grid::iterator end() noexcept
Returns an iterator to one past the last element of the map.
Definition: ndt_map.hpp:154
const VoxelViewVector & cell(float32_t x, float32_t y, float32_t z) const
Definition: ndt_map.hpp:83
auto cell_size() const noexcept
Definition: ndt_map.hpp:123
Definition: ndt_voxel.hpp:98
geometry_msgs::msg::Point32 Point
Definition: intersection.hpp:52
Grid::const_iterator cbegin() const noexcept
Returns a const iterator to the first element of the map.
Definition: ndt_map.hpp:142
Grid::const_iterator end() const noexcept
Returns a const iterator to one past the last element of the map.
Definition: ndt_map.hpp:148
This file defines the lanelet2_map_provider_node class.
Definition: quick_sort.hpp:24
auto & yr_(PointT &pt)
Gets a reference to the y value for a point.
Definition: common_2d.hpp:83
void insert_(const sensor_msgs::msg::PointCloud2 &msg)
Definition: ndt_map.hpp:277
const Derived & impl() const
Definition: crtp.hpp:32
NDTMapBase & operator=(const NDTMapBase &)=delete
autoware::perception::filters::voxel_grid::Config Config
Definition: ndt_map.hpp:57
Definition: ndt_map.hpp:219
std::vector< VoxelView< StaticNDTVoxel > > VoxelViewVector
Definition: ndt_map.hpp:59
uint32_t NDT_PUBLIC validate_pcl_map(const sensor_msgs::msg::PointCloud2 &msg)
Definition: ndt_map.cpp:28
VoxelT & voxel(uint64_t idx)
Definition: ndt_map.hpp:198
std::unordered_map< uint64_t, Voxel > Grid
Definition: ndt_map.hpp:224
TIME_UTILS_PUBLIC std::chrono::system_clock::time_point from_message(builtin_interfaces::msg::Time t) noexcept
Convert from std::chrono::time_point from time message.
Definition: time_utils.cpp:84
DifferentialState x
Definition: kinematic_bicycle.snippet.hpp:28
Definition: ndt_map.hpp:52
float float32_t
Definition: types.hpp:36
A configuration class for the VoxelGrid data structure, also includes some helper functionality for c...
Definition: perception/filters/voxel_grid/include/voxel_grid/config.hpp:52
std::unordered_map< uint64_t, StaticNDTVoxel > Grid
Definition: ndt_map.hpp:55
auto & xr_(PointT &pt)
Gets a reference to the x value for a point.
Definition: common_2d.hpp:74
void clear() noexcept
Clear all voxels in the map.
Definition: ndt_map.hpp:166
Definition: ndt_map.hpp:262
NDTMapBase(const Config &voxel_grid_config)
Definition: ndt_map.hpp:63
Definition: ndt_voxel.hpp:44
auto y_(const PointT &pt)
Gets the y value for a point.
Definition: common_2d.hpp:56
void insert(const sensor_msgs::msg::PointCloud2 &msg)
Definition: ndt_map.hpp:106
auto z_(const PointT &pt)
Gets the z value for a point.
Definition: common_2d.hpp:65
uint64_t size() const noexcept
Definition: ndt_map.hpp:116
auto & zr_(PointT &pt)
Gets a reference to the z value for a point.
Definition: common_2d.hpp:92
const std::string & frame_id() const noexcept
Definition: ndt_map.hpp:180
uint64_t index(const PointT &pt) const
Computes index for a given point given the voxelgrid configuration parameters.
Definition: perception/filters/voxel_grid/include/voxel_grid/config.hpp:84
Eigen::Vector3d Point
Definition: ndt_map.hpp:226
const VoxelViewVector & cell(const Point &pt) const
Definition: ndt_map.hpp:92