vtkIntersectionPolyDataFilter crashing

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

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)

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

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

Yes, I forgot to include it, it says:

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

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

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

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.

1 Like

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