使用分割算法分割完成後,會將分割的點雲索引保存在pcl::PointIndices類型的數據中,其實是一個vector的數組。經過該indices使用pcl::ExtractIndices<PointT>把點雲提取到單獨的點雲中。php
http://pointclouds.org/documentation/tutorials/cylinder_segmentation.php#cylinder-segmentation算法
#include <pcl/filters/extract_indices.h> typedef pcl::PointXYZ PointT; //分割的輸入點雲 pcl::PointCloud<PointT>::Ptr cloud(new pcl::PointCloud<PointT>); //保存分割後點雲的數據索引 pcl::PointIndices::Ptr inliers_plane(new pcl::PointIndices); //提取 pcl::ExtractIndices<PointT> extract; extract.setInputCloud(cloud); extract.setIndices(inliers_plane); //保存提取的plane點雲 extract.setNegative(false); //存放提取的plane點雲 pcl::PointCloud<PointT>::Ptr cloud_plane(new pcl::PointCloud<PointT>()); extract.filter(*cloud_plane); // Remove the planar inliers, extract the rest extract.setNegative(true); pcl::PointCloud<PointT>::Ptr cloud_filtered2(new pcl::PointCloud<PointT>); //提取剩餘的點雲 extract.filter(*cloud_filtered2);