vtkDistancePolyDataFilter segmentation fault

Hello,

I’d like to compare 2 surface meshes (model-to-model avg distance). I have looked through the code and found few examples. Theoretically, it should work but on getting the output from PolyDataFilter I have seg fault.

Code:

def calculate_surface_distance_between_two_meshes(mesh_1, mesh_2):
    input1 = torch_data_to_vtk_polydata(mesh_1)
    input2 = torch_data_to_vtk_polydata(mesh_2)
    distanceFilter = vtk.vtkDistancePolyDataFilter()
    distanceFilter.SetInputData(0, input1)
    distanceFilter.SetInputData(1, input2)
    distanceFilter.SignedDistanceOff()
    distanceFilter.Update()  # Calculate distance
    return None
def torch_data_to_vtk_polydata(points, faces):
    nodes = vtk.vtkPoints()
    for point in points:
        nodes.InsertNextPoint(point)

    elements = vtk.vtkCellArray()
    for face in faces:
        elementIdList = vtk.vtkIdList()
        for nodeId in face:
            elementIdList.InsertNextId(nodeId)
        elements.InsertNextCell(elementIdList)

    polydata = vtk.vtkPolyData()
    polydata.SetPoints(nodes)
    polydata.SetPolys(elements)
    return polydata

the points, faces are here - they should be loaded with np load and passed to torch_data_to_vtk_polydata.
GitHub - BraveDistribution/VtkSegFault (I couldn’t upload it here, since I am a new user).

Would you be so kind to help me with this?

I have a feeling that I am not creating the polydata from numpy data right:

print(mesh.GetNumberOfPolys())
print(mesh.GetNumberOfVerts())

returns:

thanks

I tried both python 3.7 and 3.7.6.
VTK versions - 9.1.0 and vtk-8.1.2

UPDATE:
It’s fixed now. The problem was with how the faces were updated. I transposed the faces array which yielded to this problem.