41 #include <pcl/gpu/segmentation/gpu_extract_labeled_clusters.h>
43 template <
typename Po
intT>
void
47 std::vector<PointIndices> &clusters,
48 unsigned int min_pts_per_cluster,
49 unsigned int max_pts_per_cluster)
54 std::vector<bool> processed (host_cloud_->
size (),
false);
58 if(max_pts_per_cluster > host_cloud_->
size ())
59 max_answers =
static_cast<int> (host_cloud_->
size ());
61 max_answers = max_pts_per_cluster;
67 for (std::size_t i = 0; i < host_cloud_->
size (); ++i)
81 PointT t = (*host_cloud_)[i];
83 p.x = t.x; p.y = t.y; p.z = t.z;
90 r.
indices.push_back (
static_cast<int> (i));
92 unsigned int found_points =
static_cast<unsigned int> (queries_host.
size ());
93 unsigned int previous_found_points = 0;
98 while (previous_found_points < found_points)
101 queries_device.
upload(queries_host);
103 tree->radiusSearch(queries_device, tolerance, max_answers, result_device);
106 previous_found_points = found_points;
109 std::vector<int> sizes, data;
115 for(std::size_t qp = 0; qp < sizes.size (); qp++)
117 for(
int qp_r = 0; qp_r < sizes[qp]; qp_r++)
119 if(processed[data[qp_r + qp * max_answers]])
122 if((*host_cloud_)[i].label == (*host_cloud_)[data[qp_r + qp * max_answers]].label)
124 processed[data[qp_r + qp * max_answers]] =
true;
125 PointT t_l = (*host_cloud_)[data[qp_r + qp * max_answers]];
127 p_l.x = t_l.x; p_l.y = t_l.y; p_l.z = t_l.z;
130 r.
indices.push_back(data[qp_r + qp * max_answers]);
136 if (found_points >= min_pts_per_cluster && found_points <= max_pts_per_cluster)
143 clusters.push_back (r);
148 template <
typename Po
intT>
void
156 tree_->setCloud(input_);
158 if (!tree_->isBuilt())
170 extractLabeledEuclideanClusters<PointT> (host_cloud_, tree_, cluster_tolerance_, clusters, min_pts_per_cluster_, max_pts_per_cluster_);
176 #define PCL_INSTANTIATE_extractLabeledEuclideanClusters(T) template void PCL_EXPORTS pcl::gpu::extractLabeledEuclideanClusters<T> (const typename pcl::PointCloud<T>::Ptr &, const pcl::gpu::Octree::Ptr &,float, std::vector<PointIndices> &, unsigned int, unsigned int);
177 #define PCL_INSTANTIATE_EuclideanLabeledClusterExtraction(T) template class PCL_EXPORTS pcl::gpu::EuclideanLabeledClusterExtraction<T>;
void push_back(const PointT &pt)
Insert a new point in the cloud, at the end of the container.
pcl::PCLHeader header
The point cloud header.
std::vector< PointT, Eigen::aligned_allocator< PointT > > VectorType
shared_ptr< PointCloud< PointT > > Ptr
void upload(const T *host_ptr, std::size_t size)
Uploads data to internal buffer in GPU memory.
void download(T *host_ptr) const
Downloads data from internal buffer to CPU memory.
Octree implementation on GPU.
shared_ptr< Octree > Ptr
Types.
bool compareLabeledPointClusters(const pcl::PointIndices &a, const pcl::PointIndices &b)
Sort clusters method (for std::sort).
void extractLabeledEuclideanClusters(const typename pcl::PointCloud< PointT >::Ptr &host_cloud_, const pcl::gpu::Octree::Ptr &tree, float tolerance, std::vector< PointIndices > &clusters, unsigned int min_pts_per_cluster, unsigned int max_pts_per_cluster)
A point structure representing Euclidean xyz coordinates.
A point structure representing Euclidean xyz coordinates, and the RGB color.