Point Cloud Library (PCL)  1.9.1-dev
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 = boost::shared_ptr<OrganizedEdgeBase<PointT, PointLT> >;
69  using ConstPtr = boost::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 difference in depth values between neighboring points. */
97  inline void
98  setDepthDisconThreshold (const float th)
99  {
100  th_depth_discon_ = th;
101  }
102 
103  /** \brief Get the tolerance in meters for difference in depth values between neighboring points. */
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  {
135  return detecting_edge_types_;
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
146  extractEdges (pcl::PointCloud<PointLT>& labels) const;
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 difference in depth values between neighboring points
169  * (The value is set for 1 meter and is adapted with respect to depth value linearly.
170  * (e.g. 2.0*th_depth_discon_ in 2 meter depth))
171  */
173 
174  /** \brief The max search distance for deciding occluding and occluded edges */
176 
177  /** \brief The bit encoded value that represents edge types to detect */
179  };
180 
181  template <typename PointT, typename PointLT>
182  class OrganizedEdgeFromRGB : virtual public OrganizedEdgeBase<PointT, PointLT>
183  {
185  using PointCloudPtr = typename PointCloud::Ptr;
186  using PointCloudConstPtr = typename PointCloud::ConstPtr;
187 
189  using PointCloudLPtr = typename PointCloudL::Ptr;
190  using PointCloudLConstPtr = typename PointCloudL::ConstPtr;
191 
192  public:
202 
203  /** \brief Constructor for OrganizedEdgeFromRGB */
205  : OrganizedEdgeBase<PointT, PointLT> ()
206  , th_rgb_canny_low_ (40.0)
207  , th_rgb_canny_high_ (100.0)
208  {
210  }
211 
212  /** \brief Destructor for OrganizedEdgeFromRGB */
213 
215  {
216  }
217 
218  /** \brief Perform the 3D edge detection (edges from depth discontinuities and RGB Canny edge) and assign point indices for each edge label
219  * \param[out] labels a PointCloud of edge labels
220  * \param[out] label_indices a vector of PointIndices corresponding to each edge label
221  */
222  void
223  compute (pcl::PointCloud<PointLT>& labels, std::vector<pcl::PointIndices>& label_indices) const;
224 
225  /** \brief Set the low threshold value for RGB Canny edge detection */
226  inline void
227  setRGBCannyLowThreshold (const float th)
228  {
229  th_rgb_canny_low_ = th;
230  }
231 
232  /** \brief Get the low threshold value for RGB Canny edge detection */
233  inline float
235  {
236  return (th_rgb_canny_low_);
237  }
238 
239  /** \brief Set the high threshold value for RGB Canny edge detection */
240  inline void
241  setRGBCannyHighThreshold (const float th)
242  {
243  th_rgb_canny_high_ = th;
244  }
245 
246  /** \brief Get the high threshold value for RGB Canny edge detection */
247  inline float
249  {
250  return (th_rgb_canny_high_);
251  }
252 
253  protected:
254  /** \brief Perform the 3D edge detection (edges from depth discontinuities and RGB Canny edge)
255  * \param[out] labels a PointCloud of edge labels
256  */
257  void
258  extractEdges (pcl::PointCloud<PointLT>& labels) const;
259 
260  /** \brief The low threshold value for RGB Canny edge detection (default: 40.0) */
262 
263  /** \brief The high threshold value for RGB Canny edge detection (default: 100.0) */
265  };
266 
267  template <typename PointT, typename PointNT, typename PointLT>
268  class OrganizedEdgeFromNormals : virtual public OrganizedEdgeBase<PointT, PointLT>
269  {
271  using PointCloudPtr = typename PointCloud::Ptr;
272  using PointCloudConstPtr = typename PointCloud::ConstPtr;
273 
275  using PointCloudNPtr = typename PointCloudN::Ptr;
276  using PointCloudNConstPtr = typename PointCloudN::ConstPtr;
277 
279  using PointCloudLPtr = typename PointCloudL::Ptr;
280  using PointCloudLConstPtr = typename PointCloudL::ConstPtr;
281 
282  public:
292 
293  /** \brief Constructor for OrganizedEdgeFromNormals */
295  : OrganizedEdgeBase<PointT, PointLT> ()
296  , normals_ ()
297  , th_hc_canny_low_ (0.4f)
298  , th_hc_canny_high_ (1.1f)
299  {
301  }
302 
303  /** \brief Destructor for OrganizedEdgeFromNormals */
304 
306  {
307  }
308 
309  /** \brief Perform the 3D edge detection (edges from depth discontinuities and high curvature regions) and assign point indices for each edge label
310  * \param[out] labels a PointCloud of edge labels
311  * \param[out] label_indices a vector of PointIndices corresponding to each edge label
312  */
313  void
314  compute (pcl::PointCloud<PointLT>& labels, std::vector<pcl::PointIndices>& label_indices) const;
315 
316  /** \brief Provide a pointer to the input normals.
317  * \param[in] normals the input normal cloud
318  */
319  inline void
320  setInputNormals (const PointCloudNConstPtr &normals)
321  {
322  normals_ = normals;
323  }
324 
325  /** \brief Get the input normals. */
326  inline PointCloudNConstPtr
328  {
329  return (normals_);
330  }
331 
332  /** \brief Set the low threshold value for high curvature Canny edge detection */
333  inline void
334  setHCCannyLowThreshold (const float th)
335  {
336  th_hc_canny_low_ = th;
337  }
338 
339  /** \brief Get the low threshold value for high curvature Canny edge detection */
340  inline float
342  {
343  return (th_hc_canny_low_);
344  }
345 
346  /** \brief Set the high threshold value for high curvature Canny edge detection */
347  inline void
348  setHCCannyHighThreshold (const float th)
349  {
350  th_hc_canny_high_ = th;
351  }
352 
353  /** \brief Get the high threshold value for high curvature Canny edge detection */
354  inline float
356  {
357  return (th_hc_canny_high_);
358  }
359 
360  protected:
361  /** \brief Perform the 3D edge detection (edges from depth discontinuities and high curvature regions)
362  * \param[out] labels a PointCloud of edge labels
363  */
364  void
365  extractEdges (pcl::PointCloud<PointLT>& labels) const;
366 
367  /** \brief A pointer to the input normals */
368  PointCloudNConstPtr normals_;
369 
370  /** \brief The low threshold value for high curvature Canny edge detection (default: 0.4) */
372 
373  /** \brief The high threshold value for high curvature Canny edge detection (default: 1.1) */
375  };
376 
377  template <typename PointT, typename PointNT, typename PointLT>
378  class OrganizedEdgeFromRGBNormals : public OrganizedEdgeFromRGB<PointT, PointLT>, public OrganizedEdgeFromNormals<PointT, PointNT, PointLT>
379  {
381  using PointCloudPtr = typename PointCloud::Ptr;
382  using PointCloudConstPtr = typename PointCloud::ConstPtr;
383 
385  using PointCloudNPtr = typename PointCloudN::Ptr;
386  using PointCloudNConstPtr = typename PointCloudN::ConstPtr;
387 
389  using PointCloudLPtr = typename PointCloudL::Ptr;
390  using PointCloudLConstPtr = typename PointCloudL::ConstPtr;
391 
392  public:
403 
404  /** \brief Constructor for OrganizedEdgeFromRGBNormals */
406  : OrganizedEdgeFromRGB<PointT, PointLT> ()
407  , OrganizedEdgeFromNormals<PointT, PointNT, PointLT> ()
408  {
410  }
411 
412  /** \brief Destructor for OrganizedEdgeFromRGBNormals */
413 
415  {
416  }
417 
418  /** \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
419  * \param[out] labels a PointCloud of edge labels
420  * \param[out] label_indices a vector of PointIndices corresponding to each edge label
421  */
422  void
423  compute (pcl::PointCloud<PointLT>& labels, std::vector<pcl::PointIndices>& label_indices) const;
424  };
425 }
426 
427 #ifdef PCL_NO_PRECOMPILE
428 #include <pcl/features/impl/organized_edge_detection.hpp>
429 #endif
void setInputNormals(const PointCloudNConstPtr &normals)
Provide a pointer to the input normals.
boost::shared_ptr< const OrganizedEdgeBase< PointT, PointLT > > ConstPtr
~OrganizedEdgeFromNormals()
Destructor for OrganizedEdgeFromNormals.
void extractEdges(pcl::PointCloud< PointLT > &labels) const
Perform the 3D edge detection (edges from depth discontinuities) and assign point indices for each ed...
void setRGBCannyLowThreshold(const float th)
Set the low threshold value for RGB Canny edge detection.
float getHCCannyLowThreshold() const
Get the low threshold value for high curvature Canny edge detection.
int detecting_edge_types_
The bit encoded value that represents edge types to detect.
float getDepthDisconThreshold() const
Get the tolerance in meters for difference in depth values between neighboring points.
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
void setHCCannyHighThreshold(const float th)
Set the high threshold value for high curvature Canny edge detection.
float getRGBCannyLowThreshold() const
Get the low threshold value for RGB Canny edge detection.
~OrganizedEdgeFromRGBNormals()
Destructor for OrganizedEdgeFromRGBNormals.
float th_rgb_canny_low_
The low threshold value for RGB Canny edge detection (default: 40.0)
int max_search_neighbors_
The max search distance for deciding occluding and occluded edges.
float th_hc_canny_low_
The low threshold value for high curvature Canny edge detection (default: 0.4)
OrganizedEdgeFromRGBNormals()
Constructor for OrganizedEdgeFromRGBNormals.
void setDepthDisconThreshold(const float th)
Set the tolerance in meters for difference in depth values between neighboring points.
float th_hc_canny_high_
The high threshold value for high curvature Canny edge detection (default: 1.1)
void compute(pcl::PointCloud< PointLT > &labels, std::vector< pcl::PointIndices > &label_indices) const
Perform the 3D edge detection (edges from depth discontinuities)
int getMaxSearchNeighbors() const
Get the max search distance for deciding occluding and occluded edges.
~OrganizedEdgeFromRGB()
Destructor for OrganizedEdgeFromRGB.
void setEdgeType(int edge_types)
Set the detecting edge types.
PCL base class.
Definition: pcl_base.h:69
typename PointCloud::Ptr PointCloudPtr
Definition: pcl_base.h:73
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:412
~OrganizedEdgeBase()
Destructor for OrganizedEdgeBase.
float th_depth_discon_
The tolerance in meters for difference in depth values between neighboring points (The value is set f...
int getEdgeType() const
Get the detecting edge types.
PointCloud represents the base class in PCL for storing collections of 3D points. ...
PointCloudNConstPtr normals_
A pointer to the input normals.
OrganizedEdgeFromNormals()
Constructor for OrganizedEdgeFromNormals.
OrganizedEdgeBase, OrganizedEdgeFromRGB, OrganizedEdgeFromNormals, and OrganizedEdgeFromRGBNormals fi...
float getHCCannyHighThreshold() const
Get the high threshold value for high curvature Canny edge detection.
OrganizedEdgeBase()
Constructor for OrganizedEdgeBase.
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:413
void setRGBCannyHighThreshold(const float th)
Set the high threshold value for RGB Canny edge detection.
A point structure representing Euclidean xyz coordinates, and the RGB color.
void setHCCannyLowThreshold(const float th)
Set the low threshold value for high curvature Canny edge detection.
float th_rgb_canny_high_
The high threshold value for RGB Canny edge detection (default: 100.0)
float getRGBCannyHighThreshold() const
Get the high threshold value for RGB Canny edge detection.
OrganizedEdgeFromRGB()
Constructor for OrganizedEdgeFromRGB.
PointCloudNConstPtr getInputNormals() const
Get the input normals.
void assignLabelIndices(pcl::PointCloud< PointLT > &labels, std::vector< pcl::PointIndices > &label_indices) const
Assign point indices for each edge label.
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: pcl_base.h:74
void setMaxSearchNeighbors(const int max_dist)
Set the max search distance for deciding occluding and occluded edges.
boost::shared_ptr< OrganizedEdgeBase< PointT, PointLT > > Ptr