Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* Tests from 2D straight skeleton module.

### Changed

* Added polygon with holes offset test.

### Removed

* Profiling dependency and decorators from examples.


## [0.7.7] 2025-03-20

Expand Down
2 changes: 0 additions & 2 deletions docs/examples/example_booleans.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from compas.geometry import Sphere
from compas.geometry import Translation
from compas_viewer import Viewer
from line_profiler import profile

from compas_cgal.booleans import boolean_difference_mesh_mesh
from compas_cgal.booleans import boolean_intersection_mesh_mesh
Expand Down Expand Up @@ -59,7 +58,6 @@ def split():
return mesh.exploded()


@profile
def main():
"""Compute the boolean difference, intersection, union, and split of two triangle meshes."""
difference = boolean_difference()
Expand Down
4 changes: 0 additions & 4 deletions docs/examples/example_intersections.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import profile

from compas.datastructures import Mesh
from compas.geometry import Box
from compas.geometry import Point
from compas.geometry import Polyline
from compas.geometry import Sphere
from compas_viewer import Viewer
from line_profiler import profile

from compas_cgal.intersections import intersection_mesh_mesh


@profile
def main():
# ==============================================================================
# Make a box and a sphere
Expand Down
2 changes: 0 additions & 2 deletions docs/examples/example_measure.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from compas.datastructures import Mesh
from compas.geometry import Box
from line_profiler import profile

from compas_cgal.measure import mesh_area
from compas_cgal.measure import mesh_centroid
from compas_cgal.measure import mesh_volume


@profile
def main(mesh):
"""Mesh measurement methods."""
area = mesh_area(mesh)
Expand Down
4 changes: 1 addition & 3 deletions docs/examples/example_meshing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
from compas.geometry import scale_vector
from compas.geometry import transform_points_numpy
from compas_viewer import Viewer
from line_profiler import profile

from compas_cgal.meshing import mesh_remesh


@profile
def main():
"""Remesh a bunny mesh that is loaded from .ply file."""

Expand All @@ -30,7 +28,7 @@ def main():
S = Scale.from_factors([100, 100, 100])
R = Rotation.from_axis_and_angle(Vector(1, 0, 0), math.radians(90))

bunny.transform(R * S * T)
# bunny.transform(R * S * T)
V0, F0 = bunny.to_vertices_and_faces()
V1 = transform_points_numpy(V0, R * S * T)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
from compas_viewer import Viewer
from compas_viewer.config import Config
from compas_viewer.scene import Collection
from line_profiler import profile

from compas_cgal.reconstruction import pointset_normal_estimation
from compas_cgal.reconstruction import pointset_reduction


@profile
def reconstruction_pointset_normal_estimation():
# ==============================================================================
# Input geometry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
from compas.geometry import Pointcloud
from compas_viewer import Viewer
from compas_viewer.config import Config
from line_profiler import profile

from compas_cgal.reconstruction import pointset_outlier_removal


@profile
def reconstruction_pointset_outlier_removal():
"""Remove outliers from a point set."""

Expand Down
2 changes: 0 additions & 2 deletions docs/examples/example_reconstruction_pointset_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
from compas.geometry import transform_points_numpy
from compas_viewer import Viewer
from compas_viewer.config import Config
from line_profiler import profile

from compas_cgal.reconstruction import pointset_reduction


@profile
def reconstruction_pointset_reduction():
"""Reduce the number of points in a point set."""

Expand Down
4 changes: 0 additions & 4 deletions docs/examples/example_reconstruction_pointset_smoothing.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
from pathlib import Path

from compas.geometry import Pointcloud
from compas.geometry import Translation
from compas.geometry import transform_points_numpy
from compas_viewer import Viewer
from compas_viewer.config import Config
from line_profiler import profile

from compas_cgal.reconstruction import pointset_smoothing


@profile
def reconstruction_pointset_smoothing():
"""Smooth a point set."""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import math
from pathlib import Path

from compas.datastructures import Mesh
from compas.geometry import Pointcloud
from compas.geometry import Rotation
from compas.geometry import Scale
from compas_viewer import Viewer
from line_profiler import profile

from compas_cgal.reconstruction import poisson_surface_reconstruction


@profile
def reconstruction_poisson_surface_reconstruction():
FILE = Path(__file__).parent.parent.parent / "data" / "oni.xyz"

Expand Down
2 changes: 0 additions & 2 deletions docs/examples/example_skeletonization.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
from compas.geometry import Scale
from compas.geometry import Translation
from compas_viewer import Viewer
from line_profiler import profile

from compas_cgal.skeletonization import mesh_skeleton


@profile
def main():
"""Skeletonize a mesh."""

Expand Down
3 changes: 0 additions & 3 deletions docs/examples/example_slicer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import math
from pathlib import Path

import numpy as np
Expand All @@ -9,12 +8,10 @@
from compas.geometry import Vector
from compas_viewer import Viewer
from compas_viewer.config import Config
from line_profiler import profile

from compas_cgal.slicer import slice_mesh


@profile
def main():
# Get Mesh from STL
FILE = Path(__file__).parent.parent.parent / "data" / "3DBenchy.stl"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from compas.geometry import Point
from compas.geometry import Polygon
from compas_viewer import Viewer
from line_profiler import profile

from compas_cgal.straight_skeleton_2 import interior_straight_skeleton


@profile
def main():
"""Compute the interior straight skeleton of a polygon."""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from compas.geometry import Polygon
from compas_viewer import Viewer
from line_profiler import profile

from compas_cgal.straight_skeleton_2 import offset_polygon
from compas_cgal.straight_skeleton_2 import offset_polygon_with_holes


@profile
def main():
"""Create offset polygons."""

Expand All @@ -27,23 +26,32 @@ def main():
offset_polygon_inner = offset_polygon(points, offset)
offset_polygon_outer = offset_polygon(points, -offset)

return offset_polygon_inner, offset_polygon_outer, polygon

result = offset_polygon_with_holes(offset_polygon_outer[0], offset_polygon_inner, -0.1)

offset_polygon_inner, offset_polygon_outer, polygon = main()

return offset_polygon_inner, offset_polygon_outer, polygon, result


offset_polygon_inner, offset_polygon_outer, polygon, result = main()

# ==============================================================================
# Visualize
# ==============================================================================

viewer = Viewer()
viewer.scene.add(polygon)
viewer.scene.add(polygon, show_faces=False)
viewer.config.renderer.show_grid = False

for opolygon in offset_polygon_inner:
viewer.scene.add(opolygon, linecolor=(1.0, 0.0, 0.0), facecolor=(1.0, 1.0, 1.0, 0.0))
viewer.scene.add(opolygon, linecolor=(1.0, 0.0, 0.0), facecolor=(1.0, 0.0, 0.0, 0.0), show_faces=False)

for opolygon in offset_polygon_outer:
viewer.scene.add(opolygon, linecolor=(0.0, 0.0, 1.0), facecolor=(1.0, 1.0, 1.0, 0.0))
viewer.scene.add(opolygon, linecolor=(0.0, 0.0, 1.0), facecolor=(0.0, 0.0, 1.0, 0.0), show_faces=False)

for opolygon, holes in result:
viewer.scene.add(opolygon, linecolor=(0.0, 0.0, 1.0), facecolor=(0.0, 0.0, 1.0, 0.0), show_faces=False)
for hole in holes:
viewer.scene.add(hole, linecolor=(0.0, 0.0, 1.0), facecolor=(0.0, 0.0, 1.0, 0.0), show_faces=False)

viewer.show()
viewer.show()
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from compas.geometry import Polygon
from compas_viewer import Viewer
from line_profiler import profile

from compas_cgal.straight_skeleton_2 import weighted_offset_polygon


@profile
def main():
"""Create weighted offset polygons."""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from compas.geometry import Polygon
from compas_viewer import Viewer
from line_profiler import profile

from compas_cgal.straight_skeleton_2 import interior_straight_skeleton_with_holes


@profile
def main():
"""Compute the interior straight skeleton of a polygon with holes."""

Expand Down
2 changes: 0 additions & 2 deletions docs/examples/example_subdivision.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
from compas.geometry import Polyhedron
from compas.geometry import Translation
from compas_viewer import Viewer
from line_profiler import profile

from compas_cgal.subdivision import mesh_subdivide_catmull_clark
from compas_cgal.subdivision import mesh_subdivide_loop
from compas_cgal.subdivision import mesh_subdivide_sqrt3


@profile
def main():
"""Subdivide a mesh using different subdivision algorithms."""

Expand Down
2 changes: 0 additions & 2 deletions docs/examples/example_triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
from compas.geometry import Polygon
from compas.geometry import Translation
from compas_viewer import Viewer
from line_profiler import profile

from compas_cgal.triangulation import conforming_delaunay_triangulation
from compas_cgal.triangulation import refined_delaunay_mesh


@profile
def main():
"""Triangulate a mesh with holes."""

Expand Down
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ bump-my-version
compas_invocations2
compas_viewer
invoke >=0.14
line_profiler >=4.0.0
pytest >=7.0.0
pytest-cov >=4.0.0
nanobind >=1.3.2
Expand Down
17 changes: 14 additions & 3 deletions src/compas_cgal/straight_skeleton_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ def offset_polygon_with_holes(points, holes, offset) -> list[Tuple[Polygon, list
"""
points = list(points)
normal = normal_polygon(points, True)

if TOL.is_allclose(normal, [0, 0, -1]):
points.reverse()
normal *= -1

if not TOL.is_allclose(normal, [0, 0, 1]):
raise ValueError("The normal of the polygon should be [0, 0, 1]. The normal of the provided polygon is {}".format(normal))
V = np.asarray(points, dtype=np.float64, order="C")
Expand All @@ -189,8 +194,14 @@ def offset_polygon_with_holes(points, holes, offset) -> list[Tuple[Polygon, list
for i, hole in enumerate(holes):
points = hole
normal_hole = normal_polygon(points, True)

if TOL.is_allclose(normal_hole, [0, 0, 1]):
points.points.reverse()
normal_hole *= -1

if not TOL.is_allclose(normal_hole, [0, 0, -1]):
raise ValueError("The normal of the hole should be [0, 0, -1]. The normal of the provided {}-th hole is {}".format(i, normal_hole))

hole = np.asarray(points, dtype=np.float64, order="C")
H.append(hole)

Expand All @@ -200,10 +211,10 @@ def offset_polygon_with_holes(points, holes, offset) -> list[Tuple[Polygon, list
offset_polygons = _straight_skeleton_2.create_offset_polygons_2_inner_with_holes(V, H, offset)

result = []
for points, holes_np in offset_polygons:
polygon = Polygon(points.tolist())
for points_list in offset_polygons:
polygon = Polygon(points_list[0].tolist())
holes = []
for hole in holes_np:
for hole in points_list[1:]:
holes.append(Polygon(hole.tolist()))
result.append((polygon, holes))
return result
Expand Down
Loading
Loading