File: octree_surface_mesh.cpp

package info (click to toggle)
cgal 6.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 144,952 kB
  • sloc: cpp: 811,597; ansic: 208,576; sh: 493; python: 411; makefile: 286; javascript: 174
file content (68 lines) | stat: -rw-r--r-- 2,998 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#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);
}