Skip to content

Commit

Permalink
Attempt several tree walker solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonCampolattaro committed Jul 7, 2020
1 parent 3a7851c commit f48b384
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 62 deletions.
20 changes: 16 additions & 4 deletions Octree/include/CGAL/Octree.h
Expand Up @@ -291,10 +291,22 @@ namespace CGAL {
}

template<class Walker>
Node_range nodes() const {
Node_walker first = Walker::first;
Node_walker next = Walker::next;
return nodes(first(m_root), next);
Node_range nodes(const Walker &walker) const {

const Node *first = walker.first(&m_root);

// Node_walker next =
// [=](const Node *n) -> const Node * {
// return walker.next(n);
// };

// Node_walker next = boost::bind(&Walker::next, walker, _1);

Node_walker next = walker;

return boost::make_iterator_range(Walker_iterator<const Node>(first, walker),
Walker_iterator<const Node>());
//return nodes(first, next);
}

/// @}
Expand Down
106 changes: 50 additions & 56 deletions Octree/include/CGAL/Octree/Walker_criterion.h
Expand Up @@ -2,6 +2,7 @@
#define OCTREE_WALKER_CRITERION_H

#include <iostream>
#include <boost/range/iterator_range.hpp>
#include "Node.h"
#include "Walker_iterator.h"

Expand All @@ -12,7 +13,7 @@ namespace CGAL {
namespace Walker {

template<class Value>
const Node::Node<Value> *next_sibling(const Node::Node<Value> *n) {
const Node::Node <Value> *next_sibling(const Node::Node <Value> *n) {

// Passing null returns the first node
if (nullptr == n)
Expand All @@ -34,7 +35,7 @@ namespace CGAL {
}

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

if (!n)
return nullptr;
Expand All @@ -53,7 +54,7 @@ namespace CGAL {
}

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

if (!n)
return nullptr;
Expand All @@ -70,12 +71,12 @@ namespace CGAL {
public:

template<class Value>
static const Node::Node<Value> *first(const Node::Node<Value> *root) {
static const Node::Node <Value> *first(const Node::Node <Value> *root) {
return root;
}

template<class Value>
static const Node::Node<Value> *next(const Node::Node<Value> *n) {
static const Node::Node <Value> *next(const Node::Node <Value> *n) {

if (n->is_leaf()) {

Expand All @@ -101,12 +102,12 @@ namespace CGAL {
struct Preorder {

template<class Value>
const Node::Node<Value> *first(const Node::Node<Value> *root) {
const Node::Node <Value> *first(const Node::Node <Value> *root) const {
return root;
}

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

if (n->is_leaf()) {

Expand All @@ -131,13 +132,13 @@ namespace CGAL {
struct Postorder {

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

return deepest_first_child(root);
}

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

auto next = deepest_first_child(next_sibling(n));

Expand All @@ -151,13 +152,13 @@ namespace CGAL {
struct Leaves {

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

return deepest_first_child(root);
}

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

auto next = deepest_first_child(next_sibling(n));

Expand All @@ -169,54 +170,47 @@ namespace CGAL {
};


// class Tree_walker {
// class Tree_walker {
//
// template<class Kernel, class PointRange>
// static const Octree_node <Kernel, PointRange> *first(const Octree_node <Kernel, PointRange> *root) {
// return root;
// }
// public:
//
// template<class Kernel, class PointRange>
// static const Octree_node <Kernel, PointRange> *next(const Octree_node <Kernel, PointRange> *node) {
// return node;
// }
// };

// class Preorder_tree_walker {
//
// public:
//
// Preorder_tree_walker() {
//
// }
//
// template<class Kernel, class PointRange>
// static const Octree_node<Kernel, PointRange> *first(const Octree_node <Kernel, PointRange> *root) {
// return root;
// }
//
// template<class Kernel, class PointRange>
// static const Octree_node <Kernel, PointRange> *next(const Octree_node <Kernel, PointRange> *n) {
//
// if (n->is_leaf()) {
//
// auto next = next_sibling(n);
//
// if (nullptr == next) {
//
// return next_sibling_up(n);
// }
//
// return next;
// template<class Value>
// virtual const Node::Node <Value> *first(const Node::Node <Value> *root) const = 0;
//
// } else {
//
// // Return the first child of this node
// return &(*n)[0];
// }
//
// }
// };
// template<class Value>
// virtual const Node::Node <Value> *next(const Node::Node <Value> *n) const = 0;
// };

class Preorder_tree_walker {

public:

template<class Value>
const Node::Node <Value> *first(const Node::Node <Value> *root) const {
return root;
}

template<class Value>
const Node::Node <Value> *next(const Node::Node <Value> *n) const {

if (n->is_leaf()) {

auto next = next_sibling(n);

if (nullptr == next) {

return next_sibling_up(n);
}

return next;

} else {

return &(*n)[0];
}

}
};


}
Expand Down
8 changes: 6 additions & 2 deletions Octree/test/Octree/test_tree_walk.cpp
Expand Up @@ -34,8 +34,7 @@ bool test_preorder_1_node() {

// Check each item in the range
auto iter = nodes.begin();
if (!(*iter == octree.root()))
return false;
assert(*iter == octree.root());

return true;
}
Expand Down Expand Up @@ -88,6 +87,11 @@ bool test_preorder_25_nodes() {
auto first = tree_walker.first(&octree.root());
auto nodes = octree.nodes(first, tree_walker);

for (auto &n : nodes) {
std::cout << n;
}
std::cout << "xxx";

// Check each item in the range
auto iter = nodes.begin();
if(!(*iter == octree.root()))
Expand Down

0 comments on commit f48b384

Please sign in to comment.