Skip to content

Commit 8866521

Browse files
ADD-GITHUB straight_skeleton_2 and reduce github action python number to 3.10
1 parent b175d57 commit 8866521

18 files changed

+1251
-2
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
matrix:
1717
os: [ubuntu-latest, macos-latest, windows-latest]
18-
python: ["3.10", "3.11", "3.12"]
18+
python: ["3.10"]
1919

2020
steps:
2121
- uses: compas-dev/compas-actions.build@v4

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,5 @@ add_nanobind_module(measure_ext src/measure.cpp)
232232
add_nanobind_module(reconstruction_ext src/reconstruction.cpp)
233233
add_nanobind_module(skeletonization_ext src/skeletonization.cpp)
234234
add_nanobind_module(slicer_ext src/slicer.cpp)
235+
add_nanobind_module(straight_skeleton_2_ext src/straight_skeleton_2.cpp)
235236

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from compas.geometry import Point
2+
from compas.geometry import Polygon
3+
from compas_viewer import Viewer
4+
from line_profiler import profile
5+
6+
from compas_cgal.straight_skeleton_2 import interior_straight_skeleton
7+
8+
9+
@profile
10+
def main():
11+
"""Compute the interior straight skeleton of a polygon."""
12+
13+
points = [
14+
Point(-1.91, 3.59, 0.0),
15+
Point(-5.53, -5.22, 0.0),
16+
Point(-0.39, -1.98, 0.0),
17+
Point(2.98, -5.51, 0.0),
18+
Point(4.83, -2.02, 0.0),
19+
Point(9.70, -3.63, 0.0),
20+
Point(12.23, 1.25, 0.0),
21+
Point(3.42, 0.66, 0.0),
22+
Point(2.92, 4.03, 0.0),
23+
Point(-1.91, 3.59, 0.0),
24+
]
25+
polygon = Polygon(points)
26+
27+
graph = interior_straight_skeleton(polygon)
28+
29+
return graph
30+
31+
32+
graph = main()
33+
34+
# ==============================================================================
35+
# Visualize
36+
# ==============================================================================
37+
38+
viewer = Viewer()
39+
40+
for edge in graph.edges():
41+
line = graph.edge_line(edge)
42+
if graph.edge_attribute(edge, "inner_bisector"):
43+
viewer.scene.add(line, linecolor=(1.0, 0.0, 0.0), linewidth=2)
44+
elif graph.edge_attribute(edge, "bisector"):
45+
viewer.scene.add(line, linecolor=(0.0, 0.0, 1.0))
46+
else:
47+
viewer.scene.add(line, linecolor=(0.0, 0.0, 0.0))
48+
49+
viewer.show()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Interior Straight Skeleton
2+
==========================
3+
4+
This example demonstrates how to compute the interior straight skeleton of a polygon using COMPAS CGAL.
5+
6+
Key Features:
7+
8+
* Computing straight skeleton from polygon points
9+
* Visualization of inner bisectors and edges
10+
* Color-coded display of different edge types
11+
12+
.. figure:: /_images/example_straight_skeleton_2_interior_straight_skeleton.png
13+
:figclass: figure
14+
:class: figure-img img-fluid
15+
16+
.. literalinclude:: example_straight_skeleton_2_interior_straight_skeleton.py
17+
:language: python
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from compas.geometry import Polygon
2+
from compas_viewer import Viewer
3+
from line_profiler import profile
4+
5+
from compas_cgal.straight_skeleton_2 import offset_polygon
6+
7+
8+
@profile
9+
def main():
10+
"""Create offset polygons."""
11+
12+
points = [
13+
(-1.91, 3.59, 0.0),
14+
(-5.53, -5.22, 0.0),
15+
(-0.39, -1.98, 0.0),
16+
(2.98, -5.51, 0.0),
17+
(4.83, -2.02, 0.0),
18+
(9.70, -3.63, 0.0),
19+
(12.23, 1.25, 0.0),
20+
(3.42, 0.66, 0.0),
21+
(2.92, 4.03, 0.0),
22+
(-1.91, 3.59, 0.0),
23+
]
24+
polygon = Polygon(points)
25+
offset = 1.5
26+
27+
offset_polygon_inner = offset_polygon(points, offset)
28+
offset_polygon_outer = offset_polygon(points, -offset)
29+
30+
return offset_polygon_inner, offset_polygon_outer, polygon
31+
32+
33+
offset_polygon_inner, offset_polygon_outer, polygon = main()
34+
35+
# ==============================================================================
36+
# Visualize
37+
# ==============================================================================
38+
39+
viewer = Viewer()
40+
viewer.scene.add(polygon)
41+
viewer.config.renderer.show_grid = False
42+
43+
for opolygon in offset_polygon_inner:
44+
viewer.scene.add(opolygon, linecolor=(1.0, 0.0, 0.0), facecolor=(1.0, 1.0, 1.0, 0.0))
45+
46+
for opolygon in offset_polygon_outer:
47+
viewer.scene.add(opolygon, linecolor=(0.0, 0.0, 1.0), facecolor=(1.0, 1.0, 1.0, 0.0))
48+
49+
viewer.show()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Polygon Offsetting
2+
==================
3+
4+
This example demonstrates how to create offset polygons (inward and outward) using COMPAS CGAL.
5+
6+
Key Features:
7+
8+
* Creating inner and outer polygon offsets
9+
* Handling complex polygon shapes
10+
* Color-coded visualization of original and offset polygons
11+
12+
.. figure:: /_images/example_straight_skeleton_2_interior_straight_skeleton_offset_polygon.png
13+
:figclass: figure
14+
:class: figure-img img-fluid
15+
16+
.. literalinclude:: example_straight_skeleton_2_interior_straight_skeleton_offset_polygon.py
17+
:language: python
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from compas.geometry import Polygon
2+
from compas_viewer import Viewer
3+
from line_profiler import profile
4+
5+
from compas_cgal.straight_skeleton_2 import weighted_offset_polygon
6+
7+
8+
@profile
9+
def main():
10+
"""Create weighted offset polygons."""
11+
12+
points = [
13+
(-1.91, 3.59, 0.0),
14+
(-5.53, -5.22, 0.0),
15+
(-0.39, -1.98, 0.0),
16+
(2.98, -5.51, 0.0),
17+
(4.83, -2.02, 0.0),
18+
(9.70, -3.63, 0.0),
19+
(12.23, 1.25, 0.0),
20+
(3.42, 0.66, 0.0),
21+
(2.92, 4.03, 0.0),
22+
(-1.91, 3.59, 0.0),
23+
]
24+
polygon = Polygon(points)
25+
26+
distances = [0.1, 0.3, 0.6, 0.1, 0.7, 0.5, 0.2, 0.4, 0.8, 0.2]
27+
weights = [1.0 / d for d in distances]
28+
offset = 1.0
29+
offset_polygons_outer = weighted_offset_polygon(points, -offset, weights)
30+
31+
return offset_polygons_outer, polygon
32+
33+
34+
offset_polygons_outer, polygon = main()
35+
36+
# ==============================================================================
37+
# Visualize
38+
# ==============================================================================
39+
40+
viewer = Viewer()
41+
viewer.scene.add(polygon)
42+
viewer.config.renderer.show_grid = False
43+
44+
for opolygon in offset_polygons_outer:
45+
viewer.scene.add(opolygon, linecolor=(0.0, 0.0, 1.0), facecolor=(1.0, 1.0, 1.0, 0.0))
46+
47+
viewer.show()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Weighted Polygon Offsetting
2+
===========================
3+
4+
This example demonstrates how to create weighted offset polygons using COMPAS CGAL.
5+
6+
Key Features:
7+
8+
* Creating weighted polygon offsets
9+
* Specifying different weights for each edge
10+
* Visualization of original and weighted offset polygons
11+
12+
.. figure:: /_images/example_straight_skeleton_2_interior_straight_skeleton_weighted_offset_polygon.png
13+
:figclass: figure
14+
:class: figure-img img-fluid
15+
16+
.. literalinclude:: example_straight_skeleton_2_interior_straight_skeleton_weighted_offset_polygon.py
17+
:language: python
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from compas.geometry import Point
2+
from compas.geometry import Polygon
3+
from compas_viewer import Viewer
4+
from line_profiler import profile
5+
6+
from compas_cgal.straight_skeleton_2 import interior_straight_skeleton_with_holes
7+
8+
9+
@profile
10+
def main():
11+
"""Compute the interior straight skeleton of a polygon with holes."""
12+
13+
# Outer boundary
14+
points_boundary = [
15+
(-1.91, 3.59, 0.0),
16+
(-5.53, -5.22, 0.0),
17+
(-0.39, -1.98, 0.0),
18+
(2.98, -5.51, 0.0),
19+
(4.83, -2.02, 0.0),
20+
(9.70, -3.63, 0.0),
21+
(12.23, 1.25, 0.0),
22+
(3.42, 0.66, 0.0),
23+
(2.92, 4.03, 0.0),
24+
(-1.91, 3.59, 0.0),
25+
]
26+
boundary = Polygon(points_boundary)
27+
28+
# Inner holes
29+
holes = [
30+
[(0.42, 0.88, 0.0), (1.1, -1.0, 0.0), (-1.97, -0.93, 0.0), (-1.25, 1.82, 0.0)],
31+
[(4.25, -0.64, 0.0), (2.9, -3.03, 0.0), (2.12, -2.16, 0.0), (2.89, -0.36, 0.0)],
32+
[(10.6, 0.29, 0.0), (9.48, -1.54, 0.0), (5.48, -1.26, 0.0), (5.98, -0.04, 0.0)],
33+
]
34+
holes = [Polygon(hole) for hole in holes]
35+
36+
graph = interior_straight_skeleton_with_holes(boundary, holes)
37+
38+
return graph
39+
40+
41+
graph = main()
42+
43+
# ==============================================================================
44+
# Visualize
45+
# ==============================================================================
46+
47+
viewer = Viewer()
48+
49+
for edge in graph.edges():
50+
line = graph.edge_line(edge)
51+
if graph.edge_attribute(edge, "inner_bisector"):
52+
viewer.scene.add(line, linecolor=(1.0, 0.0, 0.0), linewidth=2)
53+
elif graph.edge_attribute(edge, "bisector"):
54+
viewer.scene.add(line, linecolor=(0.0, 0.0, 1.0))
55+
else:
56+
viewer.scene.add(line, linecolor=(0.0, 0.0, 0.0))
57+
58+
viewer.show()
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Straight Skeleton with Holes
2+
============================
3+
4+
This example demonstrates how to compute the straight skeleton of a polygon with holes using COMPAS CGAL.
5+
6+
Key Features:
7+
8+
* Computing straight skeleton for polygons with holes
9+
* Handling multiple interior holes
10+
* Color-coded visualization of different edge types
11+
* Distinction between inner bisectors and regular edges
12+
13+
.. figure:: /_images/example_straight_skeleton_2_interior_straight_skeleton_with_holes.png
14+
:figclass: figure
15+
:class: figure-img img-fluid
16+
17+
.. literalinclude:: example_straight_skeleton_2_interior_straight_skeleton_with_holes.py
18+
:language: python

0 commit comments

Comments
 (0)