Point Cloud Library (PCL) 1.15.1-dev
Loading...
Searching...
No Matches
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
43///////////////////////////////////////////////////////////////////////////////////////////
44template <typename PointT, class Tree>
46 : pcl::search::Search<PointT> ("KdTree", sorted)
47 , tree_ (new Tree (sorted))
48{
49}
50
51template <typename PointT, class Tree>
52pcl::search::KdTree<PointT,Tree>::KdTree (const std::string& name, bool sorted)
53 : pcl::search::Search<PointT> (name, sorted)
54{
55}
56
57///////////////////////////////////////////////////////////////////////////////////////////
58template <typename PointT, class Tree> bool
60 const PointRepresentationConstPtr &point_representation)
61{
62 if(tree_) {
63 tree_->setPointRepresentation (point_representation);
64 return true;
65 } else {
66 PCL_ERROR("Calling setPointRepresentation on KdTreeNanoflann that has been cast to KdTree is not possible in this PCL version. Call setPointRepresentation directly on the KdTreeNanoflann object.\n");
67 return false;
68 }
69}
70
71///////////////////////////////////////////////////////////////////////////////////////////
72template <typename PointT, class Tree> void
74{
75 sorted_results_ = sorted_results;
76 tree_->setSortedResults (sorted_results);
77}
78
79///////////////////////////////////////////////////////////////////////////////////////////
80template <typename PointT, class Tree> void
82{
83 if(tree_)
84 tree_->setEpsilon (eps);
85 else
86 PCL_ERROR("Calling setEpsilon on KdTreeNanoflann that has been cast to KdTree is not possible in this PCL version. Call setEpsilon directly on the KdTreeNanoflann object.\n");
87}
88
89///////////////////////////////////////////////////////////////////////////////////////////
90template <typename PointT, class Tree> bool
92 const PointCloudConstPtr& cloud,
93 const IndicesConstPtr& indices)
94{
95 tree_->setInputCloud (cloud, indices);
96 input_ = cloud;
97 indices_ = indices;
98 return true;
99}
100
101///////////////////////////////////////////////////////////////////////////////////////////
102template <typename PointT, class Tree> int
104 const PointT &point, int k, Indices &k_indices,
105 std::vector<float> &k_sqr_distances) const
106{
107 return (tree_->nearestKSearch (point, k, k_indices, k_sqr_distances));
108}
109
110///////////////////////////////////////////////////////////////////////////////////////////
111template <typename PointT, class Tree> int
113 const PointT& point, double radius,
114 Indices &k_indices, std::vector<float> &k_sqr_distances,
115 unsigned int max_nn) const
116{
117 return (tree_->radiusSearch (point, radius, k_indices, k_sqr_distances, max_nn));
118}
119
120#define PCL_INSTANTIATE_KdTree(T) template class PCL_EXPORTS pcl::search::KdTree<T>;
121
122#endif //#ifndef _PCL_SEARCH_KDTREE_IMPL_HPP_
123
124
int nearestKSearch(const PointT &point, int k, Indices &k_indices, std::vector< float > &k_sqr_distances) const override
Search for the k-nearest neighbors for the given query point.
Definition kdtree.hpp:103
virtual void setEpsilon(float eps)
Set the search epsilon precision (error bound) for nearest neighbors searches.
Definition kdtree.hpp:81
bool setPointRepresentation(const PointRepresentationConstPtr &point_representation) override
Provide a pointer to the point representation to use to convert points into k-D vectors.
Definition kdtree.hpp:59
void setSortedResults(bool sorted_results) override
Sets whether the results have to be sorted or not.
Definition kdtree.hpp:73
typename Search< PointT >::PointCloudConstPtr PointCloudConstPtr
Definition kdtree.h:65
typename PointRepresentation< PointT >::ConstPtr PointRepresentationConstPtr
Definition kdtree.h:80
bool setInputCloud(const PointCloudConstPtr &cloud, const IndicesConstPtr &indices=IndicesConstPtr()) override
Provide a pointer to the input dataset.
Definition kdtree.hpp:91
KdTree(bool sorted=true)
Constructor for KdTree.
Definition kdtree.hpp:45
int radiusSearch(const PointT &point, double radius, Indices &k_indices, std::vector< float > &k_sqr_distances, unsigned int max_nn=0) const override
Search for all the nearest neighbors of the query point in a given radius.
Definition kdtree.hpp:112
Generic search class.
Definition search.h:78
pcl::IndicesConstPtr IndicesConstPtr
Definition search.h:88
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition types.h:133
A point structure representing Euclidean xyz coordinates, and the RGB color.