# vtkDistancePolyDataFilter segmentation fault

**URL:** https://discourse.vtk.org/t/vtkdistancepolydatafilter-segmentation-fault/8952
**Category:** Support
**Created:** [July 14, 2022, 1:45pm UTC](https://discourse.vtk.org/t/vtkdistancepolydatafilter-segmentation-fault/8952 "2022-07-14T13:45:36Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![BraveDistribution](https://discourse.vtk.org/user_avatar/discourse.vtk.org/bravedistribution/32/5510_2.png) [@BraveDistribution](https://discourse.vtk.org/u/BraveDistribution)
#### Post date: [July 14, 2022, 1:45pm UTC](https://discourse.vtk.org/t/vtkdistancepolydatafilter-segmentation-fault/8952/1 "2022-07-14T13:45:36Z")

</div>

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:

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

```

```auto
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](https://github.com/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:

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