MCPcopy Create free account
hub / github.com/thygate/stable-diffusion-webui-depthmap-script / combine_end_node

Function combine_end_node

inpaint/mesh.py:542–634  ·  view source on GitHub ↗
(mesh, edge_mesh, edge_ccs, depth)

Source from the content-addressed store, hash-verified

540 return discont_ccs, LDI, discont_graph
541
542def combine_end_node(mesh, edge_mesh, edge_ccs, depth):
543 import collections
544 mesh_nodes = mesh.nodes
545 connect_dict = dict()
546 for valid_edge_id, valid_edge_cc in enumerate(edge_ccs):
547 connect_info = []
548 for valid_edge_node in valid_edge_cc:
549 single_connect = set()
550 for ne_node in mesh.neighbors(valid_edge_node):
551 if mesh_nodes[ne_node].get('far') is not None:
552 for fn in mesh_nodes[ne_node].get('far'):
553 if mesh.has_node(fn) and mesh_nodes[fn].get('edge_id') is not None:
554 single_connect.add(mesh_nodes[fn]['edge_id'])
555 if mesh_nodes[ne_node].get('near') is not None:
556 for fn in mesh_nodes[ne_node].get('near'):
557 if mesh.has_node(fn) and mesh_nodes[fn].get('edge_id') is not None:
558 single_connect.add(mesh_nodes[fn]['edge_id'])
559 connect_info.extend([*single_connect])
560 connect_dict[valid_edge_id] = collections.Counter(connect_info)
561
562 end_maps = np.zeros((mesh.graph['H'], mesh.graph['W']))
563 edge_maps = np.zeros((mesh.graph['H'], mesh.graph['W'])) - 1
564 for valid_edge_id, valid_edge_cc in enumerate(edge_ccs):
565 for valid_edge_node in valid_edge_cc:
566 edge_maps[valid_edge_node[0], valid_edge_node[1]] = valid_edge_id
567 if len([*edge_mesh.neighbors(valid_edge_node)]) == 1:
568 num_ne = 1
569 if num_ne == 1:
570 end_maps[valid_edge_node[0], valid_edge_node[1]] = valid_edge_node[2]
571 nxs, nys = np.where(end_maps != 0)
572 invalid_nodes = set()
573 for nx, ny in zip(nxs, nys):
574 if mesh.has_node((nx, ny, end_maps[nx, ny])) is False:
575 invalid_nodes.add((nx, ny))
576 continue
577 four_nes = [xx for xx in [(nx - 1, ny), (nx + 1, ny), (nx, ny - 1), (nx, ny + 1)] \
578 if 0 <= xx[0] < mesh.graph['H'] and 0 <= xx[1] < mesh.graph['W'] and \
579 end_maps[xx[0], xx[1]] != 0]
580 mesh_nes = [*mesh.neighbors((nx, ny, end_maps[nx, ny]))]
581 remove_num = 0
582 for fne in four_nes:
583 if (fne[0], fne[1], end_maps[fne[0], fne[1]]) in mesh_nes:
584 remove_num += 1
585 if remove_num == len(four_nes):
586 invalid_nodes.add((nx, ny))
587 for invalid_node in invalid_nodes:
588 end_maps[invalid_node[0], invalid_node[1]] = 0
589
590 nxs, nys = np.where(end_maps != 0)
591 invalid_nodes = set()
592 for nx, ny in zip(nxs, nys):
593 if mesh_nodes[(nx, ny, end_maps[nx, ny])].get('edge_id') is None:
594 continue
595 else:
596 self_id = mesh_nodes[(nx, ny, end_maps[nx, ny])].get('edge_id')
597 self_connect = connect_dict[self_id] if connect_dict.get(self_id) is not None else dict()
598 four_nes = [xx for xx in [(nx - 1, ny), (nx + 1, ny), (nx, ny - 1), (nx, ny + 1)] \
599 if 0 <= xx[0] < mesh.graph['H'] and 0 <= xx[1] < mesh.graph['W'] and \

Callers 1

write_meshFunction · 0.85

Calls 1

getMethod · 0.80

Tested by

no test coverage detected