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