Ejemplo n.º 1
0
def union_negative_overlap_sb(parent, child, siblings):
    sibling_polygons = mp.map_layoutsamples_to_geometricobjects(
        siblings, shape_name="shape")
    child_polygon = mp.map_layoutsamples_to_geometricobjects(
        [child], shape_name="shape")[0]

    return -(cascaded_union([
        sibling_polygon.intersection(child_polygon)
        for sibling_polygon in sibling_polygons
    ]).area)
Ejemplo n.º 2
0
def combinatory_surface_ratio_absolute(parent,siblings,target_ratio):
    if not 0<= target_ratio <=1:
        raise ValueError("Target ration should be between 0 and 1, it's values was: ",target_ratio)
    sibling_polygons=mp.map_layoutsamples_to_geometricobjects(siblings,shape_name="shape")
    parent_polygon=mp.map_layoutsamples_to_geometricobjects([parent],shape_name="shape")[0]

    sibling_union=cascaded_union(sibling_polygons)
    area_siblings_parent= sibling_union.intersection(parent_polygon).area
    area_diff=np.abs(area_siblings_parent/parent_polygon.area-target_ratio)

    return -area_diff
Ejemplo n.º 3
0
def centroid_dist_sb(parent,child,siblings,dist_metric=np.linalg.norm):
    sibling_polygons=mp.map_layoutsamples_to_geometricobjects(siblings,shape_name="shape")
    child_polygon=mp.map_layoutsamples_to_geometricobjects([child],shape_name="shape")
    parent_polygon_centr=np.array(mp.map_layoutsample_to_geometricobject(parent,shape_name="shape")[0].centroid)


    sibling_polygons_group_centr = np.array(MultiPolygon(sibling_polygons).centroid)
    sibling_child_polygons_group_centr = np.array(MultiPolygon(sibling_polygons+child_polygon).centroid)

    centr_dist_without_child=dist_metric(sibling_polygons_group_centr-parent_polygon_centr)
    centr_dist_with_child=dist_metric(sibling_child_polygons_group_centr-parent_polygon_centr)
    #if the distance grows by adding a child it is bad
    return centr_dist_without_child-centr_dist_with_child
Ejemplo n.º 4
0
def combinatory_surface_ratio_absolute(parent, siblings, target_ratio):
    if not 0 <= target_ratio <= 1:
        raise ValueError(
            "Target ration should be between 0 and 1, it's values was: ",
            target_ratio)
    sibling_polygons = mp.map_layoutsamples_to_geometricobjects(
        siblings, shape_name="shape")
    parent_polygon = mp.map_layoutsamples_to_geometricobjects(
        [parent], shape_name="shape")[0]

    sibling_union = cascaded_union(sibling_polygons)
    area_siblings_parent = sibling_union.intersection(parent_polygon).area
    area_diff = np.abs(area_siblings_parent / parent_polygon.area -
                       target_ratio)

    return -area_diff
Ejemplo n.º 5
0
def draw_node_sample_tree(root, color, ax=None):
    samples = root.get_flat_list()
    polygons = mp.map_layoutsamples_to_geometricobjects(samples, "shape")
    draw_polygons(polygons=polygons,
                  ax=ax,
                  color=color,
                  size=1.3,
                  set_range=True)
Ejemplo n.º 6
0
def centroid_dist_sb(parent, child, siblings, dist_metric=np.linalg.norm):
    sibling_polygons = mp.map_layoutsamples_to_geometricobjects(
        siblings, shape_name="shape")
    child_polygon = mp.map_layoutsamples_to_geometricobjects(
        [child], shape_name="shape")
    parent_polygon_centr = np.array(
        mp.map_layoutsample_to_geometricobject(parent,
                                               shape_name="shape")[0].centroid)

    sibling_polygons_group_centr = np.array(
        MultiPolygon(sibling_polygons).centroid)
    sibling_child_polygons_group_centr = np.array(
        MultiPolygon(sibling_polygons + child_polygon).centroid)

    centr_dist_without_child = dist_metric(sibling_polygons_group_centr -
                                           parent_polygon_centr)
    centr_dist_with_child = dist_metric(sibling_child_polygons_group_centr -
                                        parent_polygon_centr)
    #if the distance grows by adding a child it is bad
    return centr_dist_without_child - centr_dist_with_child
Ejemplo n.º 7
0
def closest_side_alignment_norm(sample0,sample1):
    polygons=mp.map_layoutsamples_to_geometricobjects([sample0,sample1],shape_name="shape")
    min_dist=float("inf")
    min_l0=None
    min_l1=None
    for p00,p01 in ut.pairwise(polygons[0].exterior.coords):
        for p10,p11 in ut.pairwise(polygons[1].exterior.coords):
            l0=LineString([p00,p01])
            l1=LineString([p10,p11])
            dist=l1.distance(l0)
            if dist<min_dist:
                min_dist=dist
                min_l0=l0.coords
                min_l1=l1.coords

    #the constraint of alignement between 2 closest sides of 2 polygons as defined in a paper
    #the difference is defined over 90 degrees
    angle0=_angle(min_l0)
    angle1=_angle(min_l1)
    return (1+np.cos(4*(angle0-angle1)))/2
Ejemplo n.º 8
0
def closest_side_alignment_norm(sample0, sample1):
    polygons = mp.map_layoutsamples_to_geometricobjects([sample0, sample1],
                                                        shape_name="shape")
    min_dist = float("inf")
    min_l0 = None
    min_l1 = None
    for p00, p01 in ut.pairwise(polygons[0].exterior.coords):
        for p10, p11 in ut.pairwise(polygons[1].exterior.coords):
            l0 = LineString([p00, p01])
            l1 = LineString([p10, p11])
            dist = l1.distance(l0)
            if dist < min_dist:
                min_dist = dist
                min_l0 = l0.coords
                min_l1 = l1.coords

    #the constraint of alignement between 2 closest sides of 2 polygons as defined in a paper
    #the difference is defined over 90 degrees
    angle0 = _angle(min_l0)
    angle1 = _angle(min_l1)
    return (1 + np.cos(4 * (angle0 - angle1))) / 2
Ejemplo n.º 9
0
def draw_node_sample_tree(root,color,ax=None):
    samples=root.get_flat_list()
    polygons = mp.map_layoutsamples_to_geometricobjects(samples,"shape")
    draw_polygons(polygons=polygons,ax=ax,color=color,size=1.3,set_range=True)
Ejemplo n.º 10
0
def positive_overlap(sample0, sample1):
    polygons = mp.map_layoutsamples_to_geometricobjects([sample0, sample1],
                                                        shape_name="shape")
    return ((polygons[0].intersection(polygons[1])).area)
Ejemplo n.º 11
0
def norm_overlap_pc(parent, child):
    polygons = mp.map_layoutsamples_to_geometricobjects([parent, child],
                                                        shape_name="shape")
    noemer = min(polygons[0].area, polygons[1].area)
    return 1 - ((polygons[0].intersection(polygons[1])).area) / noemer
Ejemplo n.º 12
0
def negative_overlap(sample0,sample1):
    polygons=mp.map_layoutsamples_to_geometricobjects([sample0,sample1],shape_name="shape")
    return -((polygons[0].intersection(polygons[1])).area)
Ejemplo n.º 13
0
def union_negative_overlap_sb(parent,child,siblings):
    sibling_polygons=mp.map_layoutsamples_to_geometricobjects(siblings,shape_name="shape")
    child_polygon=mp.map_layoutsamples_to_geometricobjects([child],shape_name="shape")[0]

    return -(cascaded_union([sibling_polygon.intersection(child_polygon) for sibling_polygon in sibling_polygons]).area)
Ejemplo n.º 14
0
def norm_overlap_pc(parent,child):
    polygons=mp.map_layoutsamples_to_geometricobjects([parent,child],shape_name="shape")
    noemer=min(polygons[0].area,polygons[1].area)
    return 1-((polygons[0].intersection(polygons[1])).area)/noemer