Skip to content

Commit

Permalink
fix(create): Ensure data trees work correctly for Straight Skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswmackey committed Oct 4, 2024
1 parent 4bf7a95 commit c81e9ee
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
4 changes: 2 additions & 2 deletions honeybee_grasshopper_core/json/HB_Straight_Skeleton.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.8.2",
"version": "1.8.3",
"nickname": "Skeleton",
"outputs": [
[
Expand Down Expand Up @@ -43,7 +43,7 @@
}
],
"subcategory": "0 :: Create",
"code": "\ntry: # import the core ladybug_geometry dependencies\n from ladybug_geometry.geometry3d import LineSegment3D\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_geometry:\\n\\t{}'.format(e))\n\ntry: # import the core ladybug_geometry dependencies\n from ladybug_geometry_polyskel.polyskel import skeleton_as_edge_list\n from ladybug_geometry_polyskel.polysplit import perimeter_core_subfaces_and_skeleton\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_geometry:\\n\\t{}'.format(e))\n\ntry: # import the ladybug_{{cad}} dependencies\n from ladybug_{{cad}}.config import tolerance\n from ladybug_{{cad}}.togeometry import to_face3d\n from ladybug_{{cad}}.fromgeometry import from_face3d, from_linesegment3d\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs, list_to_data_tree\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component):\n # extract the straight skeleton and sub-faces from the geometry\n skeleton, perim_poly, core_poly = [], [], []\n for face in to_face3d(_floor_geo):\n face = face.remove_colinear_vertices(tolerance)\n if offset_ is not None and offset_ > 0:\n skel, perim, core = perimeter_core_subfaces_and_skeleton(\n face, offset_, tolerance)\n skeleton.append([from_linesegment3d(lin) for lin in skel])\n perim_poly.append([from_face3d(p) for p in perim])\n core_poly.append([from_face3d(c) for c in core])\n else:\n skel_2d = skeleton_as_edge_list(\n face.boundary_polygon2d, face.hole_polygon2d,\n tolerance, intersect=True)\n skel_3d = []\n for seg in skel_2d:\n verts_3d = tuple(face.plane.xy_to_xyz(pt) for pt in seg.vertices)\n skel_3d.append(LineSegment3D.from_end_points(*verts_3d))\n skeleton.append([from_linesegment3d(lin) for lin in skel_3d])\n\n # convert outputs to data trees\n skeleton = list_to_data_tree(skeleton)\n perim_poly = list_to_data_tree(perim_poly)\n core_poly = list_to_data_tree(core_poly)\n",
"code": "\ntry: # import the core ladybug_geometry dependencies\n from ladybug_geometry.geometry3d import LineSegment3D\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_geometry:\\n\\t{}'.format(e))\n\ntry: # import the core ladybug_geometry dependencies\n from ladybug_geometry_polyskel.polyskel import skeleton_as_edge_list\n from ladybug_geometry_polyskel.polysplit import perimeter_core_subfaces_and_skeleton\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_geometry:\\n\\t{}'.format(e))\n\ntry: # import the ladybug_{{cad}} dependencies\n from ladybug_{{cad}}.config import tolerance\n from ladybug_{{cad}}.togeometry import to_face3d\n from ladybug_{{cad}}.fromgeometry import from_face3d, from_linesegment3d\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs, list_to_data_tree\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component):\n # extract the straight skeleton and sub-faces from the geometry\n skeleton, perim_poly, core_poly = [], [], []\n for face in to_face3d(_floor_geo):\n face = face.remove_colinear_vertices(tolerance)\n if offset_ is not None and offset_ > 0:\n skel, perim, core = perimeter_core_subfaces_and_skeleton(\n face, offset_, tolerance)\n skeleton.extend([from_linesegment3d(lin) for lin in skel])\n perim_poly.extend([from_face3d(p) for p in perim])\n core_poly.extend([from_face3d(c) for c in core])\n else:\n skel_2d = skeleton_as_edge_list(\n face.boundary_polygon2d, face.hole_polygon2d,\n tolerance, intersect=True)\n skel_3d = []\n for seg in skel_2d:\n verts_3d = tuple(face.plane.xy_to_xyz(pt) for pt in seg.vertices)\n skel_3d.append(LineSegment3D.from_end_points(*verts_3d))\n skeleton.extend([from_linesegment3d(lin) for lin in skel_3d])\n",
"category": "Honeybee",
"name": "HB Straight Skeleton",
"description": "Get the straight skeleton and core/perimeter sub-faces for any planar geometry.\n_\nThis component uses a modified version of the the polyskel package\n(https://github.com/Botffy/polyskel) by Armin Scipiades (aka. @Bottfy),\nwhich is, itself, a Python implementation of the straight skeleton\nalgorithm as described by Felkel and Obdrzalek in their 1998 conference paper\nStraight skeleton implementation\n(https://github.com/Botffy/polyskel/blob/master/doc/StraightSkeletonImplementation.pdf).\n-"
Expand Down
15 changes: 5 additions & 10 deletions honeybee_grasshopper_core/src/HB Straight Skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

ghenv.Component.Name = 'HB Straight Skeleton'
ghenv.Component.NickName = 'Skeleton'
ghenv.Component.Message = '1.8.2'
ghenv.Component.Message = '1.8.3'
ghenv.Component.Category = 'Honeybee'
ghenv.Component.SubCategory = '0 :: Create'
ghenv.Component.AdditionalHelpFromDocStrings = '0'
Expand Down Expand Up @@ -73,9 +73,9 @@
if offset_ is not None and offset_ > 0:
skel, perim, core = perimeter_core_subfaces_and_skeleton(
face, offset_, tolerance)
skeleton.append([from_linesegment3d(lin) for lin in skel])
perim_poly.append([from_face3d(p) for p in perim])
core_poly.append([from_face3d(c) for c in core])
skeleton.extend([from_linesegment3d(lin) for lin in skel])
perim_poly.extend([from_face3d(p) for p in perim])
core_poly.extend([from_face3d(c) for c in core])
else:
skel_2d = skeleton_as_edge_list(
face.boundary_polygon2d, face.hole_polygon2d,
Expand All @@ -84,9 +84,4 @@
for seg in skel_2d:
verts_3d = tuple(face.plane.xy_to_xyz(pt) for pt in seg.vertices)
skel_3d.append(LineSegment3D.from_end_points(*verts_3d))
skeleton.append([from_linesegment3d(lin) for lin in skel_3d])

# convert outputs to data trees
skeleton = list_to_data_tree(skeleton)
perim_poly = list_to_data_tree(perim_poly)
core_poly = list_to_data_tree(core_poly)
skeleton.extend([from_linesegment3d(lin) for lin in skel_3d])
Binary file not shown.

0 comments on commit c81e9ee

Please # to comment.