-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changing straight skeleton return data into Graph
#33
Changes from 6 commits
4212b73
48d446f
f57112e
e0c2a66
e872aa5
c7b5cd9
3003642
32e30dc
f6490b1
ad78cd0
bfa62a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,31 @@ | ||
import numpy as np | ||
from compas.datastructures import Graph | ||
from compas.geometry import Polygon | ||
from compas.geometry import normal_polygon | ||
from compas.tolerance import TOL | ||
|
||
from compas_cgal._cgal import straight_skeleton_2 | ||
|
||
from .types import PolylinesNumpy | ||
|
||
def graph_from_skeleton_data(skeleton_data) -> Graph: | ||
Mv, Mvi, Me, Mei = skeleton_data | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not split these parameters? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point, made the changes and added doc for graph_from_skeleton_data |
||
|
||
def create_interior_straight_skeleton(points) -> PolylinesNumpy: | ||
graph = Graph() | ||
for pt, i in zip(Mv, Mvi): | ||
graph.add_node(key=i, x=pt[0], y=pt[1], z=pt[2]) | ||
|
||
for edge, etype in zip(Me, Mei): | ||
edge = graph.add_edge(*edge) | ||
if etype == 0: | ||
graph.edge_attribute(edge, "inner_bisector", True) | ||
elif etype == 1: | ||
graph.edge_attribute(edge, "bisector", True) | ||
else: | ||
graph.edge_attribute(edge, "boundary", True) | ||
return graph | ||
|
||
|
||
def create_interior_straight_skeleton(points) -> Graph: | ||
"""Compute the skeleton of a polygon. | ||
|
||
Parameters | ||
|
@@ -31,10 +48,10 @@ def create_interior_straight_skeleton(points) -> PolylinesNumpy: | |
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) | ||
return straight_skeleton_2.create_interior_straight_skeleton(V) | ||
return graph_from_skeleton_data(straight_skeleton_2.create_interior_straight_skeleton(V)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you "star" the output, you could split the params in |
||
|
||
|
||
def create_interior_straight_skeleton_with_holes(points, holes) -> PolylinesNumpy: | ||
def create_interior_straight_skeleton_with_holes(points, holes) -> Graph: | ||
"""Compute the skeleton of a polygon with holes. | ||
|
||
Parameters | ||
|
@@ -69,7 +86,7 @@ def create_interior_straight_skeleton_with_holes(points, holes) -> PolylinesNump | |
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) | ||
H.append(hole) | ||
return straight_skeleton_2.create_interior_straight_skeleton_with_holes(V, H) | ||
return graph_from_skeleton_data(straight_skeleton_2.create_interior_straight_skeleton_with_holes(V, H)) | ||
|
||
|
||
def create_offset_polygons_2(points, offset) -> list[Polygon]: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just fyi, there is
line = graph.edge_line(edge)