pyvista / pyvista-support

[moved] Please head over to the Discussions tab of the PyVista repository
https://github.com/pyvista/pyvista/discussions
60 stars 4 forks source link

Converting pointcloud to watertight mesh #170

Open RohanChacko opened 4 years ago

RohanChacko commented 4 years ago

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

akaszynski commented 4 years ago

@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?

banesullivan commented 4 years ago

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 commented 4 years ago

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

RohanChacko commented 4 years ago

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

banesullivan commented 4 years ago

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

banesullivan commented 4 years ago

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

ttsesm commented 4 years ago

@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.

banesullivan commented 4 years ago

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

bluetyson commented 4 years ago

Interesting example, anyway!

adam-grant-hendry commented 3 years ago

@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!

akaszynski commented 3 years ago

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)...

PyCody commented 1 year ago

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!

banesullivan commented 1 year ago

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