File: corefinement_OM_union.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 (101 lines) | stat: -rw-r--r-- 3,388 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh>

#include <CGAL/boost/graph/graph_traits_PolyMesh_ArrayKernelT.h>

#include <CGAL/Polygon_mesh_processing/corefinement.h>

#include <iostream>
#include <string>

typedef CGAL::Exact_predicates_inexact_constructions_kernel   K; // default kernel for OpenMesh point type
typedef CGAL::Exact_predicates_exact_constructions_kernel     EK; // alternatice kernel we want to use
typedef OpenMesh::PolyMesh_ArrayKernelT< >                    Mesh;

typedef boost::property_map<Mesh, CGAL::dynamic_vertex_property_t<EK::Point_3> >::type Exact_point_map;

struct Exact_vertex_point_map
{
  // typedef for the property map
  typedef boost::property_traits<Exact_point_map>::value_type value_type;
  typedef boost::property_traits<Exact_point_map>::reference reference;
  typedef boost::property_traits<Exact_point_map>::key_type key_type;
  typedef boost::read_write_property_map_tag category;

  // exterior references
  Exact_point_map exact_point_map;
  Mesh* tm_ptr;

  // Converters
  CGAL::Cartesian_converter<K, EK> to_exact;
  CGAL::Cartesian_converter<EK, K> to_input;

  Exact_vertex_point_map()
    : tm_ptr(nullptr)
  {}

  Exact_vertex_point_map(const Exact_point_map& ep, Mesh& tm)
    : exact_point_map(ep)
    , tm_ptr(&tm)
  {
    for (key_type v : vertices(tm))
      put(exact_point_map, v, to_exact(get(boost::vertex_point, tm, v)));
  }

  friend
  reference get(const Exact_vertex_point_map& map, key_type k)
  {
    CGAL_precondition(map.tm_ptr!=nullptr);
    return get(map.exact_point_map, k);
  }

  friend
  void put(const Exact_vertex_point_map& map, key_type k, const EK::Point_3& p)
  {
    CGAL_precondition(map.tm_ptr!=nullptr);
    put(map.exact_point_map, k, p);
    // create the input point from the exact one
    put(boost::vertex_point, *map.tm_ptr, k, map.to_input(p));
  }
};

namespace PMP = CGAL::Polygon_mesh_processing;

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

  Mesh mesh1, mesh2;

  OpenMesh::IO::read_mesh(mesh1, filename1);
  OpenMesh::IO::read_mesh(mesh2, filename2);

  Mesh out;

  // Create exact map properties
  Exact_point_map pm_1  = get(CGAL::dynamic_vertex_property_t<EK::Point_3>(), mesh1);
  Exact_point_map pm_2  = get(CGAL::dynamic_vertex_property_t<EK::Point_3>(), mesh2);
  Exact_point_map pm_out  = get(CGAL::dynamic_vertex_property_t<EK::Point_3>(), out);

  // Create exact vertex point map that will provide the point to another kernel and fill the default map
  Exact_vertex_point_map vpm_1(pm_1, mesh1);
  Exact_vertex_point_map vpm_2(pm_2, mesh2);
  Exact_vertex_point_map vpm_out(pm_out, out);

  bool valid_union = PMP::corefine_and_compute_union(mesh1, mesh2, out,
    CGAL::parameters::vertex_point_map(vpm_1),
    CGAL::parameters::vertex_point_map(vpm_2),
    CGAL::parameters::vertex_point_map(vpm_out));

  if (valid_union)
  {
    std::cout << "Union was successfully computed\n";
    OpenMesh::IO::write_mesh(out, "union.off");
    return 0;
  }
  std::cout << "Union could not be computed\n";
  return 1;
}