mirror of https://github.com/CGAL/cgal
Begin implementing depth first traversal
This commit is contained in:
parent
0ae7a4f07a
commit
c32fb24efb
|
|
@ -176,7 +176,7 @@ namespace CGAL {
|
|||
|
||||
const Node &root() const { return m_root; }
|
||||
|
||||
void print(std::ostream &os, std::function<Node *(Node *)> tree_walker) {
|
||||
void print(std::ostream &os, std::function<Node *(Node *, Node *)> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@ namespace CGAL {
|
|||
struct Siblings {
|
||||
|
||||
template<class Node>
|
||||
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<class Node>
|
||||
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;
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue