Point Cloud Library (PCL) 1.13.0
organized_edge_detection.h
1/*
2 * Software License Agreement (BSD License)
3 *
4 * Point Cloud Library (PCL) - www.pointclouds.org
5 * Copyright (c) 2012-, Open Perception, Inc.
6 *
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials provided
18 * with the distribution.
19 * * Neither the name of the copyright holder(s) nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 *
36 */
37
38#pragma once
39
40#include <pcl/pcl_base.h>
41#include <pcl/PointIndices.h>
42
43namespace pcl
44{
45 /** \brief OrganizedEdgeBase, OrganizedEdgeFromRGB, OrganizedEdgeFromNormals,
46 * and OrganizedEdgeFromRGBNormals find 3D edges from an organized point
47 * cloud data. Given an organized point cloud, they will output a PointCloud
48 * of edge labels and a vector of PointIndices.
49 * OrganizedEdgeBase accepts PCL_XYZ_POINT_TYPES and returns EDGELABEL_NAN_BOUNDARY, EDGELABEL_OCCLUDING, and EDGELABEL_OCCLUDED.
50 * OrganizedEdgeFromRGB accepts PCL_RGB_POINT_TYPES and returns EDGELABEL_NAN_BOUNDARY, EDGELABEL_OCCLUDING, EDGELABEL_OCCLUDED, and EDGELABEL_RGB_CANNY.
51 * OrganizedEdgeFromNormals accepts PCL_XYZ_POINT_TYPES with PCL_NORMAL_POINT_TYPES and returns EDGELABEL_NAN_BOUNDARY, EDGELABEL_OCCLUDING, EDGELABEL_OCCLUDED, and EDGELABEL_HIGH_CURVATURE.
52 * OrganizedEdgeFromRGBNormals accepts PCL_RGB_POINT_TYPES with PCL_NORMAL_POINT_TYPES and returns EDGELABEL_NAN_BOUNDARY, EDGELABEL_OCCLUDING, EDGELABEL_OCCLUDED, EDGELABEL_HIGH_CURVATURE, and EDGELABEL_RGB_CANNY.
53 *
54 * \author Changhyun Choi
55 */
56 template <typename PointT, typename PointLT>
57 class OrganizedEdgeBase : public PCLBase<PointT>
58 {
60 using PointCloudPtr = typename PointCloud::Ptr;
62
64 using PointCloudLPtr = typename PointCloudL::Ptr;
65 using PointCloudLConstPtr = typename PointCloudL::ConstPtr;
66
67 public:
68 using Ptr = shared_ptr<OrganizedEdgeBase<PointT, PointLT> >;
69 using ConstPtr = shared_ptr<const OrganizedEdgeBase<PointT, PointLT> >;
74
75 /** \brief Constructor for OrganizedEdgeBase */
77 : th_depth_discon_ (0.02f)
80 {
81 }
82
83 /** \brief Destructor for OrganizedEdgeBase */
84
85 ~OrganizedEdgeBase () override = default;
86
87 /** \brief Perform the 3D edge detection (edges from depth discontinuities)
88 * \param[out] labels a PointCloud of edge labels
89 * \param[out] label_indices a vector of PointIndices corresponding to each edge label
90 */
91 void
92 compute (pcl::PointCloud<PointLT>& labels, std::vector<pcl::PointIndices>& label_indices) const;
93
94 /** \brief Set the tolerance in meters for the relative difference in depth values between neighboring points.
95 * e.g. If a point has a depth (z) value of 2.0 meters, a neighboring point is discontinuous if its depth differs by > 2.0 * th. */
96 inline void
97 setDepthDisconThreshold (const float th)
98 {
100 }
101
102 /** \brief Get the tolerance in meters for the relative difference in depth values between neighboring points.
103 * e.g. If a point has a depth (z) value of 2.0 meters, a neighboring point is discontinuous if its depth differs by > 2.0 * th. */
104 inline float
106 {
107 return (th_depth_discon_);
108 }
109
110 /** \brief Set the max search distance for deciding occluding and occluded edges. */
111 inline void
112 setMaxSearchNeighbors (const int max_dist)
113 {
114 max_search_neighbors_ = max_dist;
115 }
116
117 /** \brief Get the max search distance for deciding occluding and occluded edges. */
118 inline int
120 {
121 return (max_search_neighbors_);
122 }
123
124 /** \brief Set the detecting edge types. */
125 inline void
126 setEdgeType (int edge_types)
127 {
128 detecting_edge_types_ = edge_types;
129 }
130
131 /** \brief Get the detecting edge types. */
132 inline int
133 getEdgeType () const
134 {
136 }
137
139 static const int num_of_edgetype_ = 5;
140
141 protected:
142 /** \brief Perform the 3D edge detection (edges from depth discontinuities) and assign point indices for each edge label
143 * \param[out] labels a PointCloud of edge labels
144 */
145 void
147
148 /** \brief Assign point indices for each edge label
149 * \param[out] labels a PointCloud of edge labels
150 * \param[out] label_indices a vector of PointIndices corresponding to each edge label
151 */
152 void
153 assignLabelIndices (pcl::PointCloud<PointLT>& labels, std::vector<pcl::PointIndices>& label_indices) const;
154
155 struct Neighbor
156 {
157 Neighbor (int dx, int dy, int didx)
158 : d_x (dx)
159 , d_y (dy)
160 , d_index (didx)
161 {}
162
163 int d_x;
164 int d_y;
165 int d_index; // = dy * width + dx: pre-calculated
166 };
167
168 /** \brief The tolerance in meters for the relative difference in depth values between neighboring points
169 * (The default value is set for .02 meters and is adapted with respect to depth value linearly.
170 * e.g. If a point has a depth (z) value of 2.0 meters, a neighboring point is discontinuous if its depth differs by > 2.0 * th. */
172
173 /** \brief The max search distance for deciding occluding and occluded edges */
175
176 /** \brief The bit encoded value that represents edge types to detect */
178 };
179
180 template <typename PointT, typename PointLT>
181 class OrganizedEdgeFromRGB : virtual public OrganizedEdgeBase<PointT, PointLT>
182 {
184 using PointCloudPtr = typename PointCloud::Ptr;
186
188 using PointCloudLPtr = typename PointCloudL::Ptr;
189 using PointCloudLConstPtr = typename PointCloudL::ConstPtr;
190
191 public:
192 using OrganizedEdgeBase<PointT, PointLT>::input_;
193 using OrganizedEdgeBase<PointT, PointLT>::indices_;
201
202 /** \brief Constructor for OrganizedEdgeFromRGB */
204 : OrganizedEdgeBase<PointT, PointLT> ()
205 , th_rgb_canny_low_ (40.0)
206 , th_rgb_canny_high_ (100.0)
207 {
209 }
210
211 /** \brief Destructor for OrganizedEdgeFromRGB */
212
213 ~OrganizedEdgeFromRGB () override = default;
214
215 /** \brief Perform the 3D edge detection (edges from depth discontinuities and RGB Canny edge) and assign point indices for each edge label
216 * \param[out] labels a PointCloud of edge labels
217 * \param[out] label_indices a vector of PointIndices corresponding to each edge label
218 */
219 void
220 compute (pcl::PointCloud<PointLT>& labels, std::vector<pcl::PointIndices>& label_indices) const;
221
222 /** \brief Set the low threshold value for RGB Canny edge detection */
223 inline void
224 setRGBCannyLowThreshold (const float th)
225 {
227 }
228
229 /** \brief Get the low threshold value for RGB Canny edge detection */
230 inline float
232 {
233 return (th_rgb_canny_low_);
234 }
235
236 /** \brief Set the high threshold value for RGB Canny edge detection */
237 inline void
239 {
241 }
242
243 /** \brief Get the high threshold value for RGB Canny edge detection */
244 inline float
246 {
247 return (th_rgb_canny_high_);
248 }
249
250 protected:
251 /** \brief Perform the 3D edge detection (edges from depth discontinuities and RGB Canny edge)
252 * \param[out] labels a PointCloud of edge labels
253 */
254 void
256
257 /** \brief The low threshold value for RGB Canny edge detection (default: 40.0) */
259
260 /** \brief The high threshold value for RGB Canny edge detection (default: 100.0) */
262 };
263
264 template <typename PointT, typename PointNT, typename PointLT>
265 class OrganizedEdgeFromNormals : virtual public OrganizedEdgeBase<PointT, PointLT>
266 {
268 using PointCloudPtr = typename PointCloud::Ptr;
270
272 using PointCloudNPtr = typename PointCloudN::Ptr;
273 using PointCloudNConstPtr = typename PointCloudN::ConstPtr;
274
276 using PointCloudLPtr = typename PointCloudL::Ptr;
277 using PointCloudLConstPtr = typename PointCloudL::ConstPtr;
278
279 public:
280 using OrganizedEdgeBase<PointT, PointLT>::input_;
281 using OrganizedEdgeBase<PointT, PointLT>::indices_;
289
290 /** \brief Constructor for OrganizedEdgeFromNormals */
292 : OrganizedEdgeBase<PointT, PointLT> ()
293 , normals_ ()
294 , th_hc_canny_low_ (0.4f)
295 , th_hc_canny_high_ (1.1f)
296 {
298 }
299
300 /** \brief Destructor for OrganizedEdgeFromNormals */
301
302 ~OrganizedEdgeFromNormals () override = default;
303
304 /** \brief Perform the 3D edge detection (edges from depth discontinuities and high curvature regions) and assign point indices for each edge label
305 * \param[out] labels a PointCloud of edge labels
306 * \param[out] label_indices a vector of PointIndices corresponding to each edge label
307 */
308 void
309 compute (pcl::PointCloud<PointLT>& labels, std::vector<pcl::PointIndices>& label_indices) const;
310
311 /** \brief Provide a pointer to the input normals.
312 * \param[in] normals the input normal cloud
313 */
314 inline void
315 setInputNormals (const PointCloudNConstPtr &normals)
316 {
317 normals_ = normals;
318 }
319
320 /** \brief Get the input normals. */
321 inline PointCloudNConstPtr
323 {
324 return (normals_);
325 }
326
327 /** \brief Set the low threshold value for high curvature Canny edge detection */
328 inline void
329 setHCCannyLowThreshold (const float th)
330 {
331 th_hc_canny_low_ = th;
332 }
333
334 /** \brief Get the low threshold value for high curvature Canny edge detection */
335 inline float
337 {
338 return (th_hc_canny_low_);
339 }
340
341 /** \brief Set the high threshold value for high curvature Canny edge detection */
342 inline void
343 setHCCannyHighThreshold (const float th)
344 {
346 }
347
348 /** \brief Get the high threshold value for high curvature Canny edge detection */
349 inline float
351 {
352 return (th_hc_canny_high_);
353 }
354
355 protected:
356 /** \brief Perform the 3D edge detection (edges from depth discontinuities and high curvature regions)
357 * \param[out] labels a PointCloud of edge labels
358 */
359 void
361
362 /** \brief A pointer to the input normals */
363 PointCloudNConstPtr normals_;
364
365 /** \brief The low threshold value for high curvature Canny edge detection (default: 0.4) */
367
368 /** \brief The high threshold value for high curvature Canny edge detection (default: 1.1) */
370 };
371
372 template <typename PointT, typename PointNT, typename PointLT>
373 class OrganizedEdgeFromRGBNormals : public OrganizedEdgeFromRGB<PointT, PointLT>, public OrganizedEdgeFromNormals<PointT, PointNT, PointLT>
374 {
376 using PointCloudPtr = typename PointCloud::Ptr;
378
380 using PointCloudNPtr = typename PointCloudN::Ptr;
381 using PointCloudNConstPtr = typename PointCloudN::ConstPtr;
382
384 using PointCloudLPtr = typename PointCloudL::Ptr;
385 using PointCloudLConstPtr = typename PointCloudL::ConstPtr;
386
387 public:
388 using OrganizedEdgeFromNormals<PointT, PointNT, PointLT>::input_;
389 using OrganizedEdgeFromNormals<PointT, PointNT, PointLT>::indices_;
390 using OrganizedEdgeFromNormals<PointT, PointNT, PointLT>::initCompute;
391 using OrganizedEdgeFromNormals<PointT, PointNT, PointLT>::deinitCompute;
398
399 /** \brief Constructor for OrganizedEdgeFromRGBNormals */
401 : OrganizedEdgeFromRGB<PointT, PointLT> ()
402 , OrganizedEdgeFromNormals<PointT, PointNT, PointLT> ()
403 {
405 }
406
407 /** \brief Destructor for OrganizedEdgeFromRGBNormals */
408
409 ~OrganizedEdgeFromRGBNormals () override = default;
410
411 /** \brief Perform the 3D edge detection (edges from depth discontinuities, RGB Canny edge, and high curvature regions) and assign point indices for each edge label
412 * \param[out] labels a PointCloud of edge labels
413 * \param[out] label_indices a vector of PointIndices corresponding to each edge label
414 */
415 void
416 compute (pcl::PointCloud<PointLT>& labels, std::vector<pcl::PointIndices>& label_indices) const;
417 };
418}
419
420#ifdef PCL_NO_PRECOMPILE
421#include <pcl/features/impl/organized_edge_detection.hpp>
422#endif
OrganizedEdgeBase, OrganizedEdgeFromRGB, OrganizedEdgeFromNormals, and OrganizedEdgeFromRGBNormals fi...
int getEdgeType() const
Get the detecting edge types.
float th_depth_discon_
The tolerance in meters for the relative difference in depth values between neighboring points (The d...
int getMaxSearchNeighbors() const
Get the max search distance for deciding occluding and occluded edges.
int detecting_edge_types_
The bit encoded value that represents edge types to detect.
OrganizedEdgeBase()
Constructor for OrganizedEdgeBase.
void assignLabelIndices(pcl::PointCloud< PointLT > &labels, std::vector< pcl::PointIndices > &label_indices) const
Assign point indices for each edge label.
float getDepthDisconThreshold() const
Get the tolerance in meters for the relative difference in depth values between neighboring points.
~OrganizedEdgeBase() override=default
Destructor for OrganizedEdgeBase.
void extractEdges(pcl::PointCloud< PointLT > &labels) const
Perform the 3D edge detection (edges from depth discontinuities) and assign point indices for each ed...
void setEdgeType(int edge_types)
Set the detecting edge types.
void setMaxSearchNeighbors(const int max_dist)
Set the max search distance for deciding occluding and occluded edges.
void compute(pcl::PointCloud< PointLT > &labels, std::vector< pcl::PointIndices > &label_indices) const
Perform the 3D edge detection (edges from depth discontinuities)
void setDepthDisconThreshold(const float th)
Set the tolerance in meters for the relative difference in depth values between neighboring points.
shared_ptr< const OrganizedEdgeBase< PointT, PointLT > > ConstPtr
shared_ptr< OrganizedEdgeBase< PointT, PointLT > > Ptr
int max_search_neighbors_
The max search distance for deciding occluding and occluded edges.
PointCloudNConstPtr getInputNormals() const
Get the input normals.
void compute(pcl::PointCloud< PointLT > &labels, std::vector< pcl::PointIndices > &label_indices) const
Perform the 3D edge detection (edges from depth discontinuities and high curvature regions) and assig...
PointCloudNConstPtr normals_
A pointer to the input normals.
void setHCCannyLowThreshold(const float th)
Set the low threshold value for high curvature Canny edge detection.
float th_hc_canny_high_
The high threshold value for high curvature Canny edge detection (default: 1.1)
void setHCCannyHighThreshold(const float th)
Set the high threshold value for high curvature Canny edge detection.
OrganizedEdgeFromNormals()
Constructor for OrganizedEdgeFromNormals.
float getHCCannyHighThreshold() const
Get the high threshold value for high curvature Canny edge detection.
~OrganizedEdgeFromNormals() override=default
Destructor for OrganizedEdgeFromNormals.
void extractEdges(pcl::PointCloud< PointLT > &labels) const
Perform the 3D edge detection (edges from depth discontinuities and high curvature regions)
void setInputNormals(const PointCloudNConstPtr &normals)
Provide a pointer to the input normals.
float th_hc_canny_low_
The low threshold value for high curvature Canny edge detection (default: 0.4)
float getHCCannyLowThreshold() const
Get the low threshold value for high curvature Canny edge detection.
float getRGBCannyLowThreshold() const
Get the low threshold value for RGB Canny edge detection.
void extractEdges(pcl::PointCloud< PointLT > &labels) const
Perform the 3D edge detection (edges from depth discontinuities and RGB Canny edge)
float getRGBCannyHighThreshold() const
Get the high threshold value for RGB Canny edge detection.
OrganizedEdgeFromRGB()
Constructor for OrganizedEdgeFromRGB.
float th_rgb_canny_high_
The high threshold value for RGB Canny edge detection (default: 100.0)
~OrganizedEdgeFromRGB() override=default
Destructor for OrganizedEdgeFromRGB.
void setRGBCannyLowThreshold(const float th)
Set the low threshold value for RGB Canny edge detection.
void setRGBCannyHighThreshold(const float th)
Set the high threshold value for RGB Canny edge detection.
float th_rgb_canny_low_
The low threshold value for RGB Canny edge detection (default: 40.0)
void compute(pcl::PointCloud< PointLT > &labels, std::vector< pcl::PointIndices > &label_indices) const
Perform the 3D edge detection (edges from depth discontinuities and RGB Canny edge) and assign point ...
void compute(pcl::PointCloud< PointLT > &labels, std::vector< pcl::PointIndices > &label_indices) const
Perform the 3D edge detection (edges from depth discontinuities, RGB Canny edge, and high curvature r...
~OrganizedEdgeFromRGBNormals() override=default
Destructor for OrganizedEdgeFromRGBNormals.
OrganizedEdgeFromRGBNormals()
Constructor for OrganizedEdgeFromRGBNormals.
PCL base class.
Definition: pcl_base.h:70
PointCloudConstPtr input_
The input point cloud dataset.
Definition: pcl_base.h:147
typename PointCloud::Ptr PointCloudPtr
Definition: pcl_base.h:73
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: pcl_base.h:74
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition: pcl_base.h:150
bool initCompute()
This method should get called before starting the actual computation.
Definition: pcl_base.hpp:138
bool deinitCompute()
This method should get called after finishing the actual computation.
Definition: pcl_base.hpp:174
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:413
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:414
A point structure representing Euclidean xyz coordinates, and the RGB color.