Point Cloud Library (PCL)  1.7.2
keypoint.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_KEYPOINT_H_
39 #define PCL_KEYPOINT_H_
40 
41 // PCL includes
42 #include <pcl/pcl_base.h>
43 #include <boost/function.hpp>
44 #include <boost/bind.hpp>
45 #include <pcl/search/pcl_search.h>
46 #include <pcl/pcl_config.h>
47 
48 namespace pcl
49 {
50  /** \brief @b Keypoint represents the base class for key points.
51  * \author Bastian Steder
52  * \ingroup keypoints
53  */
54  template <typename PointInT, typename PointOutT>
55  class Keypoint : public PCLBase<PointInT>
56  {
57  public:
58  typedef boost::shared_ptr<Keypoint<PointInT, PointOutT> > Ptr;
59  typedef boost::shared_ptr<const Keypoint<PointInT, PointOutT> > ConstPtr;
60 
63 
71  typedef boost::function<int (int, double, std::vector<int> &, std::vector<float> &)> SearchMethod;
72  typedef boost::function<int (const PointCloudIn &cloud, int index, double, std::vector<int> &, std::vector<float> &)> SearchMethodSurface;
73 
74  public:
75  /** \brief Empty constructor. */
76  Keypoint () :
77  BaseClass (),
78  name_ (),
79  search_method_ (),
81  surface_ (),
82  tree_ (),
83  search_parameter_ (0),
84  search_radius_ (0),
85  k_ (0)
86  {};
87 
88  /** \brief Empty destructor */
89  virtual ~Keypoint () {}
90 
91  /** \brief Provide a pointer to the input dataset that we need to estimate features at every point for.
92  * \param cloud the const boost shared pointer to a PointCloud message
93  */
94  virtual void
95  setSearchSurface (const PointCloudInConstPtr &cloud) { surface_ = cloud; }
96 
97  /** \brief Get a pointer to the surface point cloud dataset. */
98  inline PointCloudInConstPtr
99  getSearchSurface () { return (surface_); }
100 
101  /** \brief Provide a pointer to the search object.
102  * \param tree a pointer to the spatial search object.
103  */
104  inline void
105  setSearchMethod (const KdTreePtr &tree) { tree_ = tree; }
106 
107  /** \brief Get a pointer to the search method used. */
108  inline KdTreePtr
109  getSearchMethod () { return (tree_); }
110 
111  /** \brief Get the internal search parameter. */
112  inline double
114 
115  /** \brief Set the number of k nearest neighbors to use for the feature estimation.
116  * \param k the number of k-nearest neighbors
117  */
118  inline void
119  setKSearch (int k) { k_ = k; }
120 
121  /** \brief get the number of k nearest neighbors used for the feature estimation. */
122  inline int
123  getKSearch () { return (k_); }
124 
125  /** \brief Set the sphere radius that is to be used for determining the nearest neighbors used for the
126  * key point detection
127  * \param radius the sphere radius used as the maximum distance to consider a point a neighbor
128  */
129  inline void
130  setRadiusSearch (double radius) { search_radius_ = radius; }
131 
132  /** \brief Get the sphere radius used for determining the neighbors. */
133  inline double
135 
136  /** \brief \return the keypoints indices in the input cloud.
137  * \note not all the daughter classes populate the keypoints indices so check emptiness before use.
138  */
141 
142  /** \brief Base method for key point detection for all points given in <setInputCloud (), setIndices ()> using
143  * the surface in setSearchSurface () and the spatial locator in setSearchMethod ()
144  * \param output the resultant point cloud model dataset containing the estimated features
145  */
146  inline void
147  compute (PointCloudOut &output);
148 
149  /** \brief Search for k-nearest neighbors using the spatial locator from \a setSearchmethod, and the given surface
150  * from \a setSearchSurface.
151  * \param index the index of the query point
152  * \param parameter the search parameter (either k or radius)
153  * \param indices the resultant vector of indices representing the k-nearest neighbors
154  * \param distances the resultant vector of distances representing the distances from the query point to the
155  * k-nearest neighbors
156  */
157  inline int
158  searchForNeighbors (int index, double parameter, std::vector<int> &indices, std::vector<float> &distances) const
159  {
160  if (surface_ == input_) // if the two surfaces are the same
161  return (search_method_ (index, parameter, indices, distances));
162  else
163  return (search_method_surface_ (*input_, index, parameter, indices, distances));
164  }
165 
166  protected:
168 
169  virtual bool
170  initCompute ();
171 
172  /** \brief The key point detection method's name. */
173  std::string name_;
174 
175  /** \brief The search method template for indices. */
177 
178  /** \brief The search method template for points. */
180 
181  /** \brief An input point cloud describing the surface that is to be used for nearest neighbors estimation. */
182  PointCloudInConstPtr surface_;
183 
184  /** \brief A pointer to the spatial search object. */
185  KdTreePtr tree_;
186 
187  /** \brief The actual search parameter (casted from either \a search_radius_ or \a k_). */
189 
190  /** \brief The nearest neighbors search radius for each point. */
192 
193  /** \brief The number of K nearest neighbors to use for each point. */
194  int k_;
195 
196  /** \brief Indices of the keypoints in the input cloud. */
198 
199  /** \brief Get a string representation of the name of this class. */
200  inline const std::string&
201  getClassName () const { return (name_); }
202 
203  /** \brief Abstract key point detection method. */
204  virtual void
205  detectKeypoints (PointCloudOut &output) = 0;
206  };
207 }
208 
209 #include <pcl/keypoints/impl/keypoint.hpp>
210 
211 #endif //#ifndef PCL_KEYPOINT_H_
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
void setRadiusSearch(double radius)
Set the sphere radius that is to be used for determining the nearest neighbors used for the key point...
Definition: keypoint.h:130
double getRadiusSearch()
Get the sphere radius used for determining the neighbors.
Definition: keypoint.h:134
void setSearchMethod(const KdTreePtr &tree)
Provide a pointer to the search object.
Definition: keypoint.h:105
pcl::PointIndicesPtr keypoints_indices_
Indices of the keypoints in the input cloud.
Definition: keypoint.h:197
void setKSearch(int k)
Set the number of k nearest neighbors to use for the feature estimation.
Definition: keypoint.h:119
std::string name_
The key point detection method's name.
Definition: keypoint.h:173
pcl::PointIndicesConstPtr getKeypointsIndices()
Definition: keypoint.h:140
pcl::PointCloud< PointInT > PointCloudIn
Definition: keypoint.h:67
pcl::search::Search< PointInT > KdTree
Definition: keypoint.h:65
virtual ~Keypoint()
Empty destructor.
Definition: keypoint.h:89
PointCloudIn::ConstPtr PointCloudInConstPtr
Definition: keypoint.h:69
void compute(PointCloudOut &output)
Base method for key point detection for all points given in using t...
Definition: keypoint.hpp:124
double search_radius_
The nearest neighbors search radius for each point.
Definition: keypoint.h:191
Keypoint()
Empty constructor.
Definition: keypoint.h:76
boost::function< int(const PointCloudIn &cloud, int index, double, std::vector< int > &, std::vector< float > &)> SearchMethodSurface
Definition: keypoint.h:72
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
Keypoint represents the base class for key points.
Definition: keypoint.h:55
KdTreePtr getSearchMethod()
Get a pointer to the search method used.
Definition: keypoint.h:109
int k_
The number of K nearest neighbors to use for each point.
Definition: keypoint.h:194
boost::shared_ptr< pcl::search::Search< PointT > > Ptr
Definition: search.h:81
PointCloudInConstPtr surface_
An input point cloud describing the surface that is to be used for nearest neighbors estimation...
Definition: keypoint.h:182
PCLBase< PointInT > BaseClass
Definition: keypoint.h:64
PCL base class.
Definition: pcl_base.h:68
virtual bool initCompute()
Definition: keypoint.hpp:43
PointCloudInConstPtr getSearchSurface()
Get a pointer to the surface point cloud dataset.
Definition: keypoint.h:99
SearchMethod search_method_
The search method template for indices.
Definition: keypoint.h:176
boost::shared_ptr< ::pcl::PointIndices const > PointIndicesConstPtr
Definition: PointIndices.h:27
int getKSearch()
get the number of k nearest neighbors used for the feature estimation.
Definition: keypoint.h:123
boost::shared_ptr< Keypoint< PointInT, PointOutT > > Ptr
Definition: keypoint.h:58
boost::shared_ptr< ::pcl::PointIndices > PointIndicesPtr
Definition: PointIndices.h:26
PointCloudIn::Ptr PointCloudInPtr
Definition: keypoint.h:68
boost::function< int(int, double, std::vector< int > &, std::vector< float > &)> SearchMethod
Definition: keypoint.h:71
double search_parameter_
The actual search parameter (casted from either search_radius_ or k_).
Definition: keypoint.h:188
double getSearchParameter()
Get the internal search parameter.
Definition: keypoint.h:113
pcl::PointCloud< PointOutT > PointCloudOut
Definition: keypoint.h:70
boost::shared_ptr< const Keypoint< PointInT, PointOutT > > ConstPtr
Definition: keypoint.h:59
PointCloudConstPtr input_
The input point cloud dataset.
Definition: pcl_base.h:150
int searchForNeighbors(int index, double parameter, std::vector< int > &indices, std::vector< float > &distances) const
Search for k-nearest neighbors using the spatial locator from setSearchmethod, and the given surface ...
Definition: keypoint.h:158
pcl::search::Search< PointInT >::Ptr KdTreePtr
Definition: keypoint.h:66
const std::string & getClassName() const
Get a string representation of the name of this class.
Definition: keypoint.h:201
virtual void detectKeypoints(PointCloudOut &output)=0
Abstract key point detection method.
SearchMethodSurface search_method_surface_
The search method template for points.
Definition: keypoint.h:179
KdTreePtr tree_
A pointer to the spatial search object.
Definition: keypoint.h:185
virtual void setSearchSurface(const PointCloudInConstPtr &cloud)
Provide a pointer to the input dataset that we need to estimate features at every point for...
Definition: keypoint.h:95