Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
kdtree.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $Id: kdtree.h 4826 2012-02-28 21:33:11Z bouffa $
37  */
38 
39 #ifndef PCL_SEARCH_KDTREE_H_
40 #define PCL_SEARCH_KDTREE_H_
41 
42 #include <pcl/search/search.h>
43 #include <pcl/kdtree/kdtree.h>
45 
46 namespace pcl
47 {
48  namespace search
49  {
58  template<typename PointT>
59  class KdTree: public Search<PointT>
60  {
61  public:
64 
65  typedef boost::shared_ptr<std::vector<int> > IndicesPtr;
66  typedef boost::shared_ptr<const std::vector<int> > IndicesConstPtr;
67 
75 
76  typedef boost::shared_ptr<KdTree<PointT> > Ptr;
77  typedef boost::shared_ptr<const KdTree<PointT> > ConstPtr;
78 
79  typedef boost::shared_ptr<pcl::KdTreeFLANN<PointT> > KdTreeFLANNPtr;
80  typedef boost::shared_ptr<const pcl::KdTreeFLANN<PointT> > KdTreeFLANNConstPtr;
81 
89  KdTree (bool sorted = true)
90  : Search<PointT> ("KdTree", sorted)
91  , tree_ (new pcl::KdTreeFLANN<PointT> (sorted))
92  {
93  }
94 
96  virtual
98  {
99  }
100 
104  virtual void
105  setSortedResults (bool sorted_results)
106  {
107  sorted_results_ = sorted_results;
108  tree_->setSortedResults (sorted_results);
109  }
110 
114  inline void
115  setEpsilon (float eps)
116  {
117  tree_->setEpsilon (eps);
118  }
119 
121  inline float
122  getEpsilon () const
123  {
124  return (tree_->getEpsilon ());
125  }
126 
131  inline void
133  {
134  tree_->setInputCloud (cloud, indices);
135  input_ = cloud;
136  indices_ = indices;
137  }
138 
147  inline int
148  nearestKSearch (const PointT &point, int k, std::vector<int> &k_indices, std::vector<float> &k_sqr_distances) const
149  {
150  return (tree_->nearestKSearch (point, k, k_indices, k_sqr_distances));
151  }
152 
163  inline int
164  radiusSearch (const PointT& point, double radius,
165  std::vector<int> &k_indices, std::vector<float> &k_sqr_distances,
166  unsigned int max_nn = 0) const
167  {
168  return (tree_->radiusSearch (point, radius, k_indices, k_sqr_distances, max_nn));
169  }
170 
171  protected:
173  KdTreeFLANNPtr tree_;
174  };
175  }
176 }
177 
178 #define PCL_INSTANTIATE_KdTree(T) template class PCL_EXPORTS pcl::search::KdTree<T>;
179 
180 #endif // PCL_SEARCH_KDTREE_H_
181