11 #include <pcl/common/common.h> 12 #include <pcl/common/transforms.h> 13 #include <pcl/conversions.h> 14 #include <pcl/filters/passthrough.h> 15 #include <pcl/filters/statistical_outlier_removal.h> 16 #include <pcl/filters/voxel_grid.h> 17 #include <pcl/io/pcd_io.h> 18 #include <pcl/kdtree/kdtree_flann.h> 19 #include <pcl/point_types.h> 20 #include <pcl/segmentation/extract_clusters.h> 25 namespace grid_map_pcl {
28 params_ = std::make_unique<grid_map_pcl::PclLoaderParameters>();
32 params_->loadParameters(filename);
36 pcl::StatisticalOutlierRemoval<pcl::PointXYZ> sor;
37 sor.setInputCloud(inputCloud);
38 sor.setMeanK(
params_->get().outlierRemoval_.meanK_);
39 sor.setStddevMulThresh(
params_->get().outlierRemoval_.stddevThreshold_);
40 Pointcloud::Ptr filteredCloud(
new Pointcloud());
41 sor.filter(*filteredCloud);
47 std::vector<Pointcloud::Ptr> clusterClouds;
48 clusterClouds.reserve(clusterIndices.size());
49 for (
const auto& indicesSet : clusterIndices) {
51 clusterClouds.push_back(clusterCloud);
60 pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(
new pcl::search::KdTree<pcl::PointXYZ>);
61 tree->setInputCloud(inputCloud);
62 std::vector<pcl::PointIndices> clusterIndices;
63 pcl::EuclideanClusterExtraction<pcl::PointXYZ> euclideanClusterExtraction;
64 euclideanClusterExtraction.setClusterTolerance(
params_->get().clusterExtraction_.clusterTolerance_);
65 euclideanClusterExtraction.setMinClusterSize(
params_->get().clusterExtraction_.minNumPoints_);
66 euclideanClusterExtraction.setMaxClusterSize(
params_->get().clusterExtraction_.maxNumPoints_);
67 euclideanClusterExtraction.setSearchMethod(tree);
68 euclideanClusterExtraction.setInputCloud(inputCloud);
69 euclideanClusterExtraction.extract(clusterIndices);
71 return clusterIndices;
77 cloud->points.reserve(indices.size());
78 for (
auto index : indices) {
79 cloud->points.push_back(inputCloud->points[index]);
82 cloud->is_dense =
true;
88 pcl::VoxelGrid<pcl::PointXYZ> voxelGrid;
89 voxelGrid.setInputCloud(inputCloud);
90 const auto& voxelSize =
params_->get().downsampling_.voxelSize_;
91 voxelGrid.setLeafSize(voxelSize.x(), voxelSize.y(), voxelSize.z());
92 Pointcloud::Ptr downsampledCloud(
new Pointcloud());
93 voxelGrid.filter(*downsampledCloud);
94 return downsampledCloud;
98 pcl::PCDWriter writer;
99 pcl::PCLPointCloud2 pointCloud2;
100 pcl::toPCLPointCloud2(cloud, pointCloud2);
101 writer.write(filename, pointCloud2, Eigen::Vector4f::Zero(), Eigen::Quaternionf::Identity(),
false);
105 auto transformedCloud =
107 params_->get().cloudTransformation_.rpyIntrinsic_));
108 return transformedCloud;
std::vector< Pointcloud::Ptr > extractClusterCloudsFromPointcloud(Pointcloud::ConstPtr inputCloud) const
Pointcloud::Ptr applyRigidBodyTransformation(Pointcloud::ConstPtr inputCloud) const
static Pointcloud::Ptr makeCloudFromIndices(const std::vector< int > &indices, Pointcloud::ConstPtr inputCloud)
Pointcloud::Ptr downsampleInputCloud(Pointcloud::ConstPtr inputCloud) const
void loadParameters(const std::string &filename)
std::vector< pcl::PointIndices > extractClusterIndicesFromPointcloud(Pointcloud::ConstPtr inputCloud) const
Pointcloud::Ptr transformCloud(Pointcloud::ConstPtr inputCloud, const Eigen::Affine3f &transformMatrix)
static void savePointCloudAsPcdFile(const std::string &filename, const Pointcloud &cloud)
Pointcloud::Ptr removeOutliersFromInputCloud(Pointcloud::ConstPtr inputCloud) const
::pcl::PointCloud< Point > Pointcloud
Eigen::Affine3f getRigidBodyTransform(const Eigen::Vector3d &translation, const Eigen::Vector3d &intrinsicRpy)
std::unique_ptr< grid_map_pcl::PclLoaderParameters > params_