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