kdtree_flann.h
Go to the documentation of this file.
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 
00046 // Forward declarations
00047 namespace flann
00048 {
00049   struct SearchParams;
00050   template <typename T> struct L2_Simple;
00051   template <typename T> class Index;
00052 }
00053 
00054 namespace pcl
00055 {
00056   // Forward declarations
00057   template <typename T> class PointRepresentation;
00058 
00065   template <typename PointT, typename Dist = ::flann::L2_Simple<float> >
00066   class KdTreeFLANN : public pcl::KdTree<PointT>
00067   {
00068     public:
00069       using KdTree<PointT>::input_;
00070       using KdTree<PointT>::indices_;
00071       using KdTree<PointT>::epsilon_;
00072       using KdTree<PointT>::sorted_;
00073       using KdTree<PointT>::point_representation_;
00074       using KdTree<PointT>::nearestKSearch;
00075       using KdTree<PointT>::radiusSearch;
00076 
00077       typedef typename KdTree<PointT>::PointCloud PointCloud;
00078       typedef typename KdTree<PointT>::PointCloudConstPtr PointCloudConstPtr;
00079 
00080       typedef boost::shared_ptr<std::vector<int> > IndicesPtr;
00081       typedef boost::shared_ptr<const std::vector<int> > IndicesConstPtr;
00082 
00083       typedef ::flann::Index<Dist> FLANNIndex;
00084 
00085       // Boost shared pointers
00086       typedef boost::shared_ptr<KdTreeFLANN<PointT> > Ptr;
00087       typedef boost::shared_ptr<const KdTreeFLANN<PointT> > ConstPtr;
00088 
00094       KdTreeFLANN (bool sorted = true);
00095 
00099       KdTreeFLANN (const KdTreeFLANN<PointT> &k);
00100 
00104       inline KdTreeFLANN<PointT>&
00105       operator = (const KdTreeFLANN<PointT>& k)
00106       {
00107         KdTree<PointT>::operator=(k);
00108         flann_index_ = k.flann_index_;
00109         cloud_ = k.cloud_;
00110         index_mapping_ = k.index_mapping_;
00111         identity_mapping_ = k.identity_mapping_;
00112         dim_ = k.dim_;
00113         total_nr_points_ = k.total_nr_points_;
00114         param_k_ = k.param_k_;
00115         param_radius_ = k.param_radius_;
00116         return (*this);
00117       }
00118 
00122       void
00123       setEpsilon (float eps);
00124 
00125       void 
00126       setSortedResults (bool sorted);
00127       
00128       inline Ptr makeShared () { return Ptr (new KdTreeFLANN<PointT> (*this)); } 
00129 
00133       virtual ~KdTreeFLANN ()
00134       {
00135         cleanup ();
00136       }
00137 
00142       void 
00143       setInputCloud (const PointCloudConstPtr &cloud, const IndicesConstPtr &indices = IndicesConstPtr ());
00144 
00159       int 
00160       nearestKSearch (const PointT &point, int k, 
00161                       std::vector<int> &k_indices, std::vector<float> &k_sqr_distances) const;
00162 
00179       int 
00180       radiusSearch (const PointT &point, double radius, std::vector<int> &k_indices,
00181                     std::vector<float> &k_sqr_distances, unsigned int max_nn = 0) const;
00182 
00183     private:
00185       void 
00186       cleanup ();
00187 
00192       void 
00193       convertCloudToArray (const PointCloud &cloud);
00194 
00200       void 
00201       convertCloudToArray (const PointCloud &cloud, const std::vector<int> &indices);
00202 
00203     private:
00205       virtual std::string 
00206       getName () const { return ("KdTreeFLANN"); }
00207 
00209       boost::shared_ptr<FLANNIndex> flann_index_;
00210 
00212       float* cloud_;
00213       
00215       std::vector<int> index_mapping_;
00216       
00218       bool identity_mapping_;
00219 
00221       int dim_;
00222 
00224       int total_nr_points_;
00225 
00227       boost::shared_ptr<flann::SearchParams> param_k_;
00228 
00230       boost::shared_ptr<flann::SearchParams> param_radius_;
00231   };
00232 }
00233 
00234 #ifdef PCL_NO_PRECOMPILE
00235 #include <pcl/kdtree/impl/kdtree_flann.hpp>
00236 #endif
00237 
00238 #endif


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:25:05