Point Cloud Library (PCL) 1.15.1
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> void
60 const PointRepresentationConstPtr &point_representation)
61{
62 if(tree_)
63 tree_->setPointRepresentation (point_representation);
64 else
65 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");
66}
67
68///////////////////////////////////////////////////////////////////////////////////////////
69template <typename PointT, class Tree> void
71{
72 sorted_results_ = sorted_results;
73 tree_->setSortedResults (sorted_results);
74}
75
76///////////////////////////////////////////////////////////////////////////////////////////
77template <typename PointT, class Tree> void
79{
80 if(tree_)
81 tree_->setEpsilon (eps);
82 else
83 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");
84}
85
86///////////////////////////////////////////////////////////////////////////////////////////
87template <typename PointT, class Tree> bool
89 const PointCloudConstPtr& cloud,
90 const IndicesConstPtr& indices)
91{
92 tree_->setInputCloud (cloud, indices);
93 input_ = cloud;
94 indices_ = indices;
95 return true;
96}
97
98///////////////////////////////////////////////////////////////////////////////////////////
99template <typename PointT, class Tree> int
101 const PointT &point, int k, Indices &k_indices,
102 std::vector<float> &k_sqr_distances) const
103{
104 return (tree_->nearestKSearch (point, k, k_indices, k_sqr_distances));
105}
106
107///////////////////////////////////////////////////////////////////////////////////////////
108template <typename PointT, class Tree> int
110 const PointT& point, double radius,
111 Indices &k_indices, std::vector<float> &k_sqr_distances,
112 unsigned int max_nn) const
113{
114 return (tree_->radiusSearch (point, radius, k_indices, k_sqr_distances, max_nn));
115}
116
117#define PCL_INSTANTIATE_KdTree(T) template class PCL_EXPORTS pcl::search::KdTree<T>;
119#endif //#ifndef _PCL_SEARCH_KDTREE_IMPL_HPP_
120
121
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:100
void setEpsilon(float eps)
Set the search epsilon precision (error bound) for nearest neighbors searches.
Definition kdtree.hpp:78
void setSortedResults(bool sorted_results) override
Sets whether the results have to be sorted or not.
Definition kdtree.hpp:70
typename Search< SceneT >::PointCloudConstPtr PointCloudConstPtr
Definition kdtree.h:65
typename PointRepresentation< PointT >::ConstPtr PointRepresentationConstPtr
Definition kdtree.h:80
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:59
bool setInputCloud(const PointCloudConstPtr &cloud, const IndicesConstPtr &indices=IndicesConstPtr()) override
Provide a pointer to the input dataset.
Definition kdtree.hpp:88
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:109
KdTreePtr tree_
A pointer to the internal KdTree object.
Definition kdtree.h:167
PointCloudConstPtr input_
Definition search.h:402
IndicesConstPtr indices_
Definition search.h:403
Search(const std::string &name="", bool sorted=false)
Constructor.
Definition search.hpp:45
pcl::IndicesConstPtr IndicesConstPtr
Definition search.h:85
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition types.h:133