This example shows how to access the adjacency information of a polyhedral mesh (consisting of a single tetrahedron):
- the incident vertices of each vertex
- the incident edges of each vertex
- the incident halffaces of each vertex
- the incident cells of each vertex
- the incident vertices of each edge
- the incident halffaces of each edge
- the incident cells of each edge
- the incident vertices of each halfface
- the incident edges of each halfface
- the associated cell of each halfface
- the opposite cell of each halfface
- the incident vertices of each cell
- the incident edges of each cell
- the incident halffaces of each cell
- the two halffaces of each face
27#include <easy3d/core/poly_mesh.h>
28#include <easy3d/util/initializer.h>
54PolyMesh *old_mesh_from_previous_example() {
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));
65 mesh->add_tetra(v0, v1, v2, v3);
70int main(
int argc,
char **argv) {
75 PolyMesh *mesh = old_mesh_from_previous_example();
77 std::cout <<
"----------------------------------------\n";
78 std::cout <<
"The incident vertices of each vertex" << std::endl;
79 std::cout <<
"----------------------------------------\n";
81 for (
auto v : mesh->vertices()) {
82 std::cout <<
"incident vertices of vertex " << v <<
": ";
84 for (
auto vv : mesh->vertices(v))
85 std::cout << vv <<
" ";
86 std::cout << std::endl;
89 std::cout <<
"----------------------------------------\n";
90 std::cout <<
"The incident edges of each vertex" << std::endl;
91 std::cout <<
"----------------------------------------\n";
93 for (
auto v : mesh->vertices()) {
94 std::cout <<
"incident edges of vertex " << v <<
": ";
96 for (
auto e : mesh->edges(v))
97 std::cout << e <<
" ";
98 std::cout << std::endl;
101 std::cout <<
"----------------------------------------\n";
102 std::cout <<
"The incident halffaces of each vertex" << std::endl;
103 std::cout <<
"----------------------------------------\n";
105 for (
auto v : mesh->vertices()) {
106 std::cout <<
"incident halffaces of vertex " << v <<
": ";
108 for (
auto h : mesh->halffaces(v))
109 std::cout << h <<
" ";
110 std::cout << std::endl;
113 std::cout <<
"----------------------------------------\n";
114 std::cout <<
"The incident cells of each vertex" << std::endl;
115 std::cout <<
"----------------------------------------\n";
117 for (
auto v : mesh->vertices()) {
118 std::cout <<
"incident cells of vertex " << v <<
": ";
120 for (
auto c : mesh->cells(v))
121 std::cout << c <<
" ";
122 std::cout << std::endl;
125 std::cout <<
"----------------------------------------\n";
126 std::cout <<
"The incident vertices of each edge" << std::endl;
127 std::cout <<
"----------------------------------------\n";
129 for (
auto e : mesh->edges()) {
130 std::cout <<
"incident vertices of edge " << e <<
": " << mesh->vertex(e, 0) <<
" " << mesh->vertex(e, 1)
134 std::cout <<
"----------------------------------------\n";
135 std::cout <<
"The incident halffaces of each edge" << std::endl;
136 std::cout <<
"----------------------------------------\n";
138 for (
auto e : mesh->edges()) {
139 std::cout <<
"incident halffaces of edge " << e <<
": ";
141 for (
auto h : mesh->halffaces(e))
142 std::cout << h <<
" ";
143 std::cout << std::endl;
146 std::cout <<
"----------------------------------------\n";
147 std::cout <<
"The incident cells of each edge" << std::endl;
148 std::cout <<
"----------------------------------------\n";
150 for (
auto e : mesh->edges()) {
151 std::cout <<
"incident cells of edge " << e <<
": ";
153 for (
auto c : mesh->cells(e))
154 std::cout << c <<
" ";
155 std::cout << std::endl;
158 std::cout <<
"----------------------------------------\n";
159 std::cout <<
"The incident vertices of each halfface" << std::endl;
160 std::cout <<
"----------------------------------------\n";
162 for (
auto h : mesh->halffaces()) {
163 std::cout <<
"incident vertices of halfface " << h <<
": ";
165 for (
auto v : mesh->vertices(h))
166 std::cout << v <<
" ";
167 std::cout << std::endl;
170 std::cout <<
"----------------------------------------\n";
171 std::cout <<
"The incident edges of each halfface" << std::endl;
172 std::cout <<
"----------------------------------------\n";
174 for (
auto h : mesh->halffaces()) {
175 std::cout <<
"incident edges of halfface " << h <<
": ";
177 for (
auto e : mesh->edges(h))
178 std::cout << e <<
" ";
179 std::cout << std::endl;
182 std::cout <<
"----------------------------------------\n";
183 std::cout <<
"The associated cell of each halfface" << std::endl;
184 std::cout <<
"----------------------------------------\n";
186 for (
auto h : mesh->halffaces()) {
187 std::cout <<
"incident associated cell of halfface " << h <<
": " << mesh->cell(h) << std::endl;
190 std::cout <<
"----------------------------------------\n";
191 std::cout <<
"The opposite halfface and cell of each halfface" << std::endl;
192 std::cout <<
"----------------------------------------\n";
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;
199 std::cout <<
"----------------------------------------\n";
200 std::cout <<
"The incident vertices of each cell" << std::endl;
201 std::cout <<
"----------------------------------------\n";
203 for (
auto c : mesh->cells()) {
204 std::cout <<
"incident vertices of cell " << c <<
": ";
206 for (
auto v : mesh->vertices(c))
207 std::cout << v <<
" ";
208 std::cout << std::endl;
211 std::cout <<
"----------------------------------------\n";
212 std::cout <<
"The incident edges of each cell" << std::endl;
213 std::cout <<
"----------------------------------------\n";
215 for (
auto c : mesh->cells()) {
216 std::cout <<
"incident edges of cell " << c <<
": ";
218 for (
auto e : mesh->edges(c))
219 std::cout << e <<
" ";
220 std::cout << std::endl;
223 std::cout <<
"----------------------------------------\n";
224 std::cout <<
"The incident halffaces of each cell" << std::endl;
225 std::cout <<
"----------------------------------------\n";
227 for (
auto c : mesh->cells()) {
228 std::cout <<
"incident halffaces of cell " << c <<
": ";
230 for (
auto h : mesh->halffaces(c))
231 std::cout << h <<
" ";
232 std::cout << std::endl;
235 std::cout <<
"----------------------------------------\n";
236 std::cout <<
"The two halffaces of each face" << std::endl;
237 std::cout <<
"----------------------------------------\n";
239 for (
auto f : mesh->faces()) {
240 std::cout <<
"incident halffaces of face " << f <<
": " << mesh->halfface(f, 0) <<
" " << mesh->halfface(f, 1)
Data structure representing a polyhedral mesh.
Definition poly_mesh.h:49
Definition collider.cpp:182