-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(vis-aperture): Add new GH Visualize Aperture Frames component
- Loading branch information
Showing
7 changed files
with
210 additions
and
5 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
honeybee_grasshopper_ph/src/HBPH - Visualize Aperture Frames.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# | ||
# Honeybee-PH: A Plugin for adding Passive-House data to LadybugTools Honeybee-Energy Models | ||
# | ||
# This component is part of the PH-Tools toolkit <https://github.com/PH-Tools>. | ||
# | ||
# Copyright (c) 2022, PH-Tools and bldgtyp, llc <[email protected]> | ||
# Honeybee-PH is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published | ||
# by the Free Software Foundation; either version 3 of the License, | ||
# or (at your option) any later version. | ||
# | ||
# Honeybee-PH is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# For a copy of the GNU General Public License | ||
# see <https://github.com/PH-Tools/honeybee_ph/blob/main/LICENSE>. | ||
# | ||
# @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+> | ||
# | ||
""" | ||
Pull out all the frame and glazing surfaces from a given list of HB-Apertures. This | ||
will create Rhino geometry for each of the elements which can be visualized in the | ||
scene and used to check the model construction. | ||
- | ||
EM May 24, 2023 | ||
Args: | ||
_aperture: (List[Aperture]) The list of HB-Aperatures to get the frame and | ||
glass geometry for. | ||
Returns: | ||
frame_surfaces_: The resulting frame element surfaces. | ||
glazing_surfaces_: The resulting glazing surfaces. | ||
""" | ||
|
||
import scriptcontext as sc | ||
import Rhino as rh | ||
import rhinoscriptsyntax as rs | ||
import ghpythonlib.components as ghc | ||
import Grasshopper as gh | ||
|
||
from honeybee_ph_rhino import gh_compo_io, gh_io | ||
|
||
# ------------------------------------------------------------------------------ | ||
import honeybee_ph_rhino._component_info_ | ||
reload(honeybee_ph_rhino._component_info_) | ||
ghenv.Component.Name = "HBPH - Visualize Aperture Frames" | ||
DEV = honeybee_ph_rhino._component_info_.set_component_params(ghenv, dev=False) | ||
if DEV: | ||
from honeybee_ph_rhino.gh_compo_io import visualize_win_frames as gh_compo_io | ||
reload(gh_compo_io) | ||
|
||
# ------------------------------------------------------------------------------ | ||
# -- GH Interface | ||
IGH = gh_io.IGH( ghdoc, ghenv, sc, rh, rs, ghc, gh ) | ||
|
||
|
||
# ------------------------------------------------------------------------------ | ||
gh_compo_interface = gh_compo_io.GHCompo_VisualizeWindowFrameElements( | ||
IGH, | ||
_apertures, | ||
) | ||
frame_surfaces_, glazing_surfaces_ = gh_compo_interface.run() |
Binary file added
BIN
+3.68 KB
honeybee_grasshopper_ph/user_objects/HBPH - Visualize Aperture Frames.ghuser
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
# -*- coding: utf-8 -*- | ||
# -*- Python Version: 2.7 -*- | ||
|
||
"""GHCompo Interface: HBPH - Visualize Window Frames.""" | ||
|
||
try: | ||
from typing import List, Iterable | ||
except ImportError: | ||
pass | ||
|
||
try: | ||
from itertools import izip # type: ignore | ||
except ImportError: | ||
izip = zip # Python 3 | ||
|
||
try: | ||
from System import Object # type: ignore | ||
from Grasshopper import DataTree # type: ignore | ||
from Grasshopper.Kernel.Data import GH_Path # type: ignore | ||
from Rhino.Geometry import Brep, Point3d # type: ignore | ||
except ImportError: | ||
pass # Outside Rhino | ||
|
||
try: | ||
from ladybug_geometry.geometry3d import LineSegment3D | ||
except ImportError as e: | ||
raise ImportError("\nFailed to import ladybug_geometry:\n\t{}".format(e)) | ||
|
||
try: | ||
from ladybug_rhino.fromgeometry import from_face3d, from_linesegment3d, from_point3d | ||
except ImportError as e: | ||
raise ImportError("\nFailed to import ladybug_rhino:\n\t{}".format(e)) | ||
|
||
try: | ||
from honeybee.aperture import Aperture | ||
except ImportError as e: | ||
raise ImportError("\nFailed to import honeybee:\n\t{}".format(e)) | ||
|
||
try: | ||
from honeybee_ph_rhino import gh_io | ||
except ImportError as e: | ||
raise ImportError("\nFailed to import honeybee_ph_rhino:\n\t{}".format(e)) | ||
|
||
|
||
class GHCompo_VisualizeWindowFrameElements(object): | ||
def __init__(self, _IGH, _apertures): | ||
# type: (gh_io.IGH, List[Aperture]) -> None | ||
self.IGH = _IGH | ||
self.apertures = _apertures | ||
self.tolerance = _IGH.sc.doc.ModelAbsoluteTolerance | ||
|
||
def get_ap_edges(self, ap): | ||
# type: (Aperture) -> tuple[LineSegment3D, LineSegment3D, LineSegment3D, LineSegment3D] | ||
lr_edges = ap.geometry.get_left_right_vertical_edges(self.tolerance) | ||
if not lr_edges: | ||
raise Exception("Failed to get left and right edges of the aperture.") | ||
ap_edge_l, ap_edge_r = lr_edges | ||
|
||
bt_edges = ap.geometry.get_top_bottom_horizontal_edges(self.tolerance) | ||
if not bt_edges: | ||
raise Exception("Failed to get bottom and top edges of the aperture.") | ||
ap_edge_b, ap_edge_t = bt_edges | ||
|
||
return (ap_edge_t, ap_edge_r, ap_edge_b, ap_edge_l) | ||
|
||
def create_frame_surface(self, _ap_edges, _ap_frame_elements, ap_ctr_pt): | ||
# type: (Iterable, Iterable, Point3d) -> List[Brep] | ||
frame_surfaces = [] | ||
for edge, frame in izip(_ap_edges, _ap_frame_elements): | ||
edge_rh = from_linesegment3d(edge) | ||
crv_mid_pt = from_point3d(edge.midpoint) | ||
extrusion_vector = self.IGH.ghc.Vector2Pt(crv_mid_pt, ap_ctr_pt, True).vector | ||
extrusion_vector = self.IGH.ghc.Amplitude(extrusion_vector, frame.width) | ||
ext = self.IGH.ghc.Extrude(base=edge_rh, direction=extrusion_vector) | ||
frame_surfaces.append(ext) | ||
|
||
return frame_surfaces | ||
|
||
def create_glazing_surface(self, _frame_surfaces, _ap_srfc, _ap_ctr_pt): | ||
# type: (List[Brep], Brep, Point3d) -> Brep | ||
joined_frames = self.IGH.ghc.BrepJoin(_frame_surfaces).breps | ||
edges = self.IGH.ghc.DeconstructBrep(joined_frames).edges | ||
win_srfcs = self.IGH.ghc.SurfaceSplit(_ap_srfc, edges) | ||
|
||
# -- Figure out which of the split surfaces is the glazing surface | ||
ct_pt_distances = [] | ||
for test_srfc in win_srfcs: | ||
ct_pt_distances.append( | ||
self.IGH.ghc.SurfaceClosestPoint(_ap_ctr_pt, test_srfc).distance | ||
) | ||
glazing_srfc = win_srfcs[ct_pt_distances.index(min(ct_pt_distances))] | ||
|
||
return glazing_srfc | ||
|
||
def run(self): | ||
# type: () -> tuple[DataTree[Object], DataTree[Object]] | ||
frame_surfaces_, glazing_surfaces_ = DataTree[Object](), DataTree[Object]() | ||
|
||
for i, ap in enumerate(self.apertures): | ||
# -- Pull out all the relevant Aperture data needed | ||
ap_srfc_rh = from_face3d(ap.geometry) | ||
ap_ctr_pt = self.IGH.ghc.Area(ap_srfc_rh).centroid | ||
ap_edges = self.get_ap_edges(ap) | ||
ap_const = ap.properties.energy.construction | ||
ap_frame_elements = ap_const.properties.ph.ph_frame.elements | ||
|
||
# -- | ||
frame_surfaces = self.create_frame_surface( | ||
ap_edges, ap_frame_elements, ap_ctr_pt | ||
) | ||
frame_surfaces_.AddRange(frame_surfaces, GH_Path(i)) | ||
|
||
# -- | ||
glazing_surfaces_.Add( | ||
self.create_glazing_surface(frame_surfaces, ap_srfc_rh, ap_ctr_pt), | ||
GH_Path(i), | ||
) | ||
|
||
return frame_surfaces_, glazing_surfaces_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters