Skip to content

Commit 17c2a48

Browse files
committed
add mesh split endpoint
1 parent 9f76e2c commit 17c2a48

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

src/booleans.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "booleans.h"
22
#include <CGAL/Polygon_mesh_processing/corefinement.h>
3+
#include <CGAL/Polygon_mesh_processing/clip.h>
34

45

56
namespace PMP = CGAL::Polygon_mesh_processing;
@@ -68,6 +69,28 @@ pmp_boolean_intersection(
6869
};
6970

7071

72+
std::tuple<compas::RowMatrixXd, compas::RowMatrixXi>
73+
pmp_split(
74+
Eigen::Ref<const compas::RowMatrixXd> &VA,
75+
Eigen::Ref<const compas::RowMatrixXi> &FA,
76+
Eigen::Ref<const compas::RowMatrixXd> &VB,
77+
Eigen::Ref<const compas::RowMatrixXi> &FB)
78+
{
79+
Mesh A = compas::mesh_from_vertices_and_faces(VA, FA);
80+
Mesh B = compas::mesh_from_vertices_and_faces(VB, FB);
81+
// Mesh C;
82+
83+
// PMP::clip(A, B, CGAL::parameters::clip_volume(false), CGAL::parameters::clip_volume(false));
84+
PMP::split(A, B);
85+
86+
// Result
87+
88+
std::tuple<compas::RowMatrixXd, compas::RowMatrixXi> R = compas::mesh_to_vertices_and_faces(A);
89+
90+
return R;
91+
};
92+
93+
7194
void init_booleans(pybind11::module &m)
7295
{
7396
pybind11::module submodule = m.def_submodule("booleans");
@@ -95,4 +118,12 @@ void init_booleans(pybind11::module &m)
95118
pybind11::arg("FA").noconvert(),
96119
pybind11::arg("VB").noconvert(),
97120
pybind11::arg("FB").noconvert());
121+
122+
submodule.def(
123+
"split",
124+
&pmp_split,
125+
pybind11::arg("VA").noconvert(),
126+
pybind11::arg("FA").noconvert(),
127+
pybind11::arg("VB").noconvert(),
128+
pybind11::arg("FB").noconvert());
98129
};

src/booleans.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@ pmp_boolean_intersection(
2828
Eigen::Ref<const compas::RowMatrixXi> &FB);
2929

3030

31+
std::tuple<compas::RowMatrixXd, compas::RowMatrixXi>
32+
pmp_clip(
33+
Eigen::Ref<const compas::RowMatrixXd> &VA,
34+
Eigen::Ref<const compas::RowMatrixXi> &FA,
35+
Eigen::Ref<const compas::RowMatrixXd> &VB,
36+
Eigen::Ref<const compas::RowMatrixXi> &FB);
37+
38+
3139
#endif /* COMPAS_BOOLEANS_H */

src/compas_cgal/booleans.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ def _boolean(A, B, operation):
4141
result = booleans.boolean_difference(VA, FA, VB, FB)
4242
elif operation == 'intersection':
4343
result = booleans.boolean_intersection(VA, FA, VB, FB)
44+
elif operation == 'split':
45+
result = booleans.split(VA, FA, VB, FB)
4446
else:
4547
raise NotImplementedError
4648

@@ -159,3 +161,9 @@ def boolean_intersection(A, B):
159161
160162
"""
161163
return _boolean(A, B, 'intersection')
164+
165+
@plugin(category='booleans', pluggable_name='split_mesh_mesh')
166+
def split(A, B):
167+
"""
168+
"""
169+
return _boolean(A, B, 'split')

src/compas_cgal/booleans.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from compas_cgal.types import VerticesFaces
44
from compas_cgal.types import VerticesFacesNumpy
55

66

7-
def _boolean(A: VerticesFaces, B: VerticesFaces, operation: Literal['union', 'difference', 'intersection']) -> VerticesFacesNumpy:
7+
def _boolean(A: VerticesFaces, B: VerticesFaces, operation: Literal['union', 'difference', 'intersection', 'split']) -> VerticesFacesNumpy:
88
pass
99

1010

@@ -18,3 +18,6 @@ def boolean_difference(A: VerticesFaces, B: VerticesFaces) -> VerticesFacesNumpy
1818

1919
def boolean_intersection(A: VerticesFaces, B: VerticesFaces) -> VerticesFacesNumpy:
2020
pass
21+
22+
def split(A: VerticesFaces, B: VerticesFaces) -> VerticesFacesNumpy:
23+
pass

0 commit comments

Comments
 (0)