Create o3d point cloud from points Args: points: (*, 3) colors: (*, 3) optional remove_nan_inf: Returns: an o3d point cloud
(
points: T.Union[torch.Tensor, np.ndarray],
colors: T.Union[torch.Tensor, np.ndarray] = None,
remove_nan_inf: bool = True,
)
| 188 | |
| 189 | |
| 190 | def create_pcd( |
| 191 | points: T.Union[torch.Tensor, np.ndarray], |
| 192 | colors: T.Union[torch.Tensor, np.ndarray] = None, |
| 193 | remove_nan_inf: bool = True, |
| 194 | ) -> o3d.geometry.PointCloud: |
| 195 | """ |
| 196 | Create o3d point cloud from points |
| 197 | Args: |
| 198 | points: |
| 199 | (*, 3) |
| 200 | colors: |
| 201 | (*, 3) optional |
| 202 | remove_nan_inf: |
| 203 | |
| 204 | Returns: |
| 205 | an o3d point cloud |
| 206 | """ |
| 207 | |
| 208 | if isinstance(points, torch.Tensor): |
| 209 | points = points.detach().cpu().numpy() |
| 210 | |
| 211 | points = points.reshape(-1, 3) # (n, 3) |
| 212 | if colors is not None: |
| 213 | colors = colors.reshape(-1, 3) # (n, 3) |
| 214 | |
| 215 | # remove any inf or nan points |
| 216 | if remove_nan_inf: |
| 217 | idxs = np.all(np.isfinite(points), axis=-1) # (n,) |
| 218 | points = points[idxs] |
| 219 | if colors is not None: |
| 220 | colors = colors[idxs] |
| 221 | |
| 222 | pcd = o3d.geometry.PointCloud() |
| 223 | pcd.points = o3d.utility.Vector3dVector(points) |
| 224 | if colors is not None: |
| 225 | pcd.colors = o3d.utility.Vector3dVector(colors) |
| 226 | |
| 227 | return pcd |
| 228 | |
| 229 | |
| 230 | def create_octree( |
no test coverage detected