PCL 欧式距离聚类分割 CPU GPU

1 cpu

 /***            1     CPU            ***/
		pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>);

		pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>);
		tree->setInputCloud(cloud_filtered);

		std::vector<pcl::PointIndices> cluster_indices;
		pcl::EuclideanClusterExtraction<pcl::PointXYZ> ec;//创建欧式聚类分割对象
		ec.setClusterTolerance(0.3); //设置近邻搜索的搜索半径
		ec.setMinClusterSize(85); //设置最小聚类尺寸
		ec.setMaxClusterSize(10000);
		ec.setSearchMethod(tree);
		ec.setInputCloud(cloud_filtered);
		ec.extract(cluster_indices);

2 gpu

#include <pcl/gpu/octree/octree.hpp>
#include <pcl/gpu/containers/device_array.hpp>
#include <pcl/gpu/segmentation/gpu_extract_clusters.h>
#include <pcl/gpu/segmentation/impl/gpu_extract_clusters.hpp>


/***            2  GPU               ***/
		pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_xyz(new pcl::PointCloud<pcl::PointXYZ>);
	
		pcl::gpu::Octree::PointCloud cloud_device;
		cloud_device.upload(cloud_xyz->points);
		pcl::gpu::Octree::Ptr octree_device (new pcl::gpu::Octree);
		octree_device->setCloud(cloud_device);
		octree_device->build();

		std::vector<pcl::PointIndices> cluster_indices;
		pcl::gpu::EuclideanClusterExtraction gec;
		gec.setClusterTolerance (0.3); 
		gec.setMinClusterSize (85);
		gec.setMaxClusterSize (10000);
		gec.setSearchMethod (octree_device);
		gec.setHostCloud(cloud_xyz);
		gec.extract (cluster_indices);

3 快速欧式距离聚类分割