Skip to content

Commit bd4ea7f

Browse files
committed
remove rdp fallback, cgal only
1 parent 7889b37 commit bd4ea7f

File tree

2 files changed

+3
-52
lines changed

2 files changed

+3
-52
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ dev = [
5757
"pytest>=7.0",
5858
"pytest-benchmark",
5959
"pytest-cov",
60-
"rdp>=0.8",
6160
"ruff",
6261
"twine",
6362
]

src/compas_slicer/post_processing/simplify_paths_rdp.py

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,21 @@
22

33
from typing import TYPE_CHECKING
44

5-
import numpy as np
65
from compas.geometry import Point
6+
from compas_cgal.polylines import simplify_polylines
77
from loguru import logger
88

9-
try:
10-
import rdp as rdp_py
11-
except ImportError:
12-
rdp_py = None
13-
149
if TYPE_CHECKING:
1510
from compas_slicer.slicers import BaseSlicer
1611

1712

1813
__all__ = ["simplify_paths_rdp"]
1914

20-
# Check for CGAL availability at module load
21-
_USE_CGAL = False
22-
try:
23-
from compas_cgal.polylines import simplify_polylines as _cgal_simplify
24-
25-
_USE_CGAL = True
26-
except ImportError:
27-
_cgal_simplify = None
28-
2915

3016
def simplify_paths_rdp(slicer: BaseSlicer, threshold: float) -> None:
3117
"""Simplify paths using the Ramer-Douglas-Peucker algorithm.
3218
33-
Uses CGAL native implementation if available (10-20x faster),
34-
otherwise falls back to Python rdp library.
19+
Uses CGAL Polyline_simplification_2 implementation.
3520
3621
Parameters
3722
----------
@@ -45,51 +30,18 @@ def simplify_paths_rdp(slicer: BaseSlicer, threshold: float) -> None:
4530
----------
4631
https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm
4732
"""
48-
if _USE_CGAL:
49-
_simplify_paths_cgal(slicer, threshold)
50-
else:
51-
_simplify_paths_python(slicer, threshold)
52-
53-
54-
def _simplify_paths_cgal(slicer: BaseSlicer, threshold: float) -> None:
55-
"""Simplify paths using CGAL Polyline_simplification_2."""
5633
logger.info("Paths simplification rdp (CGAL)")
5734
remaining_pts_num = 0
5835

5936
for layer in slicer.layers:
6037
if layer.is_raft:
6138
continue
6239

63-
# Batch all paths in this layer for efficient CGAL processing
6440
polylines = [[[pt[0], pt[1], pt[2]] for pt in path.points] for path in layer.paths]
65-
simplified = _cgal_simplify(polylines, threshold)
41+
simplified = simplify_polylines(polylines, threshold)
6642

6743
for path, pts_simplified in zip(layer.paths, simplified):
6844
path.points = [Point(pt[0], pt[1], pt[2]) for pt in pts_simplified]
6945
remaining_pts_num += len(path.points)
7046

7147
logger.info(f"{remaining_pts_num} points remaining after simplification")
72-
73-
74-
def _simplify_paths_python(slicer: BaseSlicer, threshold: float) -> None:
75-
"""Simplify paths using Python rdp library."""
76-
if rdp_py is None:
77-
raise ImportError("rdp package required for Python fallback. Install with: pip install rdp")
78-
79-
logger.info("Paths simplification rdp (Python)")
80-
remaining_pts_num = 0
81-
82-
for layer in slicer.layers:
83-
if layer.is_raft:
84-
continue
85-
86-
for path in layer.paths:
87-
pts_rdp = rdp_py.rdp(np.array(path.points), epsilon=threshold)
88-
path.points = [Point(pt[0], pt[1], pt[2]) for pt in pts_rdp]
89-
remaining_pts_num += len(path.points)
90-
91-
logger.info(f"{remaining_pts_num} points remaining after simplification")
92-
93-
94-
if __name__ == "__main__":
95-
pass

0 commit comments

Comments
 (0)