Skip to content

Commit

Permalink
fix(geometry): Add an option for geo_block_ to Direct Sun Hours
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswmackey authored and Chris Mackey committed Jun 12, 2024
1 parent 289d881 commit f59f56b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
Binary file modified ladybug_grasshopper/icon/LB Direct Sun Hours.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions ladybug_grasshopper/json/LB_Direct_Sun_Hours.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.8.0",
"version": "1.8.1",
"nickname": "DirectSunHours",
"outputs": [
[
Expand Down Expand Up @@ -90,6 +90,13 @@
"type": "double",
"default": null
},
{
"access": "item",
"name": "geo_block_",
"description": "Set to \"True\" to count the input _geometry as opaque and\nset to \"False\" to discount the _geometry from the calculation and\nonly look at context_ that blocks the view. (Default: False).",
"type": "bool",
"default": null
},
{
"access": "item",
"name": "legend_par_",
Expand All @@ -113,7 +120,7 @@
}
],
"subcategory": "3 :: Analyze Geometry",
"code": "\ntry:\n from ladybug.color import Colorset\n from ladybug.graphic import GraphicContainer\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.config import conversion_to_meters\n from ladybug_{{cad}}.togeometry import to_joined_gridded_mesh3d, to_vector3d\n from ladybug_{{cad}}.fromgeometry import from_mesh3d, from_point3d, from_vector3d\n from ladybug_{{cad}}.fromobjects import legend_objects\n from ladybug_{{cad}}.text import text_objects\n from ladybug_{{cad}}.intersect import join_geometry_to_mesh, intersect_mesh_rays\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs, hide_output, \\\n show_output, objectify_output, recommended_processor_count\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component) and _run:\n # set the default offset distance and _cpu_count_\n _offset_dist_ = _offset_dist_ if _offset_dist_ is not None \\\n else 0.1 / conversion_to_meters()\n workers = _cpu_count_ if _cpu_count_ is not None else recommended_processor_count()\n\n # create the gridded mesh from the geometry\n study_mesh = to_joined_gridded_mesh3d(_geometry, _grid_size)\n points = [from_point3d(pt.move(vec * _offset_dist_)) for pt, vec in\n zip(study_mesh.face_centroids, study_mesh.face_normals)]\n hide_output(ghenv.Component, 1)\n\n # mesh the geometry and context\n shade_mesh = join_geometry_to_mesh(_geometry + context_)\n\n # get the study points and reverse the sun vectors (for backward ray-tracting)\n rev_vec = [from_vector3d(to_vector3d(vec).reverse()) for vec in _vectors]\n normals = [from_vector3d(vec) for vec in study_mesh.face_normals]\n\n # intersect the rays with the mesh\n int_matrix, angles = intersect_mesh_rays(\n shade_mesh, points, rev_vec, normals, cpu_count=workers)\n\n # compute the results\n int_mtx = objectify_output('Sun Intersection Matrix', int_matrix)\n if _timestep_ and _timestep_ != 1: # divide by the timestep before output\n results = [sum(int_list) / _timestep_ for int_list in int_matrix]\n else: # no division required\n results = [sum(int_list) for int_list in int_matrix]\n\n # create the mesh and legend outputs\n graphic = GraphicContainer(results, study_mesh.min, study_mesh.max, legend_par_)\n graphic.legend_parameters.title = 'hours'\n if legend_par_ is None or legend_par_.are_colors_default:\n graphic.legend_parameters.colors = Colorset.ecotect()\n title = text_objects('Direct Sun Hours', graphic.lower_title_location,\n graphic.legend_parameters.text_height * 1.5,\n graphic.legend_parameters.font)\n\n # create all of the visual outputs\n study_mesh.colors = graphic.value_colors\n mesh = from_mesh3d(study_mesh)\n legend = legend_objects(graphic.legend)\n",
"code": "\ntry:\n from ladybug.color import Colorset\n from ladybug.graphic import GraphicContainer\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.config import conversion_to_meters\n from ladybug_{{cad}}.togeometry import to_joined_gridded_mesh3d, to_vector3d\n from ladybug_{{cad}}.fromgeometry import from_mesh3d, from_point3d, from_vector3d\n from ladybug_{{cad}}.fromobjects import legend_objects\n from ladybug_{{cad}}.text import text_objects\n from ladybug_{{cad}}.intersect import join_geometry_to_mesh, intersect_mesh_rays\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs, hide_output, \\\n show_output, objectify_output, recommended_processor_count\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component) and _run:\n # set the default offset distance and _cpu_count_\n _offset_dist_ = _offset_dist_ if _offset_dist_ is not None \\\n else 0.1 / conversion_to_meters()\n workers = _cpu_count_ if _cpu_count_ is not None else recommended_processor_count()\n\n # create the gridded mesh from the geometry\n study_mesh = to_joined_gridded_mesh3d(_geometry, _grid_size)\n points = [from_point3d(pt.move(vec * _offset_dist_)) for pt, vec in\n zip(study_mesh.face_centroids, study_mesh.face_normals)]\n hide_output(ghenv.Component, 1)\n\n # mesh the geometry and context\n shade_mesh = join_geometry_to_mesh(context_) if geo_block_ else \\\n join_geometry_to_mesh(_geometry + context_)\n\n # get the study points and reverse the sun vectors (for backward ray-tracting)\n rev_vec = [from_vector3d(to_vector3d(vec).reverse()) for vec in _vectors]\n normals = None if geo_block_ else \\\n [from_vector3d(vec) for vec in study_mesh.face_normals]\n\n # intersect the rays with the mesh\n int_matrix, angles = intersect_mesh_rays(\n shade_mesh, points, rev_vec, normals, cpu_count=workers)\n\n # compute the results\n int_mtx = objectify_output('Sun Intersection Matrix', int_matrix)\n if _timestep_ and _timestep_ != 1: # divide by the timestep before output\n results = [sum(int_list) / _timestep_ for int_list in int_matrix]\n else: # no division required\n results = [sum(int_list) for int_list in int_matrix]\n\n # create the mesh and legend outputs\n graphic = GraphicContainer(results, study_mesh.min, study_mesh.max, legend_par_)\n graphic.legend_parameters.title = 'hours'\n if legend_par_ is None or legend_par_.are_colors_default:\n graphic.legend_parameters.colors = Colorset.ecotect()\n title = text_objects('Direct Sun Hours', graphic.lower_title_location,\n graphic.legend_parameters.text_height * 1.5,\n graphic.legend_parameters.font)\n\n # create all of the visual outputs\n study_mesh.colors = graphic.value_colors\n mesh = from_mesh3d(study_mesh)\n legend = legend_objects(graphic.legend)\n",
"category": "Ladybug",
"name": "LB Direct Sun Hours",
"description": "Calculate the number of hours of direct sunlight received by geometry using sun\nvectors obtained from the \"LB SunPath\" component.\n_\nSuch direct sun calculations can be used for shadow studies of outdoor enviroments\nor can be used to estimate glare potential from direct sun on the indoors.\n_\nNote that this component uses the CAD environment's ray intersection methods,\nwhich can be fast for geometries with low complexity but does not scale well\nfor complex geometries or many test points. For such complex studies,\nhoneybee-radiance should be used.\n-"
Expand Down
11 changes: 8 additions & 3 deletions ladybug_grasshopper/src/LB Direct Sun Hours.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
of the input _geometry. Typically, this should be a small positive
number to ensure points are not blocked by the mesh. (Default: 10 cm
in the equivalent Rhino Model units).
geo_block_: Set to "True" to count the input _geometry as opaque and
set to "False" to discount the _geometry from the calculation and
only look at context_ that blocks the view. (Default: False).
legend_par_: Optional legend parameters from the "LB Legend Parameters"
that will be used to customize the display of the results.
_cpu_count_: An integer to set the number of CPUs used in the execution of the
Expand Down Expand Up @@ -80,7 +83,7 @@

ghenv.Component.Name = "LB Direct Sun Hours"
ghenv.Component.NickName = 'DirectSunHours'
ghenv.Component.Message = '1.8.0'
ghenv.Component.Message = '1.8.1'
ghenv.Component.Category = 'Ladybug'
ghenv.Component.SubCategory = '3 :: Analyze Geometry'
ghenv.Component.AdditionalHelpFromDocStrings = '1'
Expand Down Expand Up @@ -117,11 +120,13 @@
hide_output(ghenv.Component, 1)

# mesh the geometry and context
shade_mesh = join_geometry_to_mesh(_geometry + context_)
shade_mesh = join_geometry_to_mesh(context_) if geo_block_ else \
join_geometry_to_mesh(_geometry + context_)

# get the study points and reverse the sun vectors (for backward ray-tracting)
rev_vec = [from_vector3d(to_vector3d(vec).reverse()) for vec in _vectors]
normals = [from_vector3d(vec) for vec in study_mesh.face_normals]
normals = None if geo_block_ else \
[from_vector3d(vec) for vec in study_mesh.face_normals]

# intersect the rays with the mesh
int_matrix, angles = intersect_mesh_rays(
Expand Down
Binary file modified ladybug_grasshopper/user_objects/LB Direct Sun Hours.ghuser
Binary file not shown.
Binary file modified samples/direct_sun_study.gh
Binary file not shown.
Binary file added samples/shadow_effect_of_one_building.gh
Binary file not shown.

0 comments on commit f59f56b

Please sign in to comment.