Point Cloud Library (PCL)  1.7.1
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 #ifndef PCL_HARRIS_KEYPOINT_6D_H_
38 #define PCL_HARRIS_KEYPOINT_6D_H_
39 
40 #include <pcl/keypoints/keypoint.h>
41 
42 namespace pcl
43 {
44 
45  /** \brief Keypoint detector for detecting corners in 3D (XYZ), 2D (intensity) AND mixed versions of these.
46  * \author Suat Gedikli
47  * \ingroup keypoints
48  */
49  template <typename PointInT, typename PointOutT, typename NormalT = pcl::Normal>
50  class HarrisKeypoint6D : public Keypoint<PointInT, PointOutT>
51  {
52  public:
53  typedef boost::shared_ptr<HarrisKeypoint6D<PointInT, PointOutT, NormalT> > Ptr;
54  typedef boost::shared_ptr<const HarrisKeypoint6D<PointInT, PointOutT, NormalT> > ConstPtr;
55 
60 
69 
70  /**
71  * @brief Constructor
72  * @param method the method to be used to determine the corner responses
73  * @param radius the radius for normal estimation as well as for non maxima suppression
74  * @param threshold the threshold to filter out weak corners
75  */
76  HarrisKeypoint6D (float radius = 0.01, float threshold = 0.0)
77  : threshold_ (threshold)
78  , refine_ (true)
79  , nonmax_ (true)
80  , threads_ (0)
81  , normals_ (new pcl::PointCloud<NormalT>)
82  , intensity_gradients_ (new pcl::PointCloud<pcl::IntensityGradient>)
83  {
84  name_ = "HarrisKeypoint6D";
85  search_radius_ = radius;
86  }
87 
88  /** \brief Empty destructor */
89  virtual ~HarrisKeypoint6D () {}
90 
91  /**
92  * @brief set the radius for normal estimation and non maxima supression.
93  * @param radius
94  */
95  void setRadius (float radius);
96 
97  /**
98  * @brief set the threshold value for detecting corners. This is only evaluated if non maxima suppression is turned on.
99  * @brief note non maxima suppression needs to be activated in order to use this feature.
100  * @param threshold
101  */
102  void setThreshold (float threshold);
103 
104  /**
105  * @brief whether non maxima suppression should be applied or the response for each point should be returned
106  * @note this value needs to be turned on in order to apply thresholding and refinement
107  * @param nonmax default is false
108  */
109  void setNonMaxSupression (bool = false);
110 
111  /**
112  * @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.
113  * @brief note non maxima supression needs to be on in order to use this feature.
114  * @param do_refine
115  */
116  void setRefine (bool do_refine);
117 
118  virtual void
119  setSearchSurface (const PointCloudInConstPtr &cloud) { surface_ = cloud; normals_->clear (); intensity_gradients_->clear ();}
120 
121  /** \brief Initialize the scheduler and set the number of threads to use.
122  * \param nr_threads the number of hardware threads to use (0 sets the value back to automatic)
123  */
124  inline void
125  setNumberOfThreads (unsigned int nr_threads = 0) { threads_ = nr_threads; }
126  protected:
127  void detectKeypoints (PointCloudOut &output);
128  void responseTomasi (PointCloudOut &output) const;
129  void refineCorners (PointCloudOut &corners) const;
130  void calculateCombinedCovar (const std::vector<int>& neighbors, float* coefficients) const;
131  private:
132  float threshold_;
133  bool refine_;
134  bool nonmax_;
135  unsigned int threads_;
136  boost::shared_ptr<pcl::PointCloud<NormalT> > normals_;
137  boost::shared_ptr<pcl::PointCloud<pcl::IntensityGradient> > intensity_gradients_;
138  } ;
139 }
140 
141 #include <pcl/keypoints/impl/harris_6d.hpp>
142 
143 #endif // #ifndef PCL_HARRIS_KEYPOINT_6D_H_
144