Point Cloud Library (PCL)  1.14.1-dev
harris_3d.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, 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 Willow Garage, Inc. 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/keypoints/keypoint.h>
41 
42 namespace pcl
43 {
44  /** \brief HarrisKeypoint3D uses the idea of 2D Harris keypoints, but instead of using image gradients, it uses
45  * surface normals.
46  *
47  * \author Suat Gedikli
48  * \ingroup keypoints
49  */
50  template <typename PointInT, typename PointOutT, typename NormalT = pcl::Normal>
51  class HarrisKeypoint3D : public Keypoint<PointInT, PointOutT>
52  {
53  public:
54  using Ptr = shared_ptr<HarrisKeypoint3D<PointInT, PointOutT, NormalT> >;
55  using ConstPtr = shared_ptr<const HarrisKeypoint3D<PointInT, PointOutT, NormalT> >;
56 
60  using PointCloudInConstPtr = typename PointCloudIn::ConstPtr;
61 
63  using PointCloudNPtr = typename PointCloudN::Ptr;
65 
77 
79 
80  /** \brief Constructor
81  * \param[in] method the method to be used to determine the corner responses
82  * \param[in] radius the radius for normal estimation as well as for non maxima suppression
83  * \param[in] threshold the threshold to filter out weak corners
84  */
85  HarrisKeypoint3D (ResponseMethod method = HARRIS, float radius = 0.01f, float threshold = 0.0f)
86  : threshold_ (threshold)
87  , method_ (method)
88  {
89  name_ = "HarrisKeypoint3D";
90  search_radius_ = radius;
91  }
92 
93  /** \brief Empty destructor */
94  ~HarrisKeypoint3D () override = default;
95 
96  /** \brief Provide a pointer to the input dataset
97  * \param[in] cloud the const boost shared pointer to a PointCloud message
98  */
99  void
100  setInputCloud (const PointCloudInConstPtr &cloud) override;
101 
102  /** \brief Set the method of the response to be calculated.
103  * \param[in] type
104  */
105  void
106  setMethod (ResponseMethod type);
107 
108  /** \brief Set the radius for normal estimation and non maxima suppression.
109  * \param[in] radius
110  */
111  void
112  setRadius (float radius);
113 
114  /** \brief Set the threshold value for detecting corners. This is only evaluated if non maxima suppression is turned on.
115  * \brief note non maxima suppression needs to be activated in order to use this feature.
116  * \param[in] threshold
117  */
118  void
119  setThreshold (float threshold);
120 
121  /** \brief Whether non maxima suppression should be applied or the response for each point should be returned
122  * \note this value needs to be turned on in order to apply thresholding and refinement
123  * \param[in] nonmax default is false
124  */
125  void
126  setNonMaxSupression (bool = false);
127 
128  /** \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.
129  * \brief note non maxima suppression needs to be on in order to use this feature.
130  * \param[in] do_refine
131  */
132  void
133  setRefine (bool do_refine);
134 
135  /** \brief Set normals if precalculated normals are available.
136  * \param normals
137  */
138  void
139  setNormals (const PointCloudNConstPtr &normals);
140 
141  /** \brief Provide a pointer to a dataset to add additional information
142  * to estimate the features for every point in the input dataset. This
143  * is optional, if this is not set, it will only use the data in the
144  * input cloud to estimate the features. This is useful when you only
145  * need to compute the features for a downsampled cloud.
146  * \param[in] cloud a pointer to a PointCloud message
147  */
148  void
149  setSearchSurface (const PointCloudInConstPtr &cloud) override { surface_ = cloud; normals_.reset(); }
150 
151  /** \brief Initialize the scheduler and set the number of threads to use.
152  * \param nr_threads the number of hardware threads to use (0 sets the value back to automatic)
153  */
154  inline void
155  setNumberOfThreads (unsigned int nr_threads = 0) { threads_ = nr_threads; }
156  protected:
157  bool
158  initCompute () override;
159  void detectKeypoints (PointCloudOut &output) override;
160  /** \brief gets the corner response for valid input points*/
161  void responseHarris (PointCloudOut &output) const;
162  void responseNoble (PointCloudOut &output) const;
163  void responseLowe (PointCloudOut &output) const;
164  void responseTomasi (PointCloudOut &output) const;
165  void responseCurvature (PointCloudOut &output) const;
166  void refineCorners (PointCloudOut &corners) const;
167  /** \brief calculates the upper triangular part of unnormalized covariance matrix over the normals given by the indices.*/
168  void calculateNormalCovar (const pcl::Indices& neighbors, float* coefficients) const;
169  private:
170  float threshold_;
171  bool refine_{true};
172  bool nonmax_{true};
173  ResponseMethod method_;
174  PointCloudNConstPtr normals_;
175  unsigned int threads_{0};
176  };
177 }
178 
179 #include <pcl/keypoints/impl/harris_3d.hpp>
HarrisKeypoint3D uses the idea of 2D Harris keypoints, but instead of using image gradients,...
Definition: harris_3d.h:52
typename PointCloudN::Ptr PointCloudNPtr
Definition: harris_3d.h:63
void responseTomasi(PointCloudOut &output) const
Definition: harris_3d.hpp:457
HarrisKeypoint3D(ResponseMethod method=HARRIS, float radius=0.01f, float threshold=0.0f)
Constructor.
Definition: harris_3d.h:85
void detectKeypoints(PointCloudOut &output) override
Definition: harris_3d.hpp:238
typename Keypoint< PointInT, PointOutT >::KdTree KdTree
Definition: harris_3d.h:59
typename PointCloudN::ConstPtr PointCloudNConstPtr
Definition: harris_3d.h:64
void responseNoble(PointCloudOut &output) const
Definition: harris_3d.hpp:359
bool initCompute() override
Definition: harris_3d.hpp:192
void responseHarris(PointCloudOut &output) const
gets the corner response for valid input points
Definition: harris_3d.hpp:318
shared_ptr< const HarrisKeypoint3D< PointInT, PointOutT, NormalT > > ConstPtr
Definition: harris_3d.h:55
typename Keypoint< PointInT, PointOutT >::PointCloudOut PointCloudOut
Definition: harris_3d.h:58
void setNormals(const PointCloudNConstPtr &normals)
Set normals if precalculated normals are available.
Definition: harris_3d.hpp:96
void setNumberOfThreads(unsigned int nr_threads=0)
Initialize the scheduler and set the number of threads to use.
Definition: harris_3d.h:155
void responseCurvature(PointCloudOut &output) const
Definition: harris_3d.hpp:439
shared_ptr< HarrisKeypoint3D< PointInT, PointOutT, NormalT > > Ptr
Definition: harris_3d.h:54
void refineCorners(PointCloudOut &corners) const
Definition: harris_3d.hpp:502
void setRadius(float radius)
Set the radius for normal estimation and non maxima suppression.
Definition: harris_3d.hpp:75
~HarrisKeypoint3D() override=default
Empty destructor.
void setNonMaxSupression(bool=false)
Whether non maxima suppression should be applied or the response for each point should be returned.
Definition: harris_3d.hpp:89
void setSearchSurface(const PointCloudInConstPtr &cloud) override
Provide a pointer to a dataset to add additional information to estimate the features for every point...
Definition: harris_3d.h:149
void setInputCloud(const PointCloudInConstPtr &cloud) override
Provide a pointer to the input dataset.
Definition: harris_3d.hpp:52
void setMethod(ResponseMethod type)
Set the method of the response to be calculated.
Definition: harris_3d.hpp:61
void setThreshold(float threshold)
Set the threshold value for detecting corners.
Definition: harris_3d.hpp:68
void responseLowe(PointCloudOut &output) const
Definition: harris_3d.hpp:399
void calculateNormalCovar(const pcl::Indices &neighbors, float *coefficients) const
calculates the upper triangular part of unnormalized covariance matrix over the normals given by the ...
Definition: harris_3d.hpp:103
typename PointCloudIn::ConstPtr PointCloudInConstPtr
Definition: harris_3d.h:60
void setRefine(bool do_refine)
Whether the detected key points should be refined or not.
Definition: harris_3d.hpp:82
typename Keypoint< PointInT, PointOutT >::PointCloudIn PointCloudIn
Definition: harris_3d.h:57
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:167
PointCloudInConstPtr surface_
An input point cloud describing the surface that is to be used for nearest neighbors estimation.
Definition: keypoint.h:176
double search_radius_
The nearest neighbors search radius for each point.
Definition: keypoint.h:185
PCL base class.
Definition: pcl_base.h:70
shared_ptr< PointCloud< NormalT > > Ptr
Definition: point_cloud.h:413
shared_ptr< const PointCloud< NormalT > > ConstPtr
Definition: point_cloud.h:414
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133