Skip to content

Commit 02cb2b5

Browse files
committed
feat: add polyline attribute example, improve polyline creation example
1 parent 903e1d3 commit 02cb2b5

4 files changed

Lines changed: 50 additions & 11 deletions

File tree

examples/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,5 @@ ENDIF()
6565
# Copy asset files to build directory
6666
configure_file(assets/catorus.geogram assets/catorus.geogram COPYONLY)
6767
configure_file(assets/tet_13225.geogram assets/tet_13225.geogram COPYONLY)
68-
configure_file(assets/quarterdisk_tri.mesh assets/quarterdisk_tri.mesh COPYONLY)
68+
configure_file(assets/quarterdisk_tri.mesh assets/quarterdisk_tri.mesh COPYONLY)
69+
configure_file(assets/pyramid.geogram assets/pyramid.geogram COPYONLY)

examples/assets/pyramid.geogram

175 Bytes
Binary file not shown.

examples/create_fill_attributes.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,24 @@ int main() {
5858

5959
// TODO
6060

61+
// --- EDGE ATTR ---
62+
63+
// Load mesh
64+
PolyLine p;
65+
read_by_extension(path + "pyramid.geogram", p);
66+
67+
// Create a edge attribute
68+
EdgeAttribute<int> edge_id_attr(p);
69+
// For all edge in polyline set edge attribute with edge id
70+
for (auto &e : p.iter_edges()) {
71+
edge_id_attr[e] = e;
72+
std::cout << (int)e << std::endl;
73+
}
74+
75+
write_by_extension("pyramid_attr.geogram", p, {{"edge_id", edge_id_attr}});
76+
77+
// --- END EDGE ATTR ---
78+
6179
// --- SAVE ALL ATTRIBUTES ---
6280

6381
// Save mesh with all previously created attributes

examples/create_polyline.cpp

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,61 @@ int main() {
1616

1717
// --- CREATE ---
1818

19-
// Create 3 points in polyline
20-
p.points.create_points(3);
21-
p.points[0] = {0,0,0};
22-
p.points[1] = {1,0,0};
23-
p.points[2] = {1,1,0};
19+
// Create 5 points in polyline
20+
p.points.create_points(5);
21+
p.points[0] = vec3(0, 0, 0);
22+
p.points[1] = vec3(1, 0, 0);
23+
p.points[2] = vec3(1, 1, 0);
24+
p.points[3] = vec3(0, 1, 0);
25+
p.points[4] = vec3(0.5, 0.5, 1);
2426

2527
// Create edges
26-
p.create_edges(2);
28+
p.create_edges(8);
2729

2830
// Link segment 0 with point 0
2931
p.vert(0, 0) = 0;
3032
// Link segment 0 with point 1
3133
p.vert(0, 1) = 1;
34+
3235
// Link segment 1 with point 0
33-
p.vert(1, 0) = 0;
36+
p.vert(1, 0) = 1;
3437
// ...
3538
p.vert(1, 1) = 2;
3639

37-
EdgeAttribute<int> edge_attr(p);
40+
p.vert(2, 0) = 2;
41+
p.vert(2, 1) = 3;
42+
43+
p.vert(3, 0) = 3;
44+
p.vert(3, 1) = 0;
45+
46+
p.vert(4, 0) = 0;
47+
p.vert(4, 1) = 4;
3848

49+
p.vert(5, 0) = 1;
50+
p.vert(5, 1) = 4;
51+
52+
p.vert(6, 0) = 2;
53+
p.vert(6, 1) = 4;
54+
55+
p.vert(7, 0) = 3;
56+
p.vert(7, 1) = 4;
57+
58+
EdgeAttribute<int> edge_attr(p);
3959
edge_attr[0] = 0;
4060
edge_attr[1] = 1;
4161

4262
// --- SAVE ---
4363

4464
// Save mesh
45-
write_by_extension("simple_polyline.geogram", p, {{}, {{"my_edge_attr", edge_attr.ptr}}});
65+
write_by_extension("pyramid.geogram", p, {{"my_edge_attr", edge_attr}});
4666

4767
// --- END ---
4868

4969
// --- RUN ---
5070

5171
#ifdef _WIN32
5272
// Open the generated mesh with Graphite
53-
int result = system((getGraphitePath() + " simple_polyline.geogram").c_str());
73+
int result = system((getGraphitePath() + " pyramid.geogram").c_str());
5474
#endif
5575

5676
return 0;

0 commit comments

Comments
 (0)