CGAL 6.0.2 - Quadtrees, Octrees, and Orthtrees

Loading...
Searching...
No Matches
Orthtree/octree_surface_mesh.cpp
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Octree.h>
#include <CGAL/Orthtree_traits_face_graph.h>
#include <CGAL/boost/graph/IO/polygon_mesh_io.h>
using K = CGAL::Exact_predicates_inexact_constructions_kernel;
using Mesh = CGAL::Surface_mesh<K::Point_3>;
using OTraits = CGAL::Orthtree_traits_face_graph<Mesh, Mesh::Property_map<Mesh::Vertex_index, K::Point_3>>;
using Octree = CGAL::Orthtree<OTraits>;
void dump_as_polylines(const Octree& ot)
{
std::ofstream out("octree.polylines.txt");
for (Octree::Node_index node : ot.traverse(CGAL::Orthtrees::Leaves_traversal<Octree>(ot)))
{
if (!ot.is_leaf(node))
continue;
auto bb = ot.bbox(node);
out << "2 " << bb.xmin() << " " << bb.ymin() << " " << bb.zmin()
<< " " << bb.xmax() << " " << bb.ymin() << " " << bb.zmin() << "\n";
out << "2 " << bb.xmin() << " " << bb.ymin() << " " << bb.zmin()
<< " " << bb.xmin() << " " << bb.ymax() << " " << bb.zmin() << "\n";
out << "2 " << bb.xmax() << " " << bb.ymin() << " " << bb.zmin()
<< " " << bb.xmax() << " " << bb.ymax() << " " << bb.zmin() << "\n";
out << "2 " << bb.xmin() << " " << bb.ymax() << " " << bb.zmin()
<< " " << bb.xmax() << " " << bb.ymax() << " " << bb.zmin() << "\n";
//
out << "2 " << bb.xmin() << " " << bb.ymin() << " " << bb.zmin()
<< " " << bb.xmin() << " " << bb.ymin() << " " << bb.zmax() << "\n";
out << "2 " << bb.xmax() << " " << bb.ymin() << " " << bb.zmin()
<< " " << bb.xmax() << " " << bb.ymin() << " " << bb.zmax() << "\n";
out << "2 " << bb.xmin() << " " << bb.ymax() << " " << bb.zmin()
<< " " << bb.xmin() << " " << bb.ymax() << " " << bb.zmax() << "\n";
out << "2 " << bb.xmax() << " " << bb.ymax() << " " << bb.zmin()
<< " " << bb.xmax() << " " << bb.ymax() << " " << bb.zmax() << "\n";
//
out << "2 " << bb.xmin() << " " << bb.ymin() << " " << bb.zmax()
<< " " << bb.xmax() << " " << bb.ymin() << " " << bb.zmax() << "\n";
out << "2 " << bb.xmin() << " " << bb.ymin() << " " << bb.zmax()
<< " " << bb.xmin() << " " << bb.ymax() << " " << bb.zmax() << "\n";
out << "2 " << bb.xmax() << " " << bb.ymin() << " " << bb.zmax()
<< " " << bb.xmax() << " " << bb.ymax() << " " << bb.zmax() << "\n";
out << "2 " << bb.xmin() << " " << bb.ymax() << " " << bb.zmax()
<< " " << bb.xmax() << " " << bb.ymax() << " " << bb.zmax() << "\n";
}
}
int main(int argc, char** argv)
{
const std::string filename = (argc > 1) ? argv[1] : CGAL::data_file_path("meshes/elephant.off");
Mesh mesh;
if(!CGAL::IO::read_polygon_mesh(filename, mesh))
{
std::cerr << "Error: cannot read file" << std::endl;
return EXIT_FAILURE;
}
Octree tree(mesh, mesh.points());
OTraits::Split_predicate_node_min_extent sp(0.01);
tree.refine(sp);
dump_as_polylines(tree);
}
CGAL::Exact_predicates_inexact_constructions_kernel
CGAL::Orthtree
A data structure using an axis-aligned hyperrectangle decomposition of dD space for efficient access ...
Definition: Orthtree.h:117
CGAL::Surface_mesh
CGAL::Octree
Orthtree< Orthtree_traits_point< GeomTraits, PointRange, PointMap, cubic_nodes, 3 > > Octree
Alias that specializes the Orthtree class to a 3D octree storing 3D points.
Definition: Octree.h:38
CGAL::Orthtree_traits_face_graph
Traits class for the Orthtree class to be used to construct a 3D octree around a triangulated surface...
Definition: Orthtree_traits_face_graph.h:42
CGAL::Orthtrees::Leaves_traversal
A class used for performing a traversal on leaves only.
Definition: Traversals.h:113