Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions examples/features/example_difference_of_normals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,6 @@ int main (int argc, char *argv[])
pcl::fromPCLPointCloud2 (blob, *cloud);
std::cout << "done." << std::endl;

SearchPtr tree;

if (cloud->isOrganized ())
{
tree.reset (new pcl::search::OrganizedNeighbor<PointT> ());
}
else
{
tree.reset (new pcl::search::KdTree<PointT> (false));
}

tree->setInputCloud (cloud);

PointCloud<PointT>::Ptr small_cloud_downsampled;
PointCloud<PointT>::Ptr large_cloud_downsampled;

Expand Down Expand Up @@ -110,7 +97,6 @@ int main (int argc, char *argv[])
// Compute normals using both small and large scales at each point
pcl::NormalEstimationOMP<PointT, PointNT> ne;
ne.setInputCloud (cloud);
ne.setSearchMethod (tree);

/**
* NOTE: setting viewpoint is very important, so that we can ensure
Expand Down
2 changes: 1 addition & 1 deletion filters/include/pcl/filters/impl/convolution_3d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ pcl::filters::Convolution3D<PointInT, PointOutT, KernelT>::initCompute ()
// Initialize the spatial locator
if (!tree_)
{
tree_.reset (pcl::search::autoSelectMethod<PointT>(surface_, false, pcl::search::Purpose::radius_search));
tree_.reset (pcl::search::autoSelectMethod<PointInT>(surface_, false, pcl::search::Purpose::radius_search));
}
else
{
Expand Down
1 change: 1 addition & 0 deletions gpu/kinfu_large_scale/tools/standalone_texture_mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <pcl/common/transforms.h>
#include <pcl/features/normal_3d.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/search/kdtree.h>
#include <pcl/surface/texture_mapping.h>
#include <pcl/io/vtk_lib_io.h>
#include <pcl/io/ply_io.h>
Expand Down
2 changes: 1 addition & 1 deletion registration/include/pcl/registration/gicp.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ class GeneralizedIterativeClosestPoint
template <typename PointT>
void
computeCovariances(typename pcl::PointCloud<PointT>::ConstPtr cloud,
const typename pcl::search::KdTree<PointT>::Ptr tree,
const typename pcl::search::Search<PointT>::Ptr tree,
MatricesVector& cloud_covariances);

/** \return trace of mat1 . mat2
Expand Down
2 changes: 1 addition & 1 deletion registration/include/pcl/registration/impl/gicp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ template <typename PointT>
void
GeneralizedIterativeClosestPoint<PointSource, PointTarget, Scalar>::computeCovariances(
typename pcl::PointCloud<PointT>::ConstPtr cloud,
const typename pcl::search::KdTree<PointT>::Ptr kdtree,
const typename pcl::search::Search<PointT>::Ptr kdtree,
MatricesVector& cloud_covariances)
{
if (k_correspondences_ > static_cast<int>(cloud->size())) {
Expand Down
13 changes: 7 additions & 6 deletions registration/include/pcl/registration/impl/ia_fpcs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <pcl/registration/ia_fpcs.h>
#include <pcl/registration/transformation_estimation_3point.h>
#include <pcl/sample_consensus/sac_model_plane.h>
#include <pcl/search/auto.h>

#include <limits>

Expand All @@ -58,8 +59,8 @@ pcl::getMeanPointDensity(const typename pcl::PointCloud<PointT>::ConstPtr& cloud
const float max_dist_sqr = max_dist * max_dist;
const std::size_t s = cloud->size();

pcl::search::KdTree<PointT> tree;
tree.setInputCloud(cloud);
typename pcl::search::Search<PointT>::Ptr tree(pcl::search::autoSelectMethod<PointT>(
cloud, true, pcl::search::Purpose::many_knn_search));

float mean_dist = 0.f;
int num = 0;
Expand All @@ -71,7 +72,7 @@ pcl::getMeanPointDensity(const typename pcl::PointCloud<PointT>::ConstPtr& cloud
firstprivate(ids, dists_sqr) reduction(+ : mean_dist, num) \
firstprivate(s, max_dist_sqr) num_threads(nr_threads)
for (int i = 0; i < 1000; i++) {
tree.nearestKSearch((*cloud)[rand() % s], 2, ids, dists_sqr);
tree->nearestKSearch((*cloud)[rand() % s], 2, ids, dists_sqr);
if (dists_sqr[1] < max_dist_sqr) {
mean_dist += std::sqrt(dists_sqr[1]);
num++;
Expand All @@ -92,8 +93,8 @@ pcl::getMeanPointDensity(const typename pcl::PointCloud<PointT>::ConstPtr& cloud
const float max_dist_sqr = max_dist * max_dist;
const std::size_t s = indices.size();

pcl::search::KdTree<PointT> tree;
tree.setInputCloud(cloud);
typename pcl::search::Search<PointT>::Ptr tree(pcl::search::autoSelectMethod<PointT>(
cloud, true, pcl::search::Purpose::many_knn_search));

float mean_dist = 0.f;
int num = 0;
Expand All @@ -109,7 +110,7 @@ pcl::getMeanPointDensity(const typename pcl::PointCloud<PointT>::ConstPtr& cloud
firstprivate(ids, dists_sqr) reduction(+ : mean_dist, num) num_threads(nr_threads)
#endif
for (int i = 0; i < 1000; i++) {
tree.nearestKSearch((*cloud)[indices[rand() % s]], 2, ids, dists_sqr);
tree->nearestKSearch((*cloud)[indices[rand() % s]], 2, ids, dists_sqr);
if (dists_sqr[1] < max_dist_sqr) {
mean_dist += std::sqrt(dists_sqr[1]);
num++;
Expand Down
15 changes: 14 additions & 1 deletion search/include/pcl/search/auto.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,20 @@ namespace pcl {
* \param[in] purpose Optional, can be used to give more information about what this search method will be used for, to achieve optimal performance
*/
template<typename PointT>
pcl::search::Search<PointT> * autoSelectMethod(const typename pcl::PointCloud<PointT>::ConstPtr& cloud, bool sorted_results, Purpose purpose = Purpose::undefined);
pcl::search::Search<PointT> * autoSelectMethod(const typename pcl::PointCloud<PointT>::ConstPtr& cloud, bool sorted_results, Purpose purpose = Purpose::undefined)
{
return autoSelectMethod<PointT>(cloud, pcl::IndicesConstPtr(), sorted_results, purpose);
}

/**
* Automatically select the fastest search method for the given point cloud. Make sure to delete the returned object after use!
* \param[in] cloud Point cloud, this function will pass it to the search method via setInputCloud
* \param[in] indices Will be passed to the search method via setInputCloud, together with the point cloud
* \param[in] sorted_results Whether the search method should always return results sorted by distance (may be slower than unsorted)
* \param[in] purpose Optional, can be used to give more information about what this search method will be used for, to achieve optimal performance
*/
template<typename PointT>
pcl::search::Search<PointT> * autoSelectMethod(const typename pcl::PointCloud<PointT>::ConstPtr& cloud, const pcl::IndicesConstPtr& indices, bool sorted_results, Purpose purpose = Purpose::undefined);
} // namespace search
} // namespace pcl

Expand Down
12 changes: 6 additions & 6 deletions search/include/pcl/search/impl/auto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,34 @@
#include <pcl/search/organized.h>

template<typename PointT>
pcl::search::Search<PointT> * pcl::search::autoSelectMethod(const typename pcl::PointCloud<PointT>::ConstPtr& cloud, bool sorted_results, pcl::search::Purpose purpose) {
pcl::search::Search<PointT> * pcl::search::autoSelectMethod(const typename pcl::PointCloud<PointT>::ConstPtr& cloud, const pcl::IndicesConstPtr& indices, bool sorted_results, pcl::search::Purpose purpose) {
pcl::search::Search<PointT> * searcher = nullptr;
if (cloud->isOrganized ()) {
searcher = new pcl::search::OrganizedNeighbor<PointT> (sorted_results);
if(searcher->setInputCloud (cloud)) { // may return false if OrganizedNeighbor cannot work with the cloud, then use another search method instead
if(searcher->setInputCloud (cloud, indices)) { // may return false if OrganizedNeighbor cannot work with the cloud, then use another search method instead
return searcher;
}
}
#if PCL_HAS_NANOFLANN
searcher = new pcl::search::KdTreeNanoflann<PointT> (sorted_results, (purpose == pcl::search::Purpose::one_knn_search ? 10 : 20));
if(searcher->setInputCloud (cloud)) {
if(searcher->setInputCloud (cloud, indices)) {
return searcher;
}
#else
pcl::utils::ignore(purpose);
#endif
#if PCL_HAS_FLANN
searcher = new pcl::search::KdTree<PointT> (sorted_results);
if(searcher->setInputCloud (cloud)) {
if(searcher->setInputCloud (cloud, indices)) {
return searcher;
}
#endif
// If nothing else works, use brute force method
searcher = new pcl::search::BruteForce<PointT> (sorted_results);
searcher->setInputCloud (cloud);
searcher->setInputCloud (cloud, indices);
return searcher;
}

#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);
#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);

#endif //#ifndef PCL_SEARCH_AUTO_IMPL_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
#define PCL_SEGMENTATION_IMPL_CONDITIONAL_EUCLIDEAN_CLUSTERING_HPP_

#include <pcl/segmentation/conditional_euclidean_clustering.h>
#include <pcl/search/organized.h> // for OrganizedNeighbor
#include <pcl/search/kdtree.h> // for KdTree
#include <pcl/search/auto.h>

template<typename PointT> void
pcl::ConditionalEuclideanClustering<PointT>::segment (pcl::IndicesClusters &clusters)
Expand All @@ -59,12 +58,12 @@ pcl::ConditionalEuclideanClustering<PointT>::segment (pcl::IndicesClusters &clus
// Initialize the search class
if (!searcher_)
{
if (input_->isOrganized ())
searcher_.reset (new pcl::search::OrganizedNeighbor<PointT> (false)); // not requiring sorted results is much faster
else
searcher_.reset (new pcl::search::KdTree<PointT> (false)); // not requiring sorted results is much faster
searcher_.reset (pcl::search::autoSelectMethod<PointT>(input_, indices_, false, pcl::search::Purpose::radius_search)); // not requiring sorted results is much faster
}
else
{
searcher_->setInputCloud (input_, indices_);
}
searcher_->setInputCloud (input_, indices_);
// If searcher_ gives sorted results, we can skip the first one because it is the query point itself
const int nn_start_idx = searcher_->getSortedResults () ? 1 : 0;

Expand Down
15 changes: 7 additions & 8 deletions segmentation/include/pcl/segmentation/impl/extract_clusters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#define PCL_SEGMENTATION_IMPL_EXTRACT_CLUSTERS_H_

#include <pcl/segmentation/extract_clusters.h>
#include <pcl/search/organized.h> // for OrganizedNeighbor
#include <pcl/search/auto.h>

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
Expand Down Expand Up @@ -234,14 +234,13 @@ pcl::EuclideanClusterExtraction<PointT>::extract (std::vector<PointIndices> &clu
// Initialize the spatial locator
if (!tree_)
{
if (input_->isOrganized ())
tree_.reset (new pcl::search::OrganizedNeighbor<PointT> ());
else
tree_.reset (new pcl::search::KdTree<PointT> (false));
tree_.reset (pcl::search::autoSelectMethod<PointT>(input_, indices_, false, pcl::search::Purpose::radius_search));
}
else
{
// Send the input dataset to the spatial locator
tree_->setInputCloud (input_, indices_);
}

// Send the input dataset to the spatial locator
tree_->setInputCloud (input_, indices_);
extractEuclideanClusters (*input_, *indices_, tree_, static_cast<float> (cluster_tolerance_), clusters, min_pts_per_cluster_, max_pts_per_cluster_);

//tree_->setInputCloud (input_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#include <boost/graph/boykov_kolmogorov_max_flow.hpp> // for boykov_kolmogorov_max_flow
#include <pcl/segmentation/min_cut_segmentation.h>
#include <pcl/search/search.h>
#include <pcl/search/kdtree.h>
#include <pcl/search/auto.h>
#include <cmath>

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -290,7 +290,13 @@ pcl::MinCutSegmentation<PointT>::buildGraph ()
return (false);

if (!search_)
search_.reset (new pcl::search::KdTree<PointT>);
{
search_.reset (pcl::search::autoSelectMethod<PointT>(input_, indices_, true, pcl::search::Purpose::many_knn_search));
}
else
{
search_->setInputCloud (input_, indices_);
}

graph_.reset (new mGraph);

Expand Down Expand Up @@ -325,7 +331,6 @@ pcl::MinCutSegmentation<PointT>::buildGraph ()

pcl::Indices neighbours;
std::vector<float> distances;
search_->setInputCloud (input_, indices_);
for (std::size_t i_point = 0; i_point < number_of_indices; i_point++)
{
index_t point_index = (*indices_)[i_point];
Expand Down
18 changes: 11 additions & 7 deletions segmentation/include/pcl/segmentation/impl/region_growing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#include <pcl/common/point_tests.h> // for pcl::isFinite
#include <pcl/console/print.h> // for PCL_ERROR
#include <pcl/search/search.h>
#include <pcl/search/kdtree.h>
#include <pcl/search/auto.h>

#include <queue>
#include <cmath>
Expand Down Expand Up @@ -303,18 +303,22 @@ pcl::RegionGrowing<PointT, NormalT>::prepareForSegmentation ()
if (neighbour_number_ == 0)
return (false);

// if user didn't set search method
if (!search_)
search_.reset (new pcl::search::KdTree<PointT>);

if (indices_)
{
if (indices_->empty ())
PCL_ERROR ("[pcl::RegionGrowing::prepareForSegmentation] Empty given indices!\n");
search_->setInputCloud (input_, indices_);
if (!search_)
search_.reset (pcl::search::autoSelectMethod<PointT>(input_, indices_, true, pcl::search::Purpose::many_knn_search));
else
search_->setInputCloud (input_, indices_);
}
else
search_->setInputCloud (input_);
{
if (!search_)
search_.reset (pcl::search::autoSelectMethod<PointT>(input_, true, pcl::search::Purpose::many_knn_search));
else
search_->setInputCloud (input_);
}

return (true);
}
Expand Down
5 changes: 0 additions & 5 deletions surface/include/pcl/surface/gp3.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
// PCL includes
#include <pcl/surface/reconstruction.h>

#include <pcl/kdtree/kdtree.h>

#include <fstream>

#include <Eigen/Geometry> // for cross
Expand Down Expand Up @@ -138,9 +136,6 @@ namespace pcl
using MeshConstruction<PointInT>::input_;
using MeshConstruction<PointInT>::indices_;

using KdTree = pcl::KdTree<PointInT>;
using KdTreePtr = typename KdTree::Ptr;

using PointCloudIn = pcl::PointCloud<PointInT>;
using PointCloudInPtr = typename PointCloudIn::Ptr;
using PointCloudInConstPtr = typename PointCloudIn::ConstPtr;
Expand Down
3 changes: 0 additions & 3 deletions surface/include/pcl/surface/grid_projection.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ namespace pcl

using PointCloudPtr = typename pcl::PointCloud<PointNT>::Ptr;

using KdTree = pcl::KdTree<PointNT>;
using KdTreePtr = typename KdTree::Ptr;

/** \brief Data leaf. */
struct Leaf
{
Expand Down
5 changes: 2 additions & 3 deletions surface/include/pcl/surface/impl/concave_hull.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,7 @@ pcl::ConcaveHull<PointInT>::performReconstruction (PointCloud &alpha_shape, std:
if (keep_information_)
{
// build a tree with the original points
pcl::KdTreeFLANN<PointInT> tree (true);
tree.setInputCloud (input_, indices_);
typename pcl::search::Search<PointInT>::Ptr tree(pcl::search::autoSelectMethod<PointInT>(input_, indices_, false, pcl::search::Purpose::one_knn_search));

pcl::Indices neighbor;
std::vector<float> distances;
Expand All @@ -581,7 +580,7 @@ pcl::ConcaveHull<PointInT>::performReconstruction (PointCloud &alpha_shape, std:

for (const auto& point: alpha_shape)
{
tree.nearestKSearch (point, 1, neighbor, distances);
tree->nearestKSearch (point, 1, neighbor, distances);
hull_indices_.indices.push_back (neighbor[0]);
}

Expand Down
Loading