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.
*
*/
#ifndef PCL_KEYPOINT_H_
#define PCL_KEYPOINT_H_
// PCL includes
#include <pcl/pcl_base.h>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <pcl/search/pcl_search.h>
#include <pcl/pcl_config.h>
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:
typedef boost::shared_ptr<Keypoint<PointInT, PointOutT> > Ptr;
typedef boost::shared_ptr<const Keypoint<PointInT, PointOutT> > ConstPtr;
using PCLBase<PointInT>::indices_;
using PCLBase<PointInT>::input_;
typedef PCLBase<PointInT> BaseClass;
typedef typename pcl::search::Search<PointInT> KdTree;
typedef typename pcl::search::Search<PointInT>::Ptr KdTreePtr;
typedef pcl::PointCloud<PointInT> PointCloudIn;
typedef typename PointCloudIn::Ptr PointCloudInPtr;
typedef typename PointCloudIn::ConstPtr PointCloudInConstPtr;
typedef pcl::PointCloud<PointOutT> PointCloudOut;
typedef boost::function<int (int, double, std::vector<int> &, std::vector<float> &)> SearchMethod;
typedef boost::function<int (const PointCloudIn &cloud, int index, double, std::vector<int> &, std::vector<float> &)> SearchMethodSurface;
public:
/** \brief Empty constructor. */
Keypoint () :
BaseClass (),
name_ (),
search_method_ (),
search_method_surface_ (),
surface_ (),
tree_ (),
search_parameter_ (0),
search_radius_ (0),
k_ (0)
{};
/** \brief Empty destructor */
virtual ~Keypoint () {}
/** \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 (int index, double parameter, std::vector<int> &indices, std::vector<float> &distances) const
{
if (surface_ == input_) // if the two surfaces are the same
return (search_method_ (index, parameter, indices, distances));
else
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_;
/** \brief The nearest neighbors search radius for each point. */
double search_radius_;
/** \brief The number of K nearest neighbors to use for each point. */
int k_;
/** \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>
#endif //#ifndef PCL_KEYPOINT_H_
pcl::Keypoint::searchForNeighbors
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::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:130
pcl::Keypoint::getRadiusSearch
double getRadiusSearch()
Get the sphere radius used for determining the neighbors.
Definition: keypoint.h:134
pcl::Keypoint::setSearchMethod
void setSearchMethod(const KdTreePtr &tree)
Provide a pointer to the search object.
Definition: keypoint.h:105
pcl::Keypoint::keypoints_indices_
pcl::PointIndicesPtr keypoints_indices_
Indices of the keypoints in the input cloud.
Definition: keypoint.h:197
pcl::Keypoint::setKSearch
void setKSearch(int k)
Set the number of k nearest neighbors to use for the feature estimation.
Definition: keypoint.h:119
pcl::Keypoint::name_
std::string name_
The key point detection method&#39;s name.
Definition: keypoint.h:173
pcl
Definition: convolution.h:45
pcl::Keypoint::getKeypointsIndices
pcl::PointIndicesConstPtr getKeypointsIndices()
Definition: keypoint.h:140
pcl::Keypoint::PointCloudIn
pcl::PointCloud< PointInT > PointCloudIn
Definition: keypoint.h:67
pcl::Keypoint::KdTree
pcl::search::Search< PointInT > KdTree
Definition: keypoint.h:65
pcl::Keypoint::~Keypoint
virtual ~Keypoint()
Empty destructor.
Definition: keypoint.h:89
pcl::Keypoint::PointCloudInConstPtr
PointCloudIn::ConstPtr PointCloudInConstPtr
Definition: keypoint.h:69
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:124
pcl::Keypoint::search_radius_
double search_radius_
The nearest neighbors search radius for each point.
Definition: keypoint.h:191
pcl::Keypoint::Keypoint
Keypoint()
Empty constructor.
Definition: keypoint.h:76
pcl::Keypoint< PointT, PointT >::SearchMethodSurface
boost::function< int(const PointCloudIn &cloud, int index, double, std::vector< int > &, std::vector< float > &)> SearchMethodSurface
Definition: keypoint.h:72
pcl::Keypoint::getClassName
const std::string & getClassName() const
Get a string representation of the name of this class.
Definition: keypoint.h:201
pcl::PointCloud::Ptr
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
pcl::Keypoint::getSearchMethod
KdTreePtr getSearchMethod()
Get a pointer to the search method used.
Definition: keypoint.h:109
pcl::Keypoint::k_
int k_
The number of K nearest neighbors to use for each point.
Definition: keypoint.h:194
pcl::search::Search::Ptr
boost::shared_ptr< pcl::search::Search< PointT > > Ptr
Definition: search.h:81
pcl::Keypoint::surface_
PointCloudInConstPtr surface_
An input point cloud describing the surface that is to be used for nearest neighbors estimation...
Definition: keypoint.h:182
pcl::Keypoint::BaseClass
PCLBase< PointInT > BaseClass
Definition: keypoint.h:64
pcl::PCLBase
PCL base class.
Definition: pcl_base.h:68
pcl::Keypoint::initCompute
virtual bool initCompute()
Definition: keypoint.hpp:43
pcl::PointCloud::ConstPtr
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
pcl::Keypoint::getSearchSurface
PointCloudInConstPtr getSearchSurface()
Get a pointer to the surface point cloud dataset.
Definition: keypoint.h:99
pcl::Keypoint::search_method_
SearchMethod search_method_
The search method template for indices.
Definition: keypoint.h:176
pcl::PointIndicesConstPtr
boost::shared_ptr< ::pcl::PointIndices const > PointIndicesConstPtr
Definition: PointIndices.h:27
pcl::Keypoint::getKSearch
int getKSearch()
get the number of k nearest neighbors used for the feature estimation.
Definition: keypoint.h:123
pcl::PointCloud< PointInT >
pcl::Keypoint::Ptr
boost::shared_ptr< Keypoint< PointInT, PointOutT > > Ptr
Definition: keypoint.h:58
pcl::PointIndicesPtr
boost::shared_ptr< ::pcl::PointIndices > PointIndicesPtr
Definition: PointIndices.h:26
pcl::Keypoint::PointCloudInPtr
PointCloudIn::Ptr PointCloudInPtr
Definition: keypoint.h:68
pcl::Keypoint< PointT, PointT >::SearchMethod
boost::function< int(int, double, std::vector< int > &, std::vector< float > &)> SearchMethod
Definition: keypoint.h:71
pcl::Keypoint::search_parameter_
double search_parameter_
The actual search parameter (casted from either search_radius_ or k_).
Definition: keypoint.h:188
pcl::Keypoint::getSearchParameter
double getSearchParameter()
Get the internal search parameter.
Definition: keypoint.h:113
pcl::Keypoint::PointCloudOut
pcl::PointCloud< PointOutT > PointCloudOut
Definition: keypoint.h:70
pcl::Keypoint::ConstPtr
boost::shared_ptr< const Keypoint< PointInT, PointOutT > > ConstPtr
Definition: keypoint.h:59
pcl::PCLBase< PointInT >::input_
PointCloudConstPtr input_
The input point cloud dataset.
Definition: pcl_base.h:150
pcl::Keypoint::KdTreePtr
pcl::search::Search< PointInT >::Ptr KdTreePtr
Definition: keypoint.h:66
pcl::Keypoint::detectKeypoints
virtual void detectKeypoints(PointCloudOut &output)=0
Abstract key point detection method.
pcl::Keypoint::search_method_surface_
SearchMethodSurface search_method_surface_
The search method template for points.
Definition: keypoint.h:179
pcl::Keypoint::tree_
KdTreePtr tree_
A pointer to the spatial search object.
Definition: keypoint.h:185
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:95
pcl::search::Search< PointInT >