gpu_extract_labeled_clusters.h
/*
* Software License Agreement (BSD License)
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2010-2011, Willow Garage, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of Willow Garage, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Id:$
*
*/
#ifndef PCL_GPU_EXTRACT_LABELED_CLUSTERS_H_
#define PCL_GPU_EXTRACT_LABELED_CLUSTERS_H_
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <pcl/PointIndices.h>
#include <pcl/pcl_macros.h>
#include <pcl/gpu/octree/octree.hpp>
#include <pcl/gpu/containers/impl/device_array.hpp>
namespace pcl
{
namespace gpu
{
template <typename PointT> void
extractLabeledEuclideanClusters (const boost::shared_ptr<pcl::PointCloud<PointT> > &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);
/** \brief @b EuclideanLabeledClusterExtraction represents a segmentation class for cluster extraction in an Euclidean sense, depending on pcl::gpu::octree
* \author Koen Buys, Radu Bogdan Rusu
* \ingroup segmentation
*/
template <typename PointT>
class EuclideanLabeledClusterExtraction
{
public:
typedef pcl::PointXYZ PointType;
typedef pcl::PointCloud<PointT> PointCloudHost;
typedef typename PointCloudHost::Ptr PointCloudHostPtr;
typedef typename PointCloudHost::ConstPtr PointCloudHostConstPtr;
typedef PointIndices::Ptr PointIndicesPtr;
typedef PointIndices::ConstPtr PointIndicesConstPtr;
typedef pcl::gpu::Octree GPUTree;
typedef pcl::gpu::Octree::Ptr GPUTreePtr;
typedef pcl::gpu::Octree::PointCloud CloudDevice;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/** \brief Empty constructor. */
EuclideanLabeledClusterExtraction () : min_pts_per_cluster_ (1), max_pts_per_cluster_ (std::numeric_limits<int>::max ())
{};
/** \brief Provide a pointer to the search object.
* \param tree a pointer to the spatial search object.
*/
inline void setSearchMethod (const GPUTreePtr &tree) { tree_ = tree; }
/** \brief Get a pointer to the search method used.
* @todo fix this for a generic search tree
*/
inline GPUTreePtr getSearchMethod () { return (tree_); }
/** \brief Set the spatial cluster tolerance as a measure in the L2 Euclidean space
* \param tolerance the spatial cluster tolerance as a measure in the L2 Euclidean space
*/
inline void setClusterTolerance (double tolerance) { cluster_tolerance_ = tolerance; }
/** \brief Get the spatial cluster tolerance as a measure in the L2 Euclidean space. */
inline double getClusterTolerance () { return (cluster_tolerance_); }
/** \brief Set the minimum number of points that a cluster needs to contain in order to be considered valid.
* \param min_cluster_size the minimum cluster size
*/
inline void setMinClusterSize (int min_cluster_size) { min_pts_per_cluster_ = min_cluster_size; }
/** \brief Get the minimum number of points that a cluster needs to contain in order to be considered valid. */
inline int getMinClusterSize () { return (min_pts_per_cluster_); }
/** \brief Set the maximum number of points that a cluster needs to contain in order to be considered valid.
* \param max_cluster_size the maximum cluster size
*/
inline void setMaxClusterSize (int max_cluster_size) { max_pts_per_cluster_ = max_cluster_size; }
/** \brief Get the maximum number of points that a cluster needs to contain in order to be considered valid. */
inline int getMaxClusterSize () { return (max_pts_per_cluster_); }
inline void setInput (CloudDevice input) {input_ = input;}
inline void setHostCloud (PointCloudHostPtr host_cloud) {host_cloud_ = host_cloud;}
/** \brief Cluster extraction in a PointCloud given by <setInputCloud (), setIndices ()>
* \param clusters the resultant point clusters
*/
void extract (std::vector<PointIndices> &clusters);
protected:
/** \brief the input cloud on the GPU */
CloudDevice input_;
/** \brief the original cloud the Host */
PointCloudHostPtr host_cloud_;
/** \brief A pointer to the spatial search object. */
GPUTreePtr tree_;
/** \brief The spatial cluster tolerance as a measure in the L2 Euclidean space. */
double cluster_tolerance_;
/** \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_;
/** \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_;
/** \brief Class getName method. */
virtual std::string getClassName () const { return ("gpu::EuclideanLabeledClusterExtraction"); }
};
/** \brief Sort clusters method (for std::sort).
* \ingroup segmentation
*/
inline bool
compareLabeledPointClusters (const pcl::PointIndices &a, const pcl::PointIndices &b)
{
return (a.indices.size () < b.indices.size ());
}
}
}
#endif //PCL_GPU_EXTRACT_LABELED_CLUSTERS_H_
pcl::gpu::EuclideanLabeledClusterExtraction::PointCloudHostConstPtr
PointCloudHost::ConstPtr PointCloudHostConstPtr
Definition: gpu_extract_labeled_clusters.h:73
pcl::gpu::EuclideanLabeledClusterExtraction::getMaxClusterSize
int getMaxClusterSize()
Get the maximum number of points that a cluster needs to contain in order to be considered valid...
Definition: gpu_extract_labeled_clusters.h:120
pcl::gpu::EuclideanLabeledClusterExtraction
EuclideanLabeledClusterExtraction represents a segmentation class for cluster extraction in an Euclid...
Definition: gpu_extract_labeled_clusters.h:67
pcl
Definition: convolution.h:45
pcl::gpu::EuclideanLabeledClusterExtraction::PointCloudHostPtr
PointCloudHost::Ptr PointCloudHostPtr
Definition: gpu_extract_labeled_clusters.h:72
pcl::gpu::EuclideanLabeledClusterExtraction::EuclideanLabeledClusterExtraction
EuclideanLabeledClusterExtraction()
Empty constructor.
Definition: gpu_extract_labeled_clusters.h:85
pcl::gpu::Octree::Ptr
boost::shared_ptr< Octree > Ptr
Types.
Definition: octree.hpp:67
pcl::gpu::EuclideanLabeledClusterExtraction::setMaxClusterSize
void setMaxClusterSize(int max_cluster_size)
Set the maximum number of points that a cluster needs to contain in order to be considered valid...
Definition: gpu_extract_labeled_clusters.h:117
std
Definition: multi_grid_octree_data.hpp:45
pcl::PointIndices::indices
std::vector< int > indices
Definition: PointIndices.h:19
pcl::gpu::EuclideanLabeledClusterExtraction::getClusterTolerance
double getClusterTolerance()
Get the spatial cluster tolerance as a measure in the L2 Euclidean space.
Definition: gpu_extract_labeled_clusters.h:104
pcl::gpu::EuclideanLabeledClusterExtraction::setSearchMethod
void setSearchMethod(const GPUTreePtr &tree)
Provide a pointer to the search object.
Definition: gpu_extract_labeled_clusters.h:91
pcl::gpu::Octree
Octree implementation on GPU.
Definition: octree.hpp:56
pcl::gpu::extractLabeledEuclideanClusters
void extractLabeledEuclideanClusters(const boost::shared_ptr< pcl::PointCloud< PointT > > &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)
Definition: gpu_extract_labeled_clusters.hpp:45
pcl::gpu::EuclideanLabeledClusterExtraction::CloudDevice
pcl::gpu::Octree::PointCloud CloudDevice
Definition: gpu_extract_labeled_clusters.h:81
pcl::gpu::EuclideanLabeledClusterExtraction::PointIndicesPtr
PointIndices::Ptr PointIndicesPtr
Definition: gpu_extract_labeled_clusters.h:75
pcl::PointCloud::Ptr
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
pcl::gpu::EuclideanLabeledClusterExtraction::setMinClusterSize
void setMinClusterSize(int min_cluster_size)
Set the minimum number of points that a cluster needs to contain in order to be considered valid...
Definition: gpu_extract_labeled_clusters.h:109
pcl::gpu::EuclideanLabeledClusterExtraction::PointType
pcl::PointXYZ PointType
Definition: gpu_extract_labeled_clusters.h:70
pcl::gpu::DeviceArray< PointType >
pcl::gpu::compareLabeledPointClusters
bool compareLabeledPointClusters(const pcl::PointIndices &a, const pcl::PointIndices &b)
Sort clusters method (for std::sort).
Definition: gpu_extract_labeled_clusters.h:157
pcl::PointIndices
Definition: PointIndices.h:12
pcl::gpu::EuclideanLabeledClusterExtraction::GPUTreePtr
pcl::gpu::Octree::Ptr GPUTreePtr
Definition: gpu_extract_labeled_clusters.h:79
point_types.h
Defines all the PCL implemented PointT point type structures.
pcl::PointXYZ
A point structure representing Euclidean xyz coordinates.
Definition: point_types.hpp:281
pcl::gpu::EuclideanLabeledClusterExtraction::cluster_tolerance_
double cluster_tolerance_
The spatial cluster tolerance as a measure in the L2 Euclidean space.
Definition: gpu_extract_labeled_clusters.h:142
pcl::gpu::EuclideanLabeledClusterExtraction::PointCloudHost
pcl::PointCloud< PointT > PointCloudHost
Definition: gpu_extract_labeled_clusters.h:71
pcl::gpu::EuclideanLabeledClusterExtraction::getSearchMethod
GPUTreePtr getSearchMethod()
Get a pointer to the search method used.
Definition: gpu_extract_labeled_clusters.h:96
pcl::PointCloud::ConstPtr
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
pcl::gpu::EuclideanLabeledClusterExtraction::min_pts_per_cluster_
int min_pts_per_cluster_
The minimum number of points that a cluster needs to contain in order to be considered valid (default...
Definition: gpu_extract_labeled_clusters.h:145
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points. ...
Definition: projection_matrix.h:53
pcl::gpu::EuclideanLabeledClusterExtraction::getClassName
virtual std::string getClassName() const
Class getName method.
Definition: gpu_extract_labeled_clusters.h:151
pcl::PointIndices::Ptr
boost::shared_ptr< ::pcl::PointIndices > Ptr
Definition: PointIndices.h:22
pcl::gpu::EuclideanLabeledClusterExtraction::PointIndicesConstPtr
PointIndices::ConstPtr PointIndicesConstPtr
Definition: gpu_extract_labeled_clusters.h:76
pcl::gpu::EuclideanLabeledClusterExtraction::getMinClusterSize
int getMinClusterSize()
Get the minimum number of points that a cluster needs to contain in order to be considered valid...
Definition: gpu_extract_labeled_clusters.h:112
pcl::gpu::EuclideanLabeledClusterExtraction::setInput
void setInput(CloudDevice input)
Definition: gpu_extract_labeled_clusters.h:122
pcl::gpu::EuclideanLabeledClusterExtraction::extract
void extract(std::vector< PointIndices > &clusters)
Cluster extraction in a PointCloud given by <setInputCloud (), setIndices ()>
Definition: gpu_extract_labeled_clusters.hpp:150
pcl::gpu::EuclideanLabeledClusterExtraction::host_cloud_
PointCloudHostPtr host_cloud_
the original cloud the Host
Definition: gpu_extract_labeled_clusters.h:136
pcl::gpu::EuclideanLabeledClusterExtraction::setClusterTolerance
void setClusterTolerance(double tolerance)
Set the spatial cluster tolerance as a measure in the L2 Euclidean space.
Definition: gpu_extract_labeled_clusters.h:101
pcl::gpu::EuclideanLabeledClusterExtraction::setHostCloud
void setHostCloud(PointCloudHostPtr host_cloud)
Definition: gpu_extract_labeled_clusters.h:124
pcl::gpu::EuclideanLabeledClusterExtraction::GPUTree
pcl::gpu::Octree GPUTree
Definition: gpu_extract_labeled_clusters.h:78
pcl::gpu::EuclideanLabeledClusterExtraction::input_
CloudDevice input_
the input cloud on the GPU
Definition: gpu_extract_labeled_clusters.h:133
pcl::gpu::EuclideanLabeledClusterExtraction::max_pts_per_cluster_
int max_pts_per_cluster_
The maximum number of points that a cluster needs to contain in order to be considered valid (default...
Definition: gpu_extract_labeled_clusters.h:148
pcl::PointIndices::ConstPtr
boost::shared_ptr< ::pcl::PointIndices const > ConstPtr
Definition: PointIndices.h:23
pcl::gpu::EuclideanLabeledClusterExtraction::tree_
GPUTreePtr tree_
A pointer to the spatial search object.
Definition: gpu_extract_labeled_clusters.h:139