pyvista-support icon indicating copy to clipboard operation
pyvista-support copied to clipboard

Converting pointcloud to watertight mesh

Open RohanChacko opened this issue 4 years ago • 13 comments

Hi

I am pretty new to pyvista and was looking to convert a numpy (n,3) array to a watertight mesh. I have a pointcloud like this (zoomed in): pointcloud

And I convert it to a mesh by:

poly = pv.PolyData(points)
shell = poly.delaunay_3d(alpha=0.005, progress_bar=True)
shell = shell.extract_geometry().triangulate()

But this is the result I end up with. There are significant holes in the reconstructed mesh: image

I tried using pymeshfix as pointed out in the other issues but was not able to fill the holes in the mesh. It looks like delaunay_3d creates triangles that overlap? Is there a way to reconstruct a watertight mesh for the same?

The pointcloud and mesh are in: mesh_repair.zip

RohanChacko avatar May 27 '20 08:05 RohanChacko

@RohanChacko, I played around with this dataset and wasn't able to get delaunay_3d to give me an acceptable mesh to input into pymeshfix. @banesullivan, can you think of any other tools that might be able to perform a reasonable 3D triangulation of a point cloud?

akaszynski avatar May 27 '20 21:05 akaszynski

The delaunay_3d filter is all we really have to offer in PyVista for this and unfortuneatley, I could not get it to work with this dataset either. PyntCloud would be my next go to for this sort of point cloud to mesh problem which has a nice interface to PyVista

banesullivan avatar May 28 '20 12:05 banesullivan

If you do find a solution down the road, please be sure to report back so we can know for future reference!

banesullivan avatar May 28 '20 12:05 banesullivan

Hi, PyntCloud also seems to have Delaunay3D. Is it the same implementation or is there some other solution I should be using?

RohanChacko avatar May 28 '20 13:05 RohanChacko

It isn't the same implementation, but I would be surprised if the results are any different

banesullivan avatar May 29 '20 01:05 banesullivan

Actually, it'd be worth trying their Delaunay 3D structure or the Voxel grid structure as your data seems to have some sort of regularness to it

banesullivan avatar May 29 '20 01:05 banesullivan

@RohanChacko you could try the open3d lib they support some nice surface reconstruction algorithms http://www.open3d.org/docs/release/tutorial/Advanced/surface_reconstruction.html https://towardsdatascience.com/5-step-guide-to-generate-3d-meshes-from-point-clouds-with-python-36bad397d8ba and it is quite easy to jump from pyvista to it and vice versa.

ttsesm avatar Jun 03 '20 10:06 ttsesm

Ah yes, I totally forgot about open3d. In the past, I had used this for some meshing of point clouds.

Here's a function I made at the time but I don't know if it's too relevant/helpful here:

import open3d as o3d

def poisson_mesh(pc, depth=8, width=0, scale=1.1, linear_fit=False):
    """`pc` is a `pyvista.PolyData` point cloud. The default arguments are abitrary"""
    cloud = o3d.geometry.PointCloud()
    cloud.points = o3d.utility.Vector3dVector(pc.points)
    cloud.normals = o3d.utility.Vector3dVector(pc["norms"])
    trimesh, _ = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(cloud, depth=depth, width=width, scale=scale, linear_fit=linear_fit)
    v = np.asarray(trimesh.vertices)
    f = np.array(trimesh.triangles)
    f = np.c_[np.full(len(f), 3), f]
    mesh = pv.PolyData(v, f)
    return mesh.clean()

Basically I was taking point clouds like:

2020-06-04 21 54 26

and creating meshed surfaces:

download

not exactly the same thing as creating water tight meshes, but hopefully this helps you see the logic of working between PyVista and open3d

banesullivan avatar Jun 05 '20 01:06 banesullivan

Interesting example, anyway!

bluetyson avatar Jul 25 '20 08:07 bluetyson

@akaszynski and @banesullivan What about GaussianSplatting? Would that work and does pyvista support it? I know VTK has it (see SplatFace). Though I do like the BallPivoting algorithm in open3d!

adam-grant-hendry avatar Sep 09 '21 15:09 adam-grant-hendry

Surface reconstruction is an open issue that we've only partially resolved with Surface Reconstruction. If we want to support ball pivoting or additional algorithms, a PR would be really helpful as I'm swamped (though we all are)...

akaszynski avatar Sep 09 '21 18:09 akaszynski

Hi,

I am using pyvista's reconstruct_surface to generate a mesh from a 3D point cloud. The visual result is impressive but something looks wrong with the curvature.

By mesh.plot_curvature I observe very similar values (for mean curvature) in both flat and more curved regions. I also computed the mean curvature values with a custom algorithm for the discrete Laplace-Beltrami operator and I still had a very little variance in curvatures.

Then I guess this depends on the definition of the mesh/ connection between points.

Have you already faced this problem? Can you help me?

Thank you in advance!

PyCody avatar Feb 08 '23 17:02 PyCody

This support forum is now closed. Please open a new discussion topic here: https://github.com/pyvista/pyvista/discussions

banesullivan avatar Feb 08 '23 18:02 banesullivan