Autoware.Auto
map.hpp
Go to the documentation of this file.
1 // Copyright 2020 the Autoware Foundation
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 // Co-developed by Tier IV, Inc. and Apex.AI, Inc.
16 
17 #ifndef POINT_CLOUD_MAPPING__MAP_HPP_
18 #define POINT_CLOUD_MAPPING__MAP_HPP_
19 
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>
25 #include <common/types.hpp>
26 #include <pcl/io/pcd_io.h>
27 #include <vector>
28 #include <string>
29 #include <unordered_map>
30 
31 namespace autoware
32 {
33 namespace mapping
34 {
35 namespace point_cloud_mapping
36 {
37 
39 enum class MapUpdateType
40 {
41  NEW,
42  UPDATE,
44  NO_CHANGE
45 };
46 
49 enum class MapStorageMode
50 {
52  Shared
53 };
54 
56 struct POINT_CLOUD_MAPPING_PUBLIC MapUpdateSummary
57 {
59  std::size_t num_added_pts;
60 };
62 
66 template<typename IncrementT, MapStorageMode StorageModeT>
67 class POINT_CLOUD_MAPPING_PUBLIC MapRepresentationBase
68 {
69 public:
70  using Increment = IncrementT;
75  virtual MapUpdateSummary try_add_observation(
76  const IncrementT & observation,
77  const geometry_msgs::msg::PoseWithCovarianceStamped & pose) = 0;
78 
81  virtual void write(const std::string & file_name_prefix) const = 0;
82 
85  virtual std::size_t size() const noexcept = 0;
86 
89  virtual std::size_t capacity() const noexcept = 0;
90 
94  static constexpr MapStorageMode storage_mode() noexcept
95  {
96  return StorageModeT;
97  }
98 
99  virtual ~MapRepresentationBase() = default;
100 
102  virtual void clear() = 0;
103 };
104 
108 class POINT_CLOUD_MAPPING_PUBLIC PlainPointCloudMap
109  : public MapRepresentationBase<sensor_msgs::msg::PointCloud2, MapStorageMode::Independent>
110 {
111 public:
112  using Base = MapRepresentationBase<sensor_msgs::msg::PointCloud2,
114  static constexpr auto NUM_FIELDS{4U};
115  // pcl cloud is used to seamlessly write the file without needing to copy/allocate.
116  using PCLCloud = pcl::PointCloud<pcl::PointXYZI>;
117  using Cloud = sensor_msgs::msg::PointCloud2;
118  using CloudIt = sensor_msgs::PointCloud2Iterator<float32_t>;
119  using CloudConstIt = sensor_msgs::PointCloud2ConstIterator<float32_t>;
120 
124  explicit PlainPointCloudMap(std::size_t capacity, const std::string & frame = "map");
125 
129  MapUpdateSummary try_add_observation(
130  const Cloud & observation,
131  const geometry_msgs::msg::PoseWithCovarianceStamped &) override;
132 
135  void write(const std::string & file_name_prefix) const override;
136  std::size_t size() const noexcept override;
137  std::size_t capacity() const noexcept override;
138  void clear() override;
139 
140 private:
141  PCLCloud m_cloud;
142  std::size_t m_capacity;
143  std::string m_frame_id;
144 };
145 
148 class POINT_CLOUD_MAPPING_PUBLIC VoxelMap
149  : public MapRepresentationBase<sensor_msgs::msg::PointCloud2, MapStorageMode::Independent>
150 {
151 public:
152  using Base = MapRepresentationBase<sensor_msgs::msg::PointCloud2,
154  static constexpr auto NUM_FIELDS{4U};
155  using PCLCloud = pcl::PointCloud<pcl::PointXYZI>;
156  using Cloud = sensor_msgs::msg::PointCloud2;
157  using CloudIt = sensor_msgs::PointCloud2Iterator<float32_t>;
158  using CloudConstIt = sensor_msgs::PointCloud2ConstIterator<float32_t>;
159 
163  explicit VoxelMap(
164  const perception::filters::voxel_grid::Config & grid_config,
165  const std::string & frame = "map");
166 
170  MapUpdateSummary try_add_observation(
171  const Cloud & observation,
172  const geometry_msgs::msg::PoseWithCovarianceStamped &) override;
175  void write(const std::string & file_name_prefix) const override;
177  std::size_t size() const noexcept override;
179  std::size_t capacity() const noexcept override;
181  void clear() override;
182 
183 private:
184  perception::filters::voxel_grid::Config m_grid_config;
185  std::unordered_map<uint64_t,
186  perception::filters::voxel_grid::CentroidVoxel<common::types::PointXYZIF>> m_grid;
187  std::string m_frame_id;
188 };
189 
190 
191 } // namespace point_cloud_mapping
192 } // namespace mapping
193 } // namespace autoware
194 
195 #endif // POINT_CLOUD_MAPPING__MAP_HPP_
autoware::mapping::point_cloud_mapping::MapUpdateType
MapUpdateType
Enum representing the type of update the observation has caused in the map.
Definition: map.hpp:39
autoware::mapping::point_cloud_mapping::MapUpdateType::PARTIAL_UPDATE
@ PARTIAL_UPDATE
autoware::mapping::point_cloud_mapping::MapUpdateType::UPDATE
@ UPDATE
autoware::mapping::point_cloud_mapping::PlainPointCloudMap::PCLCloud
pcl::PointCloud< pcl::PointXYZI > PCLCloud
Definition: map.hpp:116
autoware::mapping::point_cloud_mapping::MapUpdateSummary::num_added_pts
std::size_t num_added_pts
Definition: map.hpp:59
autoware::mapping::point_cloud_mapping::MapRepresentationBase< sensor_msgs::msg::PointCloud2, MapStorageMode::Independent >::Increment
sensor_msgs::msg::PointCloud2 Increment
Definition: map.hpp:70
types.hpp
This file includes common type definition.
voxel_grid.hpp
This file defines the voxel grid data structure for downsampling point clouds.
autoware::mapping::point_cloud_mapping::VoxelMap::CloudConstIt
sensor_msgs::PointCloud2ConstIterator< float32_t > CloudConstIt
Definition: map.hpp:158
visibility_control.hpp
autoware::mapping::point_cloud_mapping::MapStorageMode::Shared
@ Shared
autoware::mapping::point_cloud_mapping::MapStorageMode::Independent
@ Independent
autoware
This file defines the lanelet2_map_provider_node class.
Definition: quick_sort.hpp:24
autoware::mapping::ndt_mapping_nodes::VoxelMap
point_cloud_mapping::VoxelMap VoxelMap
Definition: ndt_mapping_nodes.hpp:50
autoware::mapping::point_cloud_mapping::MapUpdateSummary
Struct containing information on the attempt to push a new observation to a map.
Definition: map.hpp:56
autoware::mapping::point_cloud_mapping::MapUpdateType::NO_CHANGE
@ NO_CHANGE
autoware::mapping::point_cloud_mapping::VoxelMap::CloudIt
sensor_msgs::PointCloud2Iterator< float32_t > CloudIt
Definition: map.hpp:157
autoware::mapping::point_cloud_mapping::MapUpdateSummary::update_type
MapUpdateType update_type
Definition: map.hpp:58
autoware::common::types::float32_t
float float32_t
Definition: types.hpp:36
autoware::perception::filters::voxel_grid::Config
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
autoware::mapping::point_cloud_mapping::PlainPointCloudMap
Definition: map.hpp:108
autoware::mapping::point_cloud_mapping::MapUpdateType::NEW
@ NEW
autoware::mapping::point_cloud_mapping::VoxelMap::Cloud
sensor_msgs::msg::PointCloud2 Cloud
Definition: map.hpp:156
autoware::mapping::point_cloud_mapping::VoxelMap
Definition: map.hpp:148
autoware::mapping::point_cloud_mapping::PlainPointCloudMap::CloudConstIt
sensor_msgs::PointCloud2ConstIterator< float32_t > CloudConstIt
Definition: map.hpp:119
autoware::mapping::point_cloud_mapping::PlainPointCloudMap::CloudIt
sensor_msgs::PointCloud2Iterator< float32_t > CloudIt
Definition: map.hpp:118
autoware::mapping::point_cloud_mapping::MapRepresentationBase
Definition: map.hpp:67
autoware::mapping::point_cloud_mapping::MapStorageMode
MapStorageMode
Definition: map.hpp:49
autoware::mapping::point_cloud_mapping::VoxelMap::PCLCloud
pcl::PointCloud< pcl::PointXYZI > PCLCloud
Definition: map.hpp:155
autoware::mapping::point_cloud_mapping::PlainPointCloudMap::Cloud
sensor_msgs::msg::PointCloud2 Cloud
Definition: map.hpp:117