MCPcopy Create free account
hub / github.com/WainWong/ComfyUI-Loop-image / loop_close

Method loop_close

flow_control.py:451–531  ·  view source on GitHub ↗
(self, flow_control, current_image, max_iterations, current_mask=None,
                  iteration_count=0, dynprompt=None, unique_id=None)

Source from the content-addressed store, hash-verified

449 self.collect_contained(child_id, upstream, contained)
450
451 def loop_close(self, flow_control, current_image, max_iterations, current_mask=None,
452 iteration_count=0, dynprompt=None, unique_id=None):
453 print(f"Iteration {iteration_count} of {max_iterations}")
454
455 # 维度处理
456 if len(current_image.shape) == 3:
457 current_image = current_image.unsqueeze(0)
458 if current_mask is not None and len(current_mask.shape) == 2:
459 current_mask = current_mask.unsqueeze(0)
460
461 # 检查是否继续循环
462 if iteration_count >= max_iterations - 1:
463 print(f"Loop finished with {iteration_count + 1} iterations")
464 return (current_image, current_mask if current_mask is not None else torch.zeros_like(current_image[:,:,:,0]))
465
466 # 准备下一次循环
467 this_node = dynprompt.get_node(unique_id)
468 upstream = {}
469 parent_ids = []
470 self.explore_dependencies(unique_id, dynprompt, upstream, parent_ids)
471 parent_ids = list(set(parent_ids))
472
473 # 获取并处理输出节点
474 prompts = dynprompt.get_original_prompt()
475 output_nodes = {}
476 for id in prompts:
477 node = prompts[id]
478 if "inputs" not in node:
479 continue
480 class_type = node["class_type"]
481 if class_type in ALL_NODE_CLASS_MAPPINGS:
482 class_def = ALL_NODE_CLASS_MAPPINGS[class_type]
483 if hasattr(class_def, 'OUTPUT_NODE') and class_def.OUTPUT_NODE == True:
484 for k, v in node['inputs'].items():
485 if is_link(v):
486 output_nodes[id] = v
487
488 # 创建新图
489 graph = GraphBuilder()
490 self.explore_output_nodes(dynprompt, upstream, output_nodes, parent_ids)
491
492 contained = {}
493 open_node = flow_control[0]
494 self.collect_contained(open_node, upstream, contained)
495 contained[unique_id] = True
496 contained[open_node] = True
497
498 # 创建节点
499 for node_id in contained:
500 original_node = dynprompt.get_node(node_id)
501 node = graph.node(original_node["class_type"],
502 "Recurse" if node_id == unique_id else node_id)
503 node.set_override_display_id(node_id)
504
505 # 设置连接
506 for node_id in contained:
507 original_node = dynprompt.get_node(node_id)
508 node = graph.lookup_node("Recurse" if node_id == unique_id else node_id)

Callers

nothing calls this directly

Calls 3

explore_dependenciesMethod · 0.95
explore_output_nodesMethod · 0.95
collect_containedMethod · 0.95

Tested by

no test coverage detected