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