diff --git a/Octree/include/CGAL/Octree.h b/Octree/include/CGAL/Octree.h index f317c7d0f8f..0075f70261e 100644 --- a/Octree/include/CGAL/Octree.h +++ b/Octree/include/CGAL/Octree.h @@ -330,6 +330,12 @@ public: return *node_for_point; } + template + void nearest_k_neighbours(const Point &p, std::size_t k, Point_output_iterator output) { + + *output++ = p; + } + /// @} /// \name Operators diff --git a/Octree/include/CGAL/Octree/IO.h b/Octree/include/CGAL/Octree/IO.h index d42e82e5f0f..7039004ead4 100644 --- a/Octree/include/CGAL/Octree/IO.h +++ b/Octree/include/CGAL/Octree/IO.h @@ -19,10 +19,35 @@ ostream &operator<<(ostream &os, const CGAL::Octree::Octree(); + // Iterate over the range and print each node +// for (auto &n : nodes) { +// +// for (int i = 0; i < n.depth() - 1; ++i) +// os << " │ "; +// +// if (!n.is_root()) { +// +// if (n.index() == 7) +// os << " └─"; +// else +// os << " ├─"; +// } +// +// os << n << std::endl; +// +// if (!n.is_leaf()) { +// +// for (int i = 0; i < n.depth(); ++i) +// os << " │ "; +// +// os << " ┬ " << std::endl; +// } +// } + // Iterate over the range and print each node for (auto &n : nodes) { - for (int i = 0; i < n.depth(); ++i) + for (int i = 0; i < n.depth() - 1; ++i) os << ". "; os << n << std::endl; diff --git a/Octree/test/Octree/test_octree_nearest_neighbor.cpp b/Octree/test/Octree/test_octree_nearest_neighbor.cpp index 1c3ec688b7d..0a3b4c9f5c0 100644 --- a/Octree/test/Octree/test_octree_nearest_neighbor.cpp +++ b/Octree/test/Octree/test_octree_nearest_neighbor.cpp @@ -22,7 +22,7 @@ typedef CGAL::Octree::Octree Octree; -void naive_vs_accelerated(std::size_t dataset_size) { +void naive_vs_octree(std::size_t dataset_size) { // Create a dataset Point_set points; @@ -63,9 +63,15 @@ void naive_vs_accelerated(std::size_t dataset_size) { // Do the same using the octree Point octree_nearest = *generator; + auto point_map = points.point_map(); + Octree octree(points, point_map); + octree.refine(10, 1); auto octree_start_time = high_resolution_clock::now(); { // TODO: Write a nearest-neighbor implementation and use it here + std::vector k_neighbors; + octree.nearest_k_neighbours(random_point, 1, std::back_inserter(k_neighbors)); + octree_nearest = *k_neighbors.begin(); } duration octree_elapsed_time = high_resolution_clock::now() - octree_start_time; @@ -87,10 +93,10 @@ void naive_vs_accelerated(std::size_t dataset_size) { int main(void) { - naive_vs_accelerated(100); - naive_vs_accelerated(1000); - naive_vs_accelerated(10000); - naive_vs_accelerated(100000); + naive_vs_octree(100); + naive_vs_octree(1000); + naive_vs_octree(10000); + naive_vs_octree(100000); return EXIT_SUCCESS; }