Actually the code is distributed in my app and I use vedo, a wrapper python lib that simplifies interactions with VTK. For more advanced stuff I directly use VTK python. I’ll turn that example into a test and integrate that in my lib.
On similar hardware (8-core, 32GB RAM), this yields a segfault only on Ubuntu. You might want to pip install vedo
.
import vtk
import vedo
import os
# Download the mous brain boundary mesh prior to testing this
# https://github.com/int-brain-lab/iblviewer/blob/main/data/surfaces/997.ply
# This mesh has around 150K polygons
test_rays = [[[-13496.7, 8629.8, -14009.0], [27944.8, -1090.3, 17709.4]],
[[-2435.4, -9487.5, -15286.4], [18739.5, 15562.2, 26610.1]],
[[-16653.4, -3609.6, -5646.1], [30438.2, 11050.2, 13714.2]]]
print('Loading mesh')
# Change this path to wherever you put the mesh file
file_path = './data/surfaces/997.ply'
plot = vedo.Plotter()
if not os.path.exists(file_path):
print('Mesh file path is invalid:', file_path)
exit()
actor = vedo.load(file_path)
print('Now intersecting', len(test_rays), 'rays with it...')
line_locator = vtk.vtkOBBTree()
# polydata is the loaded surface mesh
line_locator.SetDataSet(actor.polydata())
line_locator.BuildLocator()
for ray_id in range(len(test_rays)):
source = test_rays[ray_id][0]
destination = test_rays[ray_id][1]
intersections = vtk.vtkPoints()
line_locator.IntersectWithLine(source, destination, intersections, None)
# Segfault here on Ubuntu
print('Ray', ray_id, 'yields', intersections.GetNumberOfPoints(), 'hits')
# Should print for each ray: "...yields 2 hits"
print('Done')