Iterate over the faces of an UnstructuredGrid

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.

If you are interested in visiting only the cells on the outside surface of the mesh then you can apply vtkGeometryFilter.

One trick to use is the following:

  • Iterate over all cells
  • For each cell C
  • For each face F of C, get the list of cell neighbors.
  • If the cell id of C < the cell id of any other cell using F, then visit F. (Or if there are no neighbors to face F, visit it).
1 Like