I have a dataset of 3-dimensional points for which I'd like to construct a mesh, using python. All the software I've seen requires that you provide the edges. Is there a program in python which takes as the input a set of points in 3D and output a mesh? If possible, I'd like the meshing to be uniform.
5 Answers
If an unrestricted triangulation is OK, you can do it with scipy.spatial.Delaunay which uses Qhull.
CGAL (http://www.cgal.org) has a number of modules for triangulating points in 3D (surface meshes from points, triangulations of points in 3D, etc). Python wrappers for a subset of CGAL modules are available (https://code.google.com/p/cgal-bindings), including for 3D triangulations. I've used the CGAL C++ interface for triangulating points in 3D, but I have no experience with the Python interface.
You could try VTK which has a Python API. I would first try ParaView and bring your points into that and then try some of the filters (e.g. Delaunay). If the filters work in ParaView with your data (which is VTK based) then you can use VTK to do the job. How successful you will be will depend on what the points look like and how nicely they suit the filters.
If VTK looks like it will work, have a look at the Kitware tutorials on VTK as I know there is one that walks through using Python/VTK.
The Python library PyVista is a wrapper of VTK.
import pyvista as pv
import numpy as np
import vtk
offset = np.array([0])
cells = np.array([8, 0, 1, 2, 3, 4, 5, 6, 7])
cell_type = np.array([vtk.VTK_HEXAHEDRON], np.int32)
pts = np.array([[-0.5, -0.5, -0.5],
[-0.5, -0.5, 0.5],
[-0.5, 0.5, 0.5],
[-0.5, 0.5, -0.5],
[ 0.5, -0.5, -0.5],
[ 0.5, 0.5, -0.5],
[ 0.5, 0.5, 0.5],
[ 0.5, -0.5, 0.5]], np.float64)
grid = pv.UnstructuredGrid(cells, cell_type, pts)
deltess = grid.delaunay_3d()
edges = deltess.extract_edges() # or extract_feature_edges if you want only the exterior edges
edges.plot()
If you have the point cloud normals available (or can estimate them using local plane fits & can re-orient them), then Poisson surface reconstruction can give quite satisfactory results. In addition, a whole range of surface reconstruction methods are available, i.e. methods in Open3D or data-driven (learning based) methods such as DSE/IER.