This example shows how to access the adjacency information of a surface mesh, i.e.,
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#include <easy3d/core/surface_mesh.h>
28#include <easy3d/util/initializer.h>
29
41
43
44
45
46
47
48#define USE_FOR_LOOP
49
50
52
54
55
60
61
62 mesh->add_triangle(v0, v1, v3);
63 mesh->add_triangle(v1, v2, v3);
64 mesh->add_triangle(v2, v0, v3);
65 mesh->add_triangle(v0, v2, v1);
66
67 return mesh;
68}
69
70
71int main(int argc, char** argv) {
72
74
75 SurfaceMesh* mesh = old_mesh_from_previous_example();
76
77 std::cout << "----------------------------------------\n";
78 std::cout << "The incident vertices of each vertex" << std::endl;
79 std::cout << "----------------------------------------\n";
80
81
82 for (auto v : mesh->vertices()) {
83 std::cout << "incident vertices of vertex " << v << ": ";
84#ifdef USE_FOR_LOOP
85
86 for (auto vv : mesh->vertices(v))
87 std::cout << vv << " ";
88#else
91 do {
93 std::cout << vv << " ";
94 ++cir;
95 } while (cir != end);
96#endif
97 std::cout << std::endl;
98 }
99
100 std::cout << "\n--------------------------------------\n";
101 std::cout << "The incident outgoing/ingoing edges of each vertex" << std::endl;
102 std::cout << "----------------------------------------\n";
103
104
105 for (auto v : mesh->vertices()) {
106 std::cout << "incident outgoing/ingoing edges of vertex " << v << ": ";
107#ifdef USE_FOR_LOOP
108
109 for (auto h : mesh->halfedges(v))
110 std::cout << h << "/" << mesh->opposite(h) << " ";
111#else
114 do {
116 std::cout << h << "/" << mesh->opposite(h) << " ";
117 ++cir;
118 } while (cir != end);
119#endif
120 std::cout << std::endl;
121 }
122
123 std::cout << "\n--------------------------------------\n";
124 std::cout << "The incident faces of each vertex" << std::endl;
125 std::cout << "----------------------------------------\n";
126
127
128 for (auto v : mesh->vertices()) {
129 std::cout << "incident faces of vertex " << v << ": ";
130#ifdef USE_FOR_LOOP
131
132 for (auto f : mesh->faces(v))
133 std::cout << f << " ";
134#else
137 do {
139 std::cout << f << " ";
140 ++cir;
141 } while (cir != end);
142#endif
143 std::cout << std::endl;
144 }
145
146 std::cout << "\n--------------------------------------\n";
147 std::cout << "The incident vertices of each face" << std::endl;
148 std::cout << "----------------------------------------\n";
149
150
151 for (auto f : mesh->faces()) {
152 std::cout << "incident vertices of face " << f << ": ";
153#ifdef USE_FOR_LOOP
154
155 for (auto v : mesh->vertices(f))
156 std::cout << v << " ";
157#else
160 do {
162 std::cout << v << " ";
163 ++cir;
164 } while (cir != end);
165#endif
166 std::cout << std::endl;
167 }
168
169 std::cout << "\n--------------------------------------\n";
170 std::cout << "The incident half-edges of each face" << std::endl;
171 std::cout << "----------------------------------------\n";
172
173
174 for (auto f : mesh->faces()) {
175 std::cout << "half-edges around face " << f << ": ";
176#ifdef USE_FOR_LOOP
177
178 for (auto h : mesh->halfedges(f))
179 std::cout << h << " ";
180#else
183 do {
185 std::cout << h << " ";
186 ++cir;
187 } while (cir != end);
188#endif
189 std::cout << std::endl;
190 }
191
192 std::cout << "\n--------------------------------------\n";
193 std::cout << "The two end points of each edge" << std::endl;
194 std::cout << "----------------------------------------\n";
195
196
197 for (auto e : mesh->edges()) {
198 std::cout << "the two end points of edge " << e << ": ";
200 std::cout << vs << " ";
202 std::cout << vt << " " << std::endl;
203 }
204
205 std::cout << "\n--------------------------------------\n";
206 std::cout << "The two faces connected by each edge" << std::endl;
207 std::cout << "----------------------------------------\n";
208
209
210 for (auto e : mesh->edges()) {
211 std::cout << "the two faces connected by edge " << e << ": ";
213 if (mesh->is_border(h0))
214 std::cout << "NULL" << " ";
215 else
216 std::cout << mesh->face(h0) << " ";
217
219 if (mesh->is_border(h1))
220 std::cout << "NULL" << " ";
221 else
222 std::cout << mesh->face(h1) << " ";
223
224 std::cout << std::endl;
225 }
226
227
228 delete mesh;
229
230 return EXIT_SUCCESS;
231}
232
Definition surface_mesh.h:1055
Definition surface_mesh.h:1265
Definition surface_mesh.h:954
Definition surface_mesh.h:1167
Definition surface_mesh.h:844
A halfedge data structure for polygonal meshes of 2-manifold.
Definition surface_mesh.h:51
Definition collider.cpp:182
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition types.h:44
void initialize(bool info_to_stdout, bool use_log_file, bool use_setting_file, const std::string &resource_dir)
Initialization of Easy3D.
Definition initializer.cpp:39
Definition surface_mesh.h:191
This type represents a halfedge (internally it is basically an index).
Definition surface_mesh.h:155
This type represents a vertex (internally it is basically an index).
Definition surface_mesh.h:135