Extract surface meshes from groundtruth and deformed/predicted volumetric meshes

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.

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)

vtkGeometryFilter can pass through original point and cell IDs.

Hi Andras,

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

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:

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()

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

data removed as asked by @isuruwi