flann_search.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-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: flann_search.h 5170 2012-03-18 04:21:56Z rusu $
00037  */
00038 
00039 #ifndef PCL_SEARCH_FLANN_SEARCH_H_
00040 #define PCL_SEARCH_FLANN_SEARCH_H_
00041 
00042 #include <pcl/search/search.h>
00043 #include <pcl/common/time.h>
00044 #include <pcl/point_representation.h>
00045 
00046 namespace flann
00047 {
00048   template<typename T> class NNIndex;
00049   template<typename T> class L2;
00050   template<typename T> class L2_Simple;
00051   template<typename T> class Matrix;
00052 }
00053 
00054 namespace pcl
00055 {
00056   namespace search
00057   {
00058 
00066     template<typename PointT, typename FlannDistance=flann::L2_Simple <float> >
00067     class FlannSearch: public Search<PointT>
00068     {
00069       typedef typename Search<PointT>::PointCloud PointCloud;
00070       typedef typename Search<PointT>::PointCloudConstPtr PointCloudConstPtr;
00071 
00072       typedef boost::shared_ptr<std::vector<int> > IndicesPtr;
00073       typedef boost::shared_ptr<const std::vector<int> > IndicesConstPtr;
00074       typedef flann::NNIndex< FlannDistance > Index;
00075       typedef boost::shared_ptr<flann::NNIndex <FlannDistance > > IndexPtr;
00076       typedef boost::shared_ptr<flann::Matrix <float> > MatrixPtr;
00077       typedef boost::shared_ptr<const flann::Matrix <float> > MatrixConstPtr;
00078 
00079       typedef pcl::PointRepresentation<PointT> PointRepresentation;
00080       //typedef boost::shared_ptr<PointRepresentation> PointRepresentationPtr;
00081       typedef boost::shared_ptr<const PointRepresentation> PointRepresentationConstPtr;
00082 
00083       using Search<PointT>::input_;
00084       using Search<PointT>::indices_;
00085       using Search<PointT>::sorted_results_;
00086 
00087       public:
00088         typedef boost::shared_ptr<FlannSearch<PointT> > Ptr;
00089         typedef boost::shared_ptr<const FlannSearch<PointT> > ConstPtr;
00090 
00096         class FlannIndexCreator
00097         {
00098           public:
00103             virtual IndexPtr createIndex (MatrixConstPtr data)=0;
00104         };
00105 
00108         class KdTreeIndexCreator: public FlannIndexCreator
00109         {
00110           public:
00115             KdTreeIndexCreator (unsigned int max_leaf_size=15) : max_leaf_size_ (max_leaf_size){}
00120             virtual IndexPtr createIndex (MatrixConstPtr data);
00121           private:
00122             unsigned int max_leaf_size_;
00123         };
00124 
00125         FlannSearch (bool sorted = true, FlannIndexCreator* creator = new KdTreeIndexCreator());
00126 
00128         virtual
00129         ~FlannSearch ();
00130 
00131 
00132         //void
00133         //setInputCloud (const PointCloudConstPtr &cloud, const IndicesConstPtr &indices = IndicesConstPtr ());
00134 
00138         inline void
00139         setEpsilon (double eps)
00140         {
00141           eps_ = eps;
00142         }
00143 
00145         inline double
00146         getEpsilon ()
00147         {
00148           return (eps_);
00149         }
00150 
00155         inline virtual void
00156         setInputCloud (const PointCloudConstPtr& cloud, const IndicesConstPtr& indices = IndicesConstPtr ());
00157 
00166         int
00167         nearestKSearch (const PointT &point, int k, std::vector<int> &k_indices, std::vector<float> &k_sqr_distances) const;
00168 
00169 
00177         virtual void
00178         nearestKSearch (const PointCloud& cloud, const std::vector<int>& indices, int k, 
00179                         std::vector< std::vector<int> >& k_indices, std::vector< std::vector<float> >& k_sqr_distances) const;
00180 
00191         int
00192         radiusSearch (const PointT& point, double radius, 
00193                       std::vector<int> &k_indices, std::vector<float> &k_sqr_distances,
00194                       unsigned int max_nn = 0) const;
00195 
00204         virtual void
00205         radiusSearch (const PointCloud& cloud, const std::vector<int>& indices, double radius, std::vector< std::vector<int> >& k_indices,
00206                 std::vector< std::vector<float> >& k_sqr_distances, unsigned int max_nn=0) const;
00207 
00211         inline void
00212         setPointRepresentation (const PointRepresentationConstPtr &point_representation)
00213         {
00214           point_representation_ = point_representation;
00215           setInputCloud (input_, indices_);  // re-create the tree, since point_represenation might change things such as the scaling of the point clouds.
00216         }
00217 
00219         inline PointRepresentationConstPtr const
00220         getPointRepresentation ()
00221         {
00222           return (point_representation_);
00223         }
00224 
00225       protected:
00226 
00229         void convertInputToFlannMatrix();
00230 
00233         IndexPtr index_;
00234 
00237         FlannIndexCreator *creator_;
00238 
00241         MatrixPtr input_flann_;
00242 
00245         float eps_;
00246         bool input_copied_for_flann_;
00247 
00248         PointRepresentationConstPtr point_representation_;
00249 
00250         int dim_;
00251 
00252         std::vector<int> index_mapping_;
00253         bool identity_mapping_;
00254 
00255     };
00256   }
00257 }
00258 
00259 #define PCL_INSTANTIATE_FlannSearch(T) template class PCL_EXPORTS pcl::search::FlannSearch<T>;
00260 
00261 #endif    // PCL_SEARCH_KDTREE_H_
00262 


pcl
Author(s): Open Perception
autogenerated on Mon Oct 6 2014 03:15:11