# vtkIntersectionPolyDataFilter crashing

**URL:** <https://discourse.vtk.org/t/vtkintersectionpolydatafilter-crashing/9428>\
**Category:** Development\
**Created:** [September 22, 2022, 11:49am UTC](https://discourse.vtk.org/t/vtkintersectionpolydatafilter-crashing/9428 "2022-09-22T11:49:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcomusy](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcomusy/32/95_2.png) [@marcomusy](https://discourse.vtk.org/u/marcomusy)\
**Post date:** [September 22, 2022, 11:49am UTC](https://discourse.vtk.org/t/vtkintersectionpolydatafilter-crashing/9428/1 "2022-09-22T11:49:14Z")

</div>

There might be a bug or numerical instability in the `vtkIntersectionPolyDataFilter` class:

```python
import numpy as np
import vtk
import vedo

# crashing
m1v = np.array([[17903.93947473, 11418.12995419, 2572.68075251],[17889.4353166, 11423.09300945, 2546.89320749],[17913.6520434, 11446.51421055, 2572.68075251],[17899.14788527, 11451.47726581, 2546.89320749]])
m2v = np.array([[17897.68174692, 11454.30365475, 2573.22453367],[17917.8546173, 11442.45883457, 2554.44274633],[17882.4917027, 11428.43354543, 2573.22453367],[17902.66457308, 11416.58872525, 2554.44274633]])

# not crashing
# m1v = np.array([[17903.9, 11418.1, 2572.7],[17889.4, 11423.1, 2546.9],[17913.6, 11446.5, 2572.7],[17899.1, 11451.5, 2546.9]])
# m2v = np.array([[17897.7, 11454.3, 2573.2],[17917.8, 11442.5, 2554.4],[17882.5 ,11428.4, 2573.2],[17902.7, 11416.6, 2554.4]])

faces = [[0,1,2], [3,2,1]] # 2 triangular faces

poly1 = vedo.Mesh([m1v, faces]).polydata() # vtkPolyData
poly2 = vedo.Mesh([m2v, faces]).polydata()

ipdf = vtk.vtkIntersectionPolyDataFilter()
ipdf.SetInputData(0, poly1)
ipdf.SetInputData(1, poly2)
ipdf.Update()

#vedo.show(poly1, poly2, ipdf.GetOutput(), axes=1)

```

 ![Screenshot from 2022-09-22 13-34-59](https://discourse.vtk.org/uploads/default/original/2X/e/e8f88dc1e8cff88257a348517b2f9b514bc61bab.png)

It seems to be happening when the 2 interanl edges are colliding.

---

<div class="post-metadata">

**Author:** ![fab672000](https://discourse.vtk.org/user_avatar/discourse.vtk.org/fab672000/32/5808_2.png) [@fab672000](https://discourse.vtk.org/u/fab672000)\
**Post date:** [September 22, 2022, 6:02pm UTC](https://discourse.vtk.org/t/vtkintersectionpolydatafilter-crashing/9428/2 "2022-09-22T18:02:36Z")

</div>

What is the error message when it is crashing could you see more information?

---

<div class="post-metadata">

**Author:** ![marcomusy](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcomusy/32/95_2.png) [@marcomusy](https://discourse.vtk.org/u/marcomusy)\
**Post date:** [September 22, 2022, 7:07pm UTC](https://discourse.vtk.org/t/vtkintersectionpolydatafilter-crashing/9428/3 "2022-09-22T19:07:27Z")

</div>

Yes, I forgot to include it, it says:

```bash
2022-09-21 12:40:50.153 ( 0.206s) [C7B50740]vtkIntersectionPolyData:804 WARN| invalid point read 5

```

---

<div class="post-metadata">

**Author:** ![fab672000](https://discourse.vtk.org/user_avatar/discourse.vtk.org/fab672000/32/5808_2.png) [@fab672000](https://discourse.vtk.org/u/fab672000)\
**Post date:** [September 22, 2022, 7:21pm UTC](https://discourse.vtk.org/t/vtkintersectionpolydatafilter-crashing/9428/4 "2022-09-22T19:21:44Z")

</div>

> [@marcomusy](#):
>
> `invalid point read`

Not sure why you get this but quickly looking to VTK source code it seems that you have less\* points than linePointsId when you get this message and it breaks in vtkIntersectionPolyDataFilter::Impl ::SplitCell():

```auto
        for (vtkIdType k = 0; k < nLinePts; k++)
        {
          if (linePtIds[k] >= interLines->GetNumberOfPoints())
          {
            vtkGenericWarningMacro(<< "invalid point read 5");
          }
          interLines->GetPoint(linePtIds[k], xyz);

```

Is it possible that when the 2 polys intersect you should duplicate some points in the intersection?  
so in this code: vedo.Mesh([m2[resp. 1]v, faces]).polydata() ?

---

<div class="post-metadata">

**Author:** ![marcomusy](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcomusy/32/95_2.png) [@marcomusy](https://discourse.vtk.org/u/marcomusy)\
**Post date:** [September 23, 2022, 9:53am UTC](https://discourse.vtk.org/t/vtkintersectionpolydatafilter-crashing/9428/5 "2022-09-23T09:53:13Z")

</div>

to be honest I don’t know, it looks to me like a genuine bug as by just rounding off a bit the vertex positions the algorithm works fine.

---

<div class="post-metadata">

**Author:** ![jarek-tuszynski](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jarek-tuszynski/32/6605_2.png) [@jarek-tuszynski](https://discourse.vtk.org/u/jarek-tuszynski)\
**Post date:** [February 23, 2023, 7:35pm UTC](https://discourse.vtk.org/t/vtkintersectionpolydatafilter-crashing/9428/6 "2023-02-23T19:35:09Z")

</div>

I am running into the same error:

2023󈚦󈚻 14:05:53.858 ( 53.223s) []vtkIntersectionPolyData:804 WARN| invalid point read 5

while doing boolean intersection of 2 watertight surface meshes using pyvista’s [PolyDataFilters.boolean\_intersection](https://docs.pyvista.org/api/core/_autosummary/pyvista.PolyDataFilters.boolean_intersection.html)
