#include #include #include #include #include #include using Kernel = CGAL::Simple_cartesian; using Point_3 = Kernel::Point_3; using Traits = CGAL::Search_traits_3; using Neighbor_search = CGAL::Orthogonal_k_neighbor_search; using Tree = Neighbor_search::Tree; using Point_with_distance = Neighbor_search::Point_with_transformed_distance; using Generator = CGAL::Random_points_in_sphere_3; int main() { const unsigned int N = 1000; const unsigned int k = 6; // Generate N points in a sphere std::vector points; points.reserve (N); Generator generator; for (unsigned int i = 0; i < N; ++ i) points.push_back (*(generator++)); // Build tree in parallel Tree tree(points.begin(), points.end()); tree.build(); // Query tree in parallel std::vector > neighbors (points.size()); tbb::parallel_for (tbb::blocked_range (0, points.size()), [&](const tbb::blocked_range& r) { for (std::size_t s = r.begin(); s != r.end(); ++ s) { // Neighbor search can be instantiated from // several threads at the same time Neighbor_search search (tree, points[s], k); neighbors[s].reserve(k); // neighbor search returns a set of pair of // point and distance , here we // keep the points only for (const Point_with_distance pwd : search) neighbors[s].push_back (pwd.first); } }); return 0; }