# How to test if two STL files intersect?

**URL:** https://discourse.vtk.org/t/how-to-test-if-two-stl-files-intersect/4742
**Category:** Support
**Created:** [November 27, 2020, 1:52am UTC](https://discourse.vtk.org/t/how-to-test-if-two-stl-files-intersect/4742 "2020-11-27T01:52:50Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![sally0226](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sally0226/32/2659_2.png) [@sally0226](https://discourse.vtk.org/u/sally0226)
#### Post date: [November 27, 2020, 1:52am UTC](https://discourse.vtk.org/t/how-to-test-if-two-stl-files-intersect/4742/1 "2020-11-27T01:52:50Z")

</div>

I want to get intersection between two stl files

so I use vtkBooleanOperationPolyDataFilter, but it didn’t work well.

usually cases work well, but some cases have error

this is my code

```auto
reader1 = vtk.vtkSTLReader()
reader2 = vtk.vtkSTLReader()

reader1.SetFileName("D:/backup/LG_Project/data/65_inch/stl/av1.stl")
reader2.SetFileName("D:/backup/LG_Project/data/65_inch/stl/test.stl")

mapper1 = vtk.vtkPolyDataMapper()
mapper2 = vtk.vtkPolyDataMapper()
if vtk.VTK_MAJOR_VERSION <= 5:
    mapper1.SetInput(reader1.GetOutput())
    mapper2.SetInput(reader2.GetOutput())
else:
    mapper1.SetInputConnection(reader1.GetOutputPort())
    mapper2.SetInputConnection(reader2.GetOutputPort())

actor1 = vtk.vtkActor()
actor2 = vtk.vtkActor()
actor1.SetMapper(mapper1)
actor2.SetMapper(mapper2)

vtk.vtkTriangl

booleanOperation = vtk.vtkBooleanOperationPolyDataFilter()
booleanOperation.SetOperationToIntersection()
booleanOperation.SetInputConnection(0, reader1.GetOutputPort())
booleanOperation.SetInputConnection(1, reader2.GetOutputPort())
booleanOperation.Update()
booleanOperationMapper = vtk.vtkPolyDataMapper()
booleanOperationMapper.SetInputConnection(booleanOperation.GetOutputPort())
booleanOperationMapper.ScalarVisibilityOff()
booleanOperationActor = vtk.vtkActor()
booleanOperationActor.SetMapper(booleanOperationMapper)

ren= vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
# Create a renderwindowinteractor
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

# Assign actor to the renderer
ren.AddActor(booleanOperationActor)

# Enable user interface interactor
iren.Initialize()
renWin.Render()
iren.Start()

```

and this is error massage  
even if I run code under the same conditions, it have different error massage .  
1.  
Process finished with exit code -1073741819 (0xC0000005)

1. 

Warning: In C:\VPP\standalone-build\VTK-source\Filters\General\vtkIntersectionPolyDataFilter.cxx, line 1675  
vtkIntersectionPolyDataFilter (0000018963EB6490): No cell with correct orientation found

ERROR: In C:\VPP\standalone-build\VTK-source\Common\ExecutionModel\vtkExecutive.cxx, line 784  
vtkCompositeDataPipeline (000001895E62D580): Algorithm vtkIntersectionPolyDataFilter(0000018963EB6490) returned failure for request: vtkInformation (0000018963E86E40)  
Debug: Off  
Modified Time: 5400  
Reference Count: 1  
Registered Events: (none)  
Request: REQUEST\_DATA  
ALGORITHM\_AFTER\_FORWARD: 1  
FORWARD\_DIRECTION: 0  
FROM\_OUTPUT\_PORT: 0

ERROR: In C:\VPP\standalone-build\VTK-source\Common\ExecutionModel\vtkExecutive.cxx, line 784  
vtkCompositeDataPipeline (000001895E62C160): Algorithm vtkBooleanOperationPolyDataFilter(000001895E6DBA70) returned failure for request: vtkInformation (0000018963E880B0)  
Debug: Off  
Modified Time: 5155  
Reference Count: 1  
Registered Events: (none)  
Request: REQUEST\_DATA  
ALGORITHM\_AFTER\_FORWARD: 1  
FORWARD\_DIRECTION: 0  
FROM\_OUTPUT\_PORT: 0

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [November 27, 2020, 3:03am UTC](https://discourse.vtk.org/t/how-to-test-if-two-stl-files-intersect/4742/2 "2020-11-27T03:03:27Z")

</div>

> [@sally0226](#):
>
> so I use vtkBooleanOperationPolyDataFilter, but it didn’t work well.

These filters are known to have issues. They can randomly fail on valid inputs. [Search on this forum for “Boolean” to learn more](https://discourse.vtk.org/search?q=boolean). I would suggest to try Roemer’s vtkbool package (it is reported to work better than the Boolean filters in VTK) or convert your polydata to images, perform Boolean operations on the images, and convert the results back to polydata.

---

<div class="post-metadata">

### Author: ![Ron84](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ron84/32/630_2.png) [@Ron84](https://discourse.vtk.org/u/Ron84)
#### Post date: [November 27, 2020, 5:03pm UTC](https://discourse.vtk.org/t/how-to-test-if-two-stl-files-intersect/4742/3 "2020-11-27T17:03:40Z")

</div>

Please send us your polydatas 😀

---

<div class="post-metadata">

### Author: ![sally0226](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sally0226/32/2659_2.png) [@sally0226](https://discourse.vtk.org/u/sally0226)
#### Post date: [December 1, 2020, 2:01am UTC](https://discourse.vtk.org/t/how-to-test-if-two-stl-files-intersect/4742/4 "2020-12-01T02:01:29Z")

</div>

Thanks for your opinion.  
I just found another way to find two stl files intersection.  
That is vtkCollisionDetectionFilter.  
and this filter is work very well. 🙂

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [December 1, 2020, 3:17am UTC](https://discourse.vtk.org/t/how-to-test-if-two-stl-files-intersect/4742/5 "2020-12-01T03:17:51Z")

</div>

Yes, of course, if you just need to know if the two polydata intersects or not then you should not use Boolean operations filter (which perform very heavy computations to give you the intersection result).

When you ask a question next time, give a high-level summary of your overall goal. That way there is a higher chance that we solve your actual problem (and not what you think your problem is).
