File: vsa_class_interface_example.cpp

package info (click to toggle)
cgal 6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144,912 kB
  • sloc: cpp: 810,858; ansic: 208,477; sh: 493; python: 411; makefile: 286; javascript: 174
file content (73 lines) | stat: -rw-r--r-- 2,248 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
69
70
71
72
73
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>

#include <CGAL/Variational_shape_approximation.h>
#include <CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h>

#include <iostream>
#include <fstream>

namespace VSA = CGAL::Surface_mesh_approximation;

typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef CGAL::Surface_mesh<Kernel::Point_3> Mesh;

typedef boost::property_map<Mesh, boost::vertex_point_t>::type Vertex_point_map;
typedef CGAL::Variational_shape_approximation<Mesh, Vertex_point_map> Mesh_approximation;

// L21 error metric
typedef Mesh_approximation::Error_metric L21_metric;

int main(int argc, char** argv)
{
  const std::string filename = (argc > 1) ? argv[1] : CGAL::data_file_path("meshes/bear.off");

  // reads input surface triangle mesh
  Mesh mesh;
  if(!CGAL::Polygon_mesh_processing::IO::read_polygon_mesh(filename, mesh) ||
     !CGAL::is_triangle_mesh(mesh))
  {
    std::cerr << "Invalid input file." << std::endl;
    return EXIT_FAILURE;
  }

  Vertex_point_map vpmap = get(boost::vertex_point, const_cast<Mesh &>(mesh));

  // error metric and fitting function
  L21_metric error_metric(mesh, vpmap);

  // creates VSA algorithm instance
  Mesh_approximation approx(mesh, vpmap, error_metric);

  // seeds 100 random proxies
  approx.initialize_seeds(CGAL::parameters::seeding_method(VSA::RANDOM)
      .max_number_of_proxies(100));

  // runs 30 iterations
  approx.run(30);

  // adds 3 proxies to the one with the maximum fitting error,
  // running 5 iterations between each addition
  approx.add_to_furthest_proxies(3, 5);

  // runs 10 iterations
  approx.run(10);

  // teleports 2 proxies to tunnel out of local minima,
  // running 5 iterations between each teleport
  approx.teleport_proxies(2, 5);

  // runs 10 iterations
  approx.run(10);

  // extract approximated mesh with default parameters
  approx.extract_mesh(CGAL::parameters::default_values());

  // get approximated triangle soup
  std::vector<Kernel::Point_3> anchors;
  std::vector<std::array<std::size_t, 3> > triangles;
  approx.output(CGAL::parameters::anchors(std::back_inserter(anchors)).
    triangles(std::back_inserter(triangles)));

  return EXIT_SUCCESS;
}