def merge_pieces_of_same_walls_alongX(wall_bboxes): ''' 1) Find all the walls with not both corners intersected 2) Merge all the walls can be merged ''' if wall_bboxes.shape[0] == 0: return wall_bboxes intersections = Bbox3D.all_intersections_by_cenline( wall_bboxes, check_same_height=False, only_on_corners=True) num_inters = np.array([it.shape[0] for it in intersections]) mask = num_inters < 2 candidate_ids = np.where(mask)[0] show = DEBUG and False if show: show_boxes = wall_bboxes.copy() show_boxes[:, 2] -= 1 show_boxes = np.concatenate([show_boxes, wall_bboxes[candidate_ids]], 0) print(f'candidate_ids:{candidate_ids}') Bbox3D.draw_bboxes(show_boxes, 'Z', False) #Bbox3D.draw_bboxes(wall_bboxes[[5,6,12]], 'Z', False) pass n = candidate_ids.shape[0] keep_mask = np.array([True] * wall_bboxes.shape[0]) for i in range(n - 1): idx_i = candidate_ids[i] for j in range(i + 1, n): idx_next = candidate_ids[j] merged_i = merge_2pieces_of_1wall(wall_bboxes[idx_i], wall_bboxes[idx_next], 'X') if merged_i is not None: keep_mask[idx_i] = False wall_bboxes[idx_next] = merged_i[0] if show: show_boxes = wall_bboxes.copy() show_boxes[:, 2] -= 1 show_boxes = np.concatenate( [show_boxes, wall_bboxes[[idx_i, idx_next]], merged_i], 0) show_boxes[-1, 2] += 1 Bbox3D.draw_bboxes(show_boxes, 'Z', False) import pdb pdb.set_trace() # XXX BREAKPOINT pass wall_bboxes = wall_bboxes[keep_mask] rm_num = np.sum(1 - keep_mask) print(f'merge along X: rm {rm_num} walls') if show: show_walls_offsetz(wall_bboxes) return wall_bboxes
def crop_walls(wall_bboxes): ''' crop walls with intersections not on the corner ''' #show_walls_1by1(wall_bboxes) if wall_bboxes.shape[0] == 0: return wall_bboxes intersections = Bbox3D.all_intersections_by_cenline( wall_bboxes, check_same_height=False, not_on_corners=True) n = wall_bboxes.shape[0] new_walls = [] keep_mask = np.array([True] * n) for i in range(n): inters_i = intersections[i] if inters_i.shape[0] == 0: continue new_walls_i = Bbox3D.split_wall_by_centroid_intersections( wall_bboxes[i], inters_i) keep_mask[i] = False new_walls.append(new_walls_i) show = False #tmp = np.concatenate(new_walls, 0) #if tmp.shape[0] >= 7: # show = True if show: #tmp = wall_bboxes.copy() tmp = new_walls_i.copy() tmp[:, 2] += 1 for ti in range(1, tmp.shape[0]): tmp[ti:, 2] += 0.2 show_box = np.concatenate([tmp, wall_bboxes[i:i + 1]], 0) Bbox3D.draw_points_bboxes(inters_i, show_box, 'Z', False) #Bbox3D.draw_bboxes(show_box, 'Z', False) import pdb pdb.set_trace() # XXX BREAKPOINT pass num_croped = np.sum(keep_mask == False) print(f'num croped:{num_croped}\nnum new:{len(new_walls)}') wall_bboxes = wall_bboxes[keep_mask] if len(new_walls) > 0: new_walls = np.concatenate(new_walls, 0) wall_bboxes = np.concatenate([wall_bboxes, new_walls], 0) #show_walls_1by1(wall_bboxes) #show_walls_offsetz(wall_bboxes) return wall_bboxes