def add_door(door, points, vectors):
    """Add Door normals."""
    points.append(from_point3d(door.center))
    vectors.append(from_vector3d(door.normal))
    for shd in door.shades:
        points.append(from_point3d(shd.center))
        vectors.append(from_vector3d(shd.normal))
def add_aperture(aperture, points, vectors):
    """Add Aperture normals."""
    points.append(from_point3d(aperture.center))
    vectors.append(from_vector3d(aperture.normal))
    for shd in aperture.shades:
        points.append(from_point3d(shd.center))
        vectors.append(from_vector3d(shd.normal))
def add_face(face, points, vectors):
    """Add Face normals."""
    points.append(from_point3d(face.center))
    vectors.append(from_vector3d(face.normal))
    for ap in face.apertures:
        add_aperture(ap, points, vectors)
    for dr in face.doors:
        add_door(ap, points, vectors)
    for shd in face.shades:
        points.append(from_point3d(shd.center))
        vectors.append(from_vector3d(shd.normal))
def add_room(room, points, vectors):
    """Add Room normals."""
    for face in room.faces:
        add_face(face, points, vectors)
    for shd in room.shades:
        points.append(from_point3d(shd.center))
        vectors.append(from_vector3d(shd.normal))
def add_model(model, points, vectors):
    """Add Model normals."""
    for room in model.rooms:
        add_room(room, points, vectors)
    for face in model.orphaned_faces:
        add_face(face, points, vectors)
    for ap in model.orphaned_apertures:
        add_aperture(ap, points, vectors)
    for dr in model.orphaned_doors:
        add_door(door, points, vectors)
    for shd in model.orphaned_shades:
        points.append(from_point3d(shd.center))
        vectors.append(from_vector3d(shd.normal))
def draw_sun_positions(suns, radius, center_pt3d):
    """Draw Rhino points from a list of sun objects.

    Args:
        suns: A list of suns to be output as points
        radius: Number for the radius of the sun path.
        center_pt3d: Point3D for the center of the sun path.

    Returns:
        A list of Rhino points for sun positions
    """
        # get points for sun positions
    if projection_ is None:
        return [from_point3d(sun.position_3d(center_pt3d, radius)) for sun in suns]
    else:
        return [from_point2d(sun.position_2d(projection_, center_pt3d, radius), z)
                for sun in suns]
def human_height_points(position, height, pt_count):
    """Get a list of points and a line representing the human geometry.

    Args:
        position: Rhino point for the position of the human.
        height: Number for the height of the human.
        pt_count: Integer for the number of points representing the human.

    Returns:
         A tuple with human points as first element and human line as second.
         Both geomtries are Rhino geometries.
    """
    lb_feet_pt = to_point3d(position).move(Vector3D(0, 0, height / 100))
    lb_hum_line = LineSegment3D(lb_feet_pt, Vector3D(0, 0, height))
    lb_pts = [lb_hum_line.midpoint] if pt_count == 1 else \
        lb_hum_line.subdivide_evenly(pt_count - 1)
    if len(lb_pts) == pt_count - 1:  # sometimes tolerance kills the last point
        lb_pts.append(lb_feet_pt.move(Vector3D(0, 0, height)))
    h_points = [from_point3d(pt) for pt in lb_pts]
    return h_points, from_linesegment3d(lb_hum_line)
Exemple #8
0
def build_window_meshes(_window_surface, _grid_size, _mesh_params):
    """Create the Ladybug Mesh3D grided mesh for the window being analysed
    
    Arguments:
        _window_surface: (Brep) A single window Brep from the scene
        _grid_size: (float)
        _mesh_params: (Rhino.Geometry.MeshingParameters)
    Returns: (tuple)
        points: (list: Ladybug Point3D) All the analysis points on the window
        normals: (list: Ladybug Normal) All the normals for the analysis points
        window_mesh: (ladybug_geometry.geometry3d.Mesh3D) The window
        window_back_mesh: (ladybug_geometry.geometry3d.Mesh3D) A copy of the window shifted 'back'
        just a little bit (0.1 units). Used when solving the 'unshaded' situation.
    """

    # create the gridded mesh for the window surface
    #---------------------------------------------------------------------------
    offset_dist = 0.001
    window_mesh = to_joined_gridded_mesh3d([_window_surface], _grid_size,
                                           offset_dist)
    window_rh_mesh = from_mesh3d(window_mesh)
    points = [from_point3d(pt) for pt in window_mesh.face_centroids]

    # Create a 'back' for the window
    #---------------------------------------------------------------------------
    # Mostly this is done so it can be passed to the ladybug_rhino.intersect.intersect_mesh_rays()
    # solver as a surfce which is certain to *not* shade the window at all
    window_back_mesh = None
    for sr in _window_surface.Surfaces:
        window_normal = sr.NormalAt(0.5, 0.5)
        window_normal.Unitize()
        window_normal = window_normal * -1 * 0.1

        window_back = _window_surface.Duplicate()
        window_back.Translate(window_normal)
        window_back_mesh = Rhino.Geometry.Mesh.CreateFromBrep(
            window_back, _mesh_params)[0]

    normals = [from_vector3d(vec) for vec in window_mesh.face_normals]

    return points, normals, window_mesh, window_back_mesh, window_rh_mesh
Exemple #9
0
ghenv.Component.NickName = 'ASE'
ghenv.Component.Message = 'VER 0.0.06\nJUL_07_2020'
ghenv.Component.Category = "HoneybeePlus"
ghenv.Component.SubCategory = '04 :: Daylight :: Daylight'
ghenv.Component.AdditionalHelpFromDocStrings = "3"

try:
    from ladybug_rhino.fromgeometry import from_point3d
    import ladybug.legend as lp
    import ladybug.color as color
except ImportError as e:
    raise ImportError('\nFailed to import ladybug:\n\t{}'.format(e))


col = color.Colorset.original()
legend_par = lp.LegendParameters(0, 250, colors=col)

if _analysis_grid:
    states = _analysis_grid.parse_blind_states(blind_states_)
    success, ASE, per_area, prblm_pts, prblm_hrs = \
        _analysis_grid.annual_sunlight_exposure(
            _threshold_, states, _occ_schedule_, _target_hrs_, _target_area_
        )

    prblm_pts = (from_point3d(s.location) for s in prblm_pts)
    # convert list of lists to data tree
    try:
        prblm_hrs = output.list_to_tree(prblm_hrs, ghenv.Component.RunCount - 1)
    except NameError:
        # dynamo
        pass
except ImportError as e:
    raise ImportError('\nFailed to import ladybug:\n\t{}'.format(e))

try:
    from ladybug_rhino.config import conversion_to_meters
    from ladybug_rhino.togeometry import to_joined_gridded_mesh3d, to_face3d, \
        to_vector3d
    from ladybug_rhino.fromgeometry import from_mesh3d, from_point3d
    from ladybug_rhino.grasshopper import all_required_inputs, hide_output
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))


if all_required_inputs(ghenv.Component) and _run:
    # set the default offset distance
    _height_limit_ = _height_limit_ if _height_limit_ is not None \
        else 100 / conversion_to_meters()

    # convert geometry, objstacles, and vectors to ladybug_geomtery
    study_mesh = to_joined_gridded_mesh3d(_geometry, _grid_size)
    obstacle_faces = [g for geo in _obstacles for g in to_face3d(geo)]
    sun_vectors = [to_vector3d(vec) for vec in _vectors]

    # compute the solar envelope
    solar_obj = SolarEnvelope(
        study_mesh, obstacle_faces, sun_vectors, _height_limit_, solar_rights_)
    lb_mesh = solar_obj.envelope_mesh()
    mesh = from_mesh3d(lb_mesh)
    points = [from_point3d(pt) for pt in lb_mesh.vertices]
    hide_output(ghenv.Component, 1)
Exemple #11
0
    cutoff_ang = math.pi / 2
    rtrace_geo = [rtrace_brep]
    rays, int_pts = [], []
    for ray, pt, norm in zip(start_rays, source_points,
                             study_mesh.face_normals):
        if norm.angle(neg_lb_vec) < cutoff_ang:
            pl_pts = trace_ray(ray, rtrace_geo, _bounce_count_ + 1)
            # if the intersection was successful, create a polyline represeting the ray
            if pl_pts:
                # gather all of the intersection points
                all_pts = [pt]
                for i_pt in pl_pts:
                    all_pts.append(to_point3d(i_pt))
                # compute the last point
                if len(pl_pts) < _bounce_count_ + 2:
                    int_norm = normal_at_point(rtrace_brep, pl_pts[-1])
                    int_norm = to_vector3d(int_norm)
                    last_vec = all_pts[-2] - all_pts[-1]
                    last_vec = last_vec.normalize()
                    final_vec = last_vec.reflect(int_norm).reverse()
                    final_pt = all_pts[-1] + (final_vec * _last_length_)
                    all_pts.append(final_pt)
                # create a Polyline3D from the points
                lb_ray_line = Polyline3D(all_pts)
                rays.append(from_polyline3d(lb_ray_line))
                int_pts.append([from_point3d(p) for p in all_pts])

    # convert the intersection points to a data tree
    int_pts = list_to_data_tree(int_pts)
    hide_output(ghenv.Component, 1)
Exemple #12
0
        if len(floor_faces) != 0:
            # create the gridded ladybug Mesh3D
            lb_mesh = to_joined_gridded_mesh3d(floor_faces, _grid_size,
                                               _dist_floor_)

            # remove points outside of the room volume if requested
            if remove_out_:
                pattern = [
                    room.geometry.is_point_inside(pt)
                    for pt in lb_mesh.face_centroids
                ]
                lb_mesh, vertex_pattern = lb_mesh.remove_faces(pattern)

            # extract positions and directions from the mesh
            base_points = [from_point3d(pt) for pt in lb_mesh.face_centroids]
            base_poss = [(pt.x, pt.y, pt.z) for pt in lb_mesh.face_centroids]
            base_dirs = [(vec.x, vec.y, vec.z) for vec in lb_mesh.face_normals]

            # create the sensor grid
            s_grid = SensorGrid.from_position_and_direction(
                room.identifier, base_poss, base_dirs)
            s_grid.display_name = clean_rad_string(room.display_name)
            s_grid.room_identifier = room.identifier
            s_grid.mesh = lb_mesh

            # append everything to the lists
            grid.append(s_grid)
            points.append(base_points)
            mesh.append(from_mesh3d(lb_mesh))
-

    Args:
        _analysis_grid: An analysis grid output from a Radiance analysis.
        _index_: An integer to pick the index of the sensor in the analysis_grid (default: 0).
    Returns:
        position: Position of the sensor
        sensor: Sensor object. Use this sensor to generate blind schedules for
            annual daylight analysis.
"""

ghenv.Component.Name = "HoneybeePlus_Sensor from analysis grid"
ghenv.Component.NickName = 'sensor'
ghenv.Component.Message = 'VER 0.0.05\nMAR_28_2020'
ghenv.Component.Category = "HoneybeePlus"
ghenv.Component.SubCategory = '04 :: Daylight :: Daylight'
ghenv.Component.AdditionalHelpFromDocStrings = "2"

try:
    from ladybug_rhino.fromgeometry import from_point3d
except ImportError as e:
    raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e))

if _analysis_grid:
    if _analysis_grid.digit_sign == 1:
        _analysis_grid.load_values_from_files()

    id = _index_ if _index_ is not None else 0
    sensor = _analysis_grid[id]
    position = from_point3d(sensor.location)
    from ladybug_rhino.grasshopper import all_required_inputs, hide_output, \
        show_output, objectify_output, de_objectify_output, recommended_processor_count
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))

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()
    workers = _cpu_count_ if _cpu_count_ is not None else recommended_processor_count(
    )

    # create the gridded mesh from the geometry
    study_mesh = to_joined_gridded_mesh3d(_geometry, _grid_size)
    points = [
        from_point3d(pt.move(vec * _offset_dist_))
        for pt, vec in zip(study_mesh.face_centroids, study_mesh.face_normals)
    ]
    hide_output(ghenv.Component, 1)

    # mesh the geometry and context
    shade_mesh = join_geometry_to_mesh(_geometry + context_)

    # deconstruct the matrix and get the sky dome vectors
    mtx = de_objectify_output(_sky_mtx)
    total_sky_rad = [
        dir_rad + dif_rad for dir_rad, dif_rad in zip(mtx[1], mtx[2])
    ]
    ground_rad = [(sum(total_sky_rad) / len(total_sky_rad)) * mtx[0][1]
                  ] * len(total_sky_rad)
    all_rad = total_sky_rad + ground_rad
    for dr in model.orphaned_doors:
        add_door(door, points, vectors)
    for shd in model.orphaned_shades:
        points.append(from_point3d(shd.center))
        vectors.append(from_vector3d(shd.normal))


if all_required_inputs(ghenv.Component):
    # list of rhino geometry to be filled with content
    points = []
    vectors = []

    # loop through all objects and add them
    for hb_obj in _hb_objs:
        if isinstance(hb_obj, Room):
            add_room(hb_obj, points, vectors)
        elif isinstance(hb_obj, Face):
            add_face(hb_obj, points, vectors)
        elif isinstance(hb_obj, Aperture):
            add_aperture(hb_obj, points, vectors)
        elif isinstance(hb_obj, Door):
            add_door(hb_obj, points, vectors)
        elif isinstance(hb_obj, Shade):
            points.append(from_point3d(hb_obj.center))
            vectors.append(from_vector3d(hb_obj.normal))
        elif isinstance(hb_obj, Model):
            add_model(hb_obj, points, vectors)
        else:
            raise TypeError(
                'Unrecognized honeybee object type: {}'.format(type(hb_obj)))
Exemple #16
0
    from ladybug_geometry.geometry3d.pointvector import Point3D
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_geometry:\n\t{}'.format(e))

try:  # import core honeybee dependencies
    from honeybee.model import Model
except ImportError as e:
    raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e))

try:  # import ladybug_rhino dependencies
    from ladybug_rhino.fromgeometry import from_point3d, from_mesh3d
    from ladybug_rhino.grasshopper import all_required_inputs, list_to_data_tree
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))

if all_required_inputs(ghenv.Component):
    assert isinstance(_model, Model), \
        'Expected Honeybee Model. Got {}.'.format(type(_model))
    # get the honeybee-radiance objects
    views = _model.properties.radiance.views
    grids = _model.properties.radiance.sensor_grids

    # get the visualizable attributes
    points = [[from_point3d(Point3D.from_array(s.pos)) for s in sg]
              for sg in grids]
    points = list_to_data_tree(points)
    meshes = []
    for grid in grids:
        if grid.mesh is not None:
            meshes.append(from_mesh3d(grid.mesh))
                direction, overhang_proj_, view_vecs)
            apply_mask_to_base_mask(strategy_pattern, over_pattern,
                                    orient_pattern)
            apply_mask_to_sky(sky_pattern, over_pattern)
        if left_fin_proj_ or right_fin_proj_:
            f_pattern = view_sphere.fin_pattern(direction, left_fin_proj_,
                                                right_fin_proj_, view_vecs)
            apply_mask_to_base_mask(strategy_pattern, f_pattern,
                                    orient_pattern)
            apply_mask_to_sky(sky_pattern, f_pattern)

# account for any input context
context_pattern = None
if len(context_) != 0:
    shade_mesh = join_geometry_to_mesh(context_)  # mesh the context
    points = [from_point3d(center_pt3d)]
    view_vecs = [from_vector3d(pt) for pt in view_vecs]
    int_matrix, angles = intersect_mesh_rays(shade_mesh, points, view_vecs)
    context_pattern = [val == 0 for val in int_matrix[0]]
    apply_mask_to_sky(sky_pattern, context_pattern)

# get the weights for each patch to be used in view factor calculation
weights = view_sphere.dome_radial_patch_weights(az_count, alt_count)
if direction is not None:
    weights = [
        wgt * abs(math.cos(ang)) * 2 for wgt, ang in zip(weights, dir_angles)
    ]

# create meshes for the masks and compute any necessary view factors
gray, black = Color(230, 230, 230), Color(0, 0, 0)
context_view, orient_view, strategy_view = 0, 0, 0
Exemple #18
0
    '3': 'Sky Exposure',
    '4': 'Sky View'
}

if all_required_inputs(ghenv.Component) and _run:
    # process the view_type_ and set the default values
    vt_str = VIEW_TYPES[_view_type]
    _resolution_ = _resolution_ if _resolution_ is not None else 1
    _offset_dist_ = _offset_dist_ if _offset_dist_ is not None \
        else 0.1 / conversion_to_meters()
    if _geo_block_ is None:
        _geo_block_ = True if vt_str in ('Sky Exposure', 'Sky View') else False

    # create the gridded mesh from the geometry
    study_mesh = to_joined_gridded_mesh3d(_geometry, _grid_size, _offset_dist_)
    points = [from_point3d(pt) for pt in study_mesh.face_centroids]
    hide_output(ghenv.Component, 1)

    # get the view vectors based on the view type
    patch_wghts = None
    if vt_str == 'Horizontal Radial':
        lb_vecs = view_sphere.horizontal_radial_vectors(30 * _resolution_)
    elif vt_str == 'Horizontal 30-Degree Offset':
        patch_mesh, lb_vecs = view_sphere.horizontal_radial_patches(
            30, _resolution_)
        patch_wghts = view_sphere.horizontal_radial_patch_weights(
            30, _resolution_)
    elif vt_str == 'Spherical':
        patch_mesh, lb_vecs = view_sphere.sphere_patches(_resolution_)
        patch_wghts = view_sphere.sphere_patch_weights(_resolution_)
    else:
Exemple #19
0
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))


if all_required_inputs(ghenv.Component) and _run:
        # set the default values
        _offset_dist_ = _offset_dist_ if _offset_dist_ is not None \
            else 0.1 / conversion_to_meters()
        if pt_weights_:
            assert len(pt_weights_) == len(_view_points), \
                'The number of pt_weights_({}) must match the number of _view_points ' \
                '({}).'.format(len(pt_weights_), len(_view_points))
        workers = _cpu_count_ if _cpu_count_ is not None else recommended_processor_count()

        # create the gridded mesh from the geometry
        study_mesh = to_joined_gridded_mesh3d(_geometry, _grid_size)
        points = [from_point3d(pt.move(vec * _offset_dist_)) for pt, vec in
                  zip(study_mesh.face_centroids, study_mesh.face_normals)]
        hide_output(ghenv.Component, 1)

        # mesh the geometry and context
        shade_mesh = join_geometry_to_mesh(_geometry + context_) if _geo_block_ \
            or _geo_block_ is None else join_geometry_to_mesh(context_)

        # intersect the lines with the mesh
        int_matrix = intersect_mesh_lines(
            shade_mesh, points, _view_points, max_dist_, cpu_count=workers)

        # compute the results
        int_mtx = objectify_output('Visibility Intersection Matrix', int_matrix)
        vec_count = len(_view_points)
        if pt_weights_:  # weight intersections by the input point weights