Point Cloud Library (PCL)  1.8.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 #ifndef PCL_FEATURES_ORGANIZED_EDGE_DETECTION_H_
39 #define PCL_FEATURES_ORGANIZED_EDGE_DETECTION_H_
40 
41 #include <pcl/pcl_base.h>
42 #include <pcl/PointIndices.h>
43 
44 namespace pcl
45 {
46  /** \brief OrganizedEdgeBase, OrganizedEdgeFromRGB, OrganizedEdgeFromNormals,
47  * and OrganizedEdgeFromRGBNormals find 3D edges from an organized point
48  * cloud data. Given an organized point cloud, they will output a PointCloud
49  * of edge labels and a vector of PointIndices.
50  * OrganizedEdgeBase accepts PCL_XYZ_POINT_TYPES and returns EDGELABEL_NAN_BOUNDARY, EDGELABEL_OCCLUDING, and EDGELABEL_OCCLUDED.
51  * OrganizedEdgeFromRGB accepts PCL_RGB_POINT_TYPES and returns EDGELABEL_NAN_BOUNDARY, EDGELABEL_OCCLUDING, EDGELABEL_OCCLUDED, and EDGELABEL_RGB_CANNY.
52  * OrganizedEdgeFromNormals accepts PCL_XYZ_POINT_TYPES with PCL_NORMAL_POINT_TYPES and returns EDGELABEL_NAN_BOUNDARY, EDGELABEL_OCCLUDING, EDGELABEL_OCCLUDED, and EDGELABEL_HIGH_CURVATURE.
53  * 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.
54  *
55  * \author Changhyun Choi
56  */
57  template <typename PointT, typename PointLT>
58  class OrganizedEdgeBase : public PCLBase<PointT>
59  {
60  typedef typename pcl::PointCloud<PointT> PointCloud;
61  typedef typename PointCloud::Ptr PointCloudPtr;
63 
64  typedef typename pcl::PointCloud<PointLT> PointCloudL;
65  typedef typename PointCloudL::Ptr PointCloudLPtr;
66  typedef typename PointCloudL::ConstPtr PointCloudLConstPtr;
67 
68  public:
69  typedef boost::shared_ptr<OrganizedEdgeBase<PointT, PointLT> > Ptr;
70  typedef boost::shared_ptr<const OrganizedEdgeBase<PointT, PointLT> > ConstPtr;
75 
76  /** \brief Constructor for OrganizedEdgeBase */
78  : th_depth_discon_ (0.02f)
81  {
82  }
83 
84  /** \brief Destructor for OrganizedEdgeBase */
85  virtual
87  {
88  }
89 
90  /** \brief Perform the 3D edge detection (edges from depth discontinuities)
91  * \param[out] labels a PointCloud of edge labels
92  * \param[out] label_indices a vector of PointIndices corresponding to each edge label
93  */
94  void
95  compute (pcl::PointCloud<PointLT>& labels, std::vector<pcl::PointIndices>& label_indices) const;
96 
97  /** \brief Set the tolerance in meters for difference in depth values between neighboring points. */
98  inline void
99  setDepthDisconThreshold (const float th)
100  {
101  th_depth_discon_ = th;
102  }
103 
104  /** \brief Get the tolerance in meters for difference in depth values between neighboring points. */
105  inline float
107  {
108  return (th_depth_discon_);
109  }
110 
111  /** \brief Set the max search distance for deciding occluding and occluded edges. */
112  inline void
113  setMaxSearchNeighbors (const int max_dist)
114  {
115  max_search_neighbors_ = max_dist;
116  }
117 
118  /** \brief Get the max search distance for deciding occluding and occluded edges. */
119  inline int
121  {
122  return (max_search_neighbors_);
123  }
124 
125  /** \brief Set the detecting edge types. */
126  inline void
127  setEdgeType (int edge_types)
128  {
129  detecting_edge_types_ = edge_types;
130  }
131 
132  /** \brief Get the detecting edge types. */
133  inline int
134  getEdgeType () const
135  {
136  return detecting_edge_types_;
137  }
138 
140  static const int num_of_edgetype_ = 5;
141 
142  protected:
143  /** \brief Perform the 3D edge detection (edges from depth discontinuities) and assign point indices for each edge label
144  * \param[out] labels a PointCloud of edge labels
145  */
146  void
147  extractEdges (pcl::PointCloud<PointLT>& labels) const;
148 
149  /** \brief Assign point indices for each edge label
150  * \param[out] labels a PointCloud of edge labels
151  * \param[out] label_indices a vector of PointIndices corresponding to each edge label
152  */
153  void
154  assignLabelIndices (pcl::PointCloud<PointLT>& labels, std::vector<pcl::PointIndices>& label_indices) const;
155 
156  struct Neighbor
157  {
158  Neighbor (int dx, int dy, int didx)
159  : d_x (dx)
160  , d_y (dy)
161  , d_index (didx)
162  {}
163 
164  int d_x;
165  int d_y;
166  int d_index; // = dy * width + dx: pre-calculated
167  };
168 
169  /** \brief The tolerance in meters for difference in depth values between neighboring points
170  * (The value is set for 1 meter and is adapted with respect to depth value linearly.
171  * (e.g. 2.0*th_depth_discon_ in 2 meter depth))
172  */
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  {
185  typedef typename pcl::PointCloud<PointT> PointCloud;
186  typedef typename PointCloud::Ptr PointCloudPtr;
187  typedef typename PointCloud::ConstPtr PointCloudConstPtr;
188 
189  typedef typename pcl::PointCloud<PointLT> PointCloudL;
190  typedef typename PointCloudL::Ptr PointCloudLPtr;
191  typedef typename PointCloudL::ConstPtr PointCloudLConstPtr;
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  virtual
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  {
271  typedef typename pcl::PointCloud<PointT> PointCloud;
272  typedef typename PointCloud::Ptr PointCloudPtr;
273  typedef typename PointCloud::ConstPtr PointCloudConstPtr;
274 
275  typedef typename pcl::PointCloud<PointNT> PointCloudN;
276  typedef typename PointCloudN::Ptr PointCloudNPtr;
277  typedef typename PointCloudN::ConstPtr PointCloudNConstPtr;
278 
279  typedef typename pcl::PointCloud<PointLT> PointCloudL;
280  typedef typename PointCloudL::Ptr PointCloudLPtr;
281  typedef typename PointCloudL::ConstPtr PointCloudLConstPtr;
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  virtual
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  {
381  typedef typename pcl::PointCloud<PointT> PointCloud;
382  typedef typename PointCloud::Ptr PointCloudPtr;
383  typedef typename PointCloud::ConstPtr PointCloudConstPtr;
384 
385  typedef typename pcl::PointCloud<PointNT> PointCloudN;
386  typedef typename PointCloudN::Ptr PointCloudNPtr;
387  typedef typename PointCloudN::ConstPtr PointCloudNConstPtr;
388 
389  typedef typename pcl::PointCloud<PointLT> PointCloudL;
390  typedef typename PointCloudL::Ptr PointCloudLPtr;
391  typedef typename PointCloudL::ConstPtr PointCloudLConstPtr;
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  virtual
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
431 
432 #endif //#ifndef PCL_FEATURES_ORGANIZED_EDGE_DETECTION_H_
void setInputNormals(const PointCloudNConstPtr &normals)
Provide a pointer to the input normals.
PointCloud::ConstPtr PointCloudConstPtr
Definition: pcl_base.h:73
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.
virtual ~OrganizedEdgeFromNormals()
Destructor for OrganizedEdgeFromNormals.
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.
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.
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)
boost::shared_ptr< OrganizedEdgeBase< PointT, PointLT > > Ptr
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)
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
int getMaxSearchNeighbors() const
Get the max search distance for deciding occluding and occluded edges.
PointCloud::Ptr PointCloudPtr
Definition: pcl_base.h:72
virtual ~OrganizedEdgeBase()
Destructor for OrganizedEdgeBase.
void setEdgeType(int edge_types)
Set the detecting edge types.
PCL base class.
Definition: pcl_base.h:68
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
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.
virtual ~OrganizedEdgeFromRGBNormals()
Destructor for OrganizedEdgeFromRGBNormals.
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.
void setRGBCannyHighThreshold(const float th)
Set the high threshold value for RGB Canny edge detection.
boost::shared_ptr< const OrganizedEdgeBase< PointT, PointLT > > ConstPtr
virtual ~OrganizedEdgeFromRGB()
Destructor for OrganizedEdgeFromRGB.
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.
void setMaxSearchNeighbors(const int max_dist)
Set the max search distance for deciding occluding and occluded edges.