# UnstructuredGrid Filter extracts too many cells

**URL:** https://discourse.vtk.org/t/unstructuredgrid-filter-extracts-too-many-cells/16433
**Category:** Development
**Tags:** code
**Created:** [May 26, 2026, 1:58pm UTC](https://discourse.vtk.org/t/unstructuredgrid-filter-extracts-too-many-cells/16433 "2026-05-26T13:58:39Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![magicmangoman](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/4af34b/32.png) [@magicmangoman](https://discourse.vtk.org/u/magicmangoman)
#### Post date: [May 26, 2026, 1:58pm UTC](https://discourse.vtk.org/t/unstructuredgrid-filter-extracts-too-many-cells/16433/1 "2026-05-26T13:58:39Z")

</div>

# Extracted surface of Bipyramid has too many cells

In the documentation of [vtkUnstructuredGridGeometryFilter](https://vtk.org/doc/nightly/html/classvtkUnstructuredGridGeometryFilter.html#details) 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**](https://en.wikipedia.org/wiki/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](https://github.com/leonschropp/vtk-surface-bug/tree/main) where this behaviour is highlighted.  
This test is run at the github workflow of [my github repo](https://github.com/leonschropp/vtk-surface-bug/tree/main), 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](https://www.paraview.org/) in order to check that these `UnstructuredGrids` look just as expected.

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

---

<div class="post-metadata">

### Author: ![user27182](https://discourse.vtk.org/user_avatar/discourse.vtk.org/user27182/32/10104_2.png) [@user27182](https://discourse.vtk.org/u/user27182)
#### Post date: [May 26, 2026, 5:04pm UTC](https://discourse.vtk.org/t/unstructuredgrid-filter-extracts-too-many-cells/16433/2 "2026-05-26T17:04:55Z")

</div>

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`

```auto
python -m pip install pyvista

```

Then run:

```auto
pyvista validate bipyramid.vtu 

```

I get

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

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

```

 ![image](https://discourse.vtk.org/uploads/default/original/2X/6/653c19f5adaa2339b2b23d84b845bdb9544139fd.jpeg)

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.

---

<div class="post-metadata">

### Author: ![magicmangoman](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/4af34b/32.png) [@magicmangoman](https://discourse.vtk.org/u/magicmangoman)
#### Post date: [May 27, 2026, 6:28am UTC](https://discourse.vtk.org/t/unstructuredgrid-filter-extracts-too-many-cells/16433/3 "2026-05-27T06:28:12Z")

</div>

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