File: hierarchy_simplification_example.cpp

package info (click to toggle)
cgal 6.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 141,840 kB
  • sloc: cpp: 797,081; ansic: 203,398; sh: 490; python: 411; makefile: 286; javascript: 174
file content (48 lines) | stat: -rw-r--r-- 1,575 bytes parent folder | download | duplicates (2)
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
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>

#include <CGAL/IO/read_points.h>
#include <CGAL/IO/write_points.h>
#include <CGAL/hierarchy_simplify_point_set.h>
#include <CGAL/Memory_sizer.h>
#include <CGAL/Timer.h>

#include <vector>
#include <fstream>

// types
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point;

int main(int argc, char*argv[])
{
  const std::string fname = (argc>1) ? argv[1] : CGAL::data_file_path("points_3/oni.pwn");

  // Reads a point set file in points[].
  std::vector<Point> points;
  if(!CGAL::IO::read_points(fname, std::back_inserter(points)))
  {
    std::cerr << "Error: cannot read file " << fname << std::endl;
    return EXIT_FAILURE;
  }

  std::cout << "Read " << points.size () << " point(s)" << std::endl;

  CGAL::Timer task_timer; task_timer.start();

  // simplification by clustering using erase-remove idiom
  points.erase(CGAL::hierarchy_simplify_point_set(points,
                                                  CGAL::parameters::size(100)// Max cluster size
                                                                   .maximum_variation(0.01)), // Max surface variation
               points.end());

  std::size_t memory = CGAL::Memory_sizer().virtual_size();

  std::cout << points.size () << " point(s) kept, computed in "
            << task_timer.time() << " seconds, "
            << (memory>>20) << " Mib allocated." << std::endl;

  CGAL::IO::write_points("out.xyz", points, CGAL::parameters::stream_precision(17));

  return EXIT_SUCCESS;
}