import torch


def get_v_coords(p_range, v_size, v_indices):
    """
    Args:
        p_range: [x_min, y_min, z_min, x_max, y_max, z_max]
        v_size: [vx, vy, vz]
        v_indices : [M, 4] -> [bs, z_i, y_i, x_i]
    Returns:
        v_coords: [M, 4] -> [bs, x, y, z]
    """
    with torch.no_grad():
        v_size = torch.tensor(v_size).unsqueeze(0).to(v_indices.device)
        min_range = torch.tensor(p_range[0:3]).unsqueeze(0).to(v_indices.device)
        v_xyz_idx = v_indices[:, [3, 2, 1]]
        v_bs = v_indices[:, [0]].float()
        v_xyz = (v_indices[:, [3, 2, 1]].float() + 0.5) * v_size + min_range
        v_coords = torch.cat([v_bs, v_xyz], dim = 1)
    return v_coords