Save a point cloud to a polygon .ply file.
(filename, xyz, rgb=None)
| 92 | |
| 93 | |
| 94 | def pcwrite(filename, xyz, rgb=None): |
| 95 | """Save a point cloud to a polygon .ply file. |
| 96 | """ |
| 97 | if rgb is None: |
| 98 | rgb = np.ones_like(xyz) * 128 |
| 99 | rgb = rgb.astype(np.uint8) |
| 100 | |
| 101 | # Write header |
| 102 | ply_file = open(filename, 'w') |
| 103 | ply_file.write("ply\n") |
| 104 | ply_file.write("format ascii 1.0\n") |
| 105 | ply_file.write("element vertex %d\n" % (xyz.shape[0])) |
| 106 | ply_file.write("property float x\n") |
| 107 | ply_file.write("property float y\n") |
| 108 | ply_file.write("property float z\n") |
| 109 | ply_file.write("property uchar red\n") |
| 110 | ply_file.write("property uchar green\n") |
| 111 | ply_file.write("property uchar blue\n") |
| 112 | ply_file.write("end_header\n") |
| 113 | |
| 114 | # Write vertex list |
| 115 | for i in range(xyz.shape[0]): |
| 116 | ply_file.write("%f %f %f %d %d %d\n" % ( |
| 117 | xyz[i, 0], xyz[i, 1], xyz[i, 2], |
| 118 | rgb[i, 0], rgb[i, 1], rgb[i, 2], |
| 119 | )) |
| 120 | |
| 121 | ''' |
| 122 | Matplotlib Visualization |
no outgoing calls
no test coverage detected