Point Cloud Library (PCL)  1.12.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 
43 namespace 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 
86  {
87  }
88 
89  /** \brief Perform the 3D edge detection (edges from depth discontinuities)
90  * \param[out] labels a PointCloud of edge labels
91  * \param[out] label_indices a vector of PointIndices corresponding to each edge label
92  */
93  void
94  compute (pcl::PointCloud<PointLT>& labels, std::vector<pcl::PointIndices>& label_indices) const;
95 
96  /** \brief Set the tolerance in meters for the relative difference in depth values between neighboring points.
97  * 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. */
98  inline void
99  setDepthDisconThreshold (const float th)
100  {
101  th_depth_discon_ = th;
102  }
103 
104  /** \brief Get the tolerance in meters for the relative difference in depth values between neighboring points.
105  * 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. */
106  inline float
108  {
109  return (th_depth_discon_);
110  }
111 
112  /** \brief Set the max search distance for deciding occluding and occluded edges. */
113  inline void
114  setMaxSearchNeighbors (const int max_dist)
115  {
116  max_search_neighbors_ = max_dist;
117  }
118 
119  /** \brief Get the max search distance for deciding occluding and occluded edges. */
120  inline int
122  {
123  return (max_search_neighbors_);
124  }
125 
126  /** \brief Set the detecting edge types. */
127  inline void
128  setEdgeType (int edge_types)
129  {
130  detecting_edge_types_ = edge_types;
131  }
132 
133  /** \brief Get the detecting edge types. */
134  inline int
135  getEdgeType () const
136  {
137  return detecting_edge_types_;
138  }
139 
141  static const int num_of_edgetype_ = 5;
142 
143  protected:
144  /** \brief Perform the 3D edge detection (edges from depth discontinuities) and assign point indices for each edge label
145  * \param[out] labels a PointCloud of edge labels
146  */
147  void
148  extractEdges (pcl::PointCloud<PointLT>& labels) const;
149 
150  /** \brief Assign point indices for each edge label
151  * \param[out] labels a PointCloud of edge labels
152  * \param[out] label_indices a vector of PointIndices corresponding to each edge label
153  */
154  void
155  assignLabelIndices (pcl::PointCloud<PointLT>& labels, std::vector<pcl::PointIndices>& label_indices) const;
156 
157  struct Neighbor
158  {
159  Neighbor (int dx, int dy, int didx)
160  : d_x (dx)
161  , d_y (dy)
162  , d_index (didx)
163  {}
164 
165  int d_x;
166  int d_y;
167  int d_index; // = dy * width + dx: pre-calculated
168  };
169 
170  /** \brief The tolerance in meters for the relative difference in depth values between neighboring points
171  * (The default value is set for .02 meters and is adapted with respect to depth value linearly.
172  * 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. */
174 
175  /** \brief The max search distance for deciding occluding and occluded edges */
177 
178  /** \brief The bit encoded value that represents edge types to detect */
180  };
181 
182  template <typename PointT, typename PointLT>
183  class OrganizedEdgeFromRGB : virtual public OrganizedEdgeBase<PointT, PointLT>
184  {
186  using PointCloudPtr = typename PointCloud::Ptr;
187  using PointCloudConstPtr = typename PointCloud::ConstPtr;
188 
190  using PointCloudLPtr = typename PointCloudL::Ptr;
191  using PointCloudLConstPtr = typename PointCloudL::ConstPtr;
192 
193  public:
203 
204  /** \brief Constructor for OrganizedEdgeFromRGB */
206  : OrganizedEdgeBase<PointT, PointLT> ()
207  , th_rgb_canny_low_ (40.0)
208  , th_rgb_canny_high_ (100.0)
209  {
211  }
212 
213  /** \brief Destructor for OrganizedEdgeFromRGB */
214 
216  {
217  }
218 
219  /** \brief Perform the 3D edge detection (edges from depth discontinuities and RGB Canny edge) and assign point indices for each edge label
220  * \param[out] labels a PointCloud of edge labels
221  * \param[out] label_indices a vector of PointIndices corresponding to each edge label
222  */
223  void
224  compute (pcl::PointCloud<PointLT>& labels, std::vector<pcl::PointIndices>& label_indices) const;
225 
226  /** \brief Set the low threshold value for RGB Canny edge detection */
227  inline void
228  setRGBCannyLowThreshold (const float th)
229  {
230  th_rgb_canny_low_ = th;
231  }
232 
233  /** \brief Get the low threshold value for RGB Canny edge detection */
234  inline float
236  {
237  return (th_rgb_canny_low_);
238  }
239 
240  /** \brief Set the high threshold value for RGB Canny edge detection */
241  inline void
242  setRGBCannyHighThreshold (const float th)
243  {
244  th_rgb_canny_high_ = th;
245  }
246 
247  /** \brief Get the high threshold value for RGB Canny edge detection */
248  inline float
250  {
251  return (th_rgb_canny_high_);
252  }
253 
254  protected:
255  /** \brief Perform the 3D edge detection (edges from depth discontinuities and RGB Canny edge)
256  * \param[out] labels a PointCloud of edge labels
257  */
258  void
259  extractEdges (pcl::PointCloud<PointLT>& labels) const;
260 
261  /** \brief The low threshold value for RGB Canny edge detection (default: 40.0) */
263 
264  /** \brief The high threshold value for RGB Canny edge detection (default: 100.0) */
266  };
267 
268  template <typename PointT, typename PointNT, typename PointLT>
269  class OrganizedEdgeFromNormals : virtual public OrganizedEdgeBase<PointT, PointLT>
270  {
272  using PointCloudPtr = typename PointCloud::Ptr;
273  using PointCloudConstPtr = typename PointCloud::ConstPtr;
274 
276  using PointCloudNPtr = typename PointCloudN::Ptr;
277  using PointCloudNConstPtr = typename PointCloudN::ConstPtr;
278 
280  using PointCloudLPtr = typename PointCloudL::Ptr;
281  using PointCloudLConstPtr = typename PointCloudL::ConstPtr;
282 
283  public:
293 
294  /** \brief Constructor for OrganizedEdgeFromNormals */
296  : OrganizedEdgeBase<PointT, PointLT> ()
297  , normals_ ()
298  , th_hc_canny_low_ (0.4f)
299  , th_hc_canny_high_ (1.1f)
300  {
302  }
303 
304  /** \brief Destructor for OrganizedEdgeFromNormals */
305 
307  {
308  }
309 
310  /** \brief Perform the 3D edge detection (edges from depth discontinuities and high curvature regions) and assign point indices for each edge label
311  * \param[out] labels a PointCloud of edge labels
312  * \param[out] label_indices a vector of PointIndices corresponding to each edge label
313  */
314  void
315  compute (pcl::PointCloud<PointLT>& labels, std::vector<pcl::PointIndices>& label_indices) const;
316 
317  /** \brief Provide a pointer to the input normals.
318  * \param[in] normals the input normal cloud
319  */
320  inline void
321  setInputNormals (const PointCloudNConstPtr &normals)
322  {
323  normals_ = normals;
324  }
325 
326  /** \brief Get the input normals. */
327  inline PointCloudNConstPtr
329  {
330  return (normals_);
331  }
332 
333  /** \brief Set the low threshold value for high curvature Canny edge detection */
334  inline void
335  setHCCannyLowThreshold (const float th)
336  {
337  th_hc_canny_low_ = th;
338  }
339 
340  /** \brief Get the low threshold value for high curvature Canny edge detection */
341  inline float
343  {
344  return (th_hc_canny_low_);
345  }
346 
347  /** \brief Set the high threshold value for high curvature Canny edge detection */
348  inline void
349  setHCCannyHighThreshold (const float th)
350  {
351  th_hc_canny_high_ = th;
352  }
353 
354  /** \brief Get the high threshold value for high curvature Canny edge detection */
355  inline float
357  {
358  return (th_hc_canny_high_);
359  }
360 
361  protected:
362  /** \brief Perform the 3D edge detection (edges from depth discontinuities and high curvature regions)
363  * \param[out] labels a PointCloud of edge labels
364  */
365  void
366  extractEdges (pcl::PointCloud<PointLT>& labels) const;
367 
368  /** \brief A pointer to the input normals */
369  PointCloudNConstPtr normals_;
370 
371  /** \brief The low threshold value for high curvature Canny edge detection (default: 0.4) */
373 
374  /** \brief The high threshold value for high curvature Canny edge detection (default: 1.1) */
376  };
377 
378  template <typename PointT, typename PointNT, typename PointLT>
379  class OrganizedEdgeFromRGBNormals : public OrganizedEdgeFromRGB<PointT, PointLT>, public OrganizedEdgeFromNormals<PointT, PointNT, PointLT>
380  {
382  using PointCloudPtr = typename PointCloud::Ptr;
383  using PointCloudConstPtr = typename PointCloud::ConstPtr;
384 
386  using PointCloudNPtr = typename PointCloudN::Ptr;
387  using PointCloudNConstPtr = typename PointCloudN::ConstPtr;
388 
390  using PointCloudLPtr = typename PointCloudL::Ptr;
391  using PointCloudLConstPtr = typename PointCloudL::ConstPtr;
392 
393  public:
404 
405  /** \brief Constructor for OrganizedEdgeFromRGBNormals */
407  : OrganizedEdgeFromRGB<PointT, PointLT> ()
408  , OrganizedEdgeFromNormals<PointT, PointNT, PointLT> ()
409  {
411  }
412 
413  /** \brief Destructor for OrganizedEdgeFromRGBNormals */
414 
416  {
417  }
418 
419  /** \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
420  * \param[out] labels a PointCloud of edge labels
421  * \param[out] label_indices a vector of PointIndices corresponding to each edge label
422  */
423  void
424  compute (pcl::PointCloud<PointLT>& labels, std::vector<pcl::PointIndices>& label_indices) const;
425  };
426 }
427 
428 #ifdef PCL_NO_PRECOMPILE
429 #include <pcl/features/impl/organized_edge_detection.hpp>
430 #endif
OrganizedEdgeBase, OrganizedEdgeFromRGB, OrganizedEdgeFromNormals, and OrganizedEdgeFromRGBNormals fi...
int getEdgeType() const
Get the detecting edge types.
~OrganizedEdgeBase()
Destructor for OrganizedEdgeBase.
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.
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.
~OrganizedEdgeFromNormals()
Destructor for OrganizedEdgeFromNormals.
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.
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()
Destructor for OrganizedEdgeFromRGB.
OrganizedEdgeFromRGB()
Constructor for OrganizedEdgeFromRGB.
float th_rgb_canny_high_
The high threshold value for RGB Canny edge detection (default: 100.0)
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()
Destructor for OrganizedEdgeFromRGBNormals.
OrganizedEdgeFromRGBNormals()
Constructor for OrganizedEdgeFromRGBNormals.
PCL base class.
Definition: pcl_base.h:70
typename PointCloud::Ptr PointCloudPtr
Definition: pcl_base.h:73
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: pcl_base.h:74
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.