# Extract surface meshes from groundtruth and deformed/predicted volumetric meshes

**URL:** https://discourse.vtk.org/t/extract-surface-meshes-from-groundtruth-and-deformed-predicted-volumetric-meshes/12053
**Category:** Support
**Tags:** python
**Created:** [July 28, 2023, 8:30am UTC](https://discourse.vtk.org/t/extract-surface-meshes-from-groundtruth-and-deformed-predicted-volumetric-meshes/12053 "2023-07-28T08:30:17Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![isuruwi](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/i/c0e974/32.png) [@isuruwi](https://discourse.vtk.org/u/isuruwi)
#### Post date: [July 28, 2023, 8:30am UTC](https://discourse.vtk.org/t/extract-surface-meshes-from-groundtruth-and-deformed-predicted-volumetric-meshes/12053/1 "2023-07-28T08:30:17Z")

</div>

Hi,

I have two volumetric meshes that have same number of nodes and connectivities (cells). The only difference is that one mesh is kind of a deformed version of the other. This means only the node positions are sligtly different.

What I want is that extract the surface meshes from those two and save back to the disk for further processing. However, when I attempt to extract by using vtk.geometryFilter (see below sample code) I enconter that the face ids are somehow different to each other.

How can I extract the surface meshes which compatible to each other so that I can compare them. This indicates only the node positions are different but the faces/tirangles ids are exactly the same.

Am I missed anything or any steps here ? If so can you elaborate the steps with an example please ?

I herewith attached a sample groundtruth mesh and its deformed/predicted version for your further reference.

```auto
import os
import vtk

def getSurfaceMesh(vol_mesh_path, out_save_path):
    meshReader = vtk.vtkUnstructuredGridReader()
    meshReader.SetFileName(vol_mesh_path)
    meshReader.ReadAllVectorsOn()
    meshReader.ReadAllScalarsOn()
    meshReader.Update()

    meshGeometryFilter = vtk.vtkGeometryFilter()
    meshGeometryFilter.SetInputData(meshReader.GetOutput())
    meshGeometryFilter.Update()

    stlWriter = vtk.vtkSTLWriter()
    stlWriter.SetFileName(out_save_path)
    stlWriter.SetInputConnection(meshGeometryFilter.GetOutputPort())
    stlWriter.Write()

volumetric_mesh_path = "F:/gt_scan_1.vtk"
surface_save_path = "F:/surface_meshes/gt_scan_1.stl"

pred_volumetric_mesh_path = "F:/pred_scan_1.vtk"
pred_surface_save_path = "F:/surface_meshes/pred_scan_1.stl"

getSurfaceMesh(volumetric_mesh_path, surface_save_path)
getSurfaceMesh(pred_volumetric_mesh_path, pred_surface_save_path)

```

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [July 29, 2023, 6:19pm UTC](https://discourse.vtk.org/t/extract-surface-meshes-from-groundtruth-and-deformed-predicted-volumetric-meshes/12053/2 "2023-07-29T18:19:29Z")

</div>

vtkGeometryFilter can pass through original point and cell IDs.

---

<div class="post-metadata">

### Author: ![isuruwi](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/i/c0e974/32.png) [@isuruwi](https://discourse.vtk.org/u/isuruwi)
#### Post date: [July 30, 2023, 9:07am UTC](https://discourse.vtk.org/t/extract-surface-meshes-from-groundtruth-and-deformed-predicted-volumetric-meshes/12053/3 "2023-07-30T09:07:55Z")

</div>

Hi Andras,

I just modified my script by adding below two lines to the code.

```auto
meshGeometryFilter.SetPassThroughCellIds(1)
meshGeometryFilter.SetPassThroughPointIds(1)

```

However, I encounter an error message saying that there is no attributes specified with SetPassThroughCellIds and SetPassThroughPointIds in vtkGeometryFilter.

**AttributeError: ‘vtkmodules.vtkFiltersGeometry.vtkGeometryFilter’ object has no attribute ‘SetPassThroughCellIds’**

**How can I set original point and cell IDs to the vtkGeometry Filter. Could you please elaborate this with a simple example code ?**

Modified code:

```auto
def getSurfaceMesh(vol_mesh_path, out_save_path):
    meshReader = vtk.vtkUnstructuredGridReader()
    meshReader.SetFileName(vol_mesh_path)
    meshReader.ReadAllVectorsOn()
    meshReader.ReadAllScalarsOn()
    meshReader.Update()

    meshGeometryFilter = vtk.vtkGeometryFilter()
    meshGeometryFilter.SetInputData(meshReader.GetOutput())
    meshGeometryFilter.SetPassThroughCellIds(1)
    meshGeometryFilter.SetPassThroughPointIds(1)
    meshGeometryFilter.Update()

    stlWriter = vtk.vtkSTLWriter()
    stlWriter.SetFileName(out_save_path)
    stlWriter.SetInputConnection(meshGeometryFilter.GetOutputPort())
    stlWriter.Write()

```

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [July 30, 2023, 12:37pm UTC](https://discourse.vtk.org/t/extract-surface-meshes-from-groundtruth-and-deformed-predicted-volumetric-meshes/12053/4 "2023-07-30T12:37:04Z")

</div>

What VTK version do you use? If it is older than 3 years then you may need to update.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [November 5, 2023, 9:48am UTC](https://discourse.vtk.org/t/extract-surface-meshes-from-groundtruth-and-deformed-predicted-volumetric-meshes/12053/5 "2023-11-05T09:48:21Z")

</div>

data removed as asked by @isuruwi
