Point Cloud Library (PCL)
1.3.1
|
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 * $Id: kdtree.h 3015 2011-11-01 02:47:42Z svn $ 00037 */ 00038 00039 #ifndef PCL_SEARCH_KDTREE_H_ 00040 #define PCL_SEARCH_KDTREE_H_ 00041 00042 #include <pcl/search/search.h> 00043 #include <pcl/kdtree/kdtree.h> 00044 #include <pcl/kdtree/kdtree_flann.h> 00045 00046 namespace pcl 00047 { 00048 namespace search 00049 { 00058 template<typename PointT> 00059 class KdTree: public Search<PointT> 00060 { 00061 typedef typename Search<PointT>::PointCloud PointCloud; 00062 typedef typename Search<PointT>::PointCloudConstPtr PointCloudConstPtr; 00063 00064 typedef boost::shared_ptr<std::vector<int> > IndicesPtr; 00065 typedef boost::shared_ptr<const std::vector<int> > IndicesConstPtr; 00066 00067 public: 00068 typedef boost::shared_ptr<KdTree<PointT> > Ptr; 00069 typedef boost::shared_ptr<const KdTree<PointT> > ConstPtr; 00070 00071 typedef boost::shared_ptr<pcl::KdTreeFLANN<PointT> > KdTreeFLANNPtr; 00072 typedef boost::shared_ptr<const pcl::KdTreeFLANN<PointT> > KdTreeFLANNConstPtr; 00073 00081 KdTree (bool sorted = true) 00082 { 00083 tree_.reset (new pcl::KdTreeFLANN<PointT> (sorted)); 00084 } 00085 00087 virtual 00088 ~KdTree () 00089 { 00090 } 00091 00095 inline void 00096 setEpsilon (double eps) 00097 { 00098 tree_->setEpsilon (eps); 00099 } 00100 00102 inline double 00103 getEpsilon () 00104 { 00105 return (tree_->getEpsilon ()); 00106 } 00107 00112 inline void 00113 setInputCloud (const PointCloudConstPtr& cloud, const IndicesConstPtr& indices) 00114 { 00115 tree_->setInputCloud (cloud, indices); 00116 } 00117 00121 inline void 00122 setInputCloud (const PointCloudConstPtr& cloud) 00123 { 00124 const IndicesConstPtr& indices = IndicesConstPtr (); 00125 setInputCloud (cloud, indices); 00126 } 00127 00129 PointCloudConstPtr 00130 getInputCloud () 00131 { 00132 return (tree_->getInputCloud ()); 00133 } 00134 00136 virtual IndicesConstPtr const 00137 getIndices () 00138 { 00139 return (tree_->getIndices ()); 00140 } 00141 00150 int 00151 nearestKSearch (const PointT &point, int k, std::vector<int> &k_indices, std::vector<float> &k_distances) 00152 { 00153 return (tree_->nearestKSearch (point, k, k_indices, k_distances)); 00154 } 00155 00165 inline int 00166 nearestKSearch (const PointCloud &cloud, int index, int k, std::vector<int> &k_indices, 00167 std::vector<float> &k_distances) 00168 { 00169 return (tree_->nearestKSearch (cloud, index, k, k_indices, k_distances)); 00170 } 00171 00183 inline int 00184 nearestKSearch (int index, int k, std::vector<int> &k_indices, std::vector<float> &k_distances) 00185 { 00186 return (tree_->nearestKSearch (index, k, k_indices, k_distances)); 00187 } 00188 00197 int 00198 radiusSearch (const PointT& point, double radius, 00199 std::vector<int> &k_indices, std::vector<float> &k_sqr_distances, 00200 int max_nn = -1) const 00201 { 00202 return (tree_->radiusSearch (point, radius, k_indices, k_sqr_distances, max_nn)); 00203 } 00204 00214 inline int 00215 radiusSearch (const PointCloud& cloud, int index, double radius, std::vector<int> &k_indices, 00216 std::vector<float> &k_distances, int max_nn = -1) 00217 { 00218 return (tree_->radiusSearch (cloud, index, radius, k_indices, k_distances, max_nn)); 00219 } 00220 00230 inline int 00231 radiusSearch (int index, double radius, std::vector<int> &k_indices, std::vector<float> &k_distances, 00232 int max_nn = -1) const 00233 { 00234 return (tree_->radiusSearch (index, radius, k_indices, k_distances, max_nn)); 00235 } 00236 00237 protected: 00239 KdTreeFLANNPtr tree_; 00240 }; 00241 } 00242 } 00243 00244 #define PCL_INSTANTIATE_KdTree(T) template class PCL_EXPORTS pcl::search::KdTree<T>; 00245 00246 #endif // PCL_SEARCH_KDTREE_H_ 00247