41 #include <pcl/gpu/segmentation/gpu_extract_labeled_clusters.h>
43 template <
typename Po
intT>
49 std::vector<PointIndices>& clusters,
50 unsigned int min_pts_per_cluster,
51 unsigned int max_pts_per_cluster)
56 std::vector<bool> processed(host_cloud_->
size(),
false);
60 if (max_pts_per_cluster > host_cloud_->
size())
61 max_answers =
static_cast<int>(host_cloud_->
size());
63 max_answers = max_pts_per_cluster;
69 for (std::size_t i = 0; i < host_cloud_->
size(); ++i) {
82 PointT t = (*host_cloud_)[i];
93 r.
indices.push_back(
static_cast<int>(i));
95 unsigned int found_points =
static_cast<unsigned int>(queries_host.
size());
96 unsigned int previous_found_points = 0;
101 while (previous_found_points < found_points) {
103 queries_device.
upload(queries_host);
105 tree->radiusSearch(queries_device, tolerance, max_answers, result_device);
108 previous_found_points = found_points;
111 std::vector<int> sizes, data;
117 for (std::size_t qp = 0; qp < sizes.size(); qp++) {
118 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 ==
123 (*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]];
132 r.
indices.push_back(data[qp_r + qp * max_answers]);
138 if (found_points >= min_pts_per_cluster && found_points <= max_pts_per_cluster) {
145 clusters.push_back(r);
150 template <
typename Po
intT>
153 std::vector<PointIndices>& clusters)
159 tree_->setCloud(input_);
161 if (!tree_->isBuilt()) {
172 extractLabeledEuclideanClusters<PointT>(host_cloud_,
176 min_pts_per_cluster_,
177 max_pts_per_cluster_);
183 #define PCL_INSTANTIATE_extractLabeledEuclideanClusters(T) \
184 template void PCL_EXPORTS pcl::gpu::extractLabeledEuclideanClusters<T>( \
185 const typename pcl::PointCloud<T>::Ptr&, \
186 const pcl::gpu::Octree::Ptr&, \
188 std::vector<PointIndices>&, \
191 #define PCL_INSTANTIATE_EuclideanLabeledClusterExtraction(T) \
192 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.