(mesh, threshold = 0.00025, xy2depth=None)
| 69 | |
| 70 | |
| 71 | def tear_edges(mesh, threshold = 0.00025, xy2depth=None): |
| 72 | remove_edge_list = [] |
| 73 | remove_horizon, remove_vertical = np.zeros((2, mesh.graph['H'], mesh.graph['W'])) |
| 74 | mesh_nodes = mesh.nodes |
| 75 | for edge in mesh.edges: |
| 76 | if abs(mesh_nodes[edge[0]]['disp'] - mesh_nodes[edge[1]]['disp']) > threshold: |
| 77 | remove_edge_list.append((edge[0], edge[1])) |
| 78 | |
| 79 | near, far = edge if abs(edge[0][2]) < abs(edge[1][2]) else edge[::-1] |
| 80 | |
| 81 | mesh_nodes[far]['near'] = [] if mesh_nodes[far].get('near') is None else mesh_nodes[far]['near'].append(near) |
| 82 | mesh_nodes[near]['far'] = [] if mesh_nodes[near].get('far') is None else mesh_nodes[near]['far'].append(far) |
| 83 | |
| 84 | if near[0] == far[0]: |
| 85 | remove_horizon[near[0], np.minimum(near[1], far[1])] = 1 |
| 86 | elif near[1] == far[1]: |
| 87 | remove_vertical[np.minimum(near[0], far[0]), near[1]] = 1 |
| 88 | mesh.remove_edges_from(remove_edge_list) |
| 89 | |
| 90 | remove_edge_list = [] |
| 91 | |
| 92 | dang_horizon = np.where(np.roll(remove_horizon, 1, 0) + np.roll(remove_horizon, -1, 0) - remove_horizon == 2) |
| 93 | dang_vertical = np.where(np.roll(remove_vertical, 1, 1) + np.roll(remove_vertical, -1, 1) - remove_vertical == 2) |
| 94 | |
| 95 | horizon_condition = lambda x, y: mesh.graph['bord_up'] + 1 <= x < mesh.graph['bord_down'] - 1 |
| 96 | vertical_condition = lambda x, y: mesh.graph['bord_left'] + 1 <= y < mesh.graph['bord_right'] - 1 |
| 97 | |
| 98 | prjto3d = lambda x, y: (x, y, xy2depth[(x, y)][0]) |
| 99 | |
| 100 | node_existence = lambda x, y: mesh.has_node(prjto3d(x, y)) |
| 101 | |
| 102 | for x, y in zip(dang_horizon[0], dang_horizon[1]): |
| 103 | if horizon_condition(x, y) and node_existence(x, y) and node_existence(x, y+1): |
| 104 | remove_edge_list.append((prjto3d(x, y), prjto3d(x, y+1))) |
| 105 | for x, y in zip(dang_vertical[0], dang_vertical[1]): |
| 106 | if vertical_condition(x, y) and node_existence(x, y) and node_existence(x+1, y): |
| 107 | remove_edge_list.append((prjto3d(x, y), prjto3d(x+1, y))) |
| 108 | mesh.remove_edges_from(remove_edge_list) |
| 109 | |
| 110 | return mesh |
| 111 | |
| 112 | def calculate_fov(mesh): |
| 113 | k = mesh.graph['cam_param'] |
no test coverage detected