def get_opening_rect(self, opening, window_shift=-3, door_shift=None): new_item = copy.deepcopy(opening) p1 = opening.placement[0].point_1 p2 = opening.placement[0].point_2 new_item.placement = [] if not window_shift: shift = -((self.shape[1] + self.shape[0]) / 2) / ( (abs(p1.x - p2.x) + abs(p1.y - p2.y)) / 2) / 10 else: shift = window_shift if opening._type != 'window': shift = self.wider if door_shift: shift = door_shift if opening._type == 'item': shift = 0 _sx = int(min(p1.x, p2.x)) - shift _ex = int(max(p1.x, p2.x)) + shift _sy = int(min(p1.y, p2.y)) - shift _ey = int(max(p1.y, p2.y)) + shift rect = Line(Point(_sx, _sy), Point(_ex, _ey)) return new_item, rect
def is_curve_door(self, placement, walls): line_in_room = [] lenght = 0 for line in placement: for wall in walls: if wall.inner_part.distance_to_point(line.point_1) == 0: line_in_room.append(line) lenght += line.line_length() if line_in_room: distance = Line(line_in_room[0].point_1, line_in_room[-1].point_2) if distance.line_length( ) != 0 and lenght / distance.line_length() > self.door_len_ratio: return True return False
def from_dict(self, obj): if 'type' in obj and obj['type'] == Door._type: if 'placement' in obj: self.placement = [ Line().from_dict(_) for _ in obj['placement'] ] return self
def align_wall(room_index, walls_index): prev_wall = room.walls[room_index].inner_part curr_wall = new_walls[walls_index].inner_part angle = prev_wall.angle_between(curr_wall) if angle < self.max_angle: pos = Line(new_walls[walls_index].inner_part.point_1, room.walls[room_index].inner_part.point_2) wall = Wall(pos) new_walls[walls_index] = wall else: new_walls.append(room.walls[room_index])
def is_curve_window(self, placement, walls): line_in_room = [] count_big_angle = 0 lenght = 0 for line in placement: for wall in walls: if wall.inner_part.distance_to_point(line.point_1) == 0: if line_in_room: angle = line.angle_between(line_in_room[-1]) if any([ a[0] < angle < a[1] for a in self.window_curve_angles ]): count_big_angle += 1 line_in_room.append(line) lenght += line.line_length() if line_in_room: distance = Line(line_in_room[0].point_1, line_in_room[-1].point_2) if distance.line_length() != 0 and lenght / distance.line_length() > self.window_len_ratio \ and count_big_angle > self.min_count_big_angle: return True return False
def process(self, parent): self.update_status(Stage.STATUS_RUNNING) max_shape = parent.config[self._name]['MAX_SHAPE'] self.max_angle = parent.config[self._name]['MAX_ANGLE'] self.th = parent.config[self._name]['TH'][0] if parent.height < max_shape[0] and parent.width < max_shape[1]: self.th = parent.config[self._name]['TH'][1] self.wall_diff = parent.config[self._name]['WALL_DIFF'] * max( parent.height, parent.width) self.r_outer_wall = int(parent.config[self._name]['R_OUTER_WALL'] * min(parent.width, parent.height)) self.r_bearing_wall = int(self.r_outer_wall * parent.config[self._name]['R_BEARING_WALL']) self.r_wall = int(self.r_outer_wall * parent.config[self._name]['R_WALL']) self.r_map = { 'wall': self.r_wall, 'bearing_wall': self.r_bearing_wall, 'outer_wall': self.r_outer_wall } self.shape = (parent.height, parent.width, 3) res = [] for i, cnt in enumerate(self.img): room = Room([], []) l = len(cnt) - 1 prev = cnt[l] room.walls = [] for curr in cnt: wall = Wall( Line(Point(prev[0][0], prev[0][1]), Point(curr[0][0], curr[0][1]))) room.walls.append(wall) prev = curr res.append(room) self.align_walls(res) self.define_walls_type(res) self.img = res self.desc = self.desc self.update_status(Stage.STATUS_SUCCEEDED)
def process(self, parent): self.update_status(Stage.STATUS_RUNNING) if parent.label_map: labels = parent.label_map else: labels = label_map_to_dict( load_label_map_file( parent.config[self._name]['LABEL_MAP_LOCATION'])) tf.logging.set_verbosity(tf.logging.WARN) if parent.graph: graph = parent.graph else: graph = load_graph(parent.config[self._name]['GRAPH_LOCATION']) (boxes, scores, classes, num) = self.proceed_with_boxes(graph) w, h = parent.width, parent.height room = Room(_openings=[]) for i in range(int(num[0])): sy, sx, ey, ex = int(boxes[0][i][0] * h), \ int(boxes[0][i][1] * w), \ int(boxes[0][i][2] * h), \ int(boxes[0][i][3] * w) placement = Line(Point(sx, sy), Point(ex, ey)) ch = CHOICE[labels[int(classes[0][i])]] t = ch[1] cl = ch[0] room.openings.append(cl(placement, t=t)) self.desc = room self.update_status(Stage.STATUS_SUCCEEDED)
def save_in_dxf(name, desc): z = 0 d = sdxf.Drawing() for room in desc: if room.type == 'kitchen': wall = room.walls[0] p1 = wall.inner_part.point_1 p2 = wall.inner_part.point_2 point = (int(p1.x + (p2.x - p1.x) / 2) - 30, int(p1.y + (p2.x - p1.y) / 2)) d.append( sdxf.Text(text='k', point=[point[0], -point[1], z], height=20)) for wall in room.walls: line = wall.inner_part d.append( sdxf.Line(points=[(line.point_1.x, -line.point_1.y, z), (line.point_2.x, -line.point_2.y, z)])) for opening in room.openings: if opening._type == 'door': for line in opening.placement: d.append( sdxf.Line(points=[ (line.point_1.x, -line.point_1.y, z), (line.point_2.x, -line.point_2.y, z) ], color=3)) continue if opening._type == 'window': for line in opening.placement: d.append( sdxf.Line(points=[ (line.point_1.x, -line.point_1.y, z), (line.point_2.x, -line.point_2.y, z) ], color=4)) continue if opening._type == 'arch': for line in opening.placement: d.append( sdxf.Line(points=[ (line.point_1.x, -int(line.point_1.y), z), (line.point_2.x, -int(line.point_2.y), z) ], color=2)) continue if opening._type == 'item': rect = opening.placement[0] p1 = rect.point_1 p3 = rect.point_2 p2 = Point(p1.x, p3.y) p4 = Point(p3.x, p1.y) lines = [ Line(p1, p2), Line(p2, p3), Line(p3, p4), Line(p1, p4) ] for line in lines: d.append( sdxf.Line(points=[ (line.point_1.x, -line.point_1.y, z), (line.point_2.x, -line.point_2.y, z) ], color=5)) continue if room.furniture: for furniture in room.furniture: rect = furniture.placement p1 = rect.point_1 p3 = rect.point_2 p2 = Point(p1.x, p3.y) p4 = Point(p3.x, p1.y) lines = [ Line(p1, p2), Line(p2, p3), Line(p3, p4), Line(p1, p4) ] for line in lines: d.append( sdxf.Line(points=[ (line.point_1.x, -line.point_1.y, z), (line.point_2.x, -line.point_2.y, z) ], color=6)) d.saveas(name)
def from_dict(self, obj): if 'type' in obj and obj['type'] == Item._type and 'placement' in obj: self.placement = [Line().from_dict(_) for _ in obj['placement']] self.item_type = obj['item_type'] return self