small_gicp
normal_estimation_tbb.hpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright 2024 Kenji Koide
2 // SPDX-License-Identifier: MIT
3 #pragma once
4 
5 #include <tbb/tbb.h>
7 
8 namespace small_gicp {
9 
10 template <typename Setter, typename PointCloud, typename KdTree>
11 void estimate_local_features_tbb(PointCloud& cloud, KdTree& kdtree, int num_neighbors) {
12  traits::resize(cloud, traits::size(cloud));
13  tbb::parallel_for(tbb::blocked_range<size_t>(0, traits::size(cloud)), [&](const tbb::blocked_range<size_t>& range) {
14  for (size_t i = range.begin(); i < range.end(); i++) {
15  estimate_local_features<Setter>(cloud, kdtree, num_neighbors, i);
16  }
17  });
18 }
19 
20 template <typename Setter, typename PointCloud>
21 void estimate_local_features_tbb(PointCloud& cloud, int num_neighbors) {
22  traits::resize(cloud, traits::size(cloud));
23  UnsafeKdTree<PointCloud> kdtree(cloud);
24 
25  tbb::parallel_for(tbb::blocked_range<size_t>(0, traits::size(cloud)), [&](const tbb::blocked_range<size_t>& range) {
26  for (size_t i = range.begin(); i < range.end(); i++) {
27  estimate_local_features<Setter>(cloud, kdtree, num_neighbors, i);
28  }
29  });
30 }
31 
37 template <typename PointCloud>
38 void estimate_normals_tbb(PointCloud& cloud, int num_neighbors = 20) {
39  estimate_local_features_tbb<NormalSetter<PointCloud>>(cloud, num_neighbors);
40 }
41 
48 template <typename PointCloud, typename KdTree>
49 void estimate_normals_tbb(PointCloud& cloud, KdTree& kdtree, int num_neighbors = 20) {
50  estimate_local_features_tbb<NormalSetter<PointCloud>>(cloud, kdtree, num_neighbors);
51 }
52 
58 template <typename PointCloud>
59 void estimate_covariances_tbb(PointCloud& cloud, int num_neighbors = 20) {
60  estimate_local_features_tbb<CovarianceSetter<PointCloud>>(cloud, num_neighbors);
61 }
62 
69 template <typename PointCloud, typename KdTree>
70 void estimate_covariances_tbb(PointCloud& cloud, KdTree& kdtree, int num_neighbors = 20) {
71  estimate_local_features_tbb<CovarianceSetter<PointCloud>>(cloud, kdtree, num_neighbors);
72 }
73 
79 template <typename PointCloud>
80 void estimate_normals_covariances_tbb(PointCloud& cloud, int num_neighbors = 20) {
81  estimate_local_features_tbb<NormalCovarianceSetter<PointCloud>>(cloud, num_neighbors);
82 }
83 
90 template <typename PointCloud, typename KdTree>
91 void estimate_normals_covariances_tbb(PointCloud& cloud, KdTree& kdtree, int num_neighbors = 20) {
92  estimate_local_features_tbb<NormalCovarianceSetter<PointCloud>>(cloud, kdtree, num_neighbors);
93 }
94 
95 } // namespace small_gicp
size_t size(const T &points)
Get the number of points.
Definition: traits.hpp:16
void resize(T &points, size_t n)
Resize the point cloud (this function should resize all attributes)
Definition: traits.hpp:58
Definition: flat_container.hpp:12
void estimate_covariances_tbb(PointCloud &cloud, int num_neighbors=20)
Estimate point covariances with TBB.
Definition: normal_estimation_tbb.hpp:59
void estimate_local_features_tbb(PointCloud &cloud, KdTree &kdtree, int num_neighbors)
Definition: normal_estimation_tbb.hpp:11
void estimate_normals_covariances_tbb(PointCloud &cloud, int num_neighbors=20)
Estimate point normals and covariances with TBB.
Definition: normal_estimation_tbb.hpp:80
void estimate_normals_tbb(PointCloud &cloud, int num_neighbors=20)
Estimate point normals with TBB.
Definition: normal_estimation_tbb.hpp:38
"Safe" KdTree that holds the ownership of the input points.
Definition: kdtree.hpp:245
Point cloud.
Definition: point_cloud.hpp:15
"Unsafe" KdTree.
Definition: kdtree.hpp:137