Skip to content

Commit d59b8c2

Browse files
committed
merge with main
2 parents 93457c2 + af20788 commit d59b8c2

File tree

5 files changed

+30
-15
lines changed

5 files changed

+30
-15
lines changed

.github/workflows/testing-and-deployment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
strategy:
8989
fail-fast: false
9090
matrix:
91-
os: [ubuntu-latest, windows-2019, macos-14, macos-13]
91+
os: [ubuntu-latest, windows-2025, macos-14, macos-13]
9292

9393
steps:
9494
- uses: actions/checkout@v4

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ci:
55

66
repos:
77
- repo: https://github.com/astral-sh/ruff-pre-commit
8-
rev: v0.11.8
8+
rev: v0.11.12
99
hooks:
1010
- id: ruff
1111
args: [--fix, --exit-non-zero-on-fix]

fast_simplification/_simplify.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ cdef extern from "wrapper.h" namespace "Simplify":
1515
void load_arrays_int32(const int, const int, double*, int*)
1616
void load_arrays_int64(const int, const int, double*, int64_t*)
1717
void simplify_mesh(int, double aggressiveness, bool verbose)
18+
void simplify_mesh_lossless(bool)
1819
void get_points(double*)
1920
void get_triangles(int*)
2021
void get_collapses(int*)
@@ -44,6 +45,8 @@ def load_int64(
4445
def simplify(int target_count, double aggressiveness=7, bool verbose=False):
4546
simplify_mesh(target_count, aggressiveness, verbose)
4647

48+
def simplify_lossless(bool verbose=False):
49+
simplify_mesh_lossless(verbose)
4750

4851

4952
def save_obj(filename):

fast_simplification/simplify.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def simplify(
3434
agg=7,
3535
verbose=False,
3636
return_collapses=False,
37+
lossless=False,
3738
):
3839
"""Simplify a triangular mesh.
3940
@@ -68,6 +69,8 @@ def simplify(
6869
``collapses[i] = [i0, i1]`` means that durint the i-th
6970
collapse, the vertex ``i1`` was collapsed into the vertex
7071
``i0``.
72+
lossless : bool, optional
73+
If True, simplify the mesh losslessly.
7174
7275
Returns
7376
-------
@@ -107,11 +110,9 @@ def simplify(
107110
... ]
108111
>>> points_out, faces_out = fast_simplification.simplify(points, faces, 0.5)
109112
110-
111113
"""
112-
if not isinstance(points, np.ndarray):
113-
points = np.array(points, dtype=np.float64)
114-
points = points.astype(np.float64, copy=False)
114+
115+
points = np.asarray(points, dtype=np.float64)
115116
if not isinstance(triangles, np.ndarray):
116117
triangles = np.array(triangles, dtype=np.int32)
117118

@@ -126,10 +127,8 @@ def simplify(
126127
raise ValueError(f"Expected ``triangles`` array to be (n, 3), not {triangles.shape}")
127128

128129
n_faces = triangles.shape[0]
129-
target_count = _check_args(target_reduction, target_count, n_faces)
130130

131-
if not triangles.flags.c_contiguous:
132-
triangles = np.ascontiguousarray(triangles)
131+
triangles = np.ascontiguousarray(triangles)
133132

134133
if triangles.dtype == np.int32:
135134
load = _simplify.load_int32
@@ -146,7 +145,11 @@ def simplify(
146145
triangles,
147146
)
148147

149-
_simplify.simplify(target_count, agg, verbose)
148+
if lossless:
149+
_simplify.simplify_lossless(verbose)
150+
else:
151+
target_count = _check_args(target_reduction, target_count, n_faces)
152+
_simplify.simplify(target_count, agg, verbose)
150153
points = _simplify.return_points()
151154
faces = _simplify.return_faces_int32_no_padding().reshape(-1, 3)
152155

@@ -199,8 +202,8 @@ def simplify_mesh(mesh, target_reduction=None, target_count=None, agg=7, verbose
199202
n_faces = mesh.n_cells
200203
_simplify.load_from_vtk(
201204
mesh.n_points,
202-
mesh.points.astype(np.float64, copy=False),
203-
mesh.faces.astype(np.int32, copy=False),
205+
mesh.points.astype(np.float64, order="C", copy=False),
206+
mesh.faces.astype(np.int32, order="C", copy=False),
204207
n_faces,
205208
)
206209

tests/test_simplify.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def test_simplify_trivial():
6565

6666
@skip_no_vtk
6767
def test_simplify_none(mesh):
68-
triangles = mesh.faces.reshape(-1, 4)[:, 1:]
68+
triangles = mesh._connectivity_array.reshape(-1, 3)
6969

7070
reduction = 0
7171
points, faces = fast_simplification.simplify(mesh.points, triangles, reduction)
@@ -75,7 +75,7 @@ def test_simplify_none(mesh):
7575

7676
@skip_no_vtk
7777
def test_simplify(mesh):
78-
triangles = mesh.faces.reshape(-1, 4)[:, 1:]
78+
triangles = mesh._connectivity_array.reshape(-1, 3)
7979
reduction = 0.5
8080
points, faces, collapses = fast_simplification.simplify(
8181
mesh.points, triangles, reduction, return_collapses=True
@@ -91,9 +91,18 @@ def test_simplify(mesh):
9191
assert points.dtype == np.float64
9292

9393

94+
@skip_no_vtk
95+
def test_simplify_lossless(mesh):
96+
triangles = mesh._connectivity_array.reshape(-1, 3)
97+
reduction = 0.5
98+
points, faces = fast_simplification.simplify(mesh.points, triangles, reduction, lossless=True)
99+
assert np.allclose(mesh.points, points)
100+
assert np.allclose(triangles, faces)
101+
102+
94103
@skip_no_vtk
95104
def test_simplify_agg(mesh):
96-
triangles = mesh.faces.reshape(-1, 4)[:, 1:]
105+
triangles = mesh._connectivity_array.reshape(-1, 3)
97106

98107
reduction = 0.5
99108
points, faces = fast_simplification.simplify(

0 commit comments

Comments
 (0)