Point Cloud Library (PCL)  1.7.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 
76 
77  typedef enum {HARRIS = 1, NOBLE, LOWE, TOMASI, CURVATURE} ResponseMethod;
78 
79  /** \brief Constructor
80  * \param[in] method the method to be used to determine the corner responses
81  * \param[in] radius the radius for normal estimation as well as for non maxima suppression
82  * \param[in] threshold the threshold to filter out weak corners
83  */
84  HarrisKeypoint3D (ResponseMethod method = HARRIS, float radius = 0.01f, float threshold = 0.0f)
85  : threshold_ (threshold)
86  , refine_ (true)
87  , nonmax_ (true)
88  , method_ (method)
89  , threads_ (0)
90  {
91  name_ = "HarrisKeypoint3D";
92  search_radius_ = radius;
93  }
94 
95  /** \brief Empty destructor */
96  virtual ~HarrisKeypoint3D () {}
97 
98  /** \brief Set the method of the response to be calculated.
99  * \param[in] type
100  */
101  void
102  setMethod (ResponseMethod type);
103 
104  /** \brief Set the radius for normal estimation and non maxima supression.
105  * \param[in] radius
106  */
107  void
108  setRadius (float radius);
109 
110  /** \brief Set the threshold value for detecting corners. This is only evaluated if non maxima suppression is turned on.
111  * \brief note non maxima suppression needs to be activated in order to use this feature.
112  * \param[in] threshold
113  */
114  void
115  setThreshold (float threshold);
116 
117  /** \brief Whether non maxima suppression should be applied or the response for each point should be returned
118  * \note this value needs to be turned on in order to apply thresholding and refinement
119  * \param[in] nonmax default is false
120  */
121  void
122  setNonMaxSupression (bool = false);
123 
124  /** \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.
125  * \brief note non maxima supression needs to be on in order to use this feature.
126  * \param[in] do_refine
127  */
128  void
129  setRefine (bool do_refine);
130 
131  /** \brief Set normals if precalculated normals are available.
132  * \param normals
133  */
134  void
135  setNormals (const PointCloudNConstPtr &normals);
136 
137  /** \brief Provide a pointer to a dataset to add additional information
138  * to estimate the features for every point in the input dataset. This
139  * is optional, if this is not set, it will only use the data in the
140  * input cloud to estimate the features. This is useful when you only
141  * need to compute the features for a downsampled cloud.
142  * \param[in] cloud a pointer to a PointCloud message
143  */
144  virtual void
145  setSearchSurface (const PointCloudInConstPtr &cloud) { surface_ = cloud; normals_.reset(); }
146 
147  /** \brief Initialize the scheduler and set the number of threads to use.
148  * \param nr_threads the number of hardware threads to use (0 sets the value back to automatic)
149  */
150  inline void
151  setNumberOfThreads (unsigned int nr_threads = 0) { threads_ = nr_threads; }
152  protected:
153  bool
154  initCompute ();
155  void detectKeypoints (PointCloudOut &output);
156  /** \brief gets the corner response for valid input points*/
157  void responseHarris (PointCloudOut &output) const;
158  void responseNoble (PointCloudOut &output) const;
159  void responseLowe (PointCloudOut &output) const;
160  void responseTomasi (PointCloudOut &output) const;
161  void responseCurvature (PointCloudOut &output) const;
162  void refineCorners (PointCloudOut &corners) const;
163  /** \brief calculates the upper triangular part of unnormalized covariance matrix over the normals given by the indices.*/
164  void calculateNormalCovar (const std::vector<int>& neighbors, float* coefficients) const;
165  private:
166  float threshold_;
167  bool refine_;
168  bool nonmax_;
169  ResponseMethod method_;
170  PointCloudNConstPtr normals_;
171  unsigned int threads_;
172  };
173 }
174 
175 #include <pcl/keypoints/impl/harris_3d.hpp>
176 
177 #endif // #ifndef PCL_HARRIS_KEYPOINT_3D_H_
178