Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
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
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
00133
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_);
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