From c32fb24efb16893b35025570ab3bc0c62dfd10e7 Mon Sep 17 00:00:00 2001 From: Jackson Campolattaro Date: Thu, 25 Jun 2020 00:10:44 -0400 Subject: [PATCH] Begin implementing depth first traversal --- Octree/include/CGAL/Octree.h | 4 +-- .../CGAL/Octree/Tree_walker_criterion.h | 36 +++++++++++-------- Octree/test/Octree/test_node_index.cpp | 3 +- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/Octree/include/CGAL/Octree.h b/Octree/include/CGAL/Octree.h index 38013e4f60a..c85fbad429c 100644 --- a/Octree/include/CGAL/Octree.h +++ b/Octree/include/CGAL/Octree.h @@ -176,7 +176,7 @@ namespace CGAL { const Node &root() const { return m_root; } - void print(std::ostream &os, std::function tree_walker) { + void print(std::ostream &os, std::function tree_walker) { Node *node = &root(); @@ -188,7 +188,7 @@ namespace CGAL { os << "(" << node->location()[0] << "," << node->location()[1] << "," << node->location()[2] << ") "; os << std::endl; - node = tree_walker(node); + node = tree_walker(&root(), node); } } diff --git a/Octree/include/CGAL/Octree/Tree_walker_criterion.h b/Octree/include/CGAL/Octree/Tree_walker_criterion.h index ca36730bc0e..dbeca07810a 100644 --- a/Octree/include/CGAL/Octree/Tree_walker_criterion.h +++ b/Octree/include/CGAL/Octree/Tree_walker_criterion.h @@ -6,11 +6,11 @@ namespace CGAL { struct Siblings { template - Node *operator()(Node *n) { + Node *operator()(Node *root, Node *n) { - // Null handler + // Passing null returns the first node if (nullptr == n) - return n; + return root; // If this node has no parent, it has no siblings if (nullptr == n->parent()) @@ -31,35 +31,43 @@ namespace CGAL { struct Depth_first { template - Node *operator()(Node *n) { + Node *operator()(Node *root, Node *n) { - // Null handler - if (nullptr == n) - return n; + // Passing null returns the first node + if (nullptr == n) { - if (n->isLeaf()) { + return root; + // Find the deepest child on the left +// Node *first = root; +// while (!first->is_leaf()) +// first = &(*first)[0]; +// return first; + } + + if (n->is_leaf()) { + + Siblings siblings; // Check if this node is the last sibling - if (false) { + if (7 != n->index().to_ulong()) { // Return the next sibling + return (siblings(root, n)); } else { // Return the next sibling of the parent - + // FIXME: this should be able to search upwards at the last sibling + return (siblings(root, n->parent())); } } else { // Return the first child of this node + return &(*n)[0]; } - - // TODO: placeholder - return n; - } }; } diff --git a/Octree/test/Octree/test_node_index.cpp b/Octree/test/Octree/test_node_index.cpp index e11ece0e0eb..f2a0e4446de 100644 --- a/Octree/test/Octree/test_node_index.cpp +++ b/Octree/test/Octree/test_node_index.cpp @@ -41,9 +41,8 @@ int main(void) { Octree octree(points, point_map); octree.refine(10, 1); - auto treeWalker = CGAL::Siblings(); + auto treeWalker = CGAL::Depth_first(); octree.print(std::cout, treeWalker); - //std::cout << *treeWalker(&octree.root()[6]); return 0; }