コード例 #1
0
def drawDNA():
    try:
        dna = DNA_File.load_dna_by_file_name(path.get())
        room_num, room_list = DNA_Object.get_room_list_from_dna(dna)
        door_num, door_pos = DNA_Object.get_door_list_from_dna(dna)
        window_num, window_pos = DNA_Object.get_window_list_from_dna(dna)
        wall_num, wall_pos = DNA_Object.get_wall_list_from_dna(dna)
    except:
        return

    #清空图像,以使得前后两次绘制的图像不会重叠
    plt.style.use('ggplot')
    fig.clf()
    dna_plt = fig.add_subplot(111)

    for i in range(room_num):
        area_center, area = DNA_Object.get_room_area(room_list[i])
        dna_plt.plot(area['x'], area['y'], linewidth='0.5', color='k')

    for i in range(wall_num):
        dna_plt.plot(wall_pos['x'][i],
                     wall_pos['y'][i],
                     alpha=0.7,
                     color='b',
                     linewidth=1,
                     solid_capstyle='round',
                     zorder=2)

    for i in range(window_num):
        dna_plt.plot(window_pos['x'][i],
                     window_pos['y'][i],
                     alpha=0.7,
                     color='c',
                     linewidth='0.5',
                     solid_capstyle='round',
                     zorder=2)

    for i in range(door_num):
        dna_plt.plot(door_pos['x'][i],
                     door_pos['y'][i],
                     alpha=0.7,
                     color='r',
                     linewidth='0.5',
                     solid_capstyle='round',
                     zorder=2)

    dna_plt.add_patch(circ)
    title = 'Id' + str(dna['solutionId'])
    dna_plt.set_title(title)
    #plt.xlim((-15000, 20000))
    #plt.ylim((-15000, 20000))
    canvas.show()
コード例 #2
0
def draw_house_wall(dna):
    cur_dict = {}

    if 'roomList' in dna:
        cur_dict = dna

    elif 'request' in dna and 'feedback' not in dna:
        cur_dict = json.loads(dna['request'])

    elif 'feedback' in dna:
        cur_dict = json.loads(dna['feedback'])

    if 'walls' in cur_dict:
        wall_num, wall_pos = DNA_Object.get_wall_from_dna(cur_dict)
        for i in range(wall_num):
            plt.plot(wall_pos['x'][i],
                     wall_pos['y'][i],
                     alpha=0.7,
                     color='b',
                     linewidth=1,
                     solid_capstyle='round',
                     zorder=2)
        return True
    else:
        return False
コード例 #3
0
def draw_house_door(dna):
    cur_dict = {}

    if 'roomList' in dna:
        cur_dict = dna

    elif 'request' in dna and 'feedback' not in dna:
        cur_dict = json.loads(dna['request'])

    elif 'feedback' in dna:
        cur_dict = json.loads(dna['feedback'])

    if 'doors' in cur_dict:
        door_num, door_pos = DNA_Object.get_door_from_dna(cur_dict)
        for i in range(door_num):
            #print('【door',i,'pos】', door_pos['x'][i], door_pos['y'][i])
            plt.plot(door_pos['x'][i],
                     door_pos['y'][i],
                     alpha=0.7,
                     color='r',
                     linewidth='0.5',
                     solid_capstyle='round',
                     zorder=2)
        return True
    else:
        return False
コード例 #4
0
def draw_house_obj(dna, obj_category, close_flag):
    room_num, room = DNA_Object.get_room_list_from_dna(dna)
    count = 0
    for i in range(room_num):
        flag = draw_room_obj(room[i], obj_category)
        if flag == True:
            count += 1
    if count == 0 and close_flag == True:
        plt.close()
コード例 #5
0
def draw_room_obj(room, obj_category):
    obj_num, obj_center, obj_size, obj_point = DNA_Object.get_obj_info_from_room(
        room, obj_category)
    if obj_num > 0:
        plt.plot(obj_point['x'], obj_point['y'], linewidth='0.5')
        #print(bed_center)
        plt.plot(obj_center[0], obj_center[1], 'o')
        return True
    else:
        return False
コード例 #6
0
def draw_area(dna, room):
    area_center, area = DNA_Object.get_room_area(room)
    plt.plot(
        area['x'],
        area['y'],
        linewidth='0.5',
        color='k',
    )
    plt.xlim((-15000, 20000))
    plt.ylim((-15000, 20000))
    #plt.plot(area_center[0], area_center[1], '*', linewidth='0.5')
    title = 'Id' + str(dna['solutionId'])
    plt.title(title)
コード例 #7
0
def show_room_layout(dna, vec_room2bed, vec_room2window, trans_vec, room_name):
    vec_window2bed = {}
    vec_window2bed['x'] = []
    vec_window2bed['y'] = []
    room = DNA_Object.get_room_by_usagename(dna, room_name)
    #print(dna['solutionId'], room['roomUsageName'])

    if 'doors' in dna:
        door_num, door_pos = DNA_Object.get_door_from_dna(dna)
    else:
        door_center, door_num, door_pos = DNA_Object.get_door_from_room(room)

    if 'walls' in dna:
        wall_num, wall_pos = DNA_Object.get_wall_from_dna(dna)
    else:
        wall_num, wall_pos = DNA_Object.get_wall_from_room(room)

    if 'windows' in dna:
        window_num, window_pos = DNA_Object.get_window_info_from_dna(dna)
    else:
        window_center, window_num, window_pos = DNA_Object.get_window_info_from_room(
            room)
    '''
    if door_num > 0:
        room_polygon = DNA_Geometry.generate_room_polygon(room)
        door_polygon_list = DNA_Geometry.generate_door_geometry(door_num, door_pos)
        
        for w in range(len(door_polygon_list)):     
            #print('hi',room_polygon.boundary.coords, len(room_polygon.boundary.coords), list(room_polygon.boundary.coords))
            if DNA_Geometry.polygon_intersect_polygon_loosely(room_polygon, door_polygon_list[w]):
                #print('hi',room_polygon.boundary.coords, len(room_polygon.boundary.coords), list(room_polygon.boundary.coords))
                #print('[', w, ']', wall_pos['x'][w], wall_pos['y'][w])
                Util.trans_by_vec(door_pos, trans_vec)
                plt.plot(door_pos['x'][w], door_pos['y'][w], linewidth='1.5')
                '''

    bed_num, bed_center, bed_size, bed_point = DNA_Object.get_obj_info_from_room(
        room, 318)
    area_center, area = DNA_Object.get_room_area(room)

    if bed_num > 0:
        if ((bed_size[0] > 1000 and bed_size[1] > 1100)
                or (bed_size[0] > 1100 and bed_size[1] > 1000)):
            print('DNA', dna['solutionId'], 'room', room_name,
                  'bed size maybe incorrect! bed_size is:', bed_size[0] * 2,
                  'x', bed_size[1] * 2)
            return
        vec_room2bed['x'].append(bed_center[0] - area_center[0])
        vec_room2bed['y'].append(bed_center[1] - area_center[1])

        Util.trans_by_vec(bed_point, trans_vec)
        Util.trans_by_vec(area_center, trans_vec)
        Util.trans_by_vec(bed_center, trans_vec)
        plt.plot(bed_point['x'], bed_point['y'], linewidth='0.5')
        #print(bed_center)
        plt.plot(bed_center[0], bed_center[1], 'o')

    wardrobe_num, wardobe_center, wardrobe_size, wardrobe_point = DNA_Object.get_obj_info_from_room(
        room, 120)
    if wardrobe_num > 0:
        Util.trans_by_vec(wardrobe_point, trans_vec)
        Util.trans_by_vec(wardobe_center, trans_vec)
        plt.plot(wardrobe_point['x'], wardrobe_point['y'], linewidth='0.5')
        #print(bed_center)
        plt.plot(wardobe_center[0], wardobe_center[1], 'o')
        if (wardobe_center[0] > 600):
            print(dna['solutionId'])
コード例 #8
0
            if flag[1] == False and DrawShape.draw_house_door(dna):
                flag[1] = True

            if flag[2] == False and DrawShape.draw_house_window(dna):
                flag[2] = True

            if flag[3] == False and DrawShape.draw_house_wall(dna):
                flag[3] = True

        #处理户型平移(同一户型的位置坐标不一样,由于户型只画了一次,家具信息每次都画,因此家具相对于户型的位置不准确,需做平移处理)
        trans_vec1 = [0, 0]
        trans_vec2 = [0, 0]

        if (i == 0):
            base_room_center1, base_area1 = DNA_Object.get_room_area(
                DNA_Object.get_room_by_usagename(dna, '主卧'))
            base_room_center2, base_area2 = DNA_Object.get_room_area(
                DNA_Object.get_room_by_usagename(dna, '次卧'))
        else:
            cur_room_center1, cur_area1 = DNA_Object.get_room_area(
                DNA_Object.get_room_by_usagename(dna, '主卧'))
            cur_room_center2, cur_area2 = DNA_Object.get_room_area(
                DNA_Object.get_room_by_usagename(dna, '次卧'))
            trans_vec1 = Util.get_trans_vector(base_room_center1,
                                               cur_room_center1)
            trans_vec2 = Util.get_trans_vector(base_room_center2,
                                               cur_room_center2)

        #show_room_layout(dna, vec_room2bed, trans_vec1, '主卧')
        #show_room_layout(dna, vec_room2bed, trans_vec2, '次卧')
        count += 1
コード例 #9
0
    #fig.canvas.mpl_connect('button_press_event', on_button_press)
    #DrawShape.draw_house_obj(dna, 318, True)
    #print(count)
    room_name_list = ['次卧']

    for n in range(len(room_name_list)):
        room_name = room_name_list[n]
        if room_name not in room_size_dict:
            room_size_dict[room_name] = {}
            room_size_dict[room_name]['x'] = []
            room_size_dict[room_name]['y'] = []

        if room_name not in room_area_point_cnt_dict:
            room_area_point_cnt_dict[room_name] = {}

        room_cnt, width, long = DNA_Object.get_room_major_size(dna, room_name)
        stat_room_size(dna, room_name, room_cnt, width, long,
                       room_size_dict[room_name])
        point_cnt, room_list = DNA_Object.get_room_area_point_num(
            dna, room_name)

        for i in range(len(point_cnt)):
            cnt = point_cnt[i]

            if True:  #cnt == 10: # and dna['solutionId'] == 11414:
                DrawShape.draw_room_area(dna, room_name)
                DrawShape.draw_house_door(dna)
                DrawShape.draw_house_window(dna)
                polygon = DNA_Geometry.generate_room_polygon(room_list[i])
                minx, miny, maxx, maxy = DNA_Geometry.get_fuzzy_bounds(polygon)
                DrawShape.draw_bounds(minx, miny, maxx, maxy)