def is_continuation(gold_node, bin_test_list, add_to_list=True, DEBUG=False): if not gold_node.has_children(): return False ancestor_node_matches = [] gold_path_length = SwcNode() # find the first matched ancestor of the gold_node ancestor_match = None ancestor_gold = gold_node.parent gold_path_length.path_length = gold_node.data.path_length gold_path_length.xy_path_length = gold_node.data.xy_path_length gold_path_length.z_path_length = gold_node.data.z_path_length is_match = False ancestor_match = False is_left = False if DEBUG: print( "gold_path_length: path_length {}, xy_path_length {}, z_path_length {}" .format(gold_path_length.path_length, gold_path_length.xy_path_length, gold_path_length.z_path_length)) while ancestor_gold is not None and not ancestor_match: if ancestor_gold in g_matches.keys(): ancestor_match = g_matches[ancestor_gold] if is_sub_continuation(gold_node, ancestor_gold, ancestor_match, is_left, gold_path_length, bin_test_list, add_to_list): return True ancestor_match = True ancestor_node_matches = get_nearby_node_list(ancestor_gold, bin_test_list, check_previous_use=True, g_matches=g_matches) for a_n_node in ancestor_node_matches: if is_sub_continuation(gold_node, ancestor_gold, ancestor_match, is_left, gold_path_length, bin_test_list, add_to_list): return True gold_path_length.path_length += ancestor_gold.data.path_length gold_path_length.xy_path_length += ancestor_gold.data.xy_path_length gold_path_length.z_path_length += ancestor_gold.data.z_path_length is_left = ancestor_gold.is_left() ancestor_gold = ancestor_gold.parent # failed return False
def get_des_in_for_continuation(first_node, ancestor_node, ancestor_match, ancestor_trajectory, path_length_map, bin_test_list, DEBUG=False): spe_ancestor_trajectory = ancestor_trajectory test_matches = [] stack = queue.LifoQueue() stack.put(first_node) while not stack.empty(): gold_node = stack.get() des_tra = gold_node.data.parent_trajectory # print("gold_node id = {}".format(gold_node.data.get_id())) if gold_node in g_matches: test_matches.append(g_matches[gold_node]) else: test_matches = get_nearby_node_list(gold_node, bin_test_list, check_previous_use=False) prev_path_length = path_length_map[gold_node.parent] gold_path_length = SwcNode() gold_path_length.path_length = gold_node.data.path_length + prev_path_length.path_length gold_path_length.xy_path_length = gold_node.data.xy_path_length + prev_path_length.xy_path_length gold_path_length.z_path_length = gold_node.data.z_path_length + prev_path_length.z_path_length path_length_map[gold_node] = gold_path_length for child_match in test_matches: test_path_length = SwcNode() test_path_length.add_data(child_match.data) tmp_node = child_match.parent # print("child match id = {}".format( # child_match.data.get_id())) done = (tmp_node == ancestor_match) while not done: if tmp_node in path_length_map.keys(): prev_path_length = path_length_map[tmp_node] test_path_length.add_length(prev_path_length) done = True else: test_path_length.add_length(tmp_node.data) tmp_node = tmp_node.parent if tmp_node is None: done = True if tmp_node == ancestor_match: done = True if tmp_node is None: if DEBUG: print("[info]: descendant not match") else: path_length_map[child_match] = test_path_length if ancestor_trajectory.get_x( ) == -1.0 or ancestor_trajectory.get_z() == -1.0: spe_ancestor_trajectory = get_trajectory_for_path( ancestor_node, gold_node) if ancestor_trajectory.get_x != -1.0: spe_ancestor_trajectory.set_x( ancestor_trajectory.get_x()) spe_ancestor_trajectory.set_y( ancestor_trajectory.get_y()) if ancestor_trajectory.get_z != -1.0: spe_ancestor_trajectory.set_z( ancestor_trajectory.get_z()) test_xy_path_length = test_path_length.xy_path_length \ + get_end_node_XY_dis_diff(ancestor_node.data, spe_ancestor_trajectory, ancestor_match.data) \ + get_end_node_XY_dis_diff(gold_node.data, des_tra, child_match.data) test_z_path_length = test_path_length.z_path_length \ + get_end_node_Z_dis_diff(ancestor_node.data, spe_ancestor_trajectory, ancestor_match.data) \ + get_end_node_Z_dis_diff(gold_node.data, des_tra, child_match.data) if path_length_matches(gold_path_length, test_xy_path_length, test_z_path_length) < 1: return child_match if gold_node.has_children() and gold_node not in g_matches: stack.put(gold_node.left_son) stack.put(gold_node.right_son) return None