Point Cloud Library (PCL) 1.15.0
Loading...
Searching...
No Matches
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 {
59 using PointCloud = pcl::PointCloud<PointT>;
60 using PointCloudPtr = typename PointCloud::Ptr;
61 using PointCloudConstPtr = typename PointCloud::ConstPtr;
62
63 using PointCloudL = pcl::PointCloud<PointLT>;
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 */
81
82 /** \brief Destructor for OrganizedEdgeBase */
83
84 ~OrganizedEdgeBase () override = default;
85
86 /** \brief Perform the 3D edge detection (edges from depth discontinuities)
87 * \param[out] labels a PointCloud of edge labels
88 * \param[out] label_indices a vector of PointIndices corresponding to each edge label
89 */
90 void
91 compute (pcl::PointCloud<PointLT>& labels, std::vector<pcl::PointIndices>& label_indices) const;
92
93 /** \brief Set the tolerance in meters for the relative difference in depth values between neighboring points.
94 * 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. */
95 inline void
96 setDepthDisconThreshold (const float th)
97 {
99 }
100
101 /** \brief Get the tolerance in meters for the relative difference in depth values between neighboring points.
102 * 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. */
103 inline float
105 {
106 return (th_depth_discon_);
107 }
108
109 /** \brief Set the max search distance for deciding occluding and occluded edges. */
110 inline void
111 setMaxSearchNeighbors (const int max_dist)
112 {
113 max_search_neighbors_ = max_dist;
114 }
115
116 /** \brief Get the max search distance for deciding occluding and occluded edges. */
117 inline int
119 {
120 return (max_search_neighbors_);
121 }
122
123 /** \brief Set the detecting edge types. */
124 inline void
125 setEdgeType (int edge_types)
126 {
127 detecting_edge_types_ = edge_types;
128 }
129
130 /** \brief Get the detecting edge types. */
131 inline int
132 getEdgeType () const
133 {
135 }
136
138 static const int num_of_edgetype_ = 5;
139
140 protected:
141 /** \brief Perform the 3D edge detection (edges from depth discontinuities) and assign point indices for each edge label
142 * \param[out] labels a PointCloud of edge labels
143 */
144 void
146
147 /** \brief Assign point indices for each edge label
148 * \param[out] labels a PointCloud of edge labels
149 * \param[out] label_indices a vector of PointIndices corresponding to each edge label
150 */
151 void
152 assignLabelIndices (pcl::PointCloud<PointLT>& labels, std::vector<pcl::PointIndices>& label_indices) const;
153
154 struct Neighbor
155 {
156 Neighbor (int dx, int dy, int didx)
157 : d_x (dx)
158 , d_y (dy)
159 , d_index (didx)
160 {}
161
162 int d_x;
163 int d_y;
164 int d_index; // = dy * width + dx: pre-calculated
165 };
166
167 /** \brief The tolerance in meters for the relative difference in depth values between neighboring points
168 * (The default value is set for .02 meters and is adapted with respect to depth value linearly.
169 * 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. */
170 float th_depth_discon_{0.02f};
171
172 /** \brief The max search distance for deciding occluding and occluded edges */
174
175 /** \brief The bit encoded value that represents edge types to detect */
177 };
178
179 template <typename PointT, typename PointLT>
180 class OrganizedEdgeFromRGB : virtual public OrganizedEdgeBase<PointT, PointLT>
181 {
182 using PointCloud = pcl::PointCloud<PointT>;
183 using PointCloudPtr = typename PointCloud::Ptr;
184 using PointCloudConstPtr = typename PointCloud::ConstPtr;
185
186 using PointCloudL = pcl::PointCloud<PointLT>;
187 using PointCloudLPtr = typename PointCloudL::Ptr;
188 using PointCloudLConstPtr = typename PointCloudL::ConstPtr;
189
190 public:
191 using OrganizedEdgeBase<PointT, PointLT>::input_;
192 using OrganizedEdgeBase<PointT, PointLT>::indices_;
200
201 /** \brief Constructor for OrganizedEdgeFromRGB */
207
208 /** \brief Destructor for OrganizedEdgeFromRGB */
209
210 ~OrganizedEdgeFromRGB () override = default;
211
212 /** \brief Perform the 3D edge detection (edges from depth discontinuities and RGB Canny edge) and assign point indices for each edge label
213 * \param[out] labels a PointCloud of edge labels
214 * \param[out] label_indices a vector of PointIndices corresponding to each edge label
215 */
216 void
217 compute (pcl::PointCloud<PointLT>& labels, std::vector<pcl::PointIndices>& label_indices) const;
218
219 /** \brief Set the low threshold value for RGB Canny edge detection */
220 inline void
221 setRGBCannyLowThreshold (const float th)
222 {
224 }
225
226 /** \brief Get the low threshold value for RGB Canny edge detection */
227 inline float
229 {
230 return (th_rgb_canny_low_);
231 }
232
233 /** \brief Set the high threshold value for RGB Canny edge detection */
234 inline void
236 {
238 }
239
240 /** \brief Get the high threshold value for RGB Canny edge detection */
241 inline float
243 {
244 return (th_rgb_canny_high_);
245 }
246
247 protected:
248 /** \brief Perform the 3D edge detection (edges from depth discontinuities and RGB Canny edge)
249 * \param[out] labels a PointCloud of edge labels
250 */
251 void
253
254 /** \brief The low threshold value for RGB Canny edge detection (default: 40.0) */
255 float th_rgb_canny_low_{40.0};
256
257 /** \brief The high threshold value for RGB Canny edge detection (default: 100.0) */
258 float th_rgb_canny_high_{100.0};
259 };
260
261 template <typename PointT, typename PointNT, typename PointLT>
262 class OrganizedEdgeFromNormals : virtual public OrganizedEdgeBase<PointT, PointLT>
263 {
264 using PointCloud = pcl::PointCloud<PointT>;
265 using PointCloudPtr = typename PointCloud::Ptr;
266 using PointCloudConstPtr = typename PointCloud::ConstPtr;
267
269 using PointCloudNPtr = typename PointCloudN::Ptr;
270 using PointCloudNConstPtr = typename PointCloudN::ConstPtr;
271
272 using PointCloudL = pcl::PointCloud<PointLT>;
273 using PointCloudLPtr = typename PointCloudL::Ptr;
274 using PointCloudLConstPtr = typename PointCloudL::ConstPtr;
275
276 public:
277 using OrganizedEdgeBase<PointT, PointLT>::input_;
278 using OrganizedEdgeBase<PointT, PointLT>::indices_;
286
287 /** \brief Constructor for OrganizedEdgeFromNormals */
294
295 /** \brief Destructor for OrganizedEdgeFromNormals */
296
297 ~OrganizedEdgeFromNormals () override = default;
298
299 /** \brief Perform the 3D edge detection (edges from depth discontinuities and high curvature regions) and assign point indices for each edge label
300 * \param[out] labels a PointCloud of edge labels
301 * \param[out] label_indices a vector of PointIndices corresponding to each edge label
302 */
303 void
304 compute (pcl::PointCloud<PointLT>& labels, std::vector<pcl::PointIndices>& label_indices) const;
305
306 /** \brief Provide a pointer to the input normals.
307 * \param[in] normals the input normal cloud
308 */
309 inline void
310 setInputNormals (const PointCloudNConstPtr &normals)
311 {
312 normals_ = normals;
313 }
314
315 /** \brief Get the input normals. */
316 inline PointCloudNConstPtr
318 {
319 return (normals_);
320 }
321
322 /** \brief Set the low threshold value for high curvature Canny edge detection */
323 inline void
324 setHCCannyLowThreshold (const float th)
325 {
326 th_hc_canny_low_ = th;
327 }
328
329 /** \brief Get the low threshold value for high curvature Canny edge detection */
330 inline float
332 {
333 return (th_hc_canny_low_);
334 }
335
336 /** \brief Set the high threshold value for high curvature Canny edge detection */
337 inline void
338 setHCCannyHighThreshold (const float th)
339 {
341 }
342
343 /** \brief Get the high threshold value for high curvature Canny edge detection */
344 inline float
346 {
347 return (th_hc_canny_high_);
348 }
349
350 protected:
351 /** \brief Perform the 3D edge detection (edges from depth discontinuities and high curvature regions)
352 * \param[out] labels a PointCloud of edge labels
353 */
354 void
356
357 /** \brief A pointer to the input normals */
358 PointCloudNConstPtr normals_;
359
360 /** \brief The low threshold value for high curvature Canny edge detection (default: 0.4) */
361 float th_hc_canny_low_{0.4f};
362
363 /** \brief The high threshold value for high curvature Canny edge detection (default: 1.1) */
364 float th_hc_canny_high_{1.1f};
365 };
366
367 template <typename PointT, typename PointNT, typename PointLT>
368 class OrganizedEdgeFromRGBNormals : public OrganizedEdgeFromRGB<PointT, PointLT>, public OrganizedEdgeFromNormals<PointT, PointNT, PointLT>
369 {
370 using PointCloud = pcl::PointCloud<PointT>;
371 using PointCloudPtr = typename PointCloud::Ptr;
372 using PointCloudConstPtr = typename PointCloud::ConstPtr;
373
375 using PointCloudNPtr = typename PointCloudN::Ptr;
376 using PointCloudNConstPtr = typename PointCloudN::ConstPtr;
377
378 using PointCloudL = pcl::PointCloud<PointLT>;
379 using PointCloudLPtr = typename PointCloudL::Ptr;
380 using PointCloudLConstPtr = typename PointCloudL::ConstPtr;
381
382 public:
383 using OrganizedEdgeFromNormals<PointT, PointNT, PointLT>::input_;
384 using OrganizedEdgeFromNormals<PointT, PointNT, PointLT>::indices_;
385 using OrganizedEdgeFromNormals<PointT, PointNT, PointLT>::initCompute;
386 using OrganizedEdgeFromNormals<PointT, PointNT, PointLT>::deinitCompute;
393
394 /** \brief Constructor for OrganizedEdgeFromRGBNormals */
401
402 /** \brief Destructor for OrganizedEdgeFromRGBNormals */
403
404 ~OrganizedEdgeFromRGBNormals () override = default;
405
406 /** \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
407 * \param[out] labels a PointCloud of edge labels
408 * \param[out] label_indices a vector of PointIndices corresponding to each edge label
409 */
410 void
411 compute (pcl::PointCloud<PointLT>& labels, std::vector<pcl::PointIndices>& label_indices) const;
412 };
413}
414
415#ifdef PCL_NO_PRECOMPILE
416#include <pcl/features/impl/organized_edge_detection.hpp>
417#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
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:175
PointCloud represents the base class in PCL for storing collections of 3D points.
shared_ptr< PointCloud< PointT > > Ptr
shared_ptr< const PointCloud< PointT > > ConstPtr
A point structure representing Euclidean xyz coordinates, and the RGB color.