Skip to content

Commit 6111908

Browse files
authored
Merge pull request #4105 from kunaltyagi/deprecate-unused-param
2 parents 0a425d3 + ace2a0c commit 6111908

File tree

3 files changed

+320
-206
lines changed

3 files changed

+320
-206
lines changed

segmentation/include/pcl/segmentation/extract_labeled_clusters.h

Lines changed: 210 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -35,155 +35,223 @@
3535

3636
#pragma once
3737

38+
#include <pcl/search/search.h>
3839
#include <pcl/pcl_base.h>
39-
#include <pcl/search/search.h> // for Search
4040

41-
namespace pcl
42-
{
41+
namespace pcl {
42+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
43+
/** \brief Decompose a region of space into clusters based on the Euclidean distance
44+
* between points
45+
* \param[in] cloud the point cloud message
46+
* \param[in] tree the spatial locator (e.g., kd-tree) used for nearest neighbors
47+
* searching
48+
* \note the tree has to be created as a spatial locator on \a cloud
49+
* \param[in] tolerance the spatial cluster tolerance as a measure in L2 Euclidean space
50+
* \param[out] labeled_clusters the resultant clusters containing point indices (as a
51+
* vector of PointIndices)
52+
* \param[in] min_pts_per_cluster minimum number of points that a cluster may contain
53+
* (default: 1)
54+
* \param[in] max_pts_per_cluster maximum number of points that a cluster may contain
55+
* (default: max int)
56+
* \param[in] max_label
57+
* \ingroup segmentation
58+
*/
59+
template <typename PointT>
60+
PCL_DEPRECATED(1, 14, "Use of max_label is deprecated")
61+
void extractLabeledEuclideanClusters(
62+
const PointCloud<PointT>& cloud,
63+
const typename search::Search<PointT>::Ptr& tree,
64+
float tolerance,
65+
std::vector<std::vector<PointIndices>>& labeled_clusters,
66+
unsigned int min_pts_per_cluster,
67+
unsigned int max_pts_per_cluster,
68+
unsigned int max_label);
69+
70+
/** \brief Decompose a region of space into clusters based on the Euclidean distance
71+
* between points \param[in] cloud the point cloud message \param[in] tree the spatial
72+
* locator (e.g., kd-tree) used for nearest neighbors searching \note the tree has to be
73+
* created as a spatial locator on \a cloud \param[in] tolerance the spatial cluster
74+
* tolerance as a measure in L2 Euclidean space \param[out] labeled_clusters the
75+
* resultant clusters containing point indices (as a vector of PointIndices) \param[in]
76+
* min_pts_per_cluster minimum number of points that a cluster may contain (default: 1)
77+
* \param[in] max_pts_per_cluster maximum number of points that a cluster may contain
78+
* (default: max int) \ingroup segmentation
79+
*/
80+
template <typename PointT>
81+
void
82+
extractLabeledEuclideanClusters(
83+
const PointCloud<PointT>& cloud,
84+
const typename search::Search<PointT>::Ptr& tree,
85+
float tolerance,
86+
std::vector<std::vector<PointIndices>>& labeled_clusters,
87+
unsigned int min_pts_per_cluster = 1,
88+
unsigned int max_pts_per_cluster = std::numeric_limits<unsigned int>::max());
89+
90+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
91+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
92+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
93+
/** \brief @b LabeledEuclideanClusterExtraction represents a segmentation class for
94+
* cluster extraction in an Euclidean sense, with label info. \author Koen Buys \ingroup
95+
* segmentation
96+
*/
97+
template <typename PointT>
98+
class LabeledEuclideanClusterExtraction : public PCLBase<PointT> {
99+
using BasePCLBase = PCLBase<PointT>;
100+
101+
public:
102+
using PointCloud = pcl::PointCloud<PointT>;
103+
using PointCloudPtr = typename PointCloud::Ptr;
104+
using PointCloudConstPtr = typename PointCloud::ConstPtr;
105+
106+
using KdTree = pcl::search::Search<PointT>;
107+
using KdTreePtr = typename KdTree::Ptr;
108+
109+
using PointIndicesPtr = PointIndices::Ptr;
110+
using PointIndicesConstPtr = PointIndices::ConstPtr;
111+
43112
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
44-
/** \brief Decompose a region of space into clusters based on the Euclidean distance between points
45-
* \param[in] cloud the point cloud message
46-
* \param[in] tree the spatial locator (e.g., kd-tree) used for nearest neighbors searching
47-
* \note the tree has to be created as a spatial locator on \a cloud
48-
* \param[in] tolerance the spatial cluster tolerance as a measure in L2 Euclidean space
49-
* \param[out] labeled_clusters the resultant clusters containing point indices (as a vector of PointIndices)
50-
* \param[in] min_pts_per_cluster minimum number of points that a cluster may contain (default: 1)
51-
* \param[in] max_pts_per_cluster maximum number of points that a cluster may contain (default: max int)
52-
* \param[in] max_label
53-
* \ingroup segmentation
54-
*/
55-
template <typename PointT> void
56-
extractLabeledEuclideanClusters (
57-
const PointCloud<PointT> &cloud, const typename search::Search<PointT>::Ptr &tree,
58-
float tolerance, std::vector<std::vector<PointIndices> > &labeled_clusters,
59-
unsigned int min_pts_per_cluster = 1, unsigned int max_pts_per_cluster = std::numeric_limits<unsigned int>::max (),
60-
unsigned int max_label = std::numeric_limits<unsigned int>::max ());
61-
62-
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
63-
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
64-
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
65-
/** \brief @b LabeledEuclideanClusterExtraction represents a segmentation class for cluster extraction in an Euclidean sense, with label info.
66-
* \author Koen Buys
67-
* \ingroup segmentation
68-
*/
69-
template <typename PointT>
70-
class LabeledEuclideanClusterExtraction: public PCLBase<PointT>
113+
/** \brief Empty constructor. */
114+
LabeledEuclideanClusterExtraction()
115+
: tree_()
116+
, cluster_tolerance_(0)
117+
, min_pts_per_cluster_(1)
118+
, max_pts_per_cluster_(std::numeric_limits<int>::max())
119+
, max_label_(std::numeric_limits<int>::max()){};
120+
121+
/** \brief Provide a pointer to the search object.
122+
* \param[in] tree a pointer to the spatial search object.
123+
*/
124+
inline void
125+
setSearchMethod(const KdTreePtr& tree)
126+
{
127+
tree_ = tree;
128+
}
129+
130+
/** \brief Get a pointer to the search method used. */
131+
inline KdTreePtr
132+
getSearchMethod() const
133+
{
134+
return (tree_);
135+
}
136+
137+
/** \brief Set the spatial cluster tolerance as a measure in the L2 Euclidean space
138+
* \param[in] tolerance the spatial cluster tolerance as a measure in the L2 Euclidean
139+
* space
140+
*/
141+
inline void
142+
setClusterTolerance(double tolerance)
143+
{
144+
cluster_tolerance_ = tolerance;
145+
}
146+
147+
/** \brief Get the spatial cluster tolerance as a measure in the L2 Euclidean space.
148+
*/
149+
inline double
150+
getClusterTolerance() const
151+
{
152+
return (cluster_tolerance_);
153+
}
154+
155+
/** \brief Set the minimum number of points that a cluster needs to contain in order
156+
* to be considered valid. \param[in] min_cluster_size the minimum cluster size
157+
*/
158+
inline void
159+
setMinClusterSize(int min_cluster_size)
160+
{
161+
min_pts_per_cluster_ = min_cluster_size;
162+
}
163+
164+
/** \brief Get the minimum number of points that a cluster needs to contain in order
165+
* to be considered valid. */
166+
inline int
167+
getMinClusterSize() const
71168
{
72-
using BasePCLBase = PCLBase<PointT>;
73-
74-
public:
75-
using PointCloud = pcl::PointCloud<PointT>;
76-
using PointCloudPtr = typename PointCloud::Ptr;
77-
using PointCloudConstPtr = typename PointCloud::ConstPtr;
78-
79-
using KdTree = pcl::search::Search<PointT>;
80-
using KdTreePtr = typename KdTree::Ptr;
81-
82-
using PointIndicesPtr = PointIndices::Ptr;
83-
using PointIndicesConstPtr = PointIndices::ConstPtr;
84-
85-
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
86-
/** \brief Empty constructor. */
87-
LabeledEuclideanClusterExtraction () :
88-
tree_ (),
89-
cluster_tolerance_ (0),
90-
min_pts_per_cluster_ (1),
91-
max_pts_per_cluster_ (std::numeric_limits<int>::max ()),
92-
max_label_ (std::numeric_limits<int>::max ())
93-
{};
94-
95-
/** \brief Provide a pointer to the search object.
96-
* \param[in] tree a pointer to the spatial search object.
97-
*/
98-
inline void
99-
setSearchMethod (const KdTreePtr &tree) { tree_ = tree; }
100-
101-
/** \brief Get a pointer to the search method used. */
102-
inline KdTreePtr
103-
getSearchMethod () const { return (tree_); }
104-
105-
/** \brief Set the spatial cluster tolerance as a measure in the L2 Euclidean space
106-
* \param[in] tolerance the spatial cluster tolerance as a measure in the L2 Euclidean space
107-
*/
108-
inline void
109-
setClusterTolerance (double tolerance) { cluster_tolerance_ = tolerance; }
110-
111-
/** \brief Get the spatial cluster tolerance as a measure in the L2 Euclidean space. */
112-
inline double
113-
getClusterTolerance () const { return (cluster_tolerance_); }
114-
115-
/** \brief Set the minimum number of points that a cluster needs to contain in order to be considered valid.
116-
* \param[in] min_cluster_size the minimum cluster size
117-
*/
118-
inline void
119-
setMinClusterSize (int min_cluster_size) { min_pts_per_cluster_ = min_cluster_size; }
120-
121-
/** \brief Get the minimum number of points that a cluster needs to contain in order to be considered valid. */
122-
inline int
123-
getMinClusterSize () const { return (min_pts_per_cluster_); }
124-
125-
/** \brief Set the maximum number of points that a cluster needs to contain in order to be considered valid.
126-
* \param[in] max_cluster_size the maximum cluster size
127-
*/
128-
inline void
129-
setMaxClusterSize (int max_cluster_size) { max_pts_per_cluster_ = max_cluster_size; }
130-
131-
/** \brief Get the maximum number of points that a cluster needs to contain in order to be considered valid. */
132-
inline int
133-
getMaxClusterSize () const { return (max_pts_per_cluster_); }
134-
135-
/** \brief Set the maximum number of labels in the cloud.
136-
* \param[in] max_label the maximum
137-
*/
138-
inline void
139-
setMaxLabels (unsigned int max_label) { max_label_ = max_label; }
140-
141-
/** \brief Get the maximum number of labels */
142-
inline unsigned int
143-
getMaxLabels () const { return (max_label_); }
144-
145-
/** \brief Cluster extraction in a PointCloud given by <setInputCloud (), setIndices ()>
146-
* \param[out] labeled_clusters the resultant point clusters
147-
*/
148-
void
149-
extract (std::vector<std::vector<PointIndices> > &labeled_clusters);
150-
151-
protected:
152-
// Members derived from the base class
153-
using BasePCLBase::input_;
154-
using BasePCLBase::indices_;
155-
using BasePCLBase::initCompute;
156-
using BasePCLBase::deinitCompute;
157-
158-
/** \brief A pointer to the spatial search object. */
159-
KdTreePtr tree_;
160-
161-
/** \brief The spatial cluster tolerance as a measure in the L2 Euclidean space. */
162-
double cluster_tolerance_;
163-
164-
/** \brief The minimum number of points that a cluster needs to contain in order to be considered valid (default = 1). */
165-
int min_pts_per_cluster_;
166-
167-
/** \brief The maximum number of points that a cluster needs to contain in order to be considered valid (default = MAXINT). */
168-
int max_pts_per_cluster_;
169-
170-
/** \brief The maximum number of labels we can find in this pointcloud (default = MAXINT)*/
171-
unsigned int max_label_;
172-
173-
/** \brief Class getName method. */
174-
virtual std::string getClassName () const { return ("LabeledEuclideanClusterExtraction"); }
175-
176-
};
177-
178-
/** \brief Sort clusters method (for std::sort).
179-
* \ingroup segmentation
180-
*/
181-
inline bool
182-
compareLabeledPointClusters (const pcl::PointIndices &a, const pcl::PointIndices &b)
169+
return (min_pts_per_cluster_);
170+
}
171+
172+
/** \brief Set the maximum number of points that a cluster needs to contain in order
173+
* to be considered valid. \param[in] max_cluster_size the maximum cluster size
174+
*/
175+
inline void
176+
setMaxClusterSize(int max_cluster_size)
183177
{
184-
return (a.indices.size () < b.indices.size ());
178+
max_pts_per_cluster_ = max_cluster_size;
185179
}
180+
181+
/** \brief Get the maximum number of points that a cluster needs to contain in order
182+
* to be considered valid. */
183+
inline int
184+
getMaxClusterSize() const
185+
{
186+
return (max_pts_per_cluster_);
187+
}
188+
189+
/** \brief Set the maximum number of labels in the cloud.
190+
* \param[in] max_label the maximum
191+
*/
192+
PCL_DEPRECATED(1, 14, "Max label is being deprecated")
193+
inline void
194+
setMaxLabels(unsigned int max_label)
195+
{
196+
max_label_ = max_label;
197+
}
198+
199+
/** \brief Get the maximum number of labels */
200+
PCL_DEPRECATED(1, 14, "Max label is being deprecated")
201+
inline unsigned int
202+
getMaxLabels() const
203+
{
204+
return (max_label_);
205+
}
206+
207+
/** \brief Cluster extraction in a PointCloud given by <setInputCloud (), setIndices
208+
* ()> \param[out] labeled_clusters the resultant point clusters
209+
*/
210+
void
211+
extract(std::vector<std::vector<PointIndices>>& labeled_clusters);
212+
213+
protected:
214+
// Members derived from the base class
215+
using BasePCLBase::deinitCompute;
216+
using BasePCLBase::indices_;
217+
using BasePCLBase::initCompute;
218+
using BasePCLBase::input_;
219+
220+
/** \brief A pointer to the spatial search object. */
221+
KdTreePtr tree_;
222+
223+
/** \brief The spatial cluster tolerance as a measure in the L2 Euclidean space. */
224+
double cluster_tolerance_;
225+
226+
/** \brief The minimum number of points that a cluster needs to contain in order to be
227+
* considered valid (default = 1). */
228+
int min_pts_per_cluster_;
229+
230+
/** \brief The maximum number of points that a cluster needs to contain in order to be
231+
* considered valid (default = MAXINT). */
232+
int max_pts_per_cluster_;
233+
234+
/** \brief The maximum number of labels we can find in this pointcloud (default =
235+
* MAXINT)*/
236+
unsigned int max_label_;
237+
238+
/** \brief Class getName method. */
239+
virtual std::string
240+
getClassName() const
241+
{
242+
return ("LabeledEuclideanClusterExtraction");
243+
}
244+
};
245+
246+
/** \brief Sort clusters method (for std::sort).
247+
* \ingroup segmentation
248+
*/
249+
inline bool
250+
compareLabeledPointClusters(const pcl::PointIndices& a, const pcl::PointIndices& b)
251+
{
252+
return (a.indices.size() < b.indices.size());
186253
}
254+
} // namespace pcl
187255

188256
#ifdef PCL_NO_PRECOMPILE
189257
#include <pcl/segmentation/impl/extract_labeled_clusters.hpp>

0 commit comments

Comments
 (0)