def get_pair_idx(source_dataset, target_position, N_views, view_type='nearest', fixed_idxs=None, is_source_target_overlap=False):
    positions = source_dataset.poses[:, :3, 3]
    dis = np.sum(np.abs((positions - target_position)), axis=(- 1))
    dis_sort = np.argsort(dis)
    if is_source_target_overlap:
        dis_sort = dis_sort[1:]
    if (view_type == 'nearest'):
        pair_idx = dis_sort[:N_views]
        pair_idx = [source_dataset.img_idx[item] for item in pair_idx]
    if (view_type == 'dense'):
        idxs = torch.randperm(int(np.rint((N_views * 1.5))))[:N_views].sort()[0]
        pair_idx = dis_sort[idxs]
        pair_idx = [source_dataset.img_idx[item] for item in pair_idx]
    if (view_type == 'random'):
        idxs = torch.randperm(len(dis_sort))[:N_views]
        pair_idx = dis_sort[idxs]
        pair_idx = [source_dataset.img_idx[item] for item in pair_idx]
    if (view_type == 'sparse'):
        idxs = torch.linspace(0, len(dis_sort), steps=(N_views + 1)).round()
        idxs = [np.random.choice(range(int(idxs[i]), int(idxs[(i + 1)]))) for i in range((len(idxs) - 1))]
        pair_idx = dis_sort[idxs]
        pair_idx = [source_dataset.img_idx[item] for item in pair_idx]
    if (view_type == 'far'):
        idxs = torch.randperm(int(np.rint((N_views * 1.5))))[:N_views].sort(descending=True)[0]
        pair_idx = dis_sort[::(- 1)][idxs]
        pair_idx = [source_dataset.img_idx[item] for item in pair_idx]
    if (view_type == 'farthest'):
        pair_idx = dis_sort[::(- 1)][:N_views]
        pair_idx = [source_dataset.img_idx[item] for item in pair_idx]
    if (view_type == 'fixed'):
        pair_idx = fixed_idxs
    return pair_idx
def get_pair_idx(source_dataset, target_position, N_views, view_type='nearest', fixed_idxs=None, is_source_target_overlap=False):
    positions = source_dataset.poses[:, :3, 3]
    dis = np.sum(np.abs((positions - target_position)), axis=(- 1))
    dis_sort = np.argsort(dis)
    if is_source_target_overlap:
        dis_sort = dis_sort[1:]
    if (view_type == 'nearest'):
        pair_idx = dis_sort[:N_views]
        pair_idx = [source_dataset.img_idx[item] for item in pair_idx]
    if (view_type == 'dense'):
        idxs = torch.randperm(int(np.rint((N_views * 1.5))))[:N_views].sort()[0]
        pair_idx = dis_sort[idxs]
        pair_idx = [source_dataset.img_idx[item] for item in pair_idx]
    if (view_type == 'random'):
        idxs = torch.randperm(len(dis_sort))[:N_views]
        pair_idx = dis_sort[idxs]
        pair_idx = [source_dataset.img_idx[item] for item in pair_idx]
    if (view_type == 'sparse'):
        idxs = torch.linspace(0, len(dis_sort), steps=(N_views + 1)).round()
        idxs = [np.random.choice(range(int(idxs[i]), int(idxs[(i + 1)]))) for i in range((len(idxs) - 1))]
        pair_idx = dis_sort[idxs]
        pair_idx = [source_dataset.img_idx[item] for item in pair_idx]
    if (view_type == 'far'):
        idxs = torch.randperm(int(np.rint((N_views * 1.5))))[:N_views].sort(descending=True)[0]
        pair_idx = dis_sort[::(- 1)][idxs]
        pair_idx = [source_dataset.img_idx[item] for item in pair_idx]
    if (view_type == 'farthest'):
        pair_idx = dis_sort[::(- 1)][:N_views]
        pair_idx = [source_dataset.img_idx[item] for item in pair_idx]
    if (view_type == 'fixed'):
        pair_idx = fixed_idxs
    return pair_idx