Intersection of 3D mesh with polydata (return only intersecting mesh region)

Hi, I would appreciate your help with a problem related to finding object intersections. I have a vtkMesh (.vtk, a brain edema), and vtkPolyData (.vtk, diffusion MRI tractography streamlines), and I want to obtain only that part of the mesh, where the streamlines intersect it. I used the vtkBooleanOperationPolyDataFilter to get the region, but an error message kept appearing:

ERROR: In …/Common/DataModel/vtkPointLocator.cxx, line 866
vtkPointLocator (0x564069cc68a0): No points to subdivide

Generic Warning: In …/Filters/General/vtkIntersectionPolyDataFilter.cxx, line 2516
No Intersection between objects

ERROR: In …/Filters/General/vtkDistancePolyDataFilter.cxx, line 78
vtkDistancePolyDataFilter (0x56406ba04530): No points/cells to operate on

ERROR: In …/Filters/General/vtkDistancePolyDataFilter.cxx, line 78
vtkDistancePolyDataFilter (0x56406ba04530): No points/cells to operate on

As the next step, I tried running the streamlines through vtkTriangleFilter, and vtkCleanPolyData filters, but now I have the following problem:

Warning: In …/Filters/General/vtkIntersectionPolyDataFilter.cxx, line 1675
vtkIntersectionPolyDataFilter (0x56406ffffb90): No cell with correct orientation found

ERROR: In …/Common/ExecutionModel/vtkExecutive.cxx, line 782
vtkCompositeDataPipeline (0x564085a0d780): Algorithm vtkIntersectionPolyDataFilter(0x56406ffffb90) returned failure for request: vtkInformation (0x56406ca76a70)
Debug: Off
Modified Time: 5953808
Reference Count: 1
Registered Events: (none)
Request: REQUEST_DATA
FROM_OUTPUT_PORT: 0
ALGORITHM_AFTER_FORWARD: 1
FORWARD_DIRECTION: 0

ERROR: In …/Common/ExecutionModel/vtkExecutive.cxx, line 782
vtkCompositeDataPipeline (0x56406ba48770): Algorithm vtkBooleanOperationPolyDataFilter(0x56406b9fc530) returned failure for request: vtkInformation (0x56406ba47e90)
Debug: Off
Modified Time: 5953564
Reference Count: 1
Registered Events: (none)
Request: REQUEST_DATA
FROM_OUTPUT_PORT: 0
ALGORITHM_AFTER_FORWARD: 1
FORWARD_DIRECTION: 0

Does anyone know which approach should be taken here? Thanks in advance for your tips.

Please provide your polydatas first.

Boolean filters in VTK are known to have issues. They can randomly fail on valid inputs. Search on this forum for “Boolean” to learn more.

I would not even recommend to try perform Boolean operations using Roemer’s VTK classes (which seem to be more robust than the built-in VTK meshes) because meshes that you get by segmenting medical images often contains error, which confuse even the most robust algorithms.

Instead, since you get your segments from image segmentation, the most common solution is to perform all Boolean operations on the binary labelmaps (before you convert them to meshes). You can use Logical operators effect in 3D Slicer’s Segment Editor module if you want to perform this interactively, using a convenient GUI (and you can access all segmentation tools from Python scripting, console, or Jupyter notebooks, too).

Thanks a lot for your tips, Andras. Meanwhile I figured out a rather simplistic solution that maps streamlines to binary masks according to a NIfTI template, and then calculates intersection regions in NIfTI space using common diffusion MR image processing tools.