# Steps to calculate the Euler characteristics and Betti number

**URL:** https://discourse.paraview.org/t/steps-to-calculate-the-euler-characteristics-and-betti-number/11777
**Category:** ParaView Support
**Created:** [March 31, 2023, 7:19pm UTC](https://discourse.paraview.org/t/steps-to-calculate-the-euler-characteristics-and-betti-number/11777 "2023-03-31T19:19:11Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![kokebdese](https://discourse.paraview.org/user_avatar/discourse.paraview.org/kokebdese/32/11182_2.png) [@kokebdese](https://discourse.paraview.org/u/kokebdese)
#### Post date: [March 31, 2023, 7:19pm UTC](https://discourse.paraview.org/t/steps-to-calculate-the-euler-characteristics-and-betti-number/11777/1 "2023-03-31T19:19:11Z")

</div>

Hi all,  
Any one who help me to calculate the Euler characteristics and Betti number of a 3D object using TTK on ParaView? Thanks

---

<div class="post-metadata">

### Author: ![jfausty](https://discourse.paraview.org/user_avatar/discourse.paraview.org/jfausty/32/9405_2.png) [@jfausty](https://discourse.paraview.org/u/jfausty)
#### Post date: [April 3, 2023, 7:06am UTC](https://discourse.paraview.org/t/steps-to-calculate-the-euler-characteristics-and-betti-number/11777/2 "2023-04-03T07:06:00Z")

</div>

@Charles_Gueunet ?

---

<div class="post-metadata">

### Author: ![Charles\_Gueunet](https://discourse.paraview.org/user_avatar/discourse.paraview.org/charles_gueunet/32/40_2.png) [@Charles\_Gueunet](https://discourse.paraview.org/u/Charles_Gueunet)
#### Post date: [April 3, 2023, 2:27pm UTC](https://discourse.paraview.org/t/steps-to-calculate-the-euler-characteristics-and-betti-number/11777/3 "2023-04-03T14:27:10Z")

</div>

@kokebdese There is an … overkill way to do it.  
The Discrete Sandwich module compute them and print them when the debug level is high enough (4 or more)  
 ![image](https://discourse.paraview.org/uploads/default/original/2X/c/c6f34df87fb97c6f860a8b00af1e11c7b06af6f7.png)

Then, in the execution log (visiblie in the terminal launching ParaView), you will have the corresponding section:

 ![image](https://discourse.paraview.org/uploads/default/original/2X/9/9756a7e8411b458a5b1e1bc33c01908b589783ad.png)  
Which corresponds to the first Betti numbers.

From my memory, there is a simpler way to compute them in 3D as in a simplicial complex, by playing with the number of connected components, vertices, edges, triangles and tetra, as well a the Euler characteristics, you just have some addition / subtraction to do.

---

<div class="post-metadata">

### Author: ![kokebdese](https://discourse.paraview.org/user_avatar/discourse.paraview.org/kokebdese/32/11182_2.png) [@kokebdese](https://discourse.paraview.org/u/kokebdese)
#### Post date: [April 3, 2023, 10:53pm UTC](https://discourse.paraview.org/t/steps-to-calculate-the-euler-characteristics-and-betti-number/11777/4 "2023-04-03T22:53:14Z")

</div>

@Charles_Gueunet, Thank you for interesting answer, however, what is Discrete Sandwich module? As I am new to the ParaView, I need to know how to get that. Thanks!

---

<div class="post-metadata">

### Author: ![Charles\_Gueunet](https://discourse.paraview.org/user_avatar/discourse.paraview.org/charles_gueunet/32/40_2.png) [@Charles\_Gueunet](https://discourse.paraview.org/u/Charles_Gueunet)
#### Post date: [April 5, 2023, 8:19am UTC](https://discourse.paraview.org/t/steps-to-calculate-the-euler-characteristics-and-betti-number/11777/5 "2023-04-05T08:19:00Z")

</div>

@kokebdese no problem 🙂

Do you have TTK enabled on your ParaView ?

**Tools** \> **Manage Plugins…**

 ![image](https://discourse.paraview.org/uploads/default/original/2X/b/b6883ec28a5c39a619f53eb91b7bce0f902a4d8a.png)

Once it is done, you should be able to access TTK filters, including the TTKPersistenceDiagram one.  
As you can see in my first anwer, the TTKPersistenceDiagram filter has a **Backend** option which by default is set to **Discrete Morse Sandwich**. This is the backend used for the computation of the persistence pairs, which record the most topological events. This module is also used in other TTK filters, so you may encounter this options in others filters while playing around. This module compute and print the Betti number when the debug level is 4 or more.

---

<div class="post-metadata">

### Author: ![kokebdese](https://discourse.paraview.org/user_avatar/discourse.paraview.org/kokebdese/32/11182_2.png) [@kokebdese](https://discourse.paraview.org/u/kokebdese)
#### Post date: [April 5, 2023, 10:07am UTC](https://discourse.paraview.org/t/steps-to-calculate-the-euler-characteristics-and-betti-number/11777/6 "2023-04-05T10:07:07Z")

</div>

@Charles_Gueunet. Thank you for your continuous support.

I face another challenge. I want to play with 3d segmented (nuclide of cell) data using electron microscope. I processed it using different image processing algorithm using matlab and finally I transferred the .mat format data to .stl format (which the ParaView able to read). However, the TTK persistent diagram filter is inactive for .stl files. Could you help me on this pls? Thank you!

 ![Screenshot from 2023-04-05 11-04-46](https://discourse.paraview.org/uploads/default/original/2X/e/e0da2aac4d7eefc08e5790fa009e69feb4987d4c.png)

---

<div class="post-metadata">

### Author: ![Charles\_Gueunet](https://discourse.paraview.org/user_avatar/discourse.paraview.org/charles_gueunet/32/40_2.png) [@Charles\_Gueunet](https://discourse.paraview.org/u/Charles_Gueunet)
#### Post date: [April 5, 2023, 12:21pm UTC](https://discourse.paraview.org/t/steps-to-calculate-the-euler-characteristics-and-betti-number/11777/7 "2023-04-05T12:21:29Z")

</div>

You need your mesh to be a valid 2 or 3 simplicial complex.  
In simple terms, here you want to **Extract Surface** and **Triangulate** you mesh.  
Be careful, you should have a clean mesh before using TTK filters. If you encounter crashes or errors, please have a look at the [ManifoldChecker example](https://topology-tool-kit.github.io/examples/manifoldCheck/)

---

<div class="post-metadata">

### Author: ![kokebdese](https://discourse.paraview.org/user_avatar/discourse.paraview.org/kokebdese/32/11182_2.png) [@kokebdese](https://discourse.paraview.org/u/kokebdese)
#### Post date: [April 5, 2023, 2:05pm UTC](https://discourse.paraview.org/t/steps-to-calculate-the-euler-characteristics-and-betti-number/11777/8 "2023-04-05T14:05:56Z")

</div>

@ Charles Gueunet  
Thank you, but I couldn’t get your explanation? How could I able to know whether my data is valid 2 or 3 simplicial complex? What do you mean by clean mesh? Thanks

---

<div class="post-metadata">

### Author: ![kokebdese](https://discourse.paraview.org/user_avatar/discourse.paraview.org/kokebdese/32/11182_2.png) [@kokebdese](https://discourse.paraview.org/u/kokebdese)
#### Post date: [April 6, 2023, 1:00pm UTC](https://discourse.paraview.org/t/steps-to-calculate-the-euler-characteristics-and-betti-number/11777/9 "2023-04-06T13:00:21Z")

</div>

@ Charles\_Gueunet, How do I **Extract Surface** and **Triangulate** my mesh? May I know how could I do that? I am new to ParaView?

Thank you for understanding.

---

<div class="post-metadata">

### Author: ![Charles\_Gueunet](https://discourse.paraview.org/user_avatar/discourse.paraview.org/charles_gueunet/32/40_2.png) [@Charles\_Gueunet](https://discourse.paraview.org/u/Charles_Gueunet)
#### Post date: [April 11, 2023, 8:06am UTC](https://discourse.paraview.org/t/steps-to-calculate-the-euler-characteristics-and-betti-number/11777/10 "2023-04-11T08:06:12Z")

</div>

> How could I able to know whether my data is valid 2 or 3 simplicial complex?

If you can share your data, I can have a quick look for you, let’s focus on easier parts first. The idea is to take inspiration from the Manifold Checker example given above.

> What do you mean by clean mesh?

I mean a mesh composed only of triangles, which do not overlap, and have a good connectivity (not 3 triangles connected on a same edge Y , not 2 triangles connected by a single point \>\< ) …  
You may have a look at the definition of a Manifold (here a 2-manifold).

> How do I **Extract Surface** and **Triangulate** my mesh? May I know how could I do that? I am new to ParaView?

Those are ParaView filters to apply to your mesh before applying a TTK filter. For this, you need select you mesh on the pipeline, then with Ctrl+Space you can choose a new filter. Select the **Extract Surface** filter and apply it. Then, on the result, Ctrl+Space again, **Triangulate** and press apply.

---

<div class="post-metadata">

### Author: ![kokebdese](https://discourse.paraview.org/user_avatar/discourse.paraview.org/kokebdese/32/11182_2.png) [@kokebdese](https://discourse.paraview.org/u/kokebdese)
#### Post date: [April 12, 2023, 8:48pm UTC](https://discourse.paraview.org/t/steps-to-calculate-the-euler-characteristics-and-betti-number/11777/11 "2023-04-12T20:48:26Z")

</div>

Hi @Charles_Gueunet:  
I really appreciate in the way you are helping me to understand a TTK. Now, I got all what you mean. However, even though I have tried to go though the mesh tutorials, still I couldn’t able to reproduce it on my own data set. Here (with the link: [hela.stl - Google Drive](https://bit.ly/406P3Pf)) is my sample data in .stl format (since it is \>4MB, I couldn’t able to upload it here [file name: hela.stl]) and could you help me in checking for Manifold? Thank you.

---

<div class="post-metadata">

### Author: ![Charles\_Gueunet](https://discourse.paraview.org/user_avatar/discourse.paraview.org/charles_gueunet/32/40_2.png) [@Charles\_Gueunet](https://discourse.paraview.org/u/Charles_Gueunet)
#### Post date: [April 13, 2023, 8:35am UTC](https://discourse.paraview.org/t/steps-to-calculate-the-euler-characteristics-and-betti-number/11777/12 "2023-04-13T08:35:38Z")

</div>

Hello @kokebdese

I have applied the `ttkManifoldChecker` on your mesh and obtained the following arrays:

![image](https://discourse.paraview.org/uploads/default/original/2X/d/dbcf917fe0f5480ec72dca1da62bac8def94c556.png)

As we can see, all of them are constant. Basically, for a surface mesh, this means that the neighborhood is always valid, your mesh is manifold.

Then we want to compute the betti numbers. We have seen the idea is to use the persistence diagram filter with a debug level of 4 to get this information, but this filter expect a scalar field, so we create a dummy one using a calculator, an elevation, a random …

![image](https://discourse.paraview.org/uploads/default/original/2X/5/561fb20ff1f2008a2f91d8deba232db35e839322.png)

During this computation, I have the following output:

![image](https://discourse.paraview.org/uploads/default/original/2X/8/8bb50631e17ce239ba3e7255d4c417e50193e31e.png)

So the first betti numbers are: 2 , 18 , 0  
We can use the connectivity filter to see that we have indeed to connected components on this data set. Of course, there is no void on a surface mesh. It seems there are 18 handles also. We could try to extract them if needed but this would be some work.

---

<div class="post-metadata">

### Author: ![kokebdese](https://discourse.paraview.org/user_avatar/discourse.paraview.org/kokebdese/32/11182_2.png) [@kokebdese](https://discourse.paraview.org/u/kokebdese)
#### Post date: [April 13, 2023, 10:07pm UTC](https://discourse.paraview.org/t/steps-to-calculate-the-euler-characteristics-and-betti-number/11777/13 "2023-04-13T22:07:45Z")

</div>

@Charles_Gueunet  
Hey,  
I thank you so much! You are making me to love TDA [TTK], which I believe is a very central topic of my current study work. I hope to continually see your kind support like this.

---

<div class="post-metadata">

### Author: ![kokebdese](https://discourse.paraview.org/user_avatar/discourse.paraview.org/kokebdese/32/11182_2.png) [@kokebdese](https://discourse.paraview.org/u/kokebdese)
#### Post date: [April 17, 2023, 11:21am UTC](https://discourse.paraview.org/t/steps-to-calculate-the-euler-characteristics-and-betti-number/11777/14 "2023-04-17T11:21:35Z")

</div>

@Charles_Gueunet

Hi

What was the reason to consider a debug level of 4 than any other number to calculate the betti number?  
Thanks

---

<div class="post-metadata">

### Author: ![Charles\_Gueunet](https://discourse.paraview.org/user_avatar/discourse.paraview.org/charles_gueunet/32/40_2.png) [@Charles\_Gueunet](https://discourse.paraview.org/u/Charles_Gueunet)
#### Post date: [April 17, 2023, 11:29am UTC](https://discourse.paraview.org/t/steps-to-calculate-the-euler-characteristics-and-betti-number/11777/15 "2023-04-17T11:29:02Z")

</div>

Hello,

This is simply because the corresponding debug message is only displayed with a debug level of 4 or more, see [the corresponding line](https://github.com/topology-tool-kit/ttk/blob/f1bf77c4fb25ff3f4dfde9fe3ae2bc8ec765450c/core/base/discreteMorseSandwich/DiscreteMorseSandwich.h#L1264).

---

<div class="post-metadata">

### Author: ![kokebdese](https://discourse.paraview.org/user_avatar/discourse.paraview.org/kokebdese/32/11182_2.png) [@kokebdese](https://discourse.paraview.org/u/kokebdese)
#### Post date: [April 17, 2023, 2:55pm UTC](https://discourse.paraview.org/t/steps-to-calculate-the-euler-characteristics-and-betti-number/11777/16 "2023-04-17T14:55:37Z")

</div>

@Charles_Gueunet  
Thank you!

---

<div class="post-metadata">

### Author: ![kokebdese](https://discourse.paraview.org/user_avatar/discourse.paraview.org/kokebdese/32/11182_2.png) [@kokebdese](https://discourse.paraview.org/u/kokebdese)
#### Post date: [April 18, 2023, 1:59pm UTC](https://discourse.paraview.org/t/steps-to-calculate-the-euler-characteristics-and-betti-number/11777/17 "2023-04-18T13:59:27Z")

</div>

@Charles_Gueunet

Hey  
“It seems there are 18 handles also” Does these handles are all holes?

---

<div class="post-metadata">

### Author: ![Charles\_Gueunet](https://discourse.paraview.org/user_avatar/discourse.paraview.org/charles_gueunet/32/40_2.png) [@Charles\_Gueunet](https://discourse.paraview.org/u/Charles_Gueunet)
#### Post date: [April 18, 2023, 2:47pm UTC](https://discourse.paraview.org/t/steps-to-calculate-the-euler-characteristics-and-betti-number/11777/18 "2023-04-18T14:47:50Z")

</div>

@kokebdese The term of “hole” usually refer both to handle and void/cavities. As there is none here, I would assume that 18 handles + 0 cavities means 18 holes

---

<div class="post-metadata">

### Author: ![kokebdese](https://discourse.paraview.org/user_avatar/discourse.paraview.org/kokebdese/32/11182_2.png) [@kokebdese](https://discourse.paraview.org/u/kokebdese)
#### Post date: [April 18, 2023, 7:41pm UTC](https://discourse.paraview.org/t/steps-to-calculate-the-euler-characteristics-and-betti-number/11777/19 "2023-04-18T19:41:52Z")

</div>

@Charles_Gueunet: Thank you!

---

<div class="post-metadata">

### Author: ![kokebdese](https://discourse.paraview.org/user_avatar/discourse.paraview.org/kokebdese/32/11182_2.png) [@kokebdese](https://discourse.paraview.org/u/kokebdese)
#### Post date: [April 20, 2023, 5:47pm UTC](https://discourse.paraview.org/t/steps-to-calculate-the-euler-characteristics-and-betti-number/11777/20 "2023-04-20T17:47:15Z")

</div>

@Charles_Gueunet  
Hey  
Is there a way to save the values displayed in the Terminal or it that the only window where the values are displayed? Thanks

[Next page](https://discourse.paraview.org/t/steps-to-calculate-the-euler-characteristics-and-betti-number/11777.md?page=2)
