marcomusy / vedo

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

Incorrect euler characteristics #710

Open jo-mueller opened 2 years ago

jo-mueller commented 2 years ago

I noticed that when I calculate the euler characteristics for the torus example data I get an euler characteristic of -119, whereas the correct value for a torus should be 0.

Here's some code to reproduce:

import vedo

mesh = vedo.shapes.Torus(r=50, thickness=10)
n_points = len(mesh.points())
n_edges = len(mesh.edges())
n_faces = len(mesh.faces())
euler_characteristic = n_points - n_edges + n_faces
marcomusy commented 2 years ago

Hi, I think it's the way vtk builds the mesh, it creates additional edges that one can visualize (in magenta):

import vedo

mesh = vedo.shapes.Torus()
# mesh = vedo.shapes.Disc()   # ok
# mesh = vedo.shapes.Circle() # ok
# mesh = vedo.shapes.Cube()   # ok
# mesh = vedo.shapes.Sphere(res=(20,30)) # ok
mesh.clean()  # remove duplicate faces

bnds = mesh.boundaries() 
mesh.lw(1).alpha(0.5).flat()

n_points = len(mesh.points())
n_edges = len(mesh.edges())
n_faces = len(mesh.faces())
euler_characteristic = n_points - n_edges + n_faces
euler_characteristic += bnds.npoints/2 +1 #only for torus correction..

# print(n_points, n_edges, n_faces, bnds.npoints)
print(euler_characteristic)

vedo.show(mesh, bnds, axes=1)

Screenshot from 2022-10-20 16-38-24

jo-mueller commented 2 years ago

@marcomusy Thanks for looking into this - I also didn't know about the mesh.cleancommand. Thanks a bunch! That being said, would you think it desirable to replace the torus dataset by one without duplicate vertices?

marcomusy commented 2 years ago

Yes.. it could be done manually but it's a bit tricky... I need to think how to do it..