Skip to content

Commit 04c4e61

Browse files
chriswmackeyChris Mackey
authored andcommitted
fix(model): Add options to include sensor grids in model vis set
1 parent efcb28d commit 04c4e61

File tree

2 files changed

+75
-12
lines changed

2 files changed

+75
-12
lines changed

honeybee_display/cli/__init__.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ def display():
7272
'--color-attr/--text-attr', help='Flag to note whether to note whether the '
7373
'input room-attr and face-attr should be expressed as a colored AnalysisGeometry '
7474
'or a ContextGeometry as text labels.', default=True, show_default=True)
75+
@click.option(
76+
'--grid-display-mode', '-m', help='Text that dictates how the ContextGeometry '
77+
'for Model SensorGrids should display in the resulting visualization. The Default '
78+
'option will draw sensor points whenever there is no grid_data_path and will not '
79+
'draw them at all when grid data is provided, assuming the AnalysisGeometry of '
80+
'the grids is sufficient. Choose from: Default, Points, Wireframe, Surface, '
81+
'SurfaceWithEdges, None.',
82+
type=str, default='Default', show_default=True)
83+
@click.option(
84+
'--hide-grid/--show-grid', ' /-sg', help='Flag to note whether the SensorGrid '
85+
'ContextGeometry should be hidden or shown by default.',
86+
default=True, show_default=True)
7587
@click.option(
7688
'--grid-data', '-g', help='An optional path to a folder containing data that '
7789
'aligns with the SensorGrids in the model. Any sub folder within this path '
@@ -86,7 +98,7 @@ def display():
8698
default=None, show_default=True,
8799
type=click.Path(file_okay=False, dir_okay=True, resolve_path=True))
88100
@click.option(
89-
'--grid-display-mode', '-m', help='Text to set the display_mode of the '
101+
'--grid-data-display-mode', '-dm', help='Text to set the display_mode of the '
90102
'AnalysisGeometry that is generated from the grid_data_path above. Note '
91103
'that this has no effect if there are no meshes associated with the model '
92104
'SensorGrids. Choose from: Surface, SurfaceWithEdges, Wireframe, Points',
@@ -104,8 +116,8 @@ def display():
104116
type=click.File('w'), default='-', show_default=True)
105117
def model_to_vis_set(
106118
model_file, color_by, wireframe, mesh, show_color_by,
107-
room_attr, face_attr, color_attr,
108-
grid_data, grid_display_mode, output_format, output_file):
119+
room_attr, face_attr, color_attr, grid_display_mode, hide_grid,
120+
grid_data, grid_data_display_mode, output_format, output_file):
109121
"""Get a JSON object with all configuration information"""
110122
try:
111123
model_obj = Model.from_file(model_file)
@@ -117,7 +129,8 @@ def model_to_vis_set(
117129
color_by=color_by, include_wireframe=wireframe, use_mesh=mesh,
118130
hide_color_by=hide_color_by, room_attr=room_attr, face_attr=face_attr,
119131
room_text_labels=text_labels, face_text_labels=text_labels,
120-
grid_data_path=grid_data, grid_display_mode=grid_display_mode)
132+
grid_display_mode=grid_display_mode, hide_grid=hide_grid,
133+
grid_data_path=grid_data, grid_data_display_mode=grid_data_display_mode)
121134
output_format = output_format.lower()
122135
if output_format in ('vsf', 'json'):
123136
output_file.write(json.dumps(vis_set.to_dict()))

honeybee_display/model.py

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from ladybug_geometry.geometry3d import Point3D
66
from ladybug.datatype.generic import GenericType
77
from ladybug.color import Color
8-
from ladybug_display.geometry3d import DisplayLineSegment3D, DisplayFace3D, \
9-
DisplayMesh3D
8+
from ladybug_display.geometry3d import DisplayPoint3D, DisplayLineSegment3D, \
9+
DisplayFace3D, DisplayMesh3D
1010
from ladybug_display.visualization import VisualizationSet, ContextGeometry, \
1111
AnalysisGeometry, VisualizationData, VisualizationMetaData
1212
from honeybee.boundarycondition import Outdoors, Ground, Surface
@@ -44,12 +44,13 @@ def model_to_vis_set(
4444
hide_color_by=False, room_attr=None, face_attr=None,
4545
room_text_labels=False, face_text_labels=False,
4646
room_legend_par=None, face_legend_par=None,
47-
grid_data_path=None, grid_display_mode='Surface'):
47+
grid_display_mode='Default', hide_grid=True,
48+
grid_data_path=None, grid_data_display_mode='Surface'):
4849
"""Translate a Honeybee Model to a VisualizationSet.
4950
5051
Args:
5152
model: A Honeybee Model object to be converted to a VisualizationSet.
52-
color_by: Text for the property that dictates the colors of the Model geometry.
53+
color_by: Text that dictates the colors of the Model geometry.
5354
If none, only a wireframe of the Model will be generated, assuming
5455
include_wireframe is True. This is useful when the primary purpose of
5556
the visualization is to display results in relation to the Model
@@ -103,6 +104,21 @@ def model_to_vis_set(
103104
face_legend_par: An optional LegendParameter object to customize the display
104105
of the face_attr. When face_text_labels is True, only the text_height
105106
and font will be used to customize the text.
107+
grid_display_mode: Text that dictates how the ContextGeometry for Model
108+
SensorGrids should display in the resulting visualization. The Default
109+
option will draw sensor points whenever there is no grid_data_path and
110+
won't draw them at all when grid data is provided, assuming the
111+
AnalysisGeometry of the grids is sufficient. Choose from the following:
112+
113+
* Default
114+
* Points
115+
* Wireframe
116+
* Surface
117+
* SurfaceWithEdges
118+
* None
119+
120+
hide_grid: Boolean to note whether the SensorGrid ContextGeometry should be
121+
hidden or shown by default. (Default: True).
106122
grid_data_path: An optional path to a folder containing data that aligns
107123
with the SensorGrids in the model. Any sub folder within this path
108124
that contains a grids_into.json (and associated CSV files) will be
@@ -113,9 +129,9 @@ def model_to_vis_set(
113129
grids_info.json exist in the root of this grid_data_path. Also
114130
note that this argument has no impact if honeybee-radiance is not
115131
installed and SensorGrids cannot be decoded. (Default: None).
116-
grid_display_mode: Optional text to set the display_mode of the AnalysisGeometry
117-
that is is generated from the grid_data_path above. Note that this
118-
has no effect if there are no meshes associated with the model
132+
grid_data_display_mode: Optional text to set the display_mode of the
133+
AnalysisGeometry that is is generated from the grid_data_path above. Note
134+
that this has no effect if there are no meshes associated with the model
119135
SensorGrids. (Default: Surface). Choose from the following:
120136
121137
* Surface
@@ -284,6 +300,40 @@ def model_to_vis_set(
284300
geo_obj.add_data_set(ra_a_geo[0])
285301
geo_objs.append(geo_obj)
286302

303+
# add the sensor grid geometry if requested
304+
gdm = grid_display_mode.lower()
305+
default_exclude = gdm == 'default' and grid_data_path is not None and \
306+
os.path.isdir(grid_data_path)
307+
if gdm != 'none' and not default_exclude:
308+
# get the sensor grids and evaluate whether they have meshes
309+
try:
310+
grid_objs = model.properties.radiance.sensor_grids
311+
except AttributeError: # honeybee-radiance is not installed
312+
grid_objs = []
313+
if len(grid_objs) != 0:
314+
grid_meshes = [g.mesh for g in grid_objs]
315+
g_meshes_avail = all(m is not None for m in grid_meshes)
316+
# create the context geometry for the sensor grids
317+
dis_geos = []
318+
if gdm in ('default', 'points') or not g_meshes_avail:
319+
for grid in grid_objs:
320+
for p in grid.positions:
321+
dis_geos.append(DisplayPoint3D(Point3D(*p)))
322+
elif gdm == 'wireframe':
323+
for mesh in grid_meshes:
324+
dis_geos.append(DisplayMesh3D(mesh, display_mode='Wireframe'))
325+
elif gdm in ('surface', 'surfacewithedges'):
326+
for mesh in grid_meshes:
327+
grey = Color(100, 100, 100)
328+
d_mesh = DisplayMesh3D(
329+
mesh, color=grey, display_mode=grid_display_mode)
330+
dis_geos.append(d_mesh)
331+
con_geo = ContextGeometry('Sensor_Grids', dis_geos)
332+
if hide_grid:
333+
con_geo.hidden = True
334+
con_geo.display_name = 'Sensor Grids'
335+
geo_objs.append(con_geo)
336+
287337
# add grid data if requested
288338
if grid_data_path is not None and os.path.isdir(grid_data_path):
289339
# first try to get all of the Model sensor grids
@@ -334,7 +384,7 @@ def model_to_vis_set(
334384
gr_pts = [Point3D(*pos) for gr in grid_objs for pos in gr.positions]
335385
a_geo = AnalysisGeometry('Grid_Data', gr_pts, data_sets)
336386
a_geo.display_name = 'Grid Data'
337-
a_geo.display_mode = grid_display_mode
387+
a_geo.display_mode = grid_data_display_mode
338388
geo_objs.append(a_geo)
339389

340390
# add the wireframe if requested

0 commit comments

Comments
 (0)