|
Point Cloud Library (PCL)
1.5.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 4502 2012-02-17 00:44:05Z gedikli $ 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 public: 00062 typedef typename Search<PointT>::PointCloud PointCloud; 00063 typedef typename Search<PointT>::PointCloudConstPtr PointCloudConstPtr; 00064 00065 typedef boost::shared_ptr<std::vector<int> > IndicesPtr; 00066 typedef boost::shared_ptr<const std::vector<int> > IndicesConstPtr; 00067 00068 using pcl::search::Search<PointT>::indices_; 00069 using pcl::search::Search<PointT>::input_; 00070 using pcl::search::Search<PointT>::getIndices; 00071 using pcl::search::Search<PointT>::getInputCloud; 00072 using pcl::search::Search<PointT>::nearestKSearch; 00073 using pcl::search::Search<PointT>::radiusSearch; 00074 using pcl::search::Search<PointT>::sorted_results_; 00075 00076 typedef boost::shared_ptr<KdTree<PointT> > Ptr; 00077 typedef boost::shared_ptr<const KdTree<PointT> > ConstPtr; 00078 00079 typedef boost::shared_ptr<pcl::KdTreeFLANN<PointT> > KdTreeFLANNPtr; 00080 typedef boost::shared_ptr<const pcl::KdTreeFLANN<PointT> > KdTreeFLANNConstPtr; 00081 00089 KdTree (bool sorted = true) : Search<PointT> ("KdTree", sorted) 00090 { 00091 tree_.reset (new pcl::KdTreeFLANN<PointT> (sorted)); 00092 } 00093 00095 virtual 00096 ~KdTree () 00097 { 00098 } 00099 00102 virtual void setSortedResults (bool sorted_results) 00103 { 00104 sorted_results_ = sorted_results; 00105 tree_->setSortedResults (sorted_results); 00106 } 00107 00111 inline void 00112 setEpsilon (double eps) 00113 { 00114 tree_->setEpsilon (eps); 00115 } 00116 00118 inline double 00119 getEpsilon () 00120 { 00121 return (tree_->getEpsilon ()); 00122 } 00123 00128 inline void 00129 setInputCloud (const PointCloudConstPtr& cloud, const IndicesConstPtr& indices = IndicesConstPtr ()) 00130 { 00131 // if same input and same indices or same input and empty indices do nothing 00132 if ((getInputCloud () == cloud && indices == getIndices ()) || 00133 (getInputCloud () == cloud && indices->empty () && getIndices ()->empty ())) 00134 return; 00135 tree_->setInputCloud (cloud, indices); 00136 input_ = cloud; 00137 indices_ = indices; 00138 } 00139 00148 inline int 00149 nearestKSearch (const PointT &point, int k, std::vector<int> &k_indices, std::vector<float> &k_sqr_distances) const 00150 { 00151 return (tree_->nearestKSearch (point, k, k_indices, k_sqr_distances)); 00152 } 00153 00164 inline int 00165 radiusSearch (const PointT& point, const double radius, 00166 std::vector<int> &k_indices, std::vector<float> &k_sqr_distances, 00167 unsigned int max_nn = 0) const 00168 { 00169 return (tree_->radiusSearch (point, radius, k_indices, k_sqr_distances, max_nn)); 00170 } 00171 00172 protected: 00174 KdTreeFLANNPtr tree_; 00175 }; 00176 } 00177 } 00178 00179 #define PCL_INSTANTIATE_KdTree(T) template class PCL_EXPORTS pcl::search::KdTree<T>; 00180 00181 #endif // PCL_SEARCH_KDTREE_H_ 00182
1.8.0