Load points and normals from a PLY file.
(path)
| 20 | from scipy.spatial import cKDTree |
| 21 | |
| 22 | def load_ply(path): |
| 23 | """ |
| 24 | Load points and normals from a PLY file. |
| 25 | """ |
| 26 | plydata = PlyData.read(path) |
| 27 | vertex = plydata['vertex'] |
| 28 | |
| 29 | points = np.stack([vertex['x'], vertex['y'], vertex['z']], axis=-1) |
| 30 | |
| 31 | if 'nx' in vertex.data.dtype.names and 'ny' in vertex.data.dtype.names and 'nz' in vertex.data.dtype.names: |
| 32 | normals = np.stack([vertex['nx'], vertex['ny'], vertex['nz']], axis=-1) |
| 33 | else: |
| 34 | raise ValueError("PLY file must contain normals (nx, ny, nz).") |
| 35 | |
| 36 | return points, normals |
| 37 | |
| 38 | def estimate_voxel_size(points, num_samples=3000): |
| 39 | """ |