Search code examples
python-3.xnumpymeshpoint-cloudsmayavi

I want to generate a mesh from a point cloud in Python


I have a point cloud from different parts of the human body, like an eye and I want to do a mesh. I tried to use Mayavi and Delaunay but I don't get a good mesh. The points of the cloud are in total disorder. I have my point cloud in .npz file

enter image description here

Using Mayavi

enter image description here

Then I want to save my model in an obj or stl file, but first I want to generate the mesh. What do you recommend me to use, do I need a special library?


Solution

  • You can use pyvista to do the 3D interpolation. You need however to manually play with the alpha parameter that controls the distance under which two points are linked.

    import numpy as np
    import pyvista as pv
    
    # points is a 3D numpy array (n_points, 3) coordinates of a sphere
    cloud = pv.PolyData(points)
    cloud.plot()
    
    volume = cloud.delaunay_3d(alpha=2.)
    shell = volume.extract_geometry()
    shell.plot()
    

    cloud viz

    mesh after delaunay interpolation