I would like to filter some surfaces based on their Euler characteristic. I need to compute the number the Euler number = V - E + F.

The number of vertices (number of points) and number of faces (number of triangles) are easy to find. What is the easiest way to find the number of edges, vtkEdgeFilter?

You probably want vtkFeatureEdges, it’s a filter than can extract edges according to their properties.

Try this filter with the settings BoundaryEdgesOn() and ManifoldEdgesOn(), and turn all other kinds of edges off, e.g. FeatureEdgesOff(), NonManifoldEdgesOff().

ManifoldEdges are edges shared by two polygons, BoundaryEdges are edges that belong to only one polygon. If your surface is a closed surface, it will have no boundary edges.

The number of line segments generated by the filter is the number of edges.

Thanks, I am currently messing around with vtkFeatureEdges. My surfaces have no non-manifold edges, but are not always closed. It must be possible… I get some weird artifacts from both vtkBool and vtkBooleanOperationPolyDataFilter and they seem like open surfaces, so my idea is to remove them based on topology.

The issue was that the output of vtkBool visually appear as closed, but they are not.

In case other people asks this question, my current solution is now:

def vtk_euler_number(polyInput):
cleaner = vtkStaticCleanPolyData()
cleaner.SetInputData(polyInput)
cleaner.Update()
poly = cleaner.GetOutput()
# FeatureEdges
edges = vtkFeatureEdges()
edges.BoundaryEdgesOn()
edges.ManifoldEdgesOn()
edges.FeatureEdgesOff()
edges.NonManifoldEdgesOff()
edges.SetInputConnection(cleaner.GetOutputPort())
V = poly.GetNumberOfPoints()
F = poly.GetNumberOfCells()
edges.Update()
E = edges.GetOutput().GetNumberOfCells()
return V - E + F