easyidp.pointcloud.write_ply#

easyidp.pointcloud.write_ply(ply_path, points, colors, normals=None, binary=True)#

Save point cloud to ply format

Parameters:
  • ply_path (str) – the output point cloud file.

  • points (ndarray) – the nx3 numpy ndarray of point XYZ info

  • colors (ndarray) – the nx3 numpy ndarray of point RGB info, dtype=np.uint8

  • normals (ndarray, optional) – the nx3 numpy ndarray of point normal info, by default None

  • binary (bool, optional) – whether save the binary file. True: save BINARY ply file (by default) False: save ASCII ply file.

Example

Prepare data:

>>> import easyidp as idp
>>> test_data = idp.data.TestData()

>>> write_points = np.asarray([[-1.9083118, -1.7775583,  -0.77878  ],
...                            [-1.9082794, -1.7772741,  -0.7802601],
...                            [-1.907196 , -1.7748289,  -0.8017483],
...                            [-1.7892904, -1.9612598,  -0.8468666],
...                            [-1.7885809, -1.9391041,  -0.839632 ],
...                            [-1.7862186, -1.9365788,  -0.8327141]], dtype=np.float64)
>>> write_colors = np.asarray([[  0,   0,   0],
...                            [  0,   0,   0],
...                            [  0,   0,   0],
...                            [192,  64, 128],
...                            [ 92,  88,  83],
...                            [ 64,  64,  64]], dtype=np.uint8)
>>> write_normals = np.asarray([[-0.03287353,  0.36604664,  0.9300157 ],
...                             [ 0.08860216,  0.07439037,  0.9932853 ],
...                             [-0.01135951,  0.2693031 ,  0.9629885 ],
...                             [ 0.4548034 , -0.15576138,  0.876865  ],
...                             [ 0.4550802 , -0.29450312,  0.8403392 ],
...                             [ 0.32758632,  0.27255052,  0.9046565 ]], dtype=np.float64)

Use this function:

>>> idp.pointcloud.write_ply(r"path/to/point_cloud.ply",  write_points, write_colors, binary=True)

Notes

(For developers)

The plyfile packages requires to convert the ndarray outputs to numpy structured arrays [1] , then save the point cloud structure looks like this:

>>> cloud_data.elements
(
    PlyElement(
        'vertex',
        (
            PlyProperty('x', 'float'),
            PlyProperty('y', 'float'),
            PlyProperty('z', 'float'),
            PlyProperty('red', 'uchar'),
            PlyProperty('green', 'uchar'),
            PlyProperty('blue', 'uchar')
        ),
        count=42454,
        comments=[]),
    )
)

convert ndarray to strucutred array [2] and method to merge to structured arrays [3]