# Euler number. Get the number of edges, faces and vertices

**URL:** https://discourse.vtk.org/t/euler-number-get-the-number-of-edges-faces-and-vertices/12717
**Category:** Support
**Created:** [November 15, 2023, 7:27pm UTC](https://discourse.vtk.org/t/euler-number-get-the-number-of-edges-faces-and-vertices/12717 "2023-11-15T19:27:30Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Jens\_Munk\_Hansen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jens_munk_hansen/32/1215_2.png) [@Jens\_Munk\_Hansen](https://discourse.vtk.org/u/Jens_Munk_Hansen)
#### Post date: [November 15, 2023, 7:27pm UTC](https://discourse.vtk.org/t/euler-number-get-the-number-of-edges-faces-and-vertices/12717/1 "2023-11-15T19:27:30Z")

</div>

Hi Developers

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?

Thanks in advance  
Jens Munk

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [November 15, 2023, 8:55pm UTC](https://discourse.vtk.org/t/euler-number-get-the-number-of-edges-faces-and-vertices/12717/2 "2023-11-15T20:55:44Z")

</div>

Hi Jens,

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.

---

<div class="post-metadata">

### Author: ![Jens\_Munk\_Hansen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jens_munk_hansen/32/1215_2.png) [@Jens\_Munk\_Hansen](https://discourse.vtk.org/u/Jens_Munk_Hansen)
#### Post date: [November 15, 2023, 9:01pm UTC](https://discourse.vtk.org/t/euler-number-get-the-number-of-edges-faces-and-vertices/12717/3 "2023-11-15T21:01:33Z")

</div>

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:

```auto
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

```
