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: octree.h 3015 2011-11-01 02:47:42Z svn $ 00037 */ 00038 00039 #ifndef PCL_SEARCH_OCTREE_H 00040 #define PCL_SEARCH_OCTREE_H 00041 00042 #include <pcl/search/search.h> 00043 #include <pcl/octree/octree_search.h> 00044 00045 namespace pcl 00046 { 00047 namespace search 00048 { 00065 template<typename PointT, typename LeafTWrap = pcl::octree::OctreeLeafDataTVector<int>, 00066 typename OctreeT = pcl::octree::OctreeBase<int, LeafTWrap> > 00067 class Octree: public Search<PointT> 00068 { 00069 public: 00070 // public typedefs 00071 typedef boost::shared_ptr<std::vector<int> > IndicesPtr; 00072 typedef boost::shared_ptr<const std::vector<int> > IndicesConstPtr; 00073 00074 typedef pcl::PointCloud<PointT> PointCloud; 00075 typedef boost::shared_ptr<PointCloud> PointCloudPtr; 00076 typedef boost::shared_ptr<const PointCloud> PointCloudConstPtr; 00077 00078 // Boost shared pointers 00079 typedef boost::shared_ptr<pcl::octree::OctreePointCloudSearch<PointT, LeafTWrap, OctreeT> > Ptr; 00080 typedef boost::shared_ptr<const pcl::octree::OctreePointCloudSearch<PointT, LeafTWrap, OctreeT> > ConstPtr; 00081 Ptr tree_; 00082 00086 Octree (const double resolution) 00087 { 00088 tree_.reset (new pcl::octree::OctreePointCloudSearch<PointT, LeafTWrap, OctreeT> (resolution)); 00089 } 00090 00092 virtual 00093 ~Octree () 00094 { 00095 } 00096 00100 inline void 00101 setInputCloud (const PointCloudConstPtr &cloud) 00102 { 00103 tree_->deleteTree (); 00104 tree_->setInputCloud (cloud); 00105 tree_->addPointsFromInputCloud (); 00106 } 00107 00112 inline void 00113 setInputCloud (const PointCloudConstPtr &cloud, const IndicesConstPtr& indices) 00114 { 00115 tree_->deleteTree (); 00116 tree_->setInputCloud (cloud, indices); 00117 tree_->addPointsFromInputCloud (); 00118 } 00119 00121 PointCloudConstPtr 00122 getInputCloud () 00123 { 00124 return (tree_->getInputCloud ()); 00125 } 00126 00128 IndicesConstPtr const 00129 getIndices () 00130 { 00131 return (tree_->getIndices ()); 00132 } 00133 00143 inline int 00144 nearestKSearch (const PointCloud &cloud, int index, int k, std::vector<int> &k_indices, 00145 std::vector<float> &k_sqr_distances) 00146 { 00147 return (tree_->nearestKSearch (cloud, index, k, k_indices, k_sqr_distances)); 00148 } 00149 00158 inline int 00159 nearestKSearch (const PointT &p, int k, std::vector<int> &k_indices, 00160 std::vector<float> &k_sqr_distances) 00161 { 00162 return (tree_->nearestKSearch (p, k, k_indices, k_sqr_distances)); 00163 } 00164 00176 inline int 00177 nearestKSearch (int index, int k, std::vector<int> &k_indices, std::vector<float> &k_sqr_distances) 00178 { 00179 return (tree_->nearestKSearch (index, k, k_indices, k_sqr_distances)); 00180 } 00181 00191 inline int 00192 radiusSearch (const PointCloud &cloud, int index, double radius, 00193 std::vector<int> &k_indices, std::vector<float> &k_sqr_distances, int max_nn = INT_MAX) 00194 { 00195 return (tree_->radiusSearch (cloud, index, radius, k_indices, k_sqr_distances, max_nn)); 00196 } 00197 00206 inline int 00207 radiusSearch (const PointT &p_q, const double radius, std::vector<int> &k_indices, 00208 std::vector<float> &k_sqr_distances, int max_nn = INT_MAX) const 00209 { 00210 return (tree_->radiusSearch (p_q, radius, k_indices, k_sqr_distances, max_nn)); 00211 } 00212 00222 inline int 00223 radiusSearch (int index, const double radius, std::vector<int> &k_indices, 00224 std::vector<float> &k_sqr_distances, int max_nn = INT_MAX) const 00225 { 00226 return (tree_->radiusSearch (index, radius, k_indices, k_sqr_distances, max_nn)); 00227 } 00228 00229 00237 inline void 00238 approxNearestSearch (const PointCloudConstPtr &cloud, int query_index, int &result_index, 00239 float &sqr_distance) 00240 { 00241 return (tree_->approxNearestSearch (query_index, result_index, sqr_distance)); 00242 } 00243 00249 inline void 00250 approxNearestSearch (const PointT &p_q, int &result_index, float &sqr_distance) 00251 { 00252 return (tree_->approxNearestSearch (p_q, result_index, sqr_distance)); 00253 } 00254 00262 inline void 00263 approxNearestSearch (int query_index, int &result_index, float &sqr_distance) 00264 { 00265 return (tree_->approxNearestSearch (query_index, result_index, sqr_distance)); 00266 } 00267 00268 }; 00269 } 00270 } 00271 00272 #define PCL_INSTANTIATE_Octree(T) template class PCL_EXPORTS pcl::search::Octree<T, pcl::octree::OctreeLeafDataTVector<int>, pcl::octree::OctreeBase<int, pcl::octree::OctreeLeafDataTVector<int> > >; 00273 00274 #endif // PCL_SEARCH_OCTREE_H