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 bool
105 setPointRepresentation (const PointRepresentationConstPtr &point_representation) override
106 {
107 point_representation_ = point_representation;
108 return true;
109 }
110
111 /** \brief Get the point representation used for converting points into k-D vectors. */
112 inline PointRepresentationConstPtr
114 {
115 return (point_representation_);
116 }
117
118 /** \brief Search for the k-nearest neighbors for the given query point.
119 * \param[in] point the given query point
120 * \param[in] k the number of neighbors to search for
121 * \param[out] k_indices the resultant indices of the neighboring points (must be resized to \a k a priori!)
122 * \param[out] k_distances the resultant squared distances to the neighboring points (must be resized to \a k
123 * a priori!)
124 * \return number of neighbors found
125 */
126 int
127 nearestKSearch (const PointT &point, int k, Indices &k_indices, std::vector<float> &k_distances) const override;
128
129 /** \brief Search for all the nearest neighbors of the query point in a given radius.
130 * \param[in] point the given query point
131 * \param[in] radius the radius of the sphere bounding all of p_q's neighbors
132 * \param[out] k_indices the resultant indices of the neighboring points
133 * \param[out] k_sqr_distances the resultant squared distances to the neighboring points
134 * \param[in] max_nn if given, bounds the maximum returned neighbors to this value. If \a max_nn is set to
135 * 0 or to a number higher than the number of points in the input cloud, all neighbors in \a radius will be
136 * returned.
137 * \return number of neighbors found in radius
138 */
139 int
140 radiusSearch (const PointT& point, double radius,
141 Indices &k_indices, std::vector<float> &k_sqr_distances,
142 unsigned int max_nn = 0) const override;
143
144 private:
145 int
146 denseKSearch (const PointT &point, int k, Indices &k_indices, std::vector<float> &k_distances) const;
147
148 int
149 sparseKSearch (const PointT &point, int k, Indices &k_indices, std::vector<float> &k_distances) const;
150
151 int
152 denseRadiusSearch (const PointT& point, double radius,
153 Indices &k_indices, std::vector<float> &k_sqr_distances,
154 unsigned int max_nn = 0) const;
155
156 int
157 sparseRadiusSearch (const PointT& point, double radius,
158 Indices &k_indices, std::vector<float> &k_sqr_distances,
159 unsigned int max_nn = 0) const;
160
161 PointRepresentationConstPtr point_representation_;
162 };
163 }
164}
165
166#ifdef PCL_NO_PRECOMPILE
167#include <pcl/search/impl/brute_force.hpp>
168#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.
~BruteForce() override=default
Destructor for KdTree.
bool setPointRepresentation(const PointRepresentationConstPtr &point_representation) override
Provide a pointer to the point representation used for converting points into k-D vectors.
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:78
PointCloudConstPtr input_
Definition search.h:431
typename PointCloud::ConstPtr PointCloudConstPtr
Definition search.h:82
IndicesConstPtr indices_
Definition search.h:432
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.