| import copy | |
| import numpy as np | |
| from scipy.spatial import Delaunay | |
| def extract_pc_in_box3d(pc: np.ndarray, box3d: np.ndarray): | |
| """Extract the subsets of points within the requested bounding box | |
| Args: | |
| pc: N x 3 (or more), | |
| box3d: 8 x 3 (or 4) | |
| """ | |
| hull = copy.copy(box3d[:, :3]) | |
| if not isinstance(hull, Delaunay): | |
| hull = Delaunay(hull) | |
| box3d_roi_inds: np.ndarray = ( | |
| hull.find_simplex(pc[:, :3]) >= 0 | |
| ) # (N, ) boolean array | |
| return pc[box3d_roi_inds, :], box3d_roi_inds | |