Loading...
Searching...
No Matches
keypoint.h
/*
* Software License Agreement (BSD License)
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2010-2011, Willow Garage, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of Willow Garage, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#pragma once
// PCL includes
#include <pcl/pcl_base.h>
#include <pcl/search/search.h> // for Search
#include <pcl/pcl_config.h>
#include <functional>
namespace pcl
{
/** \brief @b Keypoint represents the base class for key points.
* \author Bastian Steder
* \ingroup keypoints
*/
template <typename PointInT, typename PointOutT>
class Keypoint : public PCLBase<PointInT>
{
public:
using Ptr = shared_ptr<Keypoint<PointInT, PointOutT> >;
using ConstPtr = shared_ptr<const Keypoint<PointInT, PointOutT> >;
using PCLBase<PointInT>::indices_;
using PCLBase<PointInT>::input_;
using BaseClass = PCLBase<PointInT>;
using KdTree = pcl::search::Search<PointInT>;
using KdTreePtr = typename KdTree::Ptr;
using PointCloudIn = pcl::PointCloud<PointInT>;
using PointCloudInPtr = typename PointCloudIn::Ptr;
using PointCloudInConstPtr = typename PointCloudIn::ConstPtr;
using PointCloudOut = pcl::PointCloud<PointOutT>;
using SearchMethod = std::function<int (pcl::index_t, double, pcl::Indices &, std::vector<float> &)>;
using SearchMethodSurface = std::function<int (const PointCloudIn &cloud, pcl::index_t index, double, pcl::Indices &, std::vector<float> &)>;
public:
/** \brief Empty constructor. */
Keypoint () :
BaseClass (),
search_method_surface_ (),
surface_ (),
tree_ ()
{};
/** \brief Empty destructor */
~Keypoint () override = default;
/** \brief Provide a pointer to the input dataset that we need to estimate features at every point for.
* \param cloud the const boost shared pointer to a PointCloud message
*/
virtual void
setSearchSurface (const PointCloudInConstPtr &cloud) { surface_ = cloud; }
/** \brief Get a pointer to the surface point cloud dataset. */
inline PointCloudInConstPtr
getSearchSurface () { return (surface_); }
/** \brief Provide a pointer to the search object.
* \param tree a pointer to the spatial search object.
*/
inline void
setSearchMethod (const KdTreePtr &tree) { tree_ = tree; }
/** \brief Get a pointer to the search method used. */
inline KdTreePtr
getSearchMethod () { return (tree_); }
/** \brief Get the internal search parameter. */
inline double
getSearchParameter () { return (search_parameter_); }
/** \brief Set the number of k nearest neighbors to use for the feature estimation.
* \param k the number of k-nearest neighbors
*/
inline void
setKSearch (int k) { k_ = k; }
/** \brief get the number of k nearest neighbors used for the feature estimation. */
inline int
getKSearch () { return (k_); }
/** \brief Set the sphere radius that is to be used for determining the nearest neighbors used for the
* key point detection
* \param radius the sphere radius used as the maximum distance to consider a point a neighbor
*/
inline void
setRadiusSearch (double radius) { search_radius_ = radius; }
/** \brief Get the sphere radius used for determining the neighbors. */
inline double
getRadiusSearch () { return (search_radius_); }
/** \brief \return the keypoints indices in the input cloud.
* \note not all the daughter classes populate the keypoints indices so check emptiness before use.
*/
pcl::PointIndicesConstPtr
getKeypointsIndices () { return (keypoints_indices_); }
/** \brief Base method for key point detection for all points given in <setInputCloud (), setIndices ()> using
* the surface in setSearchSurface () and the spatial locator in setSearchMethod ()
* \param output the resultant point cloud model dataset containing the estimated features
*/
inline void
compute (PointCloudOut &output);
/** \brief Search for k-nearest neighbors using the spatial locator from \a setSearchmethod, and the given surface
* from \a setSearchSurface.
* \param index the index of the query point
* \param parameter the search parameter (either k or radius)
* \param indices the resultant vector of indices representing the k-nearest neighbors
* \param distances the resultant vector of distances representing the distances from the query point to the
* k-nearest neighbors
*/
inline int
searchForNeighbors (pcl::index_t index, double parameter, pcl::Indices &indices, std::vector<float> &distances) const
{
if (surface_ == input_) // if the two surfaces are the same
return (search_method_ (index, parameter, indices, distances));
return (search_method_surface_ (*input_, index, parameter, indices, distances));
}
protected:
using PCLBase<PointInT>::deinitCompute;
virtual bool
initCompute ();
/** \brief The key point detection method's name. */
std::string name_;
/** \brief The search method template for indices. */
SearchMethod search_method_;
/** \brief The search method template for points. */
SearchMethodSurface search_method_surface_;
/** \brief An input point cloud describing the surface that is to be used for nearest neighbors estimation. */
PointCloudInConstPtr surface_;
/** \brief A pointer to the spatial search object. */
KdTreePtr tree_;
/** \brief The actual search parameter (casted from either \a search_radius_ or \a k_). */
double search_parameter_{0.0};
/** \brief The nearest neighbors search radius for each point. */
double search_radius_{0.0};
/** \brief The number of K nearest neighbors to use for each point. */
int k_{0};
/** \brief Indices of the keypoints in the input cloud. */
pcl::PointIndicesPtr keypoints_indices_;
/** \brief Get a string representation of the name of this class. */
inline const std::string&
getClassName () const { return (name_); }
/** \brief Abstract key point detection method. */
virtual void
detectKeypoints (PointCloudOut &output) = 0;
};
}
#include <pcl/keypoints/impl/keypoint.hpp>
pcl::Keypoint::compute
void compute(PointCloudOut &output)
Base method for key point detection for all points given in <setInputCloud (), setIndices ()> using t...
Definition keypoint.hpp:137
pcl::Keypoint::search_method_
SearchMethod search_method_
The search method template for indices.
Definition keypoint.h:170
pcl::Keypoint::detectKeypoints
virtual void detectKeypoints(PointCloudOut &output)=0
Abstract key point detection method.
pcl::Keypoint::~Keypoint
~Keypoint() override=default
Empty destructor.
pcl::Keypoint::setRadiusSearch
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
pcl::Keypoint::getClassName
const std::string & getClassName() const
Get a string representation of the name of this class.
Definition keypoint.h:195
pcl::Keypoint::getKSearch
int getKSearch()
get the number of k nearest neighbors used for the feature estimation.
Definition keypoint.h:118
pcl::Keypoint::SearchMethod
std::function< int(pcl::index_t, double, pcl::Indices &, std::vector< float > &)> SearchMethod
Definition keypoint.h:70
pcl::Keypoint::getSearchSurface
PointCloudInConstPtr getSearchSurface()
Get a pointer to the surface point cloud dataset.
Definition keypoint.h:94
pcl::Keypoint::SearchMethodSurface
std::function< int(const PointCloudIn &cloud, pcl::index_t index, double, pcl::Indices &, std::vector< float > &)> SearchMethodSurface
Definition keypoint.h:71
pcl::Keypoint::Ptr
shared_ptr< Keypoint< PointInT, PointOutT > > Ptr
Definition keypoint.h:57
pcl::Keypoint::setSearchMethod
void setSearchMethod(const KdTreePtr &tree)
Provide a pointer to the search object.
Definition keypoint.h:100
pcl::Keypoint::getRadiusSearch
double getRadiusSearch()
Get the sphere radius used for determining the neighbors.
Definition keypoint.h:129
pcl::Keypoint::PointCloudInPtr
typename PointCloudIn::Ptr PointCloudInPtr
Definition keypoint.h:67
pcl::Keypoint::getKeypointsIndices
pcl::PointIndicesConstPtr getKeypointsIndices()
Definition keypoint.h:135
pcl::Keypoint::k_
int k_
The number of K nearest neighbors to use for each point.
Definition keypoint.h:188
pcl::Keypoint::name_
std::string name_
The key point detection method's name.
Definition keypoint.h:167
pcl::Keypoint::initCompute
virtual bool initCompute()
Definition keypoint.hpp:51
pcl::Keypoint::search_parameter_
double search_parameter_
The actual search parameter (casted from either search_radius_ or k_).
Definition keypoint.h:182
pcl::Keypoint::PointCloudInConstPtr
typename PointCloudIn::ConstPtr PointCloudInConstPtr
Definition keypoint.h:68
pcl::Keypoint::setSearchSurface
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
pcl::Keypoint::getSearchMethod
KdTreePtr getSearchMethod()
Get a pointer to the search method used.
Definition keypoint.h:104
pcl::Keypoint::keypoints_indices_
pcl::PointIndicesPtr keypoints_indices_
Indices of the keypoints in the input cloud.
Definition keypoint.h:191
pcl::Keypoint::search_method_surface_
SearchMethodSurface search_method_surface_
The search method template for points.
Definition keypoint.h:173
pcl::Keypoint::PointCloudOut
pcl::PointCloud< PointOutT > PointCloudOut
Definition keypoint.h:69
pcl::Keypoint::KdTreePtr
typename KdTree::Ptr KdTreePtr
Definition keypoint.h:65
pcl::Keypoint::tree_
KdTreePtr tree_
A pointer to the spatial search object.
Definition keypoint.h:179
pcl::Keypoint::surface_
PointCloudInConstPtr surface_
An input point cloud describing the surface that is to be used for nearest neighbors estimation.
Definition keypoint.h:176
pcl::Keypoint::Keypoint
Keypoint()
Empty constructor.
Definition keypoint.h:75
pcl::Keypoint::search_radius_
double search_radius_
The nearest neighbors search radius for each point.
Definition keypoint.h:185
pcl::Keypoint::searchForNeighbors
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
pcl::Keypoint::setKSearch
void setKSearch(int k)
Set the number of k nearest neighbors to use for the feature estimation.
Definition keypoint.h:114
pcl::Keypoint::ConstPtr
shared_ptr< const Keypoint< PointInT, PointOutT > > ConstPtr
Definition keypoint.h:58
pcl::Keypoint::getSearchParameter
double getSearchParameter()
Get the internal search parameter.
Definition keypoint.h:108
pcl::PCLBase
PCL base class.
Definition pcl_base.h:70
pcl::PCLBase< PointInT >::input_
PointCloudConstPtr input_
The input point cloud dataset.
Definition pcl_base.h:147
pcl::PCLBase< PointInT >::indices_
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition pcl_base.h:150
pcl::PCLBase< PointInT >::deinitCompute
bool deinitCompute()
This method should get called after finishing the actual computation.
Definition pcl_base.hpp:175
pcl::PointCloud< PointInT >
pcl::PointCloud< PointInT >::Ptr
shared_ptr< PointCloud< PointInT > > Ptr
Definition point_cloud.h:413
pcl::PointCloud< PointInT >::ConstPtr
shared_ptr< const PointCloud< PointInT > > ConstPtr
Definition point_cloud.h:414
pcl::search::Search< PointInT >
pcl::search::Search< PointInT >::Ptr
shared_ptr< pcl::search::Search< PointInT > > Ptr
Definition search.h:81
pcl
Definition convolution.h:46
pcl::index_t
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
pcl::Indices
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition types.h:133
pcl::PointIndicesPtr
PointIndices::Ptr PointIndicesPtr
Definition PointIndices.h:23
pcl::PointIndicesConstPtr
PointIndices::ConstPtr PointIndicesConstPtr
Definition PointIndices.h:24