Point Cloud Library (PCL) 1.15.1-dev
Loading...
Searching...
No Matches
brute_force.h
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 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#pragma once
39
40#include <pcl/point_representation.h>
41#include <pcl/search/search.h>
42
43namespace pcl
44{
45 namespace search
46 {
47 /** \brief Implementation of a simple brute force search algorithm.
48 * \author Suat Gedikli
49 * \ingroup search
50 */
51 template<typename PointT>
52 class BruteForce: public Search<PointT>
53 {
54 using PointCloud = typename Search<PointT>::PointCloud;
55 using PointCloudConstPtr = typename Search<PointT>::PointCloudConstPtr;
56 using PointRepresentationConstPtr = typename PointRepresentation<PointT>::ConstPtr;
57
58 using IndicesPtr = pcl::IndicesPtr;
59 using IndicesConstPtr = pcl::IndicesConstPtr;
60
64
65 struct Entry
66 {
67 Entry (index_t idx, float dist) : index (idx), distance (dist) {}
68
69 Entry () : index (0), distance (0) {}
70 index_t index;
71 float distance;
72
73 inline bool
74 operator < (const Entry& other) const
75 {
76 return (distance < other.distance);
77 }
78
79 inline bool
80 operator > (const Entry& other) const
81 {
82 return (distance > other.distance);
83 }
84 };
85
86 // replace by some metric functor
87 float getDistSqr (const PointT& point1, const PointT& point2) const;
88
89 public:
90 BruteForce (bool sorted_results = false)
91 : Search<PointT> ("BruteForce", sorted_results)
92 , point_representation_ (new DefaultPointRepresentation<PointT>)
93 {
94 }
95
96 /** \brief Destructor for KdTree. */
97
98 ~BruteForce () override = default;
99
100 /** \brief Provide a pointer to the point representation used for converting
101 * points into k-D vectors.
102 * \param[in] point_representation the const shared pointer to a PointRepresentation
103 */
104 inline void
105 setPointRepresentation (const PointRepresentationConstPtr &point_representation)
106 {
107 point_representation_ = point_representation;
108 }
109
110 /** \brief Get the point representation used for converting points into k-D vectors. */
111 inline PointRepresentationConstPtr
113 {
114 return (point_representation_);
115 }
116
117 /** \brief Search for the k-nearest neighbors for the given query point.
118 * \param[in] point the given query point
119 * \param[in] k the number of neighbors to search for
120 * \param[out] k_indices the resultant indices of the neighboring points (must be resized to \a k a priori!)
121 * \param[out] k_distances the resultant squared distances to the neighboring points (must be resized to \a k
122 * a priori!)
123 * \return number of neighbors found
124 */
125 int
126 nearestKSearch (const PointT &point, int k, Indices &k_indices, std::vector<float> &k_distances) const override;
127
128 /** \brief Search for all the nearest neighbors of the query point in a given radius.
129 * \param[in] point the given query point
130 * \param[in] radius the radius of the sphere bounding all of p_q's neighbors
131 * \param[out] k_indices the resultant indices of the neighboring points
132 * \param[out] k_sqr_distances the resultant squared distances to the neighboring points
133 * \param[in] max_nn if given, bounds the maximum returned neighbors to this value. If \a max_nn is set to
134 * 0 or to a number higher than the number of points in the input cloud, all neighbors in \a radius will be
135 * returned.
136 * \return number of neighbors found in radius
137 */
138 int
139 radiusSearch (const PointT& point, double radius,
140 Indices &k_indices, std::vector<float> &k_sqr_distances,
141 unsigned int max_nn = 0) const override;
142
143 private:
144 int
145 denseKSearch (const PointT &point, int k, Indices &k_indices, std::vector<float> &k_distances) const;
146
147 int
148 sparseKSearch (const PointT &point, int k, Indices &k_indices, std::vector<float> &k_distances) const;
149
150 int
151 denseRadiusSearch (const PointT& point, double radius,
152 Indices &k_indices, std::vector<float> &k_sqr_distances,
153 unsigned int max_nn = 0) const;
154
155 int
156 sparseRadiusSearch (const PointT& point, double radius,
157 Indices &k_indices, std::vector<float> &k_sqr_distances,
158 unsigned int max_nn = 0) const;
159
160 PointRepresentationConstPtr point_representation_;
161 };
162 }
163}
164
165#ifdef PCL_NO_PRECOMPILE
166#include <pcl/search/impl/brute_force.hpp>
167#endif
DefaultPointRepresentation extends PointRepresentation to define default behavior for common point ty...
PointCloud represents the base class in PCL for storing collections of 3D points.
shared_ptr< const PointRepresentation< PointT > > ConstPtr
Implementation of a simple brute force search algorithm.
Definition brute_force.h:53
int nearestKSearch(const PointT &point, int k, Indices &k_indices, std::vector< float > &k_distances) const override
Search for the k-nearest neighbors for the given query point.
PointRepresentationConstPtr getPointRepresentation() const
Get the point representation used for converting points into k-D vectors.
void setPointRepresentation(const PointRepresentationConstPtr &point_representation)
Provide a pointer to the point representation used for converting points into k-D vectors.
~BruteForce() override=default
Destructor for KdTree.
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.
BruteForce(bool sorted_results=false)
Definition brute_force.h:90
Generic search class.
Definition search.h:75
PointCloudConstPtr input_
Definition search.h:415
typename PointCloud::ConstPtr PointCloudConstPtr
Definition search.h:79
IndicesConstPtr indices_
Definition search.h:416
shared_ptr< const Indices > IndicesConstPtr
Definition pcl_base.h:59
detail::int_type_t< detail::index_type_size, detail::index_type_signed > index_t
Type used for an index in PCL.
Definition types.h:112
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition types.h:133
shared_ptr< Indices > IndicesPtr
Definition pcl_base.h:58
A point structure representing Euclidean xyz coordinates, and the RGB color.