forked from compas-dev/compas_cgal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubdivision.cpp
More file actions
106 lines (99 loc) · 3.52 KB
/
subdivision.cpp
File metadata and controls
106 lines (99 loc) · 3.52 KB
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
#include "subdivision.h"
std::tuple<compas::RowMatrixXd, compas::RowMatrixXi>
subd_catmullclark(
Eigen::Ref<const compas::RowMatrixXd> vertices,
const std::vector<std::vector<int>>& faces,
unsigned int num_iterations)
{
compas::Mesh mesh = compas::ngon_from_vertices_and_faces(vertices, faces);
CGAL::Subdivision_method_3::CatmullClark_subdivision(mesh, CGAL::parameters::number_of_iterations(num_iterations));
mesh.collect_garbage();
return compas::quadmesh_to_vertices_and_faces(mesh);
}
std::tuple<compas::RowMatrixXd, compas::RowMatrixXi>
subd_loop(
Eigen::Ref<const compas::RowMatrixXd> vertices,
Eigen::Ref<const compas::RowMatrixXi> faces,
unsigned int num_iterations)
{
compas::Mesh mesh = compas::mesh_from_vertices_and_faces(vertices, faces);
CGAL::Subdivision_method_3::Loop_subdivision(mesh, CGAL::parameters::number_of_iterations(num_iterations));
mesh.collect_garbage();
return compas::mesh_to_vertices_and_faces(mesh);
}
std::tuple<compas::RowMatrixXd, compas::RowMatrixXi>
subd_sqrt3(
Eigen::Ref<const compas::RowMatrixXd> vertices,
Eigen::Ref<const compas::RowMatrixXi> faces,
unsigned int num_iterations)
{
compas::Mesh mesh = compas::mesh_from_vertices_and_faces(vertices, faces);
CGAL::Subdivision_method_3::Sqrt3_subdivision(mesh, CGAL::parameters::number_of_iterations(num_iterations));
mesh.collect_garbage();
return compas::mesh_to_vertices_and_faces(mesh);
}
NB_MODULE(_subdivision, m) {
m.def(
"subd_catmullclark",
&subd_catmullclark,
"Catmull-Clark subdivision of a polygonal mesh.\n\n"
"Parameters\n"
"----------\n"
"vertices : array-like\n"
" Matrix of vertex positions (Nx3, float64)\n"
"faces : list\n"
" List of face vertex indices (list of lists)\n"
"num_iterations : int\n"
" Number of subdivision steps\n"
"\n"
"Returns\n"
"-------\n"
"tuple\n"
" - Matrix of subdivided vertex positions (Mx3, float64)\n"
" - Matrix of subdivided face vertex indices (Px4, int32)",
"vertices"_a,
"faces"_a,
"num_iterations"_a);
m.def(
"subd_loop",
&subd_loop,
"Loop subdivision of a triangular mesh.\n\n"
"Parameters\n"
"----------\n"
"vertices : array-like\n"
" Matrix of vertex positions (Nx3, float64)\n"
"faces : array-like\n"
" Matrix of face vertex indices (Mx3, int32)\n"
"num_iterations : int\n"
" Number of subdivision steps\n"
"\n"
"Returns\n"
"-------\n"
"tuple\n"
" - Matrix of subdivided vertex positions (Px3, float64)\n"
" - Matrix of subdivided face vertex indices (Qx3, int32)",
"vertices"_a,
"faces"_a,
"num_iterations"_a);
m.def(
"subd_sqrt3",
&subd_sqrt3,
"Sqrt3 subdivision of a triangular mesh.\n\n"
"Parameters\n"
"----------\n"
"vertices : array-like\n"
" Matrix of vertex positions (Nx3, float64)\n"
"faces : array-like\n"
" Matrix of face vertex indices (Mx3, int32)\n"
"num_iterations : int\n"
" Number of subdivision steps\n"
"\n"
"Returns\n"
"-------\n"
"tuple\n"
" - Matrix of subdivided vertex positions (Px3, float64)\n"
" - Matrix of subdivided face vertex indices (Qx3, int32)",
"vertices"_a,
"faces"_a,
"num_iterations"_a);
}