//  [python]
def center_scale_poses_and_compute_frustum(poses, bbox=None):
    transform=torch.eye(4)

    scale_factor = 1
    use_bbox = False
    if bbox is not None:
        if bbox.shape[0] == 6:
            use_bbox = True

    if use_bbox:
        sampling_xyz_min = torch.tensor(bbox[:3])
        sampling_xyz_max = torch.tensor(bbox[3:])
        Cs = poses[:, :3, 3]
        Cs_min = Cs.amin((0))
        Cs_max = Cs.amax((0))
        xyz_min = torch.minimum(sampling_xyz_min, Cs_min)
        xyz_max = torch.maximum(sampling_xyz_max, Cs_max)
        translation = torch.tensor(
            [
                (sampling_xyz_min[0] + sampling_xyz_max[0]) / 2,
                (sampling_xyz_min[1] + sampling_xyz_max[1]) / 2,
                (sampling_xyz_min[2] + sampling_xyz_max[2]) / 2,
            ]
        )
        ##center
        poses[:, :3, 3] -= translation
        sampling_xyz_min -= translation
        sampling_xyz_max -= translation
        xyz_min -= translation
        xyz_max -= translation
        ## find the radius
        r1 = torch.linalg.norm(torch.tensor([sampling_xyz_min[0], sampling_xyz_min[1], sampling_xyz_min[2]]))
        r2 = torch.linalg.norm(torch.tensor([sampling_xyz_min[0], sampling_xyz_min[1], sampling_xyz_max[2]]))
        r3 = torch.linalg.norm(torch.tensor([sampling_xyz_min[0], sampling_xyz_max[1], sampling_xyz_min[2]]))
        r4 = torch.linalg.norm(torch.tensor([sampling_xyz_min[0], sampling_xyz_max[1], sampling_xyz_max[2]]))
        r5 = torch.linalg.norm(torch.tensor([sampling_xyz_max[0], sampling_xyz_min[1], sampling_xyz_min[2]]))
        r6 = torch.linalg.norm(torch.tensor([sampling_xyz_max[0], sampling_xyz_min[1], sampling_xyz_max[2]]))
        r7 = torch.linalg.norm(torch.tensor([sampling_xyz_max[0], sampling_xyz_max[1], sampling_xyz_min[2]]))
        r8 = torch.linalg.norm(torch.tensor([sampling_xyz_max[0], sampling_xyz_max[1], sampling_xyz_max[2]]))
        radius = torch.max(torch.tensor([r1, r2, r3, r4, r5, r6, r7, r8]))

        # scale = scale_factor / max(max(xyz_max[0] - xyz_min[0], xyz_max[1] - xyz_min[1]), xyz_max[2] - xyz_min[2])
        scale = scale_factor / radius
        poses[:, :3, 3] *= scale
        sampling_xyz_min *= scale
        sampling_xyz_max *= scale
        xyz_min *= scale
        xyz_max *= scale


        #compute transoform of poses from input space to nerf space
        transform[0,3]=translation[0]
        transform[1,3]=translation[1]
        transform[2,3]=translation[2]
        transform[0,0]=scale
        transform[1,1]=scale
        transform[2,2]=scale
        # bbox = np.array(bbox).astype(np.float64)
        # # center
        # translation = poses[..., :3, 3]
        # mean_translation = torch.mean(translation, dim=0)
        # translation = mean_translation
        # poses[:, :3, 3] -= translation
        # bbox[0] -= translation[0]
        # bbox[3] -= translation[0]
        # bbox[1] -= translation[1]
        # bbox[4] -= translation[1]
        # bbox[2] -= translation[2]
        # bbox[5] -= translation[2]

        # # scale by minimal near plane
        # sc = scale_factor / nears.min()
        # poses[:, :3, 3] *= sc
        # bbox *= sc.numpy()
        # sampling_xyz_min = torch.tensor(bbox[:3])
        # sampling_xyz_max = torch.tensor(bbox[3:])
        # Cs = poses[:, :3, 3]
        # Cs_min = Cs.amin((0))
        # Cs_max = Cs.amax((0))
        # xyz_min = torch.minimum(sampling_xyz_min, Cs_min)
        # xyz_max = torch.maximum(sampling_xyz_max, Cs_max)
        return xyz_min, xyz_max, sampling_xyz_min, sampling_xyz_max, poses, -translation,scale
    else:
        assert (use_bbox == False, "please give the bbox")