#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>
void dump_as_polylines(const Octree& ot)
{
std::ofstream out("octree.polylines.txt");
{
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);
}
A data structure using an axis-aligned hyperrectangle decomposition of dD space for efficient access ...
Definition: Orthtree.h:117
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
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
A class used for performing a traversal on leaves only.
Definition: Traversals.h:113