00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2010-2012, Willow Garage, Inc. 00006 * Copyright (c) 2012-, Open Perception, Inc. 00007 * 00008 * All rights reserved. 00009 * 00010 * Redistribution and use in source and binary forms, with or without 00011 * modification, are permitted provided that the following conditions 00012 * are met: 00013 * 00014 * * Redistributions of source code must retain the above copyright 00015 * notice, this list of conditions and the following disclaimer. 00016 * * Redistributions in binary form must reproduce the above 00017 * copyright notice, this list of conditions and the following 00018 * disclaimer in the documentation and/or other materials provided 00019 * with the distribution. 00020 * * Neither the name of the copyright holder(s) nor the names of its 00021 * contributors may be used to endorse or promote products derived 00022 * from this software without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00025 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00026 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00027 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00028 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00029 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00030 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00031 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00032 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00033 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00034 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00035 * POSSIBILITY OF SUCH DAMAGE. 00036 * 00037 * $Id: kdtree_flann.h 36261 2011-02-26 01:34:42Z mariusm $ 00038 * 00039 */ 00040 00041 #ifndef PCL_KDTREE_KDTREE_FLANN_H_ 00042 #define PCL_KDTREE_KDTREE_FLANN_H_ 00043 00044 #include <pcl/kdtree/kdtree.h> 00045 #include <pcl/kdtree/flann.h> 00046 00047 // Forward declarations 00048 namespace flann 00049 { 00050 struct SearchParams; 00051 template <typename T> struct L2_Simple; 00052 template <typename T> class Index; 00053 } 00054 00055 namespace pcl 00056 { 00057 // Forward declarations 00058 template <typename T> class PointRepresentation; 00059 00060 /** \brief KdTreeFLANN is a generic type of 3D spatial locator using kD-tree structures. The class is making use of 00061 * the FLANN (Fast Library for Approximate Nearest Neighbor) project by Marius Muja and David Lowe. 00062 * 00063 * \author Radu B. Rusu, Marius Muja 00064 * \ingroup kdtree 00065 */ 00066 template <typename PointT, typename Dist = ::flann::L2_Simple<float> > 00067 class KdTreeFLANN : public pcl::KdTree<PointT> 00068 { 00069 public: 00070 using KdTree<PointT>::input_; 00071 using KdTree<PointT>::indices_; 00072 using KdTree<PointT>::epsilon_; 00073 using KdTree<PointT>::sorted_; 00074 using KdTree<PointT>::point_representation_; 00075 using KdTree<PointT>::nearestKSearch; 00076 using KdTree<PointT>::radiusSearch; 00077 00078 typedef typename KdTree<PointT>::PointCloud PointCloud; 00079 typedef typename KdTree<PointT>::PointCloudConstPtr PointCloudConstPtr; 00080 00081 typedef boost::shared_ptr<std::vector<int> > IndicesPtr; 00082 typedef boost::shared_ptr<const std::vector<int> > IndicesConstPtr; 00083 00084 typedef ::flann::Index<Dist> FLANNIndex; 00085 00086 // Boost shared pointers 00087 typedef boost::shared_ptr<KdTreeFLANN<PointT> > Ptr; 00088 typedef boost::shared_ptr<const KdTreeFLANN<PointT> > ConstPtr; 00089 00090 /** \brief Default Constructor for KdTreeFLANN. 00091 * \param[in] sorted set to true if the application that the tree will be used for requires sorted nearest neighbor indices (default). False otherwise. 00092 * 00093 * By setting sorted to false, the \ref radiusSearch operations will be faster. 00094 */ 00095 KdTreeFLANN (bool sorted = true); 00096 00097 /** \brief Copy constructor 00098 * \param[in] tree the tree to copy into this 00099 */ 00100 KdTreeFLANN (const KdTreeFLANN<PointT> &k); 00101 00102 /** \brief Copy operator 00103 * \param[in] tree the tree to copy into this 00104 */ 00105 inline KdTreeFLANN<PointT>& 00106 operator = (const KdTreeFLANN<PointT>& k) 00107 { 00108 KdTree<PointT>::operator=(k); 00109 flann_index_ = k.flann_index_; 00110 cloud_ = k.cloud_; 00111 index_mapping_ = k.index_mapping_; 00112 identity_mapping_ = k.identity_mapping_; 00113 dim_ = k.dim_; 00114 total_nr_points_ = k.total_nr_points_; 00115 param_k_ = k.param_k_; 00116 param_radius_ = k.param_radius_; 00117 return (*this); 00118 } 00119 00120 /** \brief Set the search epsilon precision (error bound) for nearest neighbors searches. 00121 * \param[in] eps precision (error bound) for nearest neighbors searches 00122 */ 00123 void 00124 setEpsilon (float eps); 00125 00126 void 00127 setSortedResults (bool sorted); 00128 00129 inline Ptr makeShared () { return Ptr (new KdTreeFLANN<PointT> (*this)); } 00130 00131 /** \brief Destructor for KdTreeFLANN. 00132 * Deletes all allocated data arrays and destroys the kd-tree structures. 00133 */ 00134 virtual ~KdTreeFLANN () 00135 { 00136 cleanup (); 00137 } 00138 00139 /** \brief Provide a pointer to the input dataset. 00140 * \param[in] cloud the const boost shared pointer to a PointCloud message 00141 * \param[in] indices the point indices subset that is to be used from \a cloud - if NULL the whole cloud is used 00142 */ 00143 void 00144 setInputCloud (const PointCloudConstPtr &cloud, const IndicesConstPtr &indices = IndicesConstPtr ()); 00145 00146 /** \brief Search for k-nearest neighbors for the given query point. 00147 * 00148 * \attention This method does not do any bounds checking for the input index 00149 * (i.e., index >= cloud.points.size () || index < 0), and assumes valid (i.e., finite) data. 00150 * 00151 * \param[in] point a given \a valid (i.e., finite) query point 00152 * \param[in] k the number of neighbors to search for 00153 * \param[out] k_indices the resultant indices of the neighboring points (must be resized to \a k a priori!) 00154 * \param[out] k_sqr_distances the resultant squared distances to the neighboring points (must be resized to \a k 00155 * a priori!) 00156 * \return number of neighbors found 00157 * 00158 * \exception asserts in debug mode if the index is not between 0 and the maximum number of points 00159 */ 00160 int 00161 nearestKSearch (const PointT &point, int k, 00162 std::vector<int> &k_indices, std::vector<float> &k_sqr_distances) const; 00163 00164 /** \brief Search for all the nearest neighbors of the query point in a given radius. 00165 * 00166 * \attention This method does not do any bounds checking for the input index 00167 * (i.e., index >= cloud.points.size () || index < 0), and assumes valid (i.e., finite) data. 00168 * 00169 * \param[in] point a given \a valid (i.e., finite) query point 00170 * \param[in] radius the radius of the sphere bounding all of p_q's neighbors 00171 * \param[out] k_indices the resultant indices of the neighboring points 00172 * \param[out] k_sqr_distances the resultant squared distances to the neighboring points 00173 * \param[in] max_nn if given, bounds the maximum returned neighbors to this value. If \a max_nn is set to 00174 * 0 or to a number higher than the number of points in the input cloud, all neighbors in \a radius will be 00175 * returned. 00176 * \return number of neighbors found in radius 00177 * 00178 * \exception asserts in debug mode if the index is not between 0 and the maximum number of points 00179 */ 00180 int 00181 radiusSearch (const PointT &point, double radius, std::vector<int> &k_indices, 00182 std::vector<float> &k_sqr_distances, unsigned int max_nn = 0) const; 00183 00184 private: 00185 /** \brief Internal cleanup method. */ 00186 void 00187 cleanup (); 00188 00189 /** \brief Converts a PointCloud to the internal FLANN point array representation. Returns the number 00190 * of points. 00191 * \param cloud the PointCloud 00192 */ 00193 void 00194 convertCloudToArray (const PointCloud &cloud); 00195 00196 /** \brief Converts a PointCloud with a given set of indices to the internal FLANN point array 00197 * representation. Returns the number of points. 00198 * \param[in] cloud the PointCloud data 00199 * \param[in] indices the point cloud indices 00200 */ 00201 void 00202 convertCloudToArray (const PointCloud &cloud, const std::vector<int> &indices); 00203 00204 private: 00205 /** \brief Class getName method. */ 00206 virtual std::string 00207 getName () const { return ("KdTreeFLANN"); } 00208 00209 /** \brief A FLANN index object. */ 00210 boost::shared_ptr<FLANNIndex> flann_index_; 00211 00212 /** \brief Internal pointer to data. */ 00213 float* cloud_; 00214 00215 /** \brief mapping between internal and external indices. */ 00216 std::vector<int> index_mapping_; 00217 00218 /** \brief whether the mapping bwwteen internal and external indices is identity */ 00219 bool identity_mapping_; 00220 00221 /** \brief Tree dimensionality (i.e. the number of dimensions per point). */ 00222 int dim_; 00223 00224 /** \brief The total size of the data (either equal to the number of points in the input cloud or to the number of indices - if passed). */ 00225 int total_nr_points_; 00226 00227 /** \brief The KdTree search parameters for K-nearest neighbors. */ 00228 ::flann::SearchParams param_k_; 00229 00230 /** \brief The KdTree search parameters for radius search. */ 00231 ::flann::SearchParams param_radius_; 00232 }; 00233 } 00234 00235 #ifdef PCL_NO_PRECOMPILE 00236 #include <pcl/kdtree/impl/kdtree_flann.hpp> 00237 #endif 00238 00239 #endif
Except where otherwise noted, the PointClouds.org web pages are licensed under Creative Commons Attribution 3.0.
Pages generated on Wed Mar 25 00:24:30 2015