# Segfault while finding intersection of vtkPolyData with python

**URL:** https://discourse.vtk.org/t/segfault-while-finding-intersection-of-vtkpolydata-with-python/317
**Category:** Support
**Created:** [February 25, 2019, 4:23am UTC](https://discourse.vtk.org/t/segfault-while-finding-intersection-of-vtkpolydata-with-python/317 "2019-02-25T04:23:12Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![banesullivan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/banesullivan/32/7143_2.png) [@banesullivan](https://discourse.vtk.org/u/banesullivan)
#### Post date: [February 27, 2019, 8:47am UTC](https://discourse.vtk.org/t/segfault-while-finding-intersection-of-vtkpolydata-with-python/317/2 "2019-02-27T08:47:46Z")

</div>

This is very similar to [How to extract surface from polydata](https://discourse.vtk.org/t/how-to-extract-surface-from-polydata/321/4)

The `vtk.vtkBooleanOperationPolyDataFilter` is simply not producing a result which is causing the segfault down your pipeline. @cory.quammen would likely have more details on how to get the `vtk.vtkBooleanOperationPolyDataFilter` working

Also, note a lot of this code can be simplified with [`vtki`](http://docs.vtki.org/en/latest/). Perhaps if we figure out how to implement this, it could become a common routine in `vtki`…

```python
import vtki
import vtk

def get_mesh_intersection(mesh1, mesh2):
    '''
    Find the intersection volume between mesh vtk objects
    and return the volume of intersection
    '''
    alg = vtk.vtkBooleanOperationPolyDataFilter()
    alg.SetInputData(0, mesh2)
    alg.SetInputData(1, mesh1)
    alg.SetOperationToIntersection()
    alg.Update()
    intersection = vtki.wrap(alg.GetOutput())
    return intersection

# Load meshes
mesh_i = vtki.read('probe0.vtk')
mesh_j = vtki.read('probe1.vtk')

print('VOLUME of probe1:\t', mesh_i.volume, '# of Polys:\t', mesh_i.n_faces)
print('VOLUME of probe2:\t', mesh_j.volume, '# of Polys:\t', mesh_j.n_faces)
intersection = get_mesh_intersection(mesh_i, mesh_j)
print('INTERSECTION VOLUME:\t', intersection.volume)

```

with output:

```nohighlight
VOLUME of probe1: 8.360612727741916 # of Polys: 344
VOLUME of probe2: 8.440116557580266 # of Polys: 480
INTERSECTION VOLUME: 0.0

```

Also, plotting is easy:

```python
vtki.MultiBlock([mesh_i, mesh_j]).plot(show_edges=1, multi_colors=1)

```

 ![download](https://discourse.vtk.org/uploads/default/original/1X/9667bc12223f57023f460617d1b6286d51e81af0.png)

or

```python
p = vtki.Plotter()
p.add_mesh(mesh_i, color='g', show_edges=1)
p.add_mesh(mesh_j, color='b', show_edges=1)
p.show()

```

---

_[View the full topic](https://discourse.vtk.org/t/segfault-while-finding-intersection-of-vtkpolydata-with-python/317)._
