Apollo 11.0
自动驾驶开放平台
pointcloud_util.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2023 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
17#pragma once
18
19#include <string>
20
21#include "pcl/filters/passthrough.h"
22#include "pcl/filters/random_sample.h"
23#include "pcl/filters/voxel_grid.h"
24#include "pcl/impl/pcl_base.hpp"
25#include "pcl/io/pcd_io.h"
26#include "pcl/pcl_base.h"
27#include "pcl/point_cloud.h"
28#include "pcl/point_types.h"
29
30#define PCL_NO_PRECOMPILE
31
32namespace apollo {
33namespace perception {
34namespace lidar {
35
36struct PCLPointXYZIT {
37 float x;
38 float y;
39 float z;
40 std::uint8_t intensity;
41 double timestamp;
42 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
43};
44
45template <typename PointT>
47 const typename pcl::PointCloud<PointT>::Ptr &input_cloud_ptr,
48 typename pcl::PointCloud<PointT>::Ptr output_cloud_ptr, float lx = 0.01f,
49 float ly = 0.01f, float lz = 0.01f) {
50 pcl::VoxelGrid<PointT> voxel_grid;
51 voxel_grid.setInputCloud(input_cloud_ptr);
52 voxel_grid.setLeafSize(lx, ly, lz);
53 voxel_grid.filter(*output_cloud_ptr);
54}
55
56template <typename PointT>
58 const typename pcl::PointCloud<PointT>::Ptr &input_cloud_ptr,
59 const std::string &filter_axis, const double &limit_min,
60 const double &limit_max,
61 typename pcl::PointCloud<PointT>::Ptr output_cloud_ptr) {
62 pcl::PassThrough<PointT> pass;
63 pass.setInputCloud(input_cloud_ptr);
64 pass.setFilterFieldName(filter_axis);
65 pass.setFilterLimits(limit_min, limit_max);
66 pass.filter(*output_cloud_ptr);
67}
68
69template <typename PointT>
70void LoadPointCloud(const std::string &filename,
71 typename pcl::PointCloud<PointT>::Ptr point_cloud) {
72 typename pcl::PointCloud<PointT>::Ptr cloud(new pcl::PointCloud<PointT>);
73 if (pcl::io::loadPCDFile<PointT>(filename, *point_cloud) == -1) {
74 throw std::runtime_error("Couldn't read file " + filename);
75 }
76 std::cout << "Loaded " << point_cloud->width * point_cloud->height
77 << " data points from " << filename << std::endl;
78}
79
80template <typename PointT>
82 const typename pcl::PointCloud<PointT>::Ptr &intput_cloud_ptr,
83 typename pcl::PointCloud<PointT>::Ptr out_cloud_ptr, int num_points) {
84 if (num_points <= 0) {
85 std::cerr << "Invalid number of points to downsample: " << num_points
86 << std::endl;
87 }
88
89 pcl::RandomSample<PointT> sampler;
90 sampler.setInputCloud(intput_cloud_ptr);
91 sampler.setSample(num_points);
92 sampler.filter(*out_cloud_ptr);
93}
94
95} // namespace lidar
96} // namespace perception
97} // namespace apollo
98
99POINT_CLOUD_REGISTER_POINT_STRUCT(perception::PCLPointXYZIT,
100 (float, x, x)(float, y, y)(float, z, z)(
101 std::uint8_t, intensity,
102 intensity)(double, timestamp, timestamp))
void FilterPointsOutsideRange(const typename pcl::PointCloud< PointT >::Ptr &input_cloud_ptr, const std::string &filter_axis, const double &limit_min, const double &limit_max, typename pcl::PointCloud< PointT >::Ptr output_cloud_ptr)
void LoadPointCloud(const std::string &filename, typename pcl::PointCloud< PointT >::Ptr point_cloud)
void DownSampleCloudByVoxelGrid(const pcl::PointCloud< pcl::PointXYZI >::Ptr &cloud_ptr, const pcl::PointCloud< pcl::PointXYZI >::Ptr &filtered_cloud_ptr, float lx=0.01f, float ly=0.01f, float lz=0.01f)
Definition pcl_util.h:128
void DownSamplePointCloud(const typename pcl::PointCloud< PointT >::Ptr &intput_cloud_ptr, typename pcl::PointCloud< PointT >::Ptr out_cloud_ptr, int num_points)
class register implement
Definition arena_queue.h:37