This example shows how to access the adjacency information of a polyhedral mesh (consisting of a single tetrahedron):
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/poly_mesh.h>
28#include <easy3d/util/initializer.h>
29
49
51
52
53
54PolyMesh *old_mesh_from_previous_example() {
55
57
58
59 auto v0 = mesh->add_vertex(
vec3(-1.0, 0.0, 0.0));
60 auto v1 = mesh->add_vertex(
vec3(0.0, 0.0, 1.0));
61 auto v2 = mesh->add_vertex(
vec3(1.0, 0.0, 0.0));
62 auto v3 = mesh->add_vertex(
vec3(0.0, 0.0, -1.0));
63
64
65 mesh->add_tetra(v0, v1, v2, v3);
66
67 return mesh;
68}
69
70int main(int argc, char **argv) {
71
73
74
75 PolyMesh *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 for (auto v : mesh->vertices()) {
82 std::cout << "incident vertices of vertex " << v << ": ";
83
84 for (auto vv : mesh->vertices(v))
85 std::cout << vv << " ";
86 std::cout << std::endl;
87 }
88
89 std::cout << "----------------------------------------\n";
90 std::cout << "The incident edges of each vertex" << std::endl;
91 std::cout << "----------------------------------------\n";
92
93 for (auto v : mesh->vertices()) {
94 std::cout << "incident edges of vertex " << v << ": ";
95
96 for (auto e : mesh->edges(v))
97 std::cout << e << " ";
98 std::cout << std::endl;
99 }
100
101 std::cout << "----------------------------------------\n";
102 std::cout << "The incident halffaces of each vertex" << std::endl;
103 std::cout << "----------------------------------------\n";
104
105 for (auto v : mesh->vertices()) {
106 std::cout << "incident halffaces of vertex " << v << ": ";
107
108 for (auto h : mesh->halffaces(v))
109 std::cout << h << " ";
110 std::cout << std::endl;
111 }
112
113 std::cout << "----------------------------------------\n";
114 std::cout << "The incident cells of each vertex" << std::endl;
115 std::cout << "----------------------------------------\n";
116
117 for (auto v : mesh->vertices()) {
118 std::cout << "incident cells of vertex " << v << ": ";
119
120 for (auto c : mesh->cells(v))
121 std::cout << c << " ";
122 std::cout << std::endl;
123 }
124
125 std::cout << "----------------------------------------\n";
126 std::cout << "The incident vertices of each edge" << std::endl;
127 std::cout << "----------------------------------------\n";
128
129 for (auto e : mesh->edges()) {
130 std::cout << "incident vertices of edge " << e << ": " << mesh->vertex(e, 0) << " " << mesh->vertex(e, 1)
131 << std::endl;
132 }
133
134 std::cout << "----------------------------------------\n";
135 std::cout << "The incident halffaces of each edge" << std::endl;
136 std::cout << "----------------------------------------\n";
137
138 for (auto e : mesh->edges()) {
139 std::cout << "incident halffaces of edge " << e << ": ";
140
141 for (auto h : mesh->halffaces(e))
142 std::cout << h << " ";
143 std::cout << std::endl;
144 }
145
146 std::cout << "----------------------------------------\n";
147 std::cout << "The incident cells of each edge" << std::endl;
148 std::cout << "----------------------------------------\n";
149
150 for (auto e : mesh->edges()) {
151 std::cout << "incident cells of edge " << e << ": ";
152
153 for (auto c : mesh->cells(e))
154 std::cout << c << " ";
155 std::cout << std::endl;
156 }
157
158 std::cout << "----------------------------------------\n";
159 std::cout << "The incident vertices of each halfface" << std::endl;
160 std::cout << "----------------------------------------\n";
161
162 for (auto h : mesh->halffaces()) {
163 std::cout << "incident vertices of halfface " << h << ": ";
164
165 for (auto v : mesh->vertices(h))
166 std::cout << v << " ";
167 std::cout << std::endl;
168 }
169
170 std::cout << "----------------------------------------\n";
171 std::cout << "The incident edges of each halfface" << std::endl;
172 std::cout << "----------------------------------------\n";
173
174 for (auto h : mesh->halffaces()) {
175 std::cout << "incident edges of halfface " << h << ": ";
176
177 for (auto e : mesh->edges(h))
178 std::cout << e << " ";
179 std::cout << std::endl;
180 }
181
182 std::cout << "----------------------------------------\n";
183 std::cout << "The associated cell of each halfface" << std::endl;
184 std::cout << "----------------------------------------\n";
185
186 for (auto h : mesh->halffaces()) {
187 std::cout << "incident associated cell of halfface " << h << ": " << mesh->cell(h) << std::endl;
188 }
189
190 std::cout << "----------------------------------------\n";
191 std::cout << "The opposite halfface and cell of each halfface" << std::endl;
192 std::cout << "----------------------------------------\n";
193
194 for (auto h : mesh->halffaces()) {
195 std::cout << "opposite halfface of halfface " << h << ": " << mesh->opposite(h) << ". ";
196 std::cout << "opposite cell of halfface " << h << ": " << mesh->cell(mesh->opposite(h)) << std::endl;
197 }
198
199 std::cout << "----------------------------------------\n";
200 std::cout << "The incident vertices of each cell" << std::endl;
201 std::cout << "----------------------------------------\n";
202
203 for (auto c : mesh->cells()) {
204 std::cout << "incident vertices of cell " << c << ": ";
205
206 for (auto v : mesh->vertices(c))
207 std::cout << v << " ";
208 std::cout << std::endl;
209 }
210
211 std::cout << "----------------------------------------\n";
212 std::cout << "The incident edges of each cell" << std::endl;
213 std::cout << "----------------------------------------\n";
214
215 for (auto c : mesh->cells()) {
216 std::cout << "incident edges of cell " << c << ": ";
217
218 for (auto e : mesh->edges(c))
219 std::cout << e << " ";
220 std::cout << std::endl;
221 }
222
223 std::cout << "----------------------------------------\n";
224 std::cout << "The incident halffaces of each cell" << std::endl;
225 std::cout << "----------------------------------------\n";
226
227 for (auto c : mesh->cells()) {
228 std::cout << "incident halffaces of cell " << c << ": ";
229
230 for (auto h : mesh->halffaces(c))
231 std::cout << h << " ";
232 std::cout << std::endl;
233 }
234
235 std::cout << "----------------------------------------\n";
236 std::cout << "The two halffaces of each face" << std::endl;
237 std::cout << "----------------------------------------\n";
238
239 for (auto f : mesh->faces()) {
240 std::cout << "incident halffaces of face " << f << ": " << mesh->halfface(f, 0) << " " << mesh->halfface(f, 1)
241 << std::endl;
242 }
243
244 return EXIT_SUCCESS;
245}
246
Data structure representing a polyhedral mesh.
Definition poly_mesh.h:49
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