File: seam_mesh.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 (156 lines) | stat: -rw-r--r-- 6,425 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156

// Enable the operator<< for a seam vertex/halfedge/edge/face
#define CGAL_SEAM_MESH_INSERT_OPERATOR

#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>

#include <CGAL/boost/graph/Seam_mesh.h>
#include <CGAL/boost/graph/io.h>
#include <CGAL/Polygon_mesh_processing/connected_components.h>

#include <iostream>
#include <fstream>
#include <vector>

typedef CGAL::Simple_cartesian<double>                       Kernel;
typedef Kernel::Point_3                                      Point;
typedef CGAL::Surface_mesh<Point>                            Mesh;

typedef boost::graph_traits<Mesh>::vertex_descriptor         SM_vertex_descriptor;
typedef boost::graph_traits<Mesh>::halfedge_descriptor       SM_halfedge_descriptor;
typedef boost::graph_traits<Mesh>::edge_descriptor           SM_edge_descriptor;
typedef boost::graph_traits<Mesh>::face_descriptor           SM_face_descriptor;

typedef Mesh::Property_map<SM_edge_descriptor, bool>            Seam_edge_pmap;
typedef Mesh::Property_map<SM_vertex_descriptor, bool>          Seam_vertex_pmap;
typedef CGAL::Seam_mesh<Mesh, Seam_edge_pmap, Seam_vertex_pmap> Seam_mesh;

typedef boost::graph_traits<Seam_mesh>::vertex_descriptor         vertex_descriptor;
typedef boost::graph_traits<Seam_mesh>::halfedge_descriptor       halfedge_descriptor;
typedef boost::graph_traits<Seam_mesh>::edge_descriptor           edge_descriptor;
typedef boost::graph_traits<Seam_mesh>::face_descriptor           face_descriptor;

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

  Mesh sm;
  if(!CGAL::IO::read_polygon_mesh(filename, sm))
  {
    std::cerr << "Invalid input." << std::endl;
    return 1;
  }

  Seam_edge_pmap seam_edge_pm =
      sm.add_property_map<SM_edge_descriptor, bool>("e:on_seam", false).first;
  Seam_vertex_pmap seam_vertex_pm =
      sm.add_property_map<SM_vertex_descriptor, bool>("v:on_seam",false).first;

  Seam_mesh mesh(sm, seam_edge_pm, seam_vertex_pm);

  // Add seams. Below are two different seam selection files (choose one).
  // 1st: Split the cube in two connected components
  // 2nd: Seams are all edges incident to a vertex
  SM_halfedge_descriptor smhd = mesh.add_seams("data/two_connected_components.selection.txt");
  // SM_halfedge_descriptor smhd = mesh.add_seams("data/flatten.selection.txt");

  assert(smhd != SM_halfedge_descriptor());

  std::cout << "Added: " << mesh.number_of_seam_edges() << " seam edges" << std::endl;

  halfedge_descriptor bhd(smhd);
  std::cout << "First seam halfedge: " << smhd << std::endl;
  std::cout << "source = " << source(smhd, mesh)
            << " (pointing to vertex: " << source(smhd, sm) << ")" << std::endl;
  std::cout << "target = " << target(smhd, mesh)
            << " (pointing to vertex: " << target(smhd, sm) << ")" << std::endl;

  std::cout << "prev of seam halfedge in (base) mesh: " << prev(smhd, sm) << std::endl;
  std::cout << "prev of seam halfedge in seam mesh: " << prev(bhd, mesh) << std::endl;

  std::cout << "next of seam halfedge in (base) mesh: " << next(smhd, sm) << std::endl;
  std::cout << "next of seam halfedge in seam mesh: " << next(bhd, mesh) << std::endl;

  std::cout << "opposite of seam halfedge in (base) mesh: " << opposite(smhd, sm) << std::endl;
  std::cout << "opposite of seam halfedge in seam mesh: " << opposite(bhd, mesh) << std::endl;

  std::cout << "vertices on one of the seams" << std::endl;
  for(halfedge_descriptor hd :
                halfedges_around_face(opposite(bhd, mesh), mesh)){
    std::cout << target(hd.tmhd, sm) << " ";
  }
  std::cout << std::endl;

  std::cout << "vertices around " << target(smhd , sm) << " in (base) mesh" << std::endl;
  for(SM_halfedge_descriptor hd : halfedges_around_target(smhd, sm)){
    std::cout << source(hd, sm) << " ";
  }
  std::cout << std::endl;

  std::cout << "vertices around " << target(bhd , mesh) << " in seam mesh" << std::endl;
  for(halfedge_descriptor hd : halfedges_around_target(bhd, mesh)){
    std::cout << source(hd.tmhd, sm) << " ";
  }
  std::cout << std::endl;

  std::cout << "vertices around " << source(smhd , sm) << " in (base) mesh" << std::endl;
  for(SM_halfedge_descriptor hd :
                halfedges_around_source(source(smhd, sm), sm)){
     std::cout << target(hd, sm) << " ";
  }
  std::cout << std::endl;

  std::cout << "vertices around " << source(bhd , mesh) << " in seam mesh" << std::endl;
  for(halfedge_descriptor hd :
                halfedges_around_source(source(bhd, mesh), mesh)){
    std::cout << target(hd.tmhd, sm) << " ";
  }
  std::cout << std::endl;

  std::cout << "vertices around vertices in seam mesh" << std::endl;
  for(vertex_descriptor vd : vertices(mesh)){
    halfedge_descriptor hd = halfedge(vd, mesh);
    std::cout << " " << vd << " has incident vertices:" << std::endl;
    for(halfedge_descriptor hd2 : halfedges_around_target(hd, mesh)){
      std::cout << "  " << hd2;
    }
    std::cout << std::endl;
  }
  std::cout << "done" << std::endl;

  std::cout << "the (base) mesh has: " << num_halfedges(sm) << " halfedges" << std::endl;
  std::cout << "the seam mesh has: " << num_halfedges(mesh) << " halfedges" << std::endl;
  std::cout << "halfedges in (base) mesh" << std::endl;
  for(SM_halfedge_descriptor hd : halfedges(sm)){
     std::cout << hd << " ";
  }
  std::cout << std::endl;

  std::cout << "halfedges in seam mesh" << std::endl;
  for(halfedge_descriptor hd : halfedges(mesh)){
     std::cout << hd << " ";
  }
  std::cout << std::endl;

  std::cout << "faces of the base and seam meshes" << std::endl;
  for(face_descriptor fd : faces(mesh)){
    std::cout << fd << " ";
  }
  std::cout << std::endl;

  std::vector<face_descriptor> faces;
  CGAL::Polygon_mesh_processing::connected_component(face(bhd, mesh),
                                                     mesh,
                                                     std::back_inserter(faces));
  std::cout << "the connected component (in the seam mesh) given by halfedge: "  << smhd;
  std::cout << " has " << faces.size() << " faces." << std::endl;

  std::cout << "accessing coordinates of the source of halfedge " << smhd << ": ";
  boost::property_map<Seam_mesh, CGAL::vertex_point_t>::type vpm =
                                                    get(CGAL::vertex_point, mesh);
  std::cout << get(vpm, source(smhd, mesh)) << std::endl;

  return 0;
}