Skip to content

Commit

Permalink
Implement leaves traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonCampolattaro committed Jun 27, 2020
1 parent 7e78099 commit 52afe2e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 11 deletions.
51 changes: 40 additions & 11 deletions Octree/include/CGAL/Octree/Tree_walker_criterion.h
Expand Up @@ -27,6 +27,25 @@ namespace CGAL {
return &((*n->parent())[index + 1]);
}

template<class Node>
const Node *next_sibling_up(const Node *n) {

if (!n)
return nullptr;

auto up = n->parent();

while (nullptr != up) {

if (nullptr != next_sibling(up))
return next_sibling(up);

up = up->parent();
}

return nullptr;
}

template<class Node>
const Node *deepest_first_child(const Node *n) {

Expand Down Expand Up @@ -56,17 +75,7 @@ namespace CGAL {

if (nullptr == next) {

auto up = n->parent();

while (nullptr != up) {

if (nullptr != next_sibling(up))
return next_sibling(up);

up = up->parent();
}

return nullptr;
return next_sibling_up(n);
}

return next;
Expand Down Expand Up @@ -99,6 +108,26 @@ namespace CGAL {
return next;
}
};

struct Leaves {

template<class Node>
const Node *first(const Node *root) {

return deepest_first_child(root);
}

template<class Node>
const Node *operator()(const Node *n) {

auto next = deepest_first_child(next_sibling(n));

if (!next)
next = deepest_first_child(next_sibling_up(n));

return next;
}
};
}

#endif //OCTREE_TREE_WALKER_CRITERION_H
17 changes: 17 additions & 0 deletions Octree/test/Octree/test_tree_walk.cpp
Expand Up @@ -69,10 +69,27 @@ int test_postorder_print() {
return 0;
}

int test_leaves_print() {

std::cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~" << std::endl;

auto points = create_example_point_collection();

auto point_map = points.point_map();
Octree octree(points, point_map);
octree.refine(10, 1);

auto tree_walker = CGAL::Leaves();
octree.print(std::cout, tree_walker.first(&octree.root()), tree_walker);

return 0;
}

int main(void) {

test_preorder_print();
test_postorder_print();
test_leaves_print();

return 0;
}

0 comments on commit 52afe2e

Please sign in to comment.