Skip to content

[segmentation] Deprecate unused max_label in extractLabeledEuclideanClusters #4105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
346 changes: 204 additions & 142 deletions segmentation/include/pcl/segmentation/extract_labeled_clusters.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,155 +35,217 @@

#pragma once

#include <pcl/search/pcl_search.h>
#include <pcl/pcl_base.h>
#include <pcl/search/search.h> // for Search

namespace pcl
{
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) \param[in] max_label \ingroup segmentation
*/
template <typename PointT>
PCL_DEPRECATED(1, 14, "Use of max_label is deprecated")
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,
unsigned int max_pts_per_cluster,
unsigned int max_label);
Comment on lines +66 to +68
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing defaults for parameters?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the deprecated version. If someone is using with a parameter, only then it affects them. Adding a default to the deprecated version will create a conflict between the two versions


/** \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 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)
* \param[in] max_label
* \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 (),
unsigned int max_label = 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>
/** \brief Empty constructor. */
LabeledEuclideanClusterExtraction()
: tree_()
, cluster_tolerance_(0)
, min_pts_per_cluster_(1)
, max_pts_per_cluster_(std::numeric_limits<int>::max())
, max_label_(std::numeric_limits<int>::max()){};

/** \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)
{
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 () :
tree_ (),
cluster_tolerance_ (0),
min_pts_per_cluster_ (1),
max_pts_per_cluster_ (std::numeric_limits<int>::max ()),
max_label_ (std::numeric_limits<int>::max ())
{};

/** \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 Set the maximum number of labels in the cloud.
* \param[in] max_label the maximum
*/
inline void
setMaxLabels (unsigned int max_label) { max_label_ = max_label; }

/** \brief Get the maximum number of labels */
inline unsigned int
getMaxLabels () const { return (max_label_); }

/** \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::input_;
using BasePCLBase::indices_;
using BasePCLBase::initCompute;
using BasePCLBase::deinitCompute;

/** \brief A pointer to the spatial search object. */
KdTreePtr 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 The maximum number of labels we can find in this pointcloud (default = MAXINT)*/
unsigned int max_label_;

/** \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)
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 (a.indices.size () < b.indices.size ());
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 Set the maximum number of labels in the cloud.
* \param[in] max_label the maximum
*/
PCL_DEPRECATED(1, 14, "Max label is being deprecated")
inline void
setMaxLabels(unsigned int max_label)
{
max_label_ = max_label;
}

/** \brief Get the maximum number of labels */
PCL_DEPRECATED(1, 14, "Max label is being deprecated")
inline unsigned int
getMaxLabels() const
{
return (max_label_);
}

/** \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_;

/** \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 The maximum number of labels we can find in this pointcloud (default =
* MAXINT)*/
unsigned int max_label_;

/** \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>
Expand Down
Loading