예제 #1
0
        values = [
            data[sim_step_] for data_list in data_mtx for data in data_list
        ]
        time_text = data_mtx[0][0].datetimes[sim_step_]
    elif period_ is not None:
        new_data = [[
            data.filter_by_analysis_period(period_) for data in data_list
        ] for data_list in data_mtx]
        values = [data.average for data_list in new_data for data in data_list]
        time_text = period_
    else:
        values = [data.average for data_list in data_mtx for data in data_list]
        time_text = header.analysis_period

    # generate Ladybug objects for the graphic
    lb_meshes = [to_mesh3d(mesh) for mesh in _mesh]
    lb_mesh = Mesh3D.join_meshes(lb_meshes)
    graphic = GraphicContainer(values,
                               lb_mesh.min,
                               lb_mesh.max,
                               legend_par_,
                               data_type=header.data_type,
                               unit=header.unit)

    # set titles and set default colors and color ranges
    if graphic.legend_parameters.are_colors_default:
        graphic.legend_parameters.colors = colors_from_data_type(
            header.data_type)
    if isinstance(header.data_type, TemperatureDelta) and graphic.legend.is_min_default \
            and graphic.legend.is_max_default:
        graphic.legend_parameters.min = -5
예제 #2
0
    Args:
        _mesh: A colored mesh (or list of colored meshes) to be baked into the Rhino
            scene as groups of colored hatches.
        layer_: Text for the layer name on which the hatch will be added. If unspecified,
            it will be baked onto the currently active layer.
        _run: Set to 'True' to bake the mesh into the scene as hatches.

    Returns:
        report: Reports, errors, warnings ...
"""

ghenv.Component.Name = 'LB Mesh to Hatch'
ghenv.Component.NickName = 'Hatch'
ghenv.Component.Message = '1.5.0'
ghenv.Component.Category = 'Ladybug'
ghenv.Component.SubCategory = '4 :: Extra'
ghenv.Component.AdditionalHelpFromDocStrings = '0'


try:
    from ladybug_rhino.togeometry import to_mesh3d
    from ladybug_rhino.bakegeometry import add_mesh3d_as_hatch_to_scene
    from ladybug_rhino.grasshopper import all_required_inputs
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))


if all_required_inputs(ghenv.Component) and _run:
    lb_mesh = to_mesh3d(_mesh, color_by_face=False)
    add_mesh3d_as_hatch_to_scene(lb_mesh, layer_)
        try:
            x_axis = to_vector3d(quad_only_)
            lb_faces = [
                Face3D(f.boundary, Plane(f.normal, f[0], x_axis), f.holes)
                for f in lb_faces
            ]
        except AttributeError:
            pass  # no plane connected; juse use default orientation
        lb_meshes = [
            geo.mesh_grid(_grid_size, offset=_offset_dist_) for geo in lb_faces
        ]
        if len(lb_meshes) == 1:
            lb_mesh = lb_meshes[0]
        elif len(lb_meshes) > 1:
            lb_mesh = Mesh3D.join_meshes(lb_meshes)
    else:  # use Rhino's default meshing
        try:  # assume it's a Rhino Brep
            lb_mesh = to_gridded_mesh3d(_geometry, _grid_size, _offset_dist_)
        except TypeError:  # assume it's a Rhino Mesh
            try:
                lb_mesh = to_mesh3d(_geometry)
            except TypeError:  # unidientified geometry type
                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)
except ImportError as e:
    raise ImportError('\nFailed to import ladybug:\n\t{}'.format(e))

try:
    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_rhino.color import color_to_color
    from ladybug_rhino.grasshopper import all_required_inputs
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))

if all_required_inputs(ghenv.Component):
    # generate Ladybug objects
    lb_mesh = to_mesh3d(_mesh)
    if offset_dom_:
        dom_st, dom_end = offset_dom_
        lb_mesh = lb_mesh.height_field_mesh(_values, (dom_st, dom_end))
    graphic = GraphicContainer(_values, lb_mesh.min, lb_mesh.max, legend_par_)

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

    # draw rhino objects
    lb_mesh.colors = graphic.value_colors
try:  # import ladybug_rhino dependencies
    from ladybug_rhino.grasshopper import all_required_inputs
    from ladybug_rhino.togeometry import to_mesh3d, to_face3d
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))

if all_required_inputs(ghenv.Component):
    # set the default name and process the points to tuples
    name = clean_and_id_rad_string('SensorGrid') if _name_ is None else _name_
    pts = [(pt.X, pt.Y, pt.Z) for pt in _positions]

    # create the sensor grid object
    id = clean_rad_string(name) if '/' not in name else clean_rad_string(
        name.split('/')[0])
    if len(_directions_) == 0:
        grid = SensorGrid.from_planar_positions(id, pts, (0, 0, 1))
    else:
        vecs = [(vec.X, vec.Y, vec.Z) for vec in _directions_]
        grid = SensorGrid.from_position_and_direction(id, pts, vecs)

    # set the display name
    if _name_ is not None:
        grid.display_name = _name_
    if '/' in name:
        grid.group_identifier = \
            '/'.join(clean_rad_string(key) for key in name.split('/')[1:])
    if mesh_ is not None:
        grid.mesh = to_mesh3d(mesh_)
    if base_geo_ is not None:
        grid.base_geometry = to_face3d(base_geo_)