17 #ifndef POINT_CLOUD_MAPPING__POINT_CLOUD_MAP_HPP_ 18 #define POINT_CLOUD_MAPPING__POINT_CLOUD_MAP_HPP_ 21 #include <sensor_msgs/msg/point_cloud2.hpp> 22 #include <sensor_msgs/point_cloud2_iterator.hpp> 24 #include <geometry_msgs/msg/pose_with_covariance_stamped.hpp> 29 #include <pcl/io/pcd_io.h> 32 #include <unordered_map> 39 namespace point_cloud_mapping
64 template<
typename LocalizerMapT>
67 using Cloud = sensor_msgs::msg::PointCloud2;
72 template<
typename Map>
73 using call_insert = decltype(std::declval<Map>().insert(std::declval<const Cloud &>()));
76 template<
typename Map>
77 using call_clear = decltype(std::declval<Map>().clear());
81 "The map should provide a `insert(msg)` method to be used for mapping");
84 "The map should provide a `clear()` method to be used for mapping");
93 template<typename LocalizerMapT, Requires = LocalizationMapConstraint<LocalizerMapT>::value>
97 static constexpr
auto NUM_FIELDS{4U};
98 using Cloud = sensor_msgs::msg::PointCloud2;
99 using CloudConstIt = sensor_msgs::PointCloud2ConstIterator<float32_t>;
107 const std::string & frame_id,
108 LocalizerMapT && localizer_map
110 : m_grid_config{grid_config}, m_frame_id{frame_id},
111 m_localizer_map{std::forward<LocalizerMapT>(localizer_map)} {}
118 if (observation.header.frame_id != m_frame_id) {
119 throw std::runtime_error(
"pointcloud map and the updates should be on the same frame");
122 const auto check_not_end = [](
const auto & its) {
123 return std::all_of(its.cbegin(), its.cend(), [](
const auto & it) {
return it != it.end();});
128 std::array<CloudConstIt, NUM_FIELDS> obs_its = {
137 for (; check_not_end(obs_its); ++obs_idx) {
139 const auto pt_key = m_grid_config.index(pt);
140 if (m_grid.size() >= capacity() &&
141 m_grid.find(pt_key) == m_grid.end())
151 m_grid[pt_key].add_observation(pt);
154 std::for_each(obs_its.begin(), obs_its.end(), [](
auto & it) {++it;});
156 m_localizer_map.insert(observation);
157 ret.num_added_pts = obs_idx;
163 void write(
const std::string & file_name_prefix)
const 168 pcl::PointCloud<pcl::PointXYZI> cloud;
169 cloud.reserve(m_grid.size());
170 for (
const auto & vx : m_grid) {
172 const auto & vx_pt = vx.second.get();
176 pt.intensity = vx_pt.intensity;
179 pcl::io::savePCDFile(file_name_prefix +
".pcd", cloud);
183 std::size_t
size() const noexcept
185 return m_grid.size();
190 return m_grid_config.get_capacity();
196 m_localizer_map.clear();
201 return m_localizer_map;
212 return m_grid.empty();
217 std::unordered_map<uint64_t,
219 std::string m_frame_id;
220 LocalizerMapT m_localizer_map;
226 #endif // POINT_CLOUD_MAPPING__POINT_CLOUD_MAP_HPP_
This file defines the voxel grid data structure for downsampling point clouds.
MapUpdateType
Enum representing the type of update the observation has caused in the map.
Definition: point_cloud_map.hpp:43
DualVoxelMap(const perception::filters::voxel_grid::Config &grid_config, const std::string &frame_id, LocalizerMapT &&localizer_map)
Definition: point_cloud_map.hpp:105
const LocalizerMapT & localizer_map() const noexcept
Get the localizer map.
Definition: point_cloud_map.hpp:199
float float32_t
Definition: types.hpp:36
Struct containing information on the attempt to push a new observation to a map.
Definition: point_cloud_map.hpp:52
Requires
Definition: point_cloud_map.hpp:59
void clear()
Clear the voxel grid.
Definition: point_cloud_map.hpp:193
This file includes common type definition.
This class encapsulates the static assertions that express the interface requirements of a localizer ...
Definition: point_cloud_map.hpp:65
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::size_t num_added_pts
Definition: point_cloud_map.hpp:55
MapUpdateType update_type
Definition: point_cloud_map.hpp:54
A specialization of the Voxel class, accumulates points to a moving centroid.
Definition: voxels.hpp:115
decltype(std::declval< Map >().clear()) call_clear
This expression requires a method that clears the map.
Definition: point_cloud_map.hpp:77
const std::string & frame_id() const noexcept
Get the frame ID of the map.
Definition: point_cloud_map.hpp:204
sensor_msgs::msg::PointCloud2 Cloud
Definition: point_cloud_map.hpp:98
This file includes common helper functions.
Definition: point_cloud_map.hpp:94
MapUpdateSummary update(const Cloud &observation)
Definition: point_cloud_map.hpp:116
std::size_t size() const noexcept
Size of the voxel grid.
Definition: point_cloud_map.hpp:183
bool empty()
Get if the map is empty.
Definition: point_cloud_map.hpp:210
sensor_msgs::PointCloud2ConstIterator< float32_t > CloudConstIt
Definition: point_cloud_map.hpp:99
std::size_t capacity() const noexcept
Capacity of the voxel grid.
Definition: point_cloud_map.hpp:188
decltype(std::declval< Map >().insert(std::declval< const Cloud & >())) call_insert
This expression requires a method that inserts a given pointcloud2 message into the map...
Definition: point_cloud_map.hpp:73
Definition: template_utils.hpp:34
void write(const std::string &file_name_prefix) const
Definition: point_cloud_map.hpp:163
sensor_msgs::msg::PointCloud2 Cloud
Definition: point_cloud_map.hpp:67
This file defines the lanelet2_map_provider_node class.
Definition: quick_sort.hpp:24