Loading...
Searching...
No Matches
extract_labeled_clusters.h
/*
* Software License Agreement (BSD License)
*
* Copyright (c) 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 the copyright holder(s) 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.
*
*/
#pragma once
#include <pcl/search/search.h>
#include <pcl/pcl_base.h>
namespace pcl {
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/** \brief Decompose a region of space into clusters based on the Euclidean distance
* between points
* \param[in] cloud the point cloud message
* \param[in] tree the spatial locator (e.g., kd-tree) used for nearest neighbors
* searching \note the tree has to be created as a spatial locator on \a cloud
* \param[in] tolerance the spatial cluster tolerance as a measure in L2 Euclidean space
* \param[out] labeled_clusters the resultant clusters containing point indices
* (as a vector of PointIndices)
* \param[in] min_pts_per_cluster minimum number of points that a cluster may contain
* (default: 1)
* \param[in] max_pts_per_cluster maximum number of points that a cluster may contain
* (default: max int)
* \ingroup segmentation
*/
template <typename PointT>
void
extractLabeledEuclideanClusters(
const PointCloud<PointT>& cloud,
const typename search::Search<PointT>::Ptr& tree,
float tolerance,
std::vector<std::vector<PointIndices>>& labeled_clusters,
unsigned int min_pts_per_cluster = 1,
unsigned int max_pts_per_cluster = std::numeric_limits<unsigned int>::max());
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/** \brief @b LabeledEuclideanClusterExtraction represents a segmentation class for
* cluster extraction in an Euclidean sense, with label info. \author Koen Buys
* \ingroup segmentation
*/
template <typename PointT>
class LabeledEuclideanClusterExtraction : public PCLBase<PointT> {
using BasePCLBase = PCLBase<PointT>;
public:
using PointCloud = pcl::PointCloud<PointT>;
using PointCloudPtr = typename PointCloud::Ptr;
using PointCloudConstPtr = typename PointCloud::ConstPtr;
using KdTree = pcl::search::Search<PointT>;
using KdTreePtr = typename KdTree::Ptr;
using PointIndicesPtr = PointIndices::Ptr;
using PointIndicesConstPtr = PointIndices::ConstPtr;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/** \brief Empty constructor. */
LabeledEuclideanClusterExtraction() = default;
/** \brief Provide a pointer to the search object.
* \param[in] tree a pointer to the spatial search object.
*/
inline void
setSearchMethod(const KdTreePtr& tree)
{
tree_ = tree;
}
/** \brief Get a pointer to the search method used. */
inline KdTreePtr
getSearchMethod() const
{
return (tree_);
}
/** \brief Set the spatial cluster tolerance as a measure in the L2 Euclidean space
* \param[in] 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() const
{
return (cluster_tolerance_);
}
/** \brief Set the minimum number of points that a cluster needs to contain in order
* to be considered valid. \param[in] 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() const
{
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[in] 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() const
{
return (max_pts_per_cluster_);
}
/** \brief Cluster extraction in a PointCloud given by <setInputCloud (), setIndices
* ()> \param[out] labeled_clusters the resultant point clusters
*/
void
extract(std::vector<std::vector<PointIndices>>& labeled_clusters);
protected:
// Members derived from the base class
using BasePCLBase::deinitCompute;
using BasePCLBase::indices_;
using BasePCLBase::initCompute;
using BasePCLBase::input_;
/** \brief A pointer to the spatial search object. */
KdTreePtr tree_{nullptr};
/** \brief The spatial cluster tolerance as a measure in the L2 Euclidean space. */
double cluster_tolerance_{0.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_{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_{std::numeric_limits<int>::max()};
/** \brief The maximum number of labels we can find in this pointcloud (default =
* MAXINT)*/
PCL_DEPRECATED(1, 18, "this member variable is unused")
unsigned int max_label_{std::numeric_limits<unsigned int>::max()};
/** \brief Class getName method. */
virtual std::string
getClassName() const
{
return ("LabeledEuclideanClusterExtraction");
}
};
/** \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());
}
} // namespace pcl
#ifdef PCL_NO_PRECOMPILE
#include <pcl/segmentation/impl/extract_labeled_clusters.hpp>
#endif
pcl::LabeledEuclideanClusterExtraction
LabeledEuclideanClusterExtraction represents a segmentation class for cluster extraction in an Euclid...
Definition extract_labeled_clusters.h:75
pcl::LabeledEuclideanClusterExtraction::max_label_
unsigned int max_label_
The maximum number of labels we can find in this pointcloud (default = MAXINT)
Definition extract_labeled_clusters.h:191
pcl::LabeledEuclideanClusterExtraction::setClusterTolerance
void setClusterTolerance(double tolerance)
Set the spatial cluster tolerance as a measure in the L2 Euclidean space.
Definition extract_labeled_clusters.h:114
pcl::LabeledEuclideanClusterExtraction::tree_
KdTreePtr tree_
A pointer to the spatial search object.
Definition extract_labeled_clusters.h:175
pcl::LabeledEuclideanClusterExtraction::cluster_tolerance_
double cluster_tolerance_
The spatial cluster tolerance as a measure in the L2 Euclidean space.
Definition extract_labeled_clusters.h:178
pcl::LabeledEuclideanClusterExtraction::KdTreePtr
typename KdTree::Ptr KdTreePtr
Definition extract_labeled_clusters.h:84
pcl::LabeledEuclideanClusterExtraction::PointCloudConstPtr
typename PointCloud::ConstPtr PointCloudConstPtr
Definition extract_labeled_clusters.h:81
pcl::LabeledEuclideanClusterExtraction::PointIndicesConstPtr
PointIndices::ConstPtr PointIndicesConstPtr
Definition extract_labeled_clusters.h:87
pcl::LabeledEuclideanClusterExtraction::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 extract_labeled_clusters.h:131
pcl::LabeledEuclideanClusterExtraction::PointCloud
pcl::PointCloud< PointT > PointCloud
Definition extract_labeled_clusters.h:79
pcl::LabeledEuclideanClusterExtraction::extract
void extract(std::vector< std::vector< PointIndices > > &labeled_clusters)
Cluster extraction in a PointCloud given by <setInputCloud (), setIndices ()>
Definition extract_labeled_clusters.hpp:129
pcl::LabeledEuclideanClusterExtraction::getMaxClusterSize
int getMaxClusterSize() const
Get the maximum number of points that a cluster needs to contain in order to be considered valid.
Definition extract_labeled_clusters.h:156
pcl::LabeledEuclideanClusterExtraction::PointIndicesPtr
PointIndices::Ptr PointIndicesPtr
Definition extract_labeled_clusters.h:86
pcl::LabeledEuclideanClusterExtraction::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 extract_labeled_clusters.h:182
pcl::LabeledEuclideanClusterExtraction::PointCloudPtr
typename PointCloud::Ptr PointCloudPtr
Definition extract_labeled_clusters.h:80
pcl::LabeledEuclideanClusterExtraction::getClusterTolerance
double getClusterTolerance() const
Get the spatial cluster tolerance as a measure in the L2 Euclidean space.
Definition extract_labeled_clusters.h:122
pcl::LabeledEuclideanClusterExtraction::getClassName
virtual std::string getClassName() const
Class getName method.
Definition extract_labeled_clusters.h:195
pcl::LabeledEuclideanClusterExtraction::getSearchMethod
KdTreePtr getSearchMethod() const
Get a pointer to the search method used.
Definition extract_labeled_clusters.h:104
pcl::LabeledEuclideanClusterExtraction::getMinClusterSize
int getMinClusterSize() const
Get the minimum number of points that a cluster needs to contain in order to be considered valid.
Definition extract_labeled_clusters.h:139
pcl::LabeledEuclideanClusterExtraction::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 extract_labeled_clusters.h:186
pcl::LabeledEuclideanClusterExtraction::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 extract_labeled_clusters.h:148
pcl::LabeledEuclideanClusterExtraction::LabeledEuclideanClusterExtraction
LabeledEuclideanClusterExtraction()=default
Empty constructor.
pcl::LabeledEuclideanClusterExtraction::setSearchMethod
void setSearchMethod(const KdTreePtr &tree)
Provide a pointer to the search object.
Definition extract_labeled_clusters.h:97
pcl::PCLBase
PCL base class.
Definition pcl_base.h:70
pcl::PCLBase::input_
PointCloudConstPtr input_
The input point cloud dataset.
Definition pcl_base.h:147
pcl::PCLBase::indices_
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition pcl_base.h:150
pcl::PCLBase::initCompute
bool initCompute()
This method should get called before starting the actual computation.
Definition pcl_base.hpp:138
pcl::PCLBase::deinitCompute
bool deinitCompute()
This method should get called after finishing the actual computation.
Definition pcl_base.hpp:175
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition point_cloud.h:173
pcl::PointCloud::Ptr
shared_ptr< PointCloud< PointT > > Ptr
Definition point_cloud.h:413
pcl::PointCloud::ConstPtr
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition point_cloud.h:414
pcl::search::Search
Generic search class.
Definition search.h:75
pcl::search::Search::Ptr
shared_ptr< pcl::search::Search< PointT > > Ptr
Definition search.h:81
pcl::extractLabeledEuclideanClusters
void extractLabeledEuclideanClusters(const PointCloud< PointT > &cloud, const typename search::Search< PointT >::Ptr &tree, float tolerance, std::vector< std::vector< PointIndices > > &labeled_clusters, unsigned int min_pts_per_cluster=1, unsigned int max_pts_per_cluster=std::numeric_limits< unsigned int >::max())
Decompose a region of space into clusters based on the Euclidean distance between points.
Definition extract_labeled_clusters.hpp:45
pcl::compareLabeledPointClusters
bool compareLabeledPointClusters(const pcl::PointIndices &a, const pcl::PointIndices &b)
Sort clusters method (for std::sort).
Definition extract_labeled_clusters.h:205
pcl
Definition convolution.h:46
PCL_DEPRECATED
#define PCL_DEPRECATED(Major, Minor, Message)
macro for compatibility across compilers and help remove old deprecated items for the Major....
Definition pcl_macros.h:158
pcl::PointIndices
Definition PointIndices.h:12
pcl::PointIndices::Ptr
shared_ptr< ::pcl::PointIndices > Ptr
Definition PointIndices.h:13
pcl::PointIndices::ConstPtr
shared_ptr< const ::pcl::PointIndices > ConstPtr
Definition PointIndices.h:14
pcl::PointIndices::indices
Indices indices
Definition PointIndices.h:20