vedo icon indicating copy to clipboard operation
vedo copied to clipboard

Incorrect euler characteristics

Open jo-mueller opened this issue 3 years ago • 3 comments

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

jo-mueller avatar Oct 20 '22 13:10 jo-mueller

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

marcomusy avatar Oct 20 '22 14:10 marcomusy

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

jo-mueller avatar Oct 25 '22 06:10 jo-mueller

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

marcomusy avatar Oct 25 '22 15:10 marcomusy