Skip to content

Commit 6afbc88

Browse files
authored
Merge pull request #5 from robinthibaut/robin/bug_hunt
clip.cpp resilience; performance overhaul
2 parents 2232aac + a41c66d commit 6afbc88

6 files changed

Lines changed: 660 additions & 666 deletions

File tree

.vscode/settings.json

Lines changed: 0 additions & 78 deletions
This file was deleted.

loop_cgal/__init__.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import pyvista as pv
33
import numpy as np
44
from typing import Tuple
5+
6+
57
def clip_pyvista_polydata_with_plane(
68
surface: pv.PolyData,
79
plane_origin: np.ndarray,
@@ -27,7 +29,7 @@ def clip_pyvista_polydata_with_plane(
2729
The origin point of the clipping plane.
2830
plane_normal : np.ndarray
2931
The normal vector of the clipping plane.
30-
target_edge_length : float, optional
32+
target_edge_length : float, optional
3133
The target edge length for the remeshing process, by default 10.0
3234
remesh_before_clipping : bool, optional
3335
Whether to remesh the surface before clipping, by default True
@@ -45,15 +47,15 @@ def clip_pyvista_polydata_with_plane(
4547
-------
4648
pyvista.PolyData
4749
The resulting clipped surface.
48-
"""
50+
"""
4951
surface = surface.triangulate()
5052
tm = NumpyMesh()
5153
tm.vertices = np.array(surface.points).copy()
5254
tm.triangles = surface.faces.reshape(-1, 4)[:, 1:].copy()
5355
plane = NumpyPlane()
5456
plane.origin = np.asarray(plane_origin, dtype=np.float64)
5557
plane.normal = np.asarray(plane_normal, dtype=np.float64)
56-
58+
5759
mesh = clip_plane(
5860
tm,
5961
plane,
@@ -66,10 +68,10 @@ def clip_pyvista_polydata_with_plane(
6668
protect_constraints=protect_constraints,
6769
relax_constraints=relax_constraints,
6870
verbose=verbose,
69-
7071
)
71-
return pv.PolyData.from_regular_faces(mesh.vertices, mesh.triangles
72-
)
72+
return pv.PolyData.from_regular_faces(mesh.vertices, mesh.triangles)
73+
74+
7375
def clip_pyvista_polydata(
7476
surface_1: pv.PolyData,
7577
surface_2: pv.PolyData,
@@ -118,9 +120,11 @@ def clip_pyvista_polydata(
118120
protect_constraints=protect_constraints,
119121
relax_constraints=relax_constraints,
120122
verbose=verbose,
121-
122123
)
123-
return pv.PolyData.from_regular_faces(mesh.vertices, mesh.triangles)
124+
out = pv.PolyData.from_regular_faces(mesh.vertices, mesh.triangles)
125+
126+
return out
127+
124128

125129
def corefine_pyvista_polydata(
126130
surface_1: pv.PolyData,
@@ -157,8 +161,18 @@ def corefine_pyvista_polydata(
157161
tm2.vertices = np.array(surface_2.points).copy()
158162
tm2.triangles = surface_2.faces.reshape(-1, 4)[:, 1:].copy()
159163

160-
tm1, tm2 = corefine_mesh(tm1, tm2, target_edge_length=target_edge_length, duplicate_vertex_threshold=duplicate_vertex_threshold, area_threshold=area_threshold, number_of_iterations=number_of_iterations, relax_constraints=relax_constraints, protect_constraints=protect_constraints, verbose=verbose)
164+
tm1, tm2 = corefine_mesh(
165+
tm1,
166+
tm2,
167+
target_edge_length=target_edge_length,
168+
duplicate_vertex_threshold=duplicate_vertex_threshold,
169+
area_threshold=area_threshold,
170+
number_of_iterations=number_of_iterations,
171+
relax_constraints=relax_constraints,
172+
protect_constraints=protect_constraints,
173+
verbose=verbose,
174+
)
161175
return (
162176
pv.PolyData.from_regular_faces(tm1.vertices, tm1.triangles),
163-
pv.PolyData.from_regular_faces(tm2.vertices, tm2.triangles)
177+
pv.PolyData.from_regular_faces(tm2.vertices, tm2.triangles),
164178
)

loop_cgal/bindings.cpp

Lines changed: 37 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,42 @@
55

66
namespace py = pybind11;
77

8-
PYBIND11_MODULE(loop_cgal, m)
9-
{
10-
11-
m.def("clip_surface", &clip_surface,
12-
py::arg("tm"),
13-
py::arg("clipper"),
14-
py::arg("target_edge_length") = 10.0,
15-
py::arg("remesh_before_clipping") = true,
16-
py::arg("remesh_after_clipping") = true,
17-
py::arg("remove_degenerate_faces") = true,
18-
py::arg("duplicate_vertex_threshold") = 1e-6,
19-
py::arg("area_threshold") = 1e-6,
20-
py::arg("protect_constraints") = false,
21-
py::arg("relax_constraints") = true,
22-
py::arg("verbose") = false,
23-
"Clip one surface with another.");
24-
m.def("clip_plane", &clip_plane,
25-
py::arg("tm"),
26-
py::arg("clipper"),
27-
py::arg("target_edge_length") = 10.0,
28-
py::arg("remesh_before_clipping") = true,
29-
py::arg("remesh_after_clipping") = true,
30-
py::arg("remove_degenerate_faces") = true,
31-
py::arg("duplicate_vertex_threshold") = 1e-6,
32-
py::arg("area_threshold") = 1e-6,
33-
py::arg("protect_constraints") = false,
34-
py::arg("relax_constraints") = true,
35-
py::arg("verbose") = false,
8+
PYBIND11_MODULE(loop_cgal, m) {
369

37-
"Clip a surface with a plane.");
38-
m.def("corefine_mesh", &corefine_mesh,
39-
py::arg("tm1"),
40-
py::arg("tm2"),
41-
py::arg("target_edge_length") = 10.0,
42-
py::arg("duplicate_vertex_threshold") = 1e-6,
43-
py::arg("area_threshold") = 1e-6,
44-
py::arg("number_of_iterations") = 3,
45-
py::arg("relax_constraints") = true,
46-
py::arg("protect_constraints") = false,
47-
py::arg("verbose") = false,
48-
"Corefine two meshes.");
49-
py::class_<NumpyMesh>(m, "NumpyMesh")
50-
.def(py::init<>())
51-
.def_readwrite("vertices", &NumpyMesh::vertices)
52-
.def_readwrite("triangles", &NumpyMesh::triangles);
53-
py::class_<NumpyPlane>(m, "NumpyPlane")
54-
.def(py::init<>())
55-
.def_readwrite("normal", &NumpyPlane::normal)
56-
.def_readwrite("origin", &NumpyPlane::origin);
10+
m.def("clip_surface", &clip_surface, py::arg("tm"), py::arg("clipper"),
11+
py::arg("target_edge_length") = 10.0,
12+
py::arg("remesh_before_clipping") = true,
13+
py::arg("remesh_after_clipping") = true,
14+
py::arg("remove_degenerate_faces") = true,
15+
py::arg("duplicate_vertex_threshold") = 1e-6,
16+
py::arg("area_threshold") = 1e-6,
17+
py::arg("protect_constraints") = false,
18+
py::arg("relax_constraints") = true, py::arg("verbose") = false,
19+
"Clip one surface with another.");
20+
m.def("clip_plane", &clip_plane, py::arg("tm"), py::arg("clipper"),
21+
py::arg("target_edge_length") = 10.0,
22+
py::arg("remesh_before_clipping") = true,
23+
py::arg("remesh_after_clipping") = true,
24+
py::arg("remove_degenerate_faces") = true,
25+
py::arg("duplicate_vertex_threshold") = 1e-6,
26+
py::arg("area_threshold") = 1e-6,
27+
py::arg("protect_constraints") = false,
28+
py::arg("relax_constraints") = true, py::arg("verbose") = false,
29+
30+
"Clip a surface with a plane.");
31+
m.def("corefine_mesh", &corefine_mesh, py::arg("tm1"), py::arg("tm2"),
32+
py::arg("target_edge_length") = 10.0,
33+
py::arg("duplicate_vertex_threshold") = 1e-6,
34+
py::arg("area_threshold") = 1e-6, py::arg("number_of_iterations") = 3,
35+
py::arg("relax_constraints") = true,
36+
py::arg("protect_constraints") = false, py::arg("verbose") = false,
37+
"Corefine two meshes.");
38+
py::class_<NumpyMesh>(m, "NumpyMesh")
39+
.def(py::init<>())
40+
.def_readwrite("vertices", &NumpyMesh::vertices)
41+
.def_readwrite("triangles", &NumpyMesh::triangles);
42+
py::class_<NumpyPlane>(m, "NumpyPlane")
43+
.def(py::init<>())
44+
.def_readwrite("normal", &NumpyPlane::normal)
45+
.def_readwrite("origin", &NumpyPlane::origin);
5746
}

0 commit comments

Comments
 (0)