Point Cloud Library (PCL) 1.15.1-dev
Loading...
Searching...
No Matches
auto.hpp
1/*
2* SPDX-License-Identifier: BSD-3-Clause
3*
4* Point Cloud Library (PCL) - www.pointclouds.org
5* Copyright (c) 2025-, Open Perception Inc.
6*
7* All rights reserved
8*/
9
10#ifndef PCL_SEARCH_AUTO_IMPL_HPP_
11#define PCL_SEARCH_AUTO_IMPL_HPP_
12
13#include <pcl/pcl_config.h>
14#include <pcl/common/utils.h> // for ignore
15#include <pcl/search/auto.h>
16#include <pcl/search/brute_force.h>
17#if PCL_HAS_FLANN
18#include <pcl/search/kdtree.h>
19#endif
20#include <pcl/search/kdtree_nanoflann.h>
21#include <pcl/search/octree.h>
22#include <pcl/search/organized.h>
23
24template<typename PointT>
26 pcl::search::Search<PointT> * searcher = nullptr;
27 if constexpr (pcl::traits::has_xyz_v<PointT>) {
28 if (cloud->isOrganized ()) {
29 searcher = new pcl::search::OrganizedNeighbor<PointT> (sorted_results);
30 if(searcher->setInputCloud (cloud, indices)) { // may return false if OrganizedNeighbor cannot work with the cloud, then use another search method instead
31 return searcher;
32 }
33 delete searcher;
34 }
35 }
36
37#if PCL_HAS_NANOFLANN
38 // we get the number of search dimensions as a compile-time-constant via NR_DIMS. NR_DIMS may be -1 if it is not possible to determine the dimensions at compile-time (only at run-time), however then searching may be slower. If NR_DIMS is not -1, it must be the same as the return value of getNumberOfDimensions().
39 searcher = new pcl::search::KdTreeNanoflann<PointT, pcl::DefaultPointRepresentation<PointT>::NR_DIMS> (sorted_results, (purpose == pcl::search::Purpose::one_knn_search ? 10 : 20));
40 if(searcher->setInputCloud (cloud, indices)) {
41 return searcher;
42 }
43 delete searcher;
44#else
45 pcl::utils::ignore(purpose);
46#endif
47
48#if PCL_HAS_FLANN
49 searcher = new pcl::search::KdTree<PointT> (sorted_results);
50 if(searcher->setInputCloud (cloud, indices)) {
51 return searcher;
52 }
53 delete searcher;
54#endif
55
56 if constexpr (pcl::traits::has_xyz_v<PointT>) {
57 searcher = new pcl::search::Octree<PointT> (0.01); // TODO a better heuristic to choose octree resolution?
58 searcher->setSortedResults (sorted_results);
59 if(searcher->setInputCloud (cloud, indices)) {
60 return searcher;
61 }
62 delete searcher;
63 }
64
65 searcher = new pcl::search::BruteForce<PointT> (sorted_results);
66 searcher->setInputCloud (cloud, indices);
67 return searcher;
68}
69
70template<typename PointT>
71pcl::search::Search<PointT> * pcl::search::autoSelectMethod(const typename pcl::PointCloud<PointT>::ConstPtr& cloud, const pcl::IndicesConstPtr& indices, const pcl::shared_ptr<const pcl::PointRepresentation<PointT> >& point_representation, bool sorted_results, pcl::search::Purpose purpose) {
72#if PCL_HAS_NANOFLANN
73 // we get the number of search dimensions from the given point_representation, but we can only get it a run-time. Often, this is the same as when DefaultPointRepresentation is used, in this case we use the fast option of KdTreeNanoflann with a static number of dimensions (second template parameter). Otherwise, we use a KdTreeNanoflann with a dynamic number of dimensions (-1 as template parameter, slightly slower).
74 if(point_representation->getNumberOfDimensions() == pcl::DefaultPointRepresentation<PointT>::NR_DIMS) {
75 auto searcher = new pcl::search::KdTreeNanoflann<PointT, pcl::DefaultPointRepresentation<PointT>::NR_DIMS> (sorted_results, (purpose == pcl::search::Purpose::one_knn_search ? 10 : 20));
76 searcher->setPointRepresentation (point_representation);
77 if(searcher->setInputCloud (cloud, indices)) {
78 return searcher;
79 }
80 delete searcher;
81 }
82 {
83 auto searcher = new pcl::search::KdTreeNanoflann<PointT, -1> (sorted_results, (purpose == pcl::search::Purpose::one_knn_search ? 10 : 20));
84 searcher->setPointRepresentation (point_representation);
85 if(searcher->setInputCloud (cloud, indices)) {
86 return searcher;
87 }
88 delete searcher;
89 }
90#else
91 pcl::utils::ignore(purpose);
92#endif
93
94#if PCL_HAS_FLANN
95 {
96 auto searcher = new pcl::search::KdTree<PointT> (sorted_results);
97 searcher->setPointRepresentation (point_representation);
98 if(searcher->setInputCloud (cloud, indices)) {
99 return searcher;
100 }
101 delete searcher;
102 }
103#endif
104
105 {
106 auto searcher = new pcl::search::BruteForce<PointT> (sorted_results);
107 searcher->setPointRepresentation (point_representation);
108 searcher->setInputCloud (cloud, indices);
109 return searcher;
110 }
111}
112
113#define PCL_INSTANTIATE_AutoSelectMethod(T) template PCL_EXPORTS pcl::search::Search<T> * pcl::search::autoSelectMethod<T>(const typename pcl::PointCloud<T>::ConstPtr& cloud, const pcl::IndicesConstPtr& indices, bool sorted_results, pcl::search::Purpose purpose);
114
115#define PCL_INSTANTIATE_AutoSelectMethod2(T) template PCL_EXPORTS pcl::search::Search<T> * pcl::search::autoSelectMethod<T>(const typename pcl::PointCloud<T>::ConstPtr& cloud, const pcl::IndicesConstPtr& indices, const pcl::shared_ptr<const pcl::PointRepresentation<T> >& point_representation, bool sorted_results, pcl::search::Purpose purpose);
116
117#endif //#ifndef PCL_SEARCH_AUTO_IMPL_HPP_
DefaultPointRepresentation extends PointRepresentation to define default behavior for common point ty...
bool isOrganized() const
Return whether a dataset is organized (e.g., arranged in a structured grid).
shared_ptr< const PointCloud< PointT > > ConstPtr
PointRepresentation provides a set of methods for converting a point structs/object into an n-dimensi...
Implementation of a simple brute force search algorithm.
Definition brute_force.h:53
search::KdTree is a wrapper class which inherits the pcl::KdTree class for performing search function...
Definition kdtree.h:62
search::Octree is a wrapper class which implements nearest neighbor search operations based on the pc...
Definition octree.h:69
OrganizedNeighbor is a class for optimized nearest neighbor search in organized projectable point clo...
Definition organized.h:66
Generic search class.
Definition search.h:78
virtual bool setInputCloud(const PointCloudConstPtr &cloud, const IndicesConstPtr &indices=IndicesConstPtr())
Pass the input dataset that the search will be performed on.
Definition search.hpp:75
virtual void setSortedResults(bool sorted)
sets whether the results should be sorted (ascending in the distance) or not
Definition search.hpp:61
@ one_knn_search
The search method will mainly be used for nearestKSearch where k is 1.
pcl::search::Search< PointT > * autoSelectMethod(const typename pcl::PointCloud< PointT >::ConstPtr &cloud, bool sorted_results, Purpose purpose=Purpose::undefined)
Automatically select the fastest search method for the given point cloud.
Definition auto.h:33
void ignore(const T &...)
Utility function to eliminate unused variable warnings.
Definition utils.h:62
shared_ptr< const Indices > IndicesConstPtr
Definition pcl_base.h:59
A point structure representing Euclidean xyz coordinates, and the RGB color.