# Iterate over Triangles in Tetrahedron Data (without redundancies)

**URL:** https://discourse.vtk.org/t/iterate-over-triangles-in-tetrahedron-data-without-redundancies/6403
**Category:** Support
**Created:** [August 17, 2021, 3:22pm UTC](https://discourse.vtk.org/t/iterate-over-triangles-in-tetrahedron-data-without-redundancies/6403 "2021-08-17T15:22:01Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Flashtim](https://discourse.vtk.org/user_avatar/discourse.vtk.org/flashtim/32/3821_2.png) [@Flashtim](https://discourse.vtk.org/u/Flashtim)
#### Post date: [August 17, 2021, 3:22pm UTC](https://discourse.vtk.org/t/iterate-over-triangles-in-tetrahedron-data-without-redundancies/6403/1 "2021-08-17T15:22:01Z")

</div>

Hey there!  
I am currently working with a `vtkUnstructuredGrid` object that is made up of a collection of tetrahedron cells. I now want to iterate over all triangles.  
One way to do so ist to use the `GetCellData();` function, but this will lead to a list of tetrahedra, which I can then use to visit all faces. This leads to several triangles being visited twice, which is a significant overhead. Does VTK offer a better way that I just haven’t found yet?

There was a similar question, which was never really answered.

> [@Iterate over the faces of an UnstructuredGrid](https://discourse.vtk.org/t/iterate-over-the-faces-of-an-unstructuredgrid/2184):
>
> What’s the most efficient way to iterate over all the faces of an UnstructuredGrid? I know I can iterate over the cells first and then get its faces for each cell, but this will lead me to visit the same face two times (one per each cell that shares the face). Is there a way to just iterate over all the faces? Thanks.

Thanks for any responses,  
-Flashtim

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [August 17, 2021, 4:02pm UTC](https://discourse.vtk.org/t/iterate-over-triangles-in-tetrahedron-data-without-redundancies/6403/2 "2021-08-17T16:02:45Z")

</div>

I answered your question in the discourse thread…

---

<div class="post-metadata">

### Author: ![Flashtim](https://discourse.vtk.org/user_avatar/discourse.vtk.org/flashtim/32/3821_2.png) [@Flashtim](https://discourse.vtk.org/u/Flashtim)
#### Post date: [August 17, 2021, 4:07pm UTC](https://discourse.vtk.org/t/iterate-over-triangles-in-tetrahedron-data-without-redundancies/6403/3 "2021-08-17T16:07:18Z")

</div>

Thanks for the suggestion, I thought of a similar way to approach this.  
But you would also say, that there is no straightforward function that would provide, e.g., an array of all unique triangles?

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [August 17, 2021, 4:38pm UTC](https://discourse.vtk.org/t/iterate-over-triangles-in-tetrahedron-data-without-redundancies/6403/4 "2021-08-17T16:38:11Z")

</div>

That’s a good suggestion, but I believe the current philosophy is that such a face structure would be too slow and too memory inefficient. However, for all I know there may be a filter (or filter combination) that can do what you want but nothing is coming to me at the moment. Are you willing to try writing some code and creating a MR? It could be added to vtkUnstructuredGridBase with an implementation in vtkUnstructuredGrid.

---

<div class="post-metadata">

### Author: ![Flashtim](https://discourse.vtk.org/user_avatar/discourse.vtk.org/flashtim/32/3821_2.png) [@Flashtim](https://discourse.vtk.org/u/Flashtim)
#### Post date: [August 17, 2021, 5:36pm UTC](https://discourse.vtk.org/t/iterate-over-triangles-in-tetrahedron-data-without-redundancies/6403/5 "2021-08-17T17:36:07Z")

</div>

Yeah, I was thinking about doing that. Let’s see, it might result as a sideproduct of my current project.  
Thanks for your suggestions.
