Point Cloud Library (PCL)
1.7.0
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2010-2011, Willow Garage, Inc. 00006 * 00007 * All rights reserved. 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions 00011 * are met: 00012 * 00013 * * Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * * Redistributions in binary form must reproduce the above 00016 * copyright notice, this list of conditions and the following 00017 * disclaimer in the documentation and/or other materials provided 00018 * with the distribution. 00019 * * Neither the name of Willow Garage, Inc. nor the names of its 00020 * contributors may be used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00026 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00027 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00029 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00032 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00033 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00034 * POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 */ 00037 00038 #ifndef PCL_KEYPOINT_H_ 00039 #define PCL_KEYPOINT_H_ 00040 00041 // PCL includes 00042 #include <pcl/pcl_base.h> 00043 #include <boost/function.hpp> 00044 #include <boost/bind.hpp> 00045 #include <pcl/search/pcl_search.h> 00046 #include <pcl/pcl_config.h> 00047 00048 namespace pcl 00049 { 00050 /** \brief @b Keypoint represents the base class for key points. 00051 * \author Bastian Steder 00052 * \ingroup keypoints 00053 */ 00054 template <typename PointInT, typename PointOutT> 00055 class Keypoint : public PCLBase<PointInT> 00056 { 00057 public: 00058 typedef boost::shared_ptr<Keypoint<PointInT, PointOutT> > Ptr; 00059 typedef boost::shared_ptr<const Keypoint<PointInT, PointOutT> > ConstPtr; 00060 00061 using PCLBase<PointInT>::indices_; 00062 using PCLBase<PointInT>::input_; 00063 00064 typedef PCLBase<PointInT> BaseClass; 00065 typedef typename pcl::search::Search<PointInT> KdTree; 00066 typedef typename pcl::search::Search<PointInT>::Ptr KdTreePtr; 00067 typedef pcl::PointCloud<PointInT> PointCloudIn; 00068 typedef typename PointCloudIn::Ptr PointCloudInPtr; 00069 typedef typename PointCloudIn::ConstPtr PointCloudInConstPtr; 00070 typedef pcl::PointCloud<PointOutT> PointCloudOut; 00071 typedef boost::function<int (int, double, std::vector<int> &, std::vector<float> &)> SearchMethod; 00072 typedef boost::function<int (const PointCloudIn &cloud, int index, double, std::vector<int> &, std::vector<float> &)> SearchMethodSurface; 00073 00074 public: 00075 /** \brief Empty constructor. */ 00076 Keypoint () : 00077 BaseClass (), 00078 name_ (), 00079 search_method_ (), 00080 search_method_surface_ (), 00081 surface_ (), 00082 tree_ (), 00083 search_parameter_ (0), 00084 search_radius_ (0), 00085 k_ (0) 00086 {}; 00087 00088 /** \brief Empty destructor */ 00089 virtual ~Keypoint () {} 00090 00091 /** \brief Provide a pointer to the input dataset that we need to estimate features at every point for. 00092 * \param cloud the const boost shared pointer to a PointCloud message 00093 */ 00094 virtual void 00095 setSearchSurface (const PointCloudInConstPtr &cloud) { surface_ = cloud; } 00096 00097 /** \brief Get a pointer to the surface point cloud dataset. */ 00098 inline PointCloudInConstPtr 00099 getSearchSurface () { return (surface_); } 00100 00101 /** \brief Provide a pointer to the search object. 00102 * \param tree a pointer to the spatial search object. 00103 */ 00104 inline void 00105 setSearchMethod (const KdTreePtr &tree) { tree_ = tree; } 00106 00107 /** \brief Get a pointer to the search method used. */ 00108 inline KdTreePtr 00109 getSearchMethod () { return (tree_); } 00110 00111 /** \brief Get the internal search parameter. */ 00112 inline double 00113 getSearchParameter () { return (search_parameter_); } 00114 00115 /** \brief Set the number of k nearest neighbors to use for the feature estimation. 00116 * \param k the number of k-nearest neighbors 00117 */ 00118 inline void 00119 setKSearch (int k) { k_ = k; } 00120 00121 /** \brief get the number of k nearest neighbors used for the feature estimation. */ 00122 inline int 00123 getKSearch () { return (k_); } 00124 00125 /** \brief Set the sphere radius that is to be used for determining the nearest neighbors used for the 00126 * key point detection 00127 * \param radius the sphere radius used as the maximum distance to consider a point a neighbor 00128 */ 00129 inline void 00130 setRadiusSearch (double radius) { search_radius_ = radius; } 00131 00132 /** \brief Get the sphere radius used for determining the neighbors. */ 00133 inline double 00134 getRadiusSearch () { return (search_radius_); } 00135 00136 /** \brief Base method for key point detection for all points given in <setInputCloud (), setIndices ()> using 00137 * the surface in setSearchSurface () and the spatial locator in setSearchMethod () 00138 * \param output the resultant point cloud model dataset containing the estimated features 00139 */ 00140 inline void 00141 compute (PointCloudOut &output); 00142 00143 /** \brief Search for k-nearest neighbors using the spatial locator from \a setSearchmethod, and the given surface 00144 * from \a setSearchSurface. 00145 * \param index the index of the query point 00146 * \param parameter the search parameter (either k or radius) 00147 * \param indices the resultant vector of indices representing the k-nearest neighbors 00148 * \param distances the resultant vector of distances representing the distances from the query point to the 00149 * k-nearest neighbors 00150 */ 00151 inline int 00152 searchForNeighbors (int index, double parameter, std::vector<int> &indices, std::vector<float> &distances) const 00153 { 00154 if (surface_ == input_) // if the two surfaces are the same 00155 return (search_method_ (index, parameter, indices, distances)); 00156 else 00157 return (search_method_surface_ (*input_, index, parameter, indices, distances)); 00158 } 00159 00160 protected: 00161 using PCLBase<PointInT>::deinitCompute; 00162 00163 virtual bool 00164 initCompute (); 00165 00166 /** \brief The key point detection method's name. */ 00167 std::string name_; 00168 00169 /** \brief The search method template for indices. */ 00170 SearchMethod search_method_; 00171 00172 /** \brief The search method template for points. */ 00173 SearchMethodSurface search_method_surface_; 00174 00175 /** \brief An input point cloud describing the surface that is to be used for nearest neighbors estimation. */ 00176 PointCloudInConstPtr surface_; 00177 00178 /** \brief A pointer to the spatial search object. */ 00179 KdTreePtr tree_; 00180 00181 /** \brief The actual search parameter (casted from either \a search_radius_ or \a k_). */ 00182 double search_parameter_; 00183 00184 /** \brief The nearest neighbors search radius for each point. */ 00185 double search_radius_; 00186 00187 /** \brief The number of K nearest neighbors to use for each point. */ 00188 int k_; 00189 00190 /** \brief Get a string representation of the name of this class. */ 00191 inline const std::string& 00192 getClassName () const { return (name_); } 00193 00194 /** \brief Abstract key point detection method. */ 00195 virtual void 00196 detectKeypoints (PointCloudOut &output) = 0; 00197 }; 00198 } 00199 00200 #include <pcl/keypoints/impl/keypoint.hpp> 00201 00202 #endif //#ifndef PCL_KEYPOINT_H_