|
Point Cloud Library (PCL)
1.4.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 * $Id: search.h 3536 2011-12-14 22:24:39Z rusu $ 00037 * 00038 */ 00039 00040 #ifndef PCL_SEARCH_SEARCH_H_ 00041 #define PCL_SEARCH_SEARCH_H_ 00042 00043 #include <pcl/point_cloud.h> 00044 #include <pcl/common/io.h> 00045 00046 namespace pcl 00047 { 00048 namespace search 00049 { 00071 template<typename PointT> 00072 class Search 00073 { 00074 public: 00075 typedef pcl::PointCloud<PointT> PointCloud; 00076 typedef typename PointCloud::Ptr PointCloudPtr; 00077 typedef typename PointCloud::ConstPtr PointCloudConstPtr; 00078 00079 typedef boost::shared_ptr<pcl::search::Search<PointT> > Ptr; 00080 typedef boost::shared_ptr<const pcl::search::Search<PointT> > ConstPtr; 00081 00082 typedef boost::shared_ptr<std::vector<int> > IndicesPtr; 00083 typedef boost::shared_ptr<const std::vector<int> > IndicesConstPtr; 00084 00086 Search () 00087 { 00088 } 00089 00091 virtual 00092 ~Search () 00093 { 00094 } 00095 00100 virtual void 00101 setInputCloud (const PointCloudConstPtr& cloud, const IndicesConstPtr& indices) {} 00102 00106 virtual void 00107 setInputCloud (const PointCloudConstPtr& cloud) = 0; 00108 00110 virtual PointCloudConstPtr 00111 getInputCloud () = 0; 00112 00114 virtual IndicesConstPtr const 00115 getIndices () { return (IndicesConstPtr ()); } 00116 00125 virtual int 00126 nearestKSearch (const PointT &point, int k, std::vector<int> &k_indices, 00127 std::vector<float> &k_sqr_distances) = 0; 00128 00137 template <typename PointTDiff> int 00138 nearestKSearchT (const PointTDiff &point, int k, std::vector<int> &k_indices, 00139 std::vector<float> &k_sqr_distances) 00140 { 00141 PointT p; 00142 // Copy all the data fields from the input cloud to the output one 00143 typedef typename pcl::traits::fieldList<PointT>::type FieldListInT; 00144 typedef typename pcl::traits::fieldList<PointTDiff>::type FieldListOutT; 00145 typedef typename pcl::intersect<FieldListInT, FieldListOutT>::type FieldList; 00146 pcl::for_each_type <FieldList> (pcl::NdConcatenateFunctor <PointTDiff, PointT> ( 00147 point, p)); 00148 return (nearestKSearch (p, k, k_indices, k_sqr_distances)); 00149 } 00150 00160 virtual int 00161 nearestKSearch (const PointCloud& cloud, int index, int k, std::vector<int>& k_indices, 00162 std::vector<float>& k_sqr_distances) = 0; 00163 00173 virtual int 00174 nearestKSearch (int index, int k, std::vector<int>& k_indices, std::vector<float>& k_sqr_distances) = 0; 00175 00183 virtual void 00184 nearestKSearch (const PointCloud& cloud, const std::vector<int>& indices, int k, std::vector< std::vector<int> >& k_indices, 00185 std::vector< std::vector<float> >& k_sqr_distances) 00186 { 00187 if (indices.empty ()) 00188 { 00189 k_indices.resize (cloud.size ()); 00190 k_sqr_distances.resize (cloud.size ()); 00191 for (size_t i = 0; i < cloud.size (); i++) 00192 nearestKSearch (cloud,(int) i,k,k_indices[i],k_sqr_distances[i]); 00193 } 00194 else 00195 { 00196 k_indices.resize (indices.size ()); 00197 k_sqr_distances.resize (indices.size ()); 00198 for (size_t i = 0; i < indices.size (); i++) 00199 nearestKSearch (cloud,indices[i],k,k_indices[i],k_sqr_distances[i]); 00200 } 00201 } 00202 00211 template <typename PointTDiff> void 00212 nearestKSearchT (const pcl::PointCloud<PointTDiff> &cloud, const std::vector<int>& indices, int k, std::vector< std::vector<int> > &k_indices, 00213 std::vector< std::vector<float> > &k_sqr_distances) 00214 { 00215 // Copy all the data fields from the input cloud to the output one 00216 typedef typename pcl::traits::fieldList<PointT>::type FieldListInT; 00217 typedef typename pcl::traits::fieldList<PointTDiff>::type FieldListOutT; 00218 typedef typename pcl::intersect<FieldListInT, FieldListOutT>::type FieldList; 00219 00220 pcl::PointCloud<PointT> pc; 00221 if (indices.empty ()) 00222 { 00223 pc.resize (cloud.size()); 00224 for (size_t i = 0; i < cloud.size(); i++) 00225 { 00226 pcl::for_each_type <FieldList> (pcl::NdConcatenateFunctor <PointTDiff, PointT> ( 00227 cloud[i], pc[i])); 00228 } 00229 nearestKSearch (pc,std::vector<int>(),k,k_indices,k_sqr_distances); 00230 } 00231 else 00232 { 00233 pc.resize (indices.size()); 00234 for (size_t i = 0; i < indices.size(); i++) 00235 { 00236 pcl::for_each_type <FieldList> (pcl::NdConcatenateFunctor <PointTDiff, PointT> ( 00237 cloud[indices[i]], pc[i])); 00238 } 00239 nearestKSearch (pc,std::vector<int>(),k,k_indices,k_sqr_distances); 00240 } 00241 } 00242 00251 virtual int 00252 radiusSearch (const PointT& point, double radius, std::vector<int>& k_indices, 00253 std::vector<float>& k_sqr_distances, int max_nn = -1) const = 0; 00254 00263 template <typename PointTDiff> int 00264 radiusSearchT (const PointTDiff& point, double radius, std::vector<int>& k_indices, 00265 std::vector<float>& k_sqr_distances, int max_nn = -1) 00266 { 00267 PointT p; 00268 // Copy all the data fields from the input cloud to the output one 00269 typedef typename pcl::traits::fieldList<PointT>::type FieldListInT; 00270 typedef typename pcl::traits::fieldList<PointTDiff>::type FieldListOutT; 00271 typedef typename pcl::intersect<FieldListInT, FieldListOutT>::type FieldList; 00272 pcl::for_each_type <FieldList> (pcl::NdConcatenateFunctor <PointTDiff, PointT> ( 00273 point, p)); 00274 return (radiusSearch (p, radius, k_indices, k_sqr_distances, max_nn)); 00275 } 00276 00286 virtual int 00287 radiusSearch (const PointCloud& cloud, int index, double radius, std::vector<int>& k_indices, 00288 std::vector<float>& k_sqr_distances, int max_nn = -1) = 0; 00289 00299 virtual int 00300 radiusSearch (int index, double radius, std::vector<int>& k_indices, std::vector<float>& k_sqr_distances, 00301 int max_nn = -1) const = 0; 00302 00311 virtual void 00312 radiusSearch (const PointCloud& cloud, const std::vector<int>& indices, double radius, std::vector< std::vector<int> >& k_indices, 00313 std::vector< std::vector<float> > & k_sqr_distances, int max_nn = -1) 00314 { 00315 if (indices.empty ()) 00316 { 00317 k_indices.resize (cloud.size ()); 00318 k_sqr_distances.resize (cloud.size ()); 00319 for (size_t i = 0; i < cloud.size (); i++) 00320 radiusSearch (cloud,(int) i,radius,k_indices[i],k_sqr_distances[i], max_nn); 00321 } 00322 else 00323 { 00324 k_indices.resize (indices.size ()); 00325 k_sqr_distances.resize (indices.size ()); 00326 for (size_t i = 0; i < indices.size (); i++) 00327 radiusSearch (cloud,indices[i],radius,k_indices[i],k_sqr_distances[i], max_nn); 00328 } 00329 } 00330 00331 00341 template <typename PointTDiff> void 00342 radiusSearchT (const pcl::PointCloud<PointTDiff> &cloud, const std::vector<int>& indices, double radius, std::vector< std::vector<int> > &k_indices, 00343 std::vector< std::vector<float> > & k_sqr_distances, int max_nn = -1) 00344 { 00345 // Copy all the data fields from the input cloud to the output one 00346 typedef typename pcl::traits::fieldList<PointT>::type FieldListInT; 00347 typedef typename pcl::traits::fieldList<PointTDiff>::type FieldListOutT; 00348 typedef typename pcl::intersect<FieldListInT, FieldListOutT>::type FieldList; 00349 00350 pcl::PointCloud<PointT> pc; 00351 if (indices.empty ()) 00352 { 00353 pc.resize (cloud.size ()); 00354 for (size_t i = 0; i < cloud.size (); ++i) 00355 pcl::for_each_type <FieldList> (pcl::NdConcatenateFunctor <PointTDiff, PointT> (cloud[i], pc[i])); 00356 radiusSearch (pc, std::vector<int> (), radius, k_indices, k_sqr_distances, max_nn); 00357 } 00358 else 00359 { 00360 pc.resize (indices.size ()); 00361 for (size_t i = 0; i < indices.size (); ++i) 00362 pcl::for_each_type <FieldList> (pcl::NdConcatenateFunctor <PointTDiff, PointT> (cloud[indices[i]], pc[i])); 00363 radiusSearch (pc, std::vector<int>(), radius, k_indices, k_sqr_distances, max_nn); 00364 } 00365 } 00366 }; 00367 } 00368 } 00369 00370 #endif //#ifndef _PCL_SEARCH_GENERIC_SEARCH_H_
1.7.6.1