Point Cloud Library (PCL)  1.15.1-dev
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/common/utils.h> // for ignore
14 #include <pcl/search/auto.h>
15 #include <pcl/search/brute_force.h>
16 #include <pcl/search/kdtree.h>
17 #include <pcl/search/kdtree_nanoflann.h>
18 #include <pcl/search/organized.h>
19 
20 template<typename PointT>
22  pcl::search::Search<PointT> * searcher = nullptr;
23  if (cloud->isOrganized ()) {
24  searcher = new pcl::search::OrganizedNeighbor<PointT> (sorted_results);
25  if(searcher->setInputCloud (cloud)) { // may return false if OrganizedNeighbor cannot work with the cloud, then use another search method instead
26  return searcher;
27  }
28  }
29 #if PCL_HAS_NANOFLANN
30  searcher = new pcl::search::KdTreeNanoflann<PointT> (sorted_results, (purpose == pcl::search::Purpose::one_knn_search ? 10 : 20));
31  if(searcher->setInputCloud (cloud)) {
32  return searcher;
33  }
34 #else
35  pcl::utils::ignore(purpose);
36 #endif
37 #if PCL_HAS_FLANN
38  searcher = new pcl::search::KdTree<PointT> (sorted_results);
39  if(searcher->setInputCloud (cloud)) {
40  return searcher;
41  }
42 #endif
43  // If nothing else works, use brute force method
44  searcher = new pcl::search::BruteForce<PointT> (sorted_results);
45  searcher->setInputCloud (cloud);
46  return searcher;
47 }
48 
49 #define PCL_INSTANTIATE_AutoSelectMethod(T) template PCL_EXPORTS pcl::search::Search<T> * pcl::search::autoSelectMethod<T>(const typename pcl::PointCloud<T>::ConstPtr& cloud, bool sorted_results, pcl::search::Purpose purpose);
50 
51 #endif //#ifndef PCL_SEARCH_AUTO_IMPL_HPP_
bool isOrganized() const
Return whether a dataset is organized (e.g., arranged in a structured grid).
Definition: point_cloud.h:311
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:415
Implementation of a simple brute force search algorithm.
Definition: brute_force.h:52
search::KdTree is a wrapper class which inherits the pcl::KdTree class for performing search function...
Definition: kdtree.h:62
OrganizedNeighbor is a class for optimized nearest neighbor search in organized projectable point clo...
Definition: organized.h:66
Generic search class.
Definition: search.h:75
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
@ 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.hpp:21
void ignore(const T &...)
Utility function to eliminate unused variable warnings.
Definition: utils.h:62