From 83b8a0dc71d13859f6a85cee35f85bba98e40cf6 Mon Sep 17 00:00:00 2001 From: Simon Giraudot Date: Tue, 27 Oct 2020 10:24:30 +0100 Subject: [PATCH] Custom traversal example --- Orthtree/doc/Orthtree/Orthtree.txt | 11 ++-- .../Orthtree/Octree_traversal_custom.cpp | 61 ++++++++++++++++++- 2 files changed, 63 insertions(+), 9 deletions(-) diff --git a/Orthtree/doc/Orthtree/Orthtree.txt b/Orthtree/doc/Orthtree/Orthtree.txt index 4584cff09cb..ae5775987e7 100644 --- a/Orthtree/doc/Orthtree/Orthtree.txt +++ b/Orthtree/doc/Orthtree/Orthtree.txt @@ -148,17 +148,14 @@ In this case, we print out the nodes of the tree without indentation instead. \cgalExample{Orthtree/Octree_traversal_preorder.cpp} - - \section Section_Orthtree_Acceleration Acceleration of Common Tasks Once an %Orthtree is built, its structure can be used to accelerate different tasks. diff --git a/Orthtree/examples/Orthtree/Octree_traversal_custom.cpp b/Orthtree/examples/Orthtree/Octree_traversal_custom.cpp index 36fdf254807..6fe10dca350 100644 --- a/Orthtree/examples/Orthtree/Octree_traversal_custom.cpp +++ b/Orthtree/examples/Orthtree/Octree_traversal_custom.cpp @@ -1,3 +1,60 @@ -// TODO +#include +#include -int main() { return 0; } +#include +#include +#include +#include + +// Type Declarations +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::Point_3 Point; +typedef CGAL::Point_set_3 Point_set; +typedef Point_set::Point_map Point_map; + +typedef CGAL::Octree Octree; + +struct First_branch_traversal +{ + template + Node first (Node root) const + { + return root; + } + + template + Node next (Node n) const + { + if (n.is_leaf()) + return Node(); + return n[0]; + } +}; + +int main(int argc, char **argv) { + + // Point set will be used to hold our points + Point_set points; + + // Load points from a file. + std::ifstream stream((argc > 1) ? argv[1] : "data/cube.pwn"); + stream >> points; + if (0 == points.number_of_points()) { + + std::cerr << "Error: cannot read file" << std::endl; + return EXIT_FAILURE; + } + std::cout << "loaded " << points.number_of_points() << " points\n" << std::endl; + + // Create an octree from the points + Octree octree(points, points.point_map()); + + // Build the octree + octree.refine(); + + // Print out the first branch using custom traversal + for (auto &node : octree.traverse()) + std::cout << node << std::endl; + + return EXIT_SUCCESS; +}