コード例 #1
0
def relations():

    for pair in itertools.permutations(entities, r=2):
        ent1 = pair[0]
        ent2 = pair[1]

        figure = ent1.name
        ground = ent2.name

        r = Relationship(scene_name, figure, ground)

        ## Get convex hulls
        # convexhull1 = Entity(ent1.convexhull)
        # convexhull2 = Entity(ent2.convexhull)

        ### Get some distance measure
        r.set_of_relations['distance'] = dist_obj(ent1, ent2)

        ### Measure the shortest distance between the meshes
        r.set_of_relations['contact'] = closest_mesh_distance(ent1, ent2)
        r.set_of_relations['contact_scaled'] = closest_mesh_distance_scaled(
            ent1, ent2)

        ### Measure distance between highest point of entity 2 and lowest point of entity 1
        ### Positive => ent1 is above ent2
        r.set_of_relations['above_measure'] = ent1.span[4] - ent2.span[5]

        ### Measure the degree of containment
        #### Currently simple version using bounding boxes
        r.set_of_relations['shared_volume'] = get_bbox_intersection(ent1, ent2)
        ### Proportion is divided by the figure volume i.e. if f in g then proportion = 1
        if ent1.volume == 0:
            r.set_of_relations['containment'] = r.set_of_relations[
                'shared_volume'] / (ent1.volume + 0.0001)
        else:
            r.set_of_relations['containment'] = r.set_of_relations[
                'shared_volume'] / ent1.volume
        if ent2.volume != 0:
            r.set_of_relations['ins'] = inside(ent1, ent2)
        else:
            r.set_of_relations['ins'] = 0

        r.save_to_csv(output_path)
                cobb_end = cobb_initial
            else:
                object_details = bounds(figure)

                ### lowest point in z-axis
                z_min_end = object_details.z.min
                z_max_end = object_details.z.max
                cobb_end = blender_utils.get_bbox_centre(figure)[2]

            ### Results

            z_min_change = round(z_min_initial - z_min_end, 4)
            z_max_change = round(z_max_initial - z_max_end, 4)
            cobb_change = round(cobb_initial - cobb_end, 4)

            values.append(
                [figure.name, z_min_change, cobb_change, z_max_change])

    return values


values = support_1(ground)
for value in values:
    figure_name = value[0]
    r = Relationship(scene_name, figure_name, ground.name)
    r.set_of_relations['raw_support:top_change'] = value[3]
    r.set_of_relations['raw_support:cobb_change'] = value[2]
    r.set_of_relations['raw_support:bottom_change'] = value[1]

    r.save_to_csv(output_path)