Point Cloud Library (PCL)  1.8.1-dev
kdtree.hpp
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2012-, Open Perception, 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 the copyright holder(s) 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  */
37 
38 #ifndef PCL_SEARCH_KDTREE_IMPL_HPP_
39 #define PCL_SEARCH_KDTREE_IMPL_HPP_
40 
41 #include <pcl/search/kdtree.h>
42 #include <pcl/search/impl/search.hpp>
43 
44 ///////////////////////////////////////////////////////////////////////////////////////////
45 template <typename PointT, class Tree>
47  : pcl::search::Search<PointT> ("KdTree", sorted)
48  , tree_ (new Tree (sorted))
49 {
50 }
51 
52 ///////////////////////////////////////////////////////////////////////////////////////////
53 template <typename PointT, class Tree> void
55  const PointRepresentationConstPtr &point_representation)
56 {
57  tree_->setPointRepresentation (point_representation);
58 }
59 
60 ///////////////////////////////////////////////////////////////////////////////////////////
61 template <typename PointT, class Tree> void
63 {
64  sorted_results_ = sorted_results;
65  tree_->setSortedResults (sorted_results);
66 }
67 
68 ///////////////////////////////////////////////////////////////////////////////////////////
69 template <typename PointT, class Tree> void
71 {
72  tree_->setEpsilon (eps);
73 }
74 
75 ///////////////////////////////////////////////////////////////////////////////////////////
76 template <typename PointT, class Tree> void
78  const PointCloudConstPtr& cloud,
79  const IndicesConstPtr& indices)
80 {
81  tree_->setInputCloud (cloud, indices);
82  input_ = cloud;
83  indices_ = indices;
84 }
85 
86 ///////////////////////////////////////////////////////////////////////////////////////////
87 template <typename PointT, class Tree> int
89  const PointT &point, int k, std::vector<int> &k_indices,
90  std::vector<float> &k_sqr_distances) const
91 {
92  return (tree_->nearestKSearch (point, k, k_indices, k_sqr_distances));
93 }
94 
95 ///////////////////////////////////////////////////////////////////////////////////////////
96 template <typename PointT, class Tree> int
98  const PointT& point, double radius,
99  std::vector<int> &k_indices, std::vector<float> &k_sqr_distances,
100  unsigned int max_nn) const
101 {
102  return (tree_->radiusSearch (point, radius, k_indices, k_sqr_distances, max_nn));
103 }
104 
105 #define PCL_INSTANTIATE_KdTree(T) template class PCL_EXPORTS pcl::search::KdTree<T>;
106 
107 #endif //#ifndef _PCL_SEARCH_KDTREE_IMPL_HPP_
108 
109 
KdTree(bool sorted=true)
Constructor for KdTree.
Definition: kdtree.hpp:46
void setPointRepresentation(const PointRepresentationConstPtr &point_representation)
Provide a pointer to the point representation to use to convert points into k-D vectors.
Definition: kdtree.hpp:54
boost::shared_ptr< const std::vector< int > > IndicesConstPtr
Definition: kdtree.h:69
Search< PointT >::PointCloudConstPtr PointCloudConstPtr
Definition: kdtree.h:66
void setEpsilon(float eps)
Set the search epsilon precision (error bound) for nearest neighbors searches.
Definition: kdtree.hpp:70
void setInputCloud(const PointCloudConstPtr &cloud, const IndicesConstPtr &indices=IndicesConstPtr())
Provide a pointer to the input dataset.
Definition: kdtree.hpp:77
int radiusSearch(const PointT &point, double radius, std::vector< int > &k_indices, std::vector< float > &k_sqr_distances, unsigned int max_nn=0) const
Search for all the nearest neighbors of the query point in a given radius.
Definition: kdtree.hpp:97
void setSortedResults(bool sorted_results)
Sets whether the results have to be sorted or not.
Definition: kdtree.hpp:62
A point structure representing Euclidean xyz coordinates, and the RGB color.
int nearestKSearch(const PointT &point, int k, std::vector< int > &k_indices, std::vector< float > &k_sqr_distances) const
Search for the k-nearest neighbors for the given query point.
Definition: kdtree.hpp:88
boost::shared_ptr< const PointRepresentation< PointT > > PointRepresentationConstPtr
Definition: kdtree.h:84
Generic search class.
Definition: search.h:74