Skip to content

Commit

Permalink
feat(visualization): Adding components to colored meshes and legends
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswmackey committed Jun 7, 2019
1 parent 0946d6a commit f835aeb
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 61 deletions.
70 changes: 70 additions & 0 deletions plugin/grasshopper/src/LadybugPlus_Color Mesh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Ladybug: A Plugin for Environmental Analysis (GPL) started by Mostapha Sadeghipour Roudsari
# This file is part of Ladybug.
#
# You should have received a copy of the GNU General Public License
# along with Ladybug; If not, see <http://www.gnu.org/licenses/>.
#
# @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+>


"""
Use this component to generate colors based on values and legend parameters.
-
Args:
_values: A list of numerical values with which to color the mesh.
The number of values must match the number of faces or vertices
in the mesh.
_mesh: A Mesh object, with a number of faces or vertices that match
the number of input values and will be colored with restults.
legend_par_: Optional legend parameters from the Ladybug
'Legend Parameters' component.
legend_title_: A text string for Legend title. Typically, the units
of the data are used here but the type of data might also be used.
Default is an empty string.
global_title_: A text string to label the entire mesh. It will be
displayed in the lower left of the result mesh. Default is for no
title.
Returns:
mesh: The input _mesh that has been colored with results.
legend: Geometry representing the legend for the mesh.
title: A text object for the global_title.
colors: The colors associated with each input value.
legend_par: The input legend parameters with defaults filled for
unset properties.
"""

ghenv.Component.Name = "LadybugPlus_Color Mesh"
ghenv.Component.NickName = 'colorMesh'
ghenv.Component.Message = 'VER 0.0.04\nMAY_31_2019'
ghenv.Component.Category = "LadybugPlus"
ghenv.Component.SubCategory = "03 :: Extra"
ghenv.Component.AdditionalHelpFromDocStrings = "1"

try:
from ladybug.resultmesh import ResultMesh
from ladybug_rhino.togeometry import to_mesh3d
from ladybug_rhino.fromgeometry import from_mesh3d
from ladybug_rhino.fromobjects import legend_objects
from ladybug_rhino.text import text_objects
from ladybug_dotnet.color import color_to_color
except ImportError as e:
raise ImportError('\nFailed to import ladybug:\n\t{}'.format(e))

if len(_values) != 0 and _values[0] is not None and _mesh:
# generate Ladybug objects
res_mesh = ResultMesh(_values, to_mesh3d(_mesh), legend_par_)

# generate titles
if legend_title_ is not None:
res_mesh.legend_parameters.title = legend_title_
if global_title_ is not None:
title = text_objects(global_title_, res_mesh.lower_title_location,
res_mesh.legend_parameters.text_height,
res_mesh.legend_parameters.font)

# draw rhino objects
lb_mesh = res_mesh.colored_mesh
mesh = from_mesh3d(lb_mesh)
legend = legend_objects(res_mesh.legend)
colors = [color_to_color(col) for col in lb_mesh.colors]
legend_par = res_mesh.legend_parameters
12 changes: 6 additions & 6 deletions plugin/grasshopper/src/LadybugPlus_Color Range.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@

ghenv.Component.Name = "LadybugPlus_Color Range"
ghenv.Component.NickName = 'colRange'
ghenv.Component.Message = 'VER 0.0.04\nFEB_07_2018'
ghenv.Component.Message = 'VER 0.0.04\nMAY_30_2019'
ghenv.Component.Category = "LadybugPlus"
ghenv.Component.SubCategory = "03 :: Extra"
ghenv.Component.AdditionalHelpFromDocStrings = "2"
ghenv.Component.AdditionalHelpFromDocStrings = "1"

try:
import ladybug.color as col
import ladybug.output as output
from ladybug.color import Colorset
from ladybug_dotnet.color import color_to_color
except ImportError as e:
raise ImportError('\nFailed to import ladybug:\n\t{}'.format(e))

_index = _index or 0
cs = col.Colorset()
colors = output.color_to_color(cs[_index])
cs = Colorset()
colors = [color_to_color(col) for col in cs[_index]]
4 changes: 2 additions & 2 deletions plugin/grasshopper/src/LadybugPlus_Download Weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@

ghenv.Component.Name = "LadybugPlus_Download Weather"
ghenv.Component.NickName = 'downloadWeather'
ghenv.Component.Message = 'VER 0.0.04\nOCT_14_2018'
ghenv.Component.Message = 'VER 0.0.04\nMAY_31_2019'
ghenv.Component.Category = "LadybugPlus"
ghenv.Component.SubCategory = '00 :: Ladybug'
ghenv.Component.AdditionalHelpFromDocStrings = "1"

import os
try:
from ladybug.dotnet import download_file
from ladybug_dotnet.download import download_file
from ladybug.futil import unzip_file
except ImportError as e:
raise ImportError('\nFailed to import ladybug:\n\t{}'.format(e))
Expand Down
5 changes: 3 additions & 2 deletions plugin/grasshopper/src/LadybugPlus_EPWmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

ghenv.Component.Name = "LadybugPlus_EPWmap"
ghenv.Component.NickName = 'epwMap'
ghenv.Component.Message = 'VER 0.0.04\nOCT_14_2018'
ghenv.Component.Message = 'VER 0.0.04\nMAY_31_2019'
ghenv.Component.Category = "LadybugPlus"
ghenv.Component.SubCategory = '00 :: Ladybug'
ghenv.Component.AdditionalHelpFromDocStrings = "1"
Expand Down Expand Up @@ -47,7 +47,8 @@
wb.get(browser[0]).open(url, 2, True)
print "Opening epwmap."
if broswer_found == False:
print "An accepable broswer was not found on your machine. Therefore, the default browser will be used."
print "An accepable broswer was not found on your machine.\n" \
"The default browser will be used but epwmap may not display correctly there."
wb.open(url, 2, True)
else:
print "Set _epw_map to True."
35 changes: 0 additions & 35 deletions plugin/grasshopper/src/LadybugPlus_Generate Colors.py

This file was deleted.

70 changes: 54 additions & 16 deletions plugin/grasshopper/src/LadybugPlus_Legend Parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,72 @@
Any Ladybug component that outputs a colored mesh and a legend will have an input
that can accept Legend Parameters from this component.
This component particularly helpful in making the colors of Ladybug graphics consistent
for a presentation or for synchonizing the numerical range and colors between Ladybug graphics.
-
Args:
_domain_: A number representing the higher boundary of the legend's numerical range. The default is set to the highest value of the data stream that the legend refers to.
_c_type_:
_colors_: A list of colors that will be used to re-color the legend and the corresponding colored mesh(es). The number of colors input here should match the numSegments_ value input above. An easy way to generate a list of colors to input here is with the Grasshopper "Gradient" component and a Grasshopper "Series" component connected to the Gradient component's "t" input. A bunch of Grasshopper "Swatch" components is another way to generate a list of custom colors. The default colors are a gradient spectrum from blue to yellow to red.
min_: A number to set the lower boundary of the legend. If None, the
minimum of the values associated with the legend will be used.
max_: A number to set the upper boundary of the legend. If None, the
maximum of the values associated with the legend will be used.
num_segs_: An interger representing the number of steps between
the high and low boundary of the legend. The default is set to 11
and any custom values input in here should always be greater than or
equal to 2.
colors_: An list of color objects. Default is Ladybug's original colorset.
continuous_col_: Boolean. If True, the colors along the legend will be in
a continuous gradient. If False, they will be categorized in
incremental groups according to the number_of_segments.
Default is False for depicting discrete categories.
num_decimals_: An optional integer to set the number of decimal
places for the numbers in the legend text. Default is 2.
larger_smaller_: Boolean noting whether to include larger than and
smaller than (> and <) values after the upper and lower legend segment
text. Default is False.
vert_or_horiz_: Boolean. If True, the legend mesh and text points
will be generated vertically. If False, they will genrate a
horizontal legend. Default is True for a vertically-oriented legend.
base_plane_: A Plane to note the starting point and orientation from
where the legend will be genrated. The default is the world XY plane
at origin (0, 0, 0).
seg_height_: An optional number to set the height of each of the legend
segments. Default is 1.
seg_width_: An optional number to set the width of each of the legend
segments. Default is 1 when legend is vertical. When horizontal, the
default is (text_height * (number_decimal_places + 2)).
text_height_: An optional number to set the size of the text in model units.
Default is half of the segment_height.
font_: An optional text string to specify the font to be used for the text.
Examples include "Arial", "Times New Roman", "Courier" (all without
quotations). Default is "Arial".
Returns:
legend_par: A legend parameters to be plugged into any of the Ladybug components with a legend.
leg_par: A legend parameter object that can be plugged into any of the
Ladybug components with a legend.
"""

ghenv.Component.Name = "LadybugPlus_Legend Parameters"
ghenv.Component.NickName = 'legendPar'
ghenv.Component.Message = 'VER 0.0.04\nOCT_14_2018'
ghenv.Component.Message = 'VER 0.0.04\nMAY_31_2019'
ghenv.Component.Category = "LadybugPlus"
ghenv.Component.SubCategory = "03 :: Extra"
ghenv.Component.AdditionalHelpFromDocStrings = "2"
ghenv.Component.AdditionalHelpFromDocStrings = "1"


try:
import ladybug.legendparameters as lpar
import ladybug.color as col
from ladybug.legend import LegendParameters
from ladybug_rhino.togeometry import to_plane
except ImportError as e:
raise ImportError('\nFailed to import ladybug:\n\t{}'.format(e))

legend_par = lpar.LegendParameters(
legend_range=_domain_, number_of_segments=11,
colors=_colors_, chart_type=_c_type_
)
if colors_ == []:
colors_ = None
if base_plane_:
base_plane_ = to_plane(base_plane_)

leg_par = LegendParameters(min=min_, max=max_, number_of_segments=num_segs_,
colors=colors_, continuous_legend=continuous_col_,
number_decimal_places=num_decimals_,
include_larger_smaller=larger_smaller_,
vertical_or_horizontal=vert_or_horiz_,
base_plane=base_plane_,
segment_height=seg_height_, segment_width=seg_width_,
text_height=text_height_, font=font_)
61 changes: 61 additions & 0 deletions plugin/grasshopper/src/Ladybug_Generate Point Grid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Ladybug: A Plugin for Environmental Analysis (GPL) started by Mostapha Sadeghipour Roudsari
# This file is part of Ladybug.
#
# You should have received a copy of the GNU General Public License
# along with Ladybug; If not, see <http://www.gnu.org/licenses/>.
#
# @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+>


"""
Genrate a mesh with corresponding test points.
The resulting mesh will be in a format that the 'Color Mesh' component will accept.
-
Args:
_geometry: Brep or Mesh from which to generate the points and grid.
_grid_size: Number for the size of the test grid.
_dist_surface_: 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 is 0.
Returns:
points: Test points at the center of each mesh face.
vectors: Vectors for the normal direction at each of the points.
face_areas: Area of each mesh face.
mesh: Analysis mesh that can be passed to the 'Color Mesh' component.
"""

ghenv.Component.Name = "Ladybug_Generate Point Grid"
ghenv.Component.NickName = 'genPts'
ghenv.Component.Message = 'VER 0.0.04\nMAY_31_2019'
ghenv.Component.Category = "LadybugPlus"
ghenv.Component.SubCategory = "03 :: Extra"
ghenv.Component.AdditionalHelpFromDocStrings = "1"

try:
from ladybug_rhino.togeometry import to_gridded_mesh3d
from ladybug_rhino.fromgeometry import from_mesh3d
from ladybug_rhino.fromgeometry import from_point3d, from_vector3d
except ImportError as e:
raise ImportError('\nFailed to import ladybug:\n\t{}'.format(e))

import Rhino.Geometry as rg


if _geometry and _grid_size is not None:
# check the input and generate the mesh.
_dist_surface_ = _dist_surface_ or 0
if type(_geometry) == rg.Brep:
lb_mesh = to_gridded_mesh3d(_geometry, _grid_size, _dist_surface_)
elif type(_geometry) == rg.Mesh:
lb_mesh = to_mesh3d(_geometry)
else:
raise TypeError(
'_geometry must be a Brep or a Mesh. Got {}.'.format(type(_geometry)))

# generate the test points, vectors, and areas.
points = [from_point3d(pt) for pt in lb_mesh.face_centroids]
vectors = [from_vector3d(vec) for vec in lb_mesh.face_normals]
face_areas = lb_mesh.face_areas
mesh = from_mesh3d(lb_mesh)
Binary file not shown.
Binary file modified plugin/grasshopper/userObjects/LadybugPlus_Color Range.ghuser
Binary file not shown.
Binary file modified plugin/grasshopper/userObjects/LadybugPlus_Download Weather.ghuser
Binary file not shown.
Binary file modified plugin/grasshopper/userObjects/LadybugPlus_EPWmap.ghuser
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit f835aeb

Please sign in to comment.