Skip to content

Commit

Permalink
fix(geometry): Fix issues in previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswmackey committed Jun 12, 2024
1 parent f59f56b commit 59afb47
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
8 changes: 4 additions & 4 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.1",
"version": "1.8.2",
"nickname": "DirectSunHours",
"outputs": [
[
Expand Down Expand Up @@ -86,14 +86,14 @@
{
"access": "item",
"name": "_offset_dist_",
"description": "A number for the distance to move points from the surfaces\nof the input _geometry. Typically, this should be a small positive\nnumber to ensure points are not blocked by the mesh. (Default: 10 cm\nin the equivalent Rhino Model units).",
"description": "A number for the distance to move points from the surfaces\nof the input _geometry. Typically, this should be a small positive\nnumber to ensure points are not blocked by the mesh but it can be\nequal to zero when geo_block_ is False. (Default: 10 cm when\ngeo_block_ is True and zero when geo_block_ is False).",
"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).",
"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 sun. (Default: True).",
"type": "bool",
"default": null
},
Expand All @@ -120,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(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",
"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 if _offset_dist_ is None:\n _offset_dist_ = 0.1 / conversion_to_meters() \\\n if geo_block_ or geo_block_ is None else 0\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 if geo_block_ or geo_block_ is None else join_geometry_to_mesh(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 if geo_block_ or geo_block_ is None else None\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
22 changes: 12 additions & 10 deletions ladybug_grasshopper/src/LB Direct Sun Hours.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@
and context_ in order to yield meaningful results.
_offset_dist_: A number for the distance to move points from the surfaces
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).
number to ensure points are not blocked by the mesh but it can be
equal to zero when geo_block_ is False. (Default: 10 cm when
geo_block_ is True and zero when geo_block_ is False).
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).
only look at context_ that blocks the sun. (Default: True).
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 @@ -83,7 +84,7 @@

ghenv.Component.Name = "LB Direct Sun Hours"
ghenv.Component.NickName = 'DirectSunHours'
ghenv.Component.Message = '1.8.1'
ghenv.Component.Message = '1.8.2'
ghenv.Component.Category = 'Ladybug'
ghenv.Component.SubCategory = '3 :: Analyze Geometry'
ghenv.Component.AdditionalHelpFromDocStrings = '1'
Expand All @@ -109,8 +110,9 @@

if all_required_inputs(ghenv.Component) and _run:
# set the default offset distance and _cpu_count_
_offset_dist_ = _offset_dist_ if _offset_dist_ is not None \
else 0.1 / conversion_to_meters()
if _offset_dist_ is None:
_offset_dist_ = 0.1 / conversion_to_meters() \
if geo_block_ or geo_block_ is None else 0
workers = _cpu_count_ if _cpu_count_ is not None else recommended_processor_count()

# create the gridded mesh from the geometry
Expand All @@ -120,13 +122,13 @@
hide_output(ghenv.Component, 1)

# mesh the geometry and context
shade_mesh = join_geometry_to_mesh(context_) if geo_block_ else \
join_geometry_to_mesh(_geometry + context_)
shade_mesh = join_geometry_to_mesh(_geometry + context_) \
if geo_block_ or geo_block_ is None else join_geometry_to_mesh(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 = None if geo_block_ else \
[from_vector3d(vec) for vec in study_mesh.face_normals]
normals = [from_vector3d(vec) for vec in study_mesh.face_normals] \
if geo_block_ or geo_block_ is None else None

# 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 modified samples/shadow_effect_of_one_building.gh
Binary file not shown.

0 comments on commit 59afb47

Please sign in to comment.