UnstructuredGrid Filter extracts too many cells

Extracted surface of Bipyramid has too many cells

In the documentation of vtkUnstructuredGridGeometryFilter it is stated that this filter provides the following functionality:

Geometry is obtained as follows: all 0D, 1D, and 2D cells are extracted. All 2D faces that are used by only one 3D cell (i.e., boundary faces) are extracted.

However, when I extract the surface of a simple vtkUnstructuredGrid modelling a Bipyramid using this filter, then the vtkUnstructuredGrid obtained as Output of this filter has 10 cells instead of 8 cells. This means that the base plate where the two pyramids are glued together is falsly regarded as surface cell and counted twice.

I have a Test test_extract_surface.cpp at my github repo where this behaviour is highlighted.
This test is run at the github workflow of my github repo, linking against the current VTK master. The output at this run explicitely shows that that the Surface has 10 instead of 8 cells.

Running test_extract_surface also produces two VTU files bipyramid.vtu and surface.vtu containing the vtkUnstructuredGrid produces in this Test. I provided them in this repository. You can open these files with Paraview in order to check that these UnstructuredGrids look just as expected.

Is this a bug or is the documentation for this Filter incorrect?

I think the issue is with the dataset. There is a downstream tool PyVista that can be used to validate meshes. If I install it with pip

python -m pip install pyvista

Then run:

pyvista validate bipyramid.vtu 

I get

UnstructuredGrid mesh 'bipyramid.vtu' is not valid:
 ▪ Mesh has 1 PYRAMID cell with inverted faces. Invalid cell id: [1]
 ▪ Mesh has 1 PYRAMID cell with negative volume. Invalid cell id: [1]

So it looks like one half of the bipyramid is incorrectly defined. We can also confirm this visually with PyVista (Python code)

import pyvista as pv
from pyvista.examples.cells import plot_cell
mesh = pv.read('bipyramid.vtu')
plot_cell(mesh, show_normals=True)

Where you can see the normal arrows are pointing inward for the bottom half.

I suspect the geometry filter is including the inner base cell as part of the extracted surface based on this (it thinks the base is an exterior cell based on the inverted orientation). If you fix the orientation, I suspect the geometry filter will then work as expected.

You’re right! Thank you! Reorienting the points of the downwards pointing pyramid helped! Seems like there is no bug at all! :+1: