Skip to content

Commit

Permalink
Add preorder traversal example
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonCampolattaro committed Aug 11, 2020
1 parent 306bf5f commit 8091145
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Octree/examples/Octree/Octree_build_from_Point_set.cpp
Expand Up @@ -27,7 +27,7 @@ int main(int argc, char **argv) {
std::cerr << "Error: cannot read file" << std::endl;
return EXIT_FAILURE;
}
std::cout << "loaded " << points.number_of_points() << " points" << std::endl;
std::cout << "loaded " << points.number_of_points() << " points\n" << std::endl;

// Create an octree from the points
Octree octree(points, points.point_map());
Expand Down
45 changes: 45 additions & 0 deletions Octree/examples/Octree/Octree_traversal_preorder.cpp
@@ -0,0 +1,45 @@
#include <fstream>
#include <iostream>

#include <CGAL/Simple_cartesian.h>
#include <CGAL/Octree.h>
#include <CGAL/Octree/IO.h>
#include <CGAL/Point_set_3.h>
#include <CGAL/Point_set_3/IO.h>

// Type Declarations
typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::Point_3 Point;
typedef CGAL::Point_set_3<Point> Point_set;
typedef Point_set::Point_map Point_map;
typedef CGAL::Octree::Octree<Point_set, Point_map> Octree;

int main(int argc, char **argv) {

// Point set will be used to hold our points
Point_set points;

// Load points from a file.
std::ifstream stream((argc > 1) ? argv[1] : "data/cube.pwn");
stream >> points;
if (0 == points.number_of_points()) {

std::cerr << "Error: cannot read file" << std::endl;
return EXIT_FAILURE;
}
std::cout << "loaded " << points.number_of_points() << " points\n" << std::endl;

// Create an octree from the points
Octree octree(points, points.point_map());

// Build the octree
octree.refine();

// Print out the octree using preorder traversal
for (auto &node : octree.walk<CGAL::Octree::Traversal::Preorder>()) {

std::cout << node << std::endl;
}

return EXIT_SUCCESS;
}

0 comments on commit 8091145

Please sign in to comment.