Skip to content

Commit

Permalink
Make gpu_extract_clusters templated.
Browse files Browse the repository at this point in the history
Make gpu_extract_clusters exported.
  • Loading branch information
larshg committed Feb 19, 2021
1 parent 05bb178 commit 8119908
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 27 deletions.
2 changes: 1 addition & 1 deletion gpu/segmentation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ set(impl_incs
set(LIB_NAME "pcl_${SUBSYS_NAME}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
PCL_ADD_LIBRARY(${LIB_NAME} COMPONENT ${SUBSYS_NAME} SOURCES ${srcs} ${incs} ${impl_incs})
target_link_libraries("${LIB_NAME}" pcl_gpu_octree pcl_gpu_utils pcl_gpu_containers)
target_link_libraries("${LIB_NAME}" pcl_common pcl_gpu_octree pcl_gpu_utils pcl_gpu_containers)
PCL_MAKE_PKGCONFIG(${LIB_NAME} COMPONENT ${SUBSYS_NAME} DESC ${SUBSYS_DESC} PCL_DEPS ${SUBSYS_DEPS})

# Install include files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ namespace pcl
{
namespace gpu
{
void
extractEuclideanClusters (const pcl::PointCloud<pcl::PointXYZ>::Ptr &host_cloud_,
template <typename PointT> void
extractEuclideanClusters (const typename pcl::PointCloud<PointT>::Ptr &host_cloud_,
const pcl::gpu::Octree::Ptr &tree,
float tolerance,
std::vector<PointIndices> &clusters,
Expand All @@ -62,13 +62,13 @@ namespace pcl
* \author Koen Buys, Radu Bogdan Rusu
* \ingroup segmentation
*/
template <typename PointT>
class EuclideanClusterExtraction
{
public:
using PointType = pcl::PointXYZ;
using PointCloudHost = pcl::PointCloud<pcl::PointXYZ>;
using PointCloudHostPtr = PointCloudHost::Ptr;
using PointCloudHostConstPtr = PointCloudHost::ConstPtr;
using PointCloudHost = pcl::PointCloud<PointT>;
using PointCloudHostPtr = typename PointCloudHost::Ptr;
using PointCloudHostConstPtr = typename PointCloudHost::ConstPtr;

using PointIndicesPtr = PointIndices::Ptr;
using PointIndicesConstPtr = PointIndices::ConstPtr;
Expand All @@ -80,7 +80,7 @@ namespace pcl

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/** \brief Empty constructor. */
EuclideanClusterExtraction () : min_pts_per_cluster_ (1), max_pts_per_cluster_ (std::numeric_limits<int>::max ())
EuclideanClusterExtraction ()
{};

/** \brief the destructor */
Expand Down Expand Up @@ -143,13 +143,13 @@ namespace pcl
GPUTreePtr tree_;

/** \brief The spatial cluster tolerance as a measure in the L2 Euclidean space. */
double cluster_tolerance_;
double cluster_tolerance_ {0};

/** \brief The minimum number of points that a cluster needs to contain in order to be considered valid (default = 1). */
int min_pts_per_cluster_;
int min_pts_per_cluster_ {1};

/** \brief The maximum number of points that a cluster needs to contain in order to be considered valid (default = MAXINT). */
int max_pts_per_cluster_;
int max_pts_per_cluster_ {std::numeric_limits<int>::max()};

/** \brief Class getName method. */
virtual std::string getClassName () const { return ("gpu::EuclideanClusterExtraction"); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@
* @author: Koen Buys
*/

#ifndef PCL_GPU_SEGMENTATION_IMPL_EXTRACT_CLUSTERS_H_
#define PCL_GPU_SEGMENTATION_IMPL_EXTRACT_CLUSTERS_H_

#pragma once
#include <pcl/common/copy_point.h>
#include <pcl/gpu/segmentation/gpu_extract_clusters.h>

void
pcl::gpu::extractEuclideanClusters (const pcl::PointCloud<pcl::PointXYZ>::Ptr &host_cloud_,
template <typename PointT> void
pcl::gpu::extractEuclideanClusters (const typename pcl::PointCloud<PointT>::Ptr &host_cloud_,
const pcl::gpu::Octree::Ptr &tree,
float tolerance,
std::vector<PointIndices> &clusters,
Expand Down Expand Up @@ -80,9 +79,14 @@ pcl::gpu::extractEuclideanClusters (const pcl::PointCloud<pcl::PointXYZ>::Ptr &
// Create the query queue on the device, point based not indices
pcl::gpu::Octree::Queries queries_device;
// Create the query queue on the host
pcl::PointCloud<pcl::PointXYZ>::VectorType queries_host;
pcl::PointCloud<pcl::PointXYZ>::VectorType queries_host;

// Buffer in a new PointXYZ type
PointXYZ p;
pcl::copyPoint((*host_cloud_)[i], p);

// Push the starting point in the vector
queries_host.push_back ((*host_cloud_)[i]);
queries_host.push_back (p);
// Clear vector
r.indices.clear();
// Push the starting point in
Expand Down Expand Up @@ -123,7 +127,12 @@ pcl::gpu::extractEuclideanClusters (const pcl::PointCloud<pcl::PointXYZ>::Ptr &
if(processed[data[i]])
continue;
processed[data[i]] = true;
queries_host.push_back ((*host_cloud_)[data[i]]);

// Buffer in a new PointXYZ type
PointXYZ p;
pcl::copyPoint((*host_cloud_)[data[i]], p);

queries_host.push_back (p);
found_points++;
r.indices.push_back(data[i]);
}
Expand Down Expand Up @@ -153,7 +162,11 @@ pcl::gpu::extractEuclideanClusters (const pcl::PointCloud<pcl::PointXYZ>::Ptr &
if(processed[data[qp_r + qp * max_answers]])
continue;
processed[data[qp_r + qp * max_answers]] = true;
queries_host.push_back ((*host_cloud_)[data[qp_r + qp * max_answers]]);
// Buffer in a new PointXYZ type
PointXYZ p;
pcl::copyPoint((*host_cloud_)[data[qp_r + qp * max_answers]], p);

queries_host.push_back (p);
found_points++;
r.indices.push_back(data[qp_r + qp * max_answers]);
}
Expand All @@ -176,8 +189,8 @@ pcl::gpu::extractEuclideanClusters (const pcl::PointCloud<pcl::PointXYZ>::Ptr &
}
}

void
pcl::gpu::EuclideanClusterExtraction::extract (std::vector<pcl::PointIndices> &clusters)
template <typename PointT> void
pcl::gpu::EuclideanClusterExtraction<PointT>::extract (std::vector<pcl::PointIndices> &clusters)
{
/*
// Initialize the GPU search tree
Expand All @@ -200,10 +213,11 @@ pcl::gpu::EuclideanClusterExtraction::extract (std::vector<pcl::PointIndices> &c
}
*/
// Extract the actual clusters
extractEuclideanClusters (host_cloud_, tree_, cluster_tolerance_, clusters, min_pts_per_cluster_, max_pts_per_cluster_);
extractEuclideanClusters<PointT> (host_cloud_, tree_, cluster_tolerance_, clusters, min_pts_per_cluster_, max_pts_per_cluster_);
std::cout << "INFO: end of extractEuclideanClusters " << std::endl;
// Sort the clusters based on their size (largest one first)
//std::sort (clusters.rbegin (), clusters.rend (), comparePointClusters);
}

#endif //PCL_GPU_SEGMENTATION_IMPL_EXTRACT_CLUSTERS_H_
#define PCL_INSTANTIATE_extractEuclideanClusters(T) template void PCL_EXPORTS pcl::gpu::extractEuclideanClusters<T> (const typename pcl::PointCloud<T>::Ptr &, const pcl::gpu::Octree::Ptr &,float, std::vector<PointIndices> &, unsigned int, unsigned int);
#define PCL_INSTANTIATE_EuclideanClusterExtraction(T) template class PCL_EXPORTS pcl::gpu::EuclideanClusterExtraction<T>;
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
*
*/

#ifndef PCL_GPU_SEGMENTATION_IMPL_EXTRACT_LABELED_CLUSTERS_H_
#define PCL_GPU_SEGMENTATION_IMPL_EXTRACT_LABELED_CLUSTERS_H_
#pragma once

#include <pcl/gpu/segmentation/gpu_extract_labeled_clusters.h>

Expand Down Expand Up @@ -176,4 +175,3 @@ pcl::gpu::EuclideanLabeledClusterExtraction<PointT>::extract (std::vector<PointI

#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);
#define PCL_INSTANTIATE_EuclideanLabeledClusterExtraction(T) template class PCL_EXPORTS pcl::gpu::EuclideanLabeledClusterExtraction<T>;
#endif //PCL_GPU_SEGMENTATION_IMPL_EXTRACT_LABELED_CLUSTERS_H_
3 changes: 3 additions & 0 deletions gpu/segmentation/src/extract_clusters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@
#include <pcl/impl/instantiate.hpp>
#include <pcl/point_types.h>
//#include <pcl/gpu/segmentation/gpu_extract_labeled_clusters.h>
#include <pcl/gpu/segmentation/impl/gpu_extract_clusters.hpp>
#include <pcl/gpu/segmentation/impl/gpu_extract_labeled_clusters.hpp>

// Instantiations of specific point types
PCL_INSTANTIATE(extractEuclideanClusters, PCL_XYZ_POINT_TYPES);
PCL_INSTANTIATE(EuclideanClusterExtraction, PCL_XYZ_POINT_TYPES);
PCL_INSTANTIATE(extractLabeledEuclideanClusters, PCL_XYZL_POINT_TYPES);
PCL_INSTANTIATE(EuclideanLabeledClusterExtraction, PCL_XYZL_POINT_TYPES);

0 comments on commit 8119908

Please sign in to comment.