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