mirror of https://github.com/CGAL/cgal
Custom traversal example
This commit is contained in:
parent
65ee28d33c
commit
83b8a0dc71
|
|
@ -148,17 +148,14 @@ In this case, we print out the nodes of the tree without indentation instead.
|
|||
|
||||
\cgalExample{Orthtree/Octree_traversal_preorder.cpp}
|
||||
|
||||
<!--
|
||||
\subsection Section_Orthtree_Custom_Traversal Using a Custom Traversal Method
|
||||
\subsection Section_Orthtree_Custom_Traversal Custom Traversal
|
||||
|
||||
\b Example
|
||||
|
||||
e.g. I've build a tree and I want to print it out, but layer by layer
|
||||
Users can define their own traversal methods by creating models of the
|
||||
`Traversal` concept. The following example shows how to define a
|
||||
custom traversal that only traverses the first branch of the %Octree:
|
||||
|
||||
\cgalExample{Orthtree/Octree_traversal_custom.cpp}
|
||||
|
||||
!-->
|
||||
|
||||
\section Section_Orthtree_Acceleration Acceleration of Common Tasks
|
||||
|
||||
Once an %Orthtree is built, its structure can be used to accelerate different tasks.
|
||||
|
|
|
|||
|
|
@ -1,3 +1,60 @@
|
|||
// TODO
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
int main() { return 0; }
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/Octree.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<Kernel, Point_set, Point_map> Octree;
|
||||
|
||||
struct First_branch_traversal
|
||||
{
|
||||
template <typename Node>
|
||||
Node first (Node root) const
|
||||
{
|
||||
return root;
|
||||
}
|
||||
|
||||
template <typename Node>
|
||||
Node next (Node n) const
|
||||
{
|
||||
if (n.is_leaf())
|
||||
return Node();
|
||||
return n[0];
|
||||
}
|
||||
};
|
||||
|
||||
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 first branch using custom traversal
|
||||
for (auto &node : octree.traverse<First_branch_traversal>())
|
||||
std::cout << node << std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue