The method seems to work well in general but not in this case when the polydata is the output of vtkAppendPolyData
:
circles.vtk (51.1 KB)
import vtk
reader = vtk.vtkPolyDataReader()
reader.SetFileName("circles.vtk")
reader.Update()
polydata = reader.GetOutput()
line_locator = vtk.vtkOBBTree()
line_locator.SetDataSet(polydata)
#line_locator.SetTolerance(0.00000001)
line_locator.BuildLocator()
p0 = (0.22, -0.18, 3.1)
p1 = (-0.11, 0.6, -0.02)
vpts = vtk.vtkPoints()
idlist = vtk.vtkIdList()
line_locator.IntersectWithLine(p0, p1, vpts, idlist)
pts = []
for i in range(vpts.GetNumberOfPoints()):
intersection = [0, 0, 0]
vpts.GetPoint(i, intersection)
pts.append(intersection)
print(pts)
#from vedo import *
#ccs = [Circle().z(i/3).rotate_x(i).triangulate() for i in range(10)]
#merge(ccs).write("circles.vtk")
Only the first hit is detected:
[[ 0.21073002 -0.15808912 3.01235652]]