File: match_faces.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 (59 lines) | stat: -rw-r--r-- 2,124 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
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Polyhedron_3.h>

#include <CGAL/boost/graph/copy_face_graph.h>
#include <CGAL/boost/graph/Euler_operations.h>
#include <CGAL/Polygon_mesh_processing/measure.h>
#include <CGAL/Named_function_parameters.h>
#include <CGAL/boost/graph/named_params_helper.h>
#include <CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h>

#include <iostream>
#include <iterator>
#include <string>

typedef CGAL::Exact_predicates_inexact_constructions_kernel       K;

typedef K::Point_3                                                Point;

typedef CGAL::Surface_mesh<Point>                                 Surface_mesh;
typedef CGAL::Polyhedron_3<K>                                     Polyhedron;
typedef boost::graph_traits<Surface_mesh>::face_descriptor        face_descriptor_1;
typedef boost::graph_traits<Polyhedron>::face_descriptor          face_descriptor_2;
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/P.off");

  Surface_mesh mesh1;
  Polyhedron mesh2;
  if(!PMP::IO::read_polygon_mesh(filename1, mesh1))
  {
    std::cerr << "Invalid input." << std::endl;
    return 1;
  }
  CGAL::copy_face_graph(mesh1, mesh2);
  CGAL::Euler::add_center_vertex(*halfedges(mesh2).begin(),mesh2);
  std::vector<std::pair<face_descriptor_1, face_descriptor_2> > common;
  std::vector<face_descriptor_1> m1_only;
  std::vector<face_descriptor_2> m2_only;

  PMP::match_faces(mesh1, mesh2, std::back_inserter(common), std::back_inserter(m1_only), std::back_inserter(m2_only));

  std::cout <<"Faces only in m1 :"<< std::endl;
  for(const face_descriptor_1& f : m1_only)
    std::cout << " " << f;

  std::cout <<"\n\nFaces only in m2:" << std::endl;
  for(const face_descriptor_2& f : m2_only)
    std::cout << " " << &(*f);

  std::cout << "\n\nFaces in both:" << std::endl;
  for(const auto& f_pair : common)
    std::cout << " (" << f_pair.first << ", " << &(*f_pair.second);
  std::cout << std::endl;

  return 0;
}