Skip to content

Commit

Permalink
Add print method which takes a tree walker as an argument
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonCampolattaro committed Jun 25, 2020
1 parent 8222f93 commit 1784035
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
16 changes: 16 additions & 0 deletions Octree/include/CGAL/Octree.h
Expand Up @@ -176,6 +176,22 @@ namespace CGAL {

const Node &root() const { return m_root; }

void print(std::ostream &os, std::function<Node *(Node *)> tree_walker) {

Node *node = &root();

while (nullptr != node) {

for (int i = 0; i < node->depth(); ++i)
os << ". ";

os << "(" << node->location()[0] << "," << node->location()[1] << "," << node->location()[2] << ") ";
os << std::endl;

node = tree_walker(node);
}
}

bool operator==(Octree<PointRange, PointMap> &rhs) {

// Identical trees should have the same bounding box
Expand Down
6 changes: 3 additions & 3 deletions Octree/include/CGAL/Octree/IO.h
Expand Up @@ -10,10 +10,10 @@
using std::ostream;

template<class Kernel, class PointRange>
void writeToStream(ostream &os, const CGAL::Octree_node<Kernel, PointRange> &node, int depth = 0) {
void writeToStream(ostream &os, const CGAL::Octree_node<Kernel, PointRange> &node) {

// Set indentation
for (int i = 0; i < depth; ++i) {
for (int i = 0; i < node.depth(); ++i) {
os << ". ";
}

Expand All @@ -28,7 +28,7 @@ void writeToStream(ostream &os, const CGAL::Octree_node<Kernel, PointRange> &nod
// Print out this node's children
if (!node.is_leaf()) {
for (int i = 0; i < 8; ++i) {
writeToStream(os, node[i], depth + 1);
writeToStream(os, node[i]);
}
}
}
Expand Down
12 changes: 2 additions & 10 deletions Octree/test/Octree/test_node_index.cpp
Expand Up @@ -41,17 +41,9 @@ int main(void) {
Octree octree(points, point_map);
octree.refine(10, 1);

std::cout << octree.root();
std::cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << std::endl;

std::cout << "Node: " << std::endl;
std::cout << octree.root()[6];
std::cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << std::endl;

std::cout << "Sibling: " << std::endl;
auto treeWalker = CGAL::Siblings();
std::cout << *treeWalker(&octree.root()[6]);

octree.print(std::cout, treeWalker);
//std::cout << *treeWalker(&octree.root()[6]);

return 0;
}

0 comments on commit 1784035

Please sign in to comment.