Point Cloud Library (PCL)  1.13.0-dev
harris_6d.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2010, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage, Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  * @author Suat Gedikli
35  */
36 
37 #pragma once
38 
39 #include <pcl/keypoints/keypoint.h>
40 
41 namespace pcl
42 {
43 
44  /** \brief Keypoint detector for detecting corners in 3D (XYZ), 2D (intensity) AND mixed versions of these.
45  * \author Suat Gedikli
46  * \ingroup keypoints
47  */
48  template <typename PointInT, typename PointOutT, typename NormalT = pcl::Normal>
49  class HarrisKeypoint6D : public Keypoint<PointInT, PointOutT>
50  {
51  public:
52  using Ptr = shared_ptr<HarrisKeypoint6D<PointInT, PointOutT, NormalT> >;
53  using ConstPtr = shared_ptr<const HarrisKeypoint6D<PointInT, PointOutT, NormalT> >;
54 
58  using PointCloudInConstPtr = typename PointCloudIn::ConstPtr;
59 
69 
70  /**
71  * @brief Constructor
72  * @param radius the radius for normal estimation as well as for non maxima suppression
73  * @param threshold the threshold to filter out weak corners
74  */
75  HarrisKeypoint6D (float radius = 0.01, float threshold = 0.0)
76  : threshold_ (threshold)
77  , refine_ (true)
78  , nonmax_ (true)
79  , threads_ (0)
80  , normals_ (new pcl::PointCloud<NormalT>)
81  , intensity_gradients_ (new pcl::PointCloud<pcl::IntensityGradient>)
82  {
83  name_ = "HarrisKeypoint6D";
84  search_radius_ = radius;
85  }
86 
87  /** \brief Empty destructor */
88  virtual ~HarrisKeypoint6D () = default;
89 
90  /**
91  * @brief set the radius for normal estimation and non maxima suppression.
92  * @param radius
93  */
94  void setRadius (float radius);
95 
96  /**
97  * @brief set the threshold value for detecting corners. This is only evaluated if non maxima suppression is turned on.
98  * @brief note non maxima suppression needs to be activated in order to use this feature.
99  * @param threshold
100  */
101  void setThreshold (float threshold);
102 
103  /**
104  * @brief whether non maxima suppression should be applied or the response for each point should be returned
105  * @note this value needs to be turned on in order to apply thresholding and refinement
106  * @param nonmax default is false
107  */
108  void setNonMaxSupression (bool = false);
109 
110  /**
111  * @brief whether the detected key points should be refined or not. If turned of, the key points are a subset of the original point cloud. Otherwise the key points may be arbitrary.
112  * @brief note non maxima suppression needs to be on in order to use this feature.
113  * @param do_refine
114  */
115  void setRefine (bool do_refine);
116 
117  virtual void
118  setSearchSurface (const PointCloudInConstPtr &cloud) { surface_ = cloud; normals_->clear (); intensity_gradients_->clear ();}
119 
120  /** \brief Initialize the scheduler and set the number of threads to use.
121  * \param nr_threads the number of hardware threads to use (0 sets the value back to automatic)
122  */
123  inline void
124  setNumberOfThreads (unsigned int nr_threads = 0) { threads_ = nr_threads; }
125  protected:
126  void detectKeypoints (PointCloudOut &output);
127  void responseTomasi (PointCloudOut &output) const;
128  void refineCorners (PointCloudOut &corners) const;
129  void calculateCombinedCovar (const pcl::Indices& neighbors, float* coefficients) const;
130  private:
131  float threshold_;
132  bool refine_;
133  bool nonmax_;
134  unsigned int threads_;
135  typename pcl::PointCloud<NormalT>::Ptr normals_;
137  } ;
138 }
139 
140 #include <pcl/keypoints/impl/harris_6d.hpp>
Keypoint detector for detecting corners in 3D (XYZ), 2D (intensity) AND mixed versions of these.
Definition: harris_6d.h:50
typename Keypoint< PointInT, PointOutT >::PointCloudIn PointCloudIn
Definition: harris_6d.h:55
void setNonMaxSupression(bool=false)
whether non maxima suppression should be applied or the response for each point should be returned
Definition: harris_6d.hpp:68
shared_ptr< const HarrisKeypoint6D< PointInT, PointOutT, NormalT > > ConstPtr
Definition: harris_6d.h:53
void setThreshold(float threshold)
set the threshold value for detecting corners.
Definition: harris_6d.hpp:50
void setRefine(bool do_refine)
whether the detected key points should be refined or not.
Definition: harris_6d.hpp:62
void setRadius(float radius)
set the radius for normal estimation and non maxima suppression.
Definition: harris_6d.hpp:56
void responseTomasi(PointCloudOut &output) const
Definition: harris_6d.hpp:267
void setNumberOfThreads(unsigned int nr_threads=0)
Initialize the scheduler and set the number of threads to use.
Definition: harris_6d.h:124
typename PointCloudIn::ConstPtr PointCloudInConstPtr
Definition: harris_6d.h:58
void detectKeypoints(PointCloudOut &output)
Definition: harris_6d.hpp:142
typename Keypoint< PointInT, PointOutT >::PointCloudOut PointCloudOut
Definition: harris_6d.h:56
void refineCorners(PointCloudOut &corners) const
Definition: harris_6d.hpp:357
typename Keypoint< PointInT, PointOutT >::KdTree KdTree
Definition: harris_6d.h:57
shared_ptr< HarrisKeypoint6D< PointInT, PointOutT, NormalT > > Ptr
Definition: harris_6d.h:52
virtual ~HarrisKeypoint6D()=default
Empty destructor.
HarrisKeypoint6D(float radius=0.01, float threshold=0.0)
Constructor.
Definition: harris_6d.h:75
virtual void setSearchSurface(const PointCloudInConstPtr &cloud)
Definition: harris_6d.h:118
void calculateCombinedCovar(const pcl::Indices &neighbors, float *coefficients) const
Definition: harris_6d.hpp:75
Keypoint represents the base class for key points.
Definition: keypoint.h:49
std::string name_
The key point detection method's name.
Definition: keypoint.h:169
PointCloudInConstPtr surface_
An input point cloud describing the surface that is to be used for nearest neighbors estimation.
Definition: keypoint.h:178
double search_radius_
The nearest neighbors search radius for each point.
Definition: keypoint.h:187
void clear()
Removes all points in a cloud and sets the width and height to 0.
Definition: point_cloud.h:885
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:413
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133
A point structure representing the intensity gradient of an XYZI point cloud.
A point structure representing normal coordinates and the surface curvature estimate.