Point Cloud Library (PCL)  1.15.1-dev
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 #pragma once
38 
39 #include <pcl/keypoints/keypoint.h>
40 #include <pcl/point_types.h> // for pcl::Normal, pcl::IntensityGradient
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  using Ptr = shared_ptr<HarrisKeypoint6D<PointInT, PointOutT, NormalT> >;
54  using ConstPtr = shared_ptr<const HarrisKeypoint6D<PointInT, PointOutT, NormalT> >;
55 
59  using PointCloudInConstPtr = typename PointCloudIn::ConstPtr;
60 
70 
71  /**
72  * @brief Constructor
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  ,
79  normals_ (new pcl::PointCloud<NormalT>)
80  , intensity_gradients_ (new pcl::PointCloud<pcl::IntensityGradient>)
81  {
82  name_ = "HarrisKeypoint6D";
83  search_radius_ = radius;
84  }
85 
86  /** \brief Empty destructor */
87  virtual ~HarrisKeypoint6D () = default;
88 
89  /**
90  * @brief set the radius for normal estimation and non maxima suppression.
91  * @param radius
92  */
93  void setRadius (float radius);
94 
95  /**
96  * @brief set the threshold value for detecting corners. This is only evaluated if non maxima suppression is turned on.
97  * @brief note non maxima suppression needs to be activated in order to use this feature.
98  * @param threshold
99  */
100  void setThreshold (float threshold);
101 
102  /**
103  * @brief whether non maxima suppression should be applied or the response for each point should be returned
104  * @note this value needs to be turned on in order to apply thresholding and refinement
105  * @param nonmax default is false
106  */
107  void setNonMaxSupression (bool = false);
108 
109  /**
110  * @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.
111  * @brief note non maxima suppression needs to be on in order to use this feature.
112  * @param do_refine
113  */
114  void setRefine (bool do_refine);
115 
116  virtual void
117  setSearchSurface (const PointCloudInConstPtr &cloud) { surface_ = cloud; normals_->clear (); intensity_gradients_->clear ();}
118 
119  /** \brief Initialize the scheduler and set the number of threads to use.
120  * \param nr_threads the number of hardware threads to use (0 sets the value back to automatic)
121  */
122  inline void
123  setNumberOfThreads (unsigned int nr_threads = 0) { threads_ = nr_threads; }
124  protected:
125  void detectKeypoints (PointCloudOut &output);
126  void responseTomasi (PointCloudOut &output) const;
127  void refineCorners (PointCloudOut &corners) const;
128  void calculateCombinedCovar (const pcl::Indices& neighbors, float* coefficients) const;
129  private:
130  float threshold_;
131  bool refine_{true};
132  bool nonmax_{true};
133  unsigned int threads_{0};
134  typename pcl::PointCloud<NormalT>::Ptr normals_;
136  } ;
137 }
138 
139 #include <pcl/keypoints/impl/harris_6d.hpp>
Keypoint detector for detecting corners in 3D (XYZ), 2D (intensity) AND mixed versions of these.
Definition: harris_6d.h:51
typename Keypoint< PointInT, PointOutT >::PointCloudIn PointCloudIn
Definition: harris_6d.h:56
void setNonMaxSupression(bool=false)
whether non maxima suppression should be applied or the response for each point should be returned
Definition: harris_6d.hpp:69
shared_ptr< const HarrisKeypoint6D< PointInT, PointOutT, NormalT > > ConstPtr
Definition: harris_6d.h:54
void setThreshold(float threshold)
set the threshold value for detecting corners.
Definition: harris_6d.hpp:51
void setRefine(bool do_refine)
whether the detected key points should be refined or not.
Definition: harris_6d.hpp:63
void setRadius(float radius)
set the radius for normal estimation and non maxima suppression.
Definition: harris_6d.hpp:57
void responseTomasi(PointCloudOut &output) const
Definition: harris_6d.hpp:268
void setNumberOfThreads(unsigned int nr_threads=0)
Initialize the scheduler and set the number of threads to use.
Definition: harris_6d.h:123
typename PointCloudIn::ConstPtr PointCloudInConstPtr
Definition: harris_6d.h:59
void detectKeypoints(PointCloudOut &output)
Definition: harris_6d.hpp:143
typename Keypoint< PointInT, PointOutT >::PointCloudOut PointCloudOut
Definition: harris_6d.h:57
void refineCorners(PointCloudOut &corners) const
Definition: harris_6d.hpp:358
typename Keypoint< PointInT, PointOutT >::KdTree KdTree
Definition: harris_6d.h:58
shared_ptr< HarrisKeypoint6D< PointInT, PointOutT, NormalT > > Ptr
Definition: harris_6d.h:53
virtual ~HarrisKeypoint6D()=default
Empty destructor.
HarrisKeypoint6D(float radius=0.01, float threshold=0.0)
Constructor.
Definition: harris_6d.h:76
virtual void setSearchSurface(const PointCloudInConstPtr &cloud)
Definition: harris_6d.h:117
void calculateCombinedCovar(const pcl::Indices &neighbors, float *coefficients) const
Definition: harris_6d.hpp:76
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
void clear()
Removes all points in a cloud and sets the width and height to 0.
Definition: point_cloud.h:886
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:414
Defines all the PCL implemented PointT point type structures.
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133
A point structure representing the intensity gradient of an XYZI point cloud.
A point structure representing normal coordinates and the surface curvature estimate.