marcomusy / vedo

A python module for scientific analysis of 3D data based on VTK and Numpy
https://vedo.embl.es
MIT License
1.98k stars 257 forks source link

Feature Request: Determine where genus are present in mesh #1084

Closed JeffreyWardman closed 2 weeks ago

JeffreyWardman commented 2 months ago

I want to be able to find where "tunnels"/"holes" are in the mesh (see below). A count of them and their bounding box would be ideal return values. For my particular use case, I want to remove them as they cause significant problems and only occur in poorly scanned regions.

image

JeffreyWardman commented 2 months ago

Number of genus can be counted via -(m.vertices.shape[0] - len(m.edges) + len(m.cells) - 2 - len(m.boundaries().split()))/2. Unsure about determining the location.

marcomusy commented 2 months ago

I think a -1 is needed in the above. Anyway consider the following:

https://en.wikipedia.org/wiki/Reeb_graph

from vedo import *

mesh = Mesh("https://discourse.paraview.org/uploads/short-url/qVuZ1fiRjwhE1qYtgGE2HGXybgo.stl")
mesh.rotate_x(10).rotate_y(15).alpha(0.5)
mesh.pointdata["scalars"] = mesh.vertices[:, 0]

printc("is_closed  :", mesh.is_closed())
printc("is_manifold:", mesh.is_manifold())
printc("euler_char :", mesh.euler_characteristic())
printc("genus      :", mesh.genus())

reeb = mesh.to_reeb_graph()
ids = reeb[0].pointdata["Vertex Ids"]
pts = Points(mesh.vertices[ids], r=10)

show([[mesh, pts], reeb], N=2, sharecam=False)

Screenshot from 2024-04-05 19-53-21

to be honest i'm not sure if that really answers the question properly, but I hope it can help.