# BooleanRegion with .stl files does not work

Im trying to use BooleanRegion[] on an .stl file. The imported .stl file is called pores and is of type MeshRegion (MeshRegionQ[] and RegionQ[] give both True).

Here is also a snippet of ?pores: pores = MeshRegion[{{6141.84, 3115.36,9443.80},...,{5617.29,3599.17,8546.06}}, {Polygon[{{1,2,3}, ..., {5253,6518,2148}}]}]

pores represent pores of a material, that was scanned. What I'm trying to do is subtracting these pores from a box=BoundingRegion[pores], which yields the rest of the material. When I try doing this with

BooleanRegion[#1 && ! #2 &, {box, pores}]


it gives me the input back unevaluated. Same happens when I try using RegionDifferece[]. I tested all possible combinations. However what is working as expected is

BooleanRegion[#1 ∨ #2 &, {box, pores}]


There is also an example in the Help of BooleanRegion[] and RegionDifference[] especially for MeshRegions, that exactly fits my case and works fine as long as is dont plug in the .stl Data (pores). Therefore i had a look at the Data itself and figured out that the MeshRegion of the pores uses polygons and RegionBound[] uses Tetrahedrons. So I thought there might be a problem, because the pores are represented by surfaces. Thus I tested the following with 1 pore only

pore=Delaunay[MeshCoordinates[pore]]
BooleanRegion[#1 && ! #2 &, {box, pore}]


The Delaunay[MeshCoordinates[pore]] gives you tetrahedron elements as well, but the results are not evaluated as before.

It seems that im not the only one encountered that problem: Is BooleanRegion limited to only the most trivial cases? Here a similar problem occured, but the author was able to use BooleanRegion for non-discretized regions and discretize everything afterwards. As far as i know i cant make a undiscretized region out of a MeshRegion, can I? Is there a way to make BooleanRegion[] work?

• Hi N.Schl and welcome! Thanks for taking the tour . It will help us to help you if you write an excellent question. Edit if improvable. In this case it would help to have a minimal working example of code and data for us to run. As you receive give back, vote and answer questions, keep the site useful, be kind, correct mistakes and share what you have learned. – rhermans Jul 7 '18 at 9:43

I can provide this alternate workflow. Let's suppose your imported mesh is R below.

R = DiscretizeRegion@Sphere[];


Now we create a bounding box B and create a BoundaryMeshRegion S containing the boundary of the pore(s) and of the box.

B = BoundaryDiscretizeRegion[Cuboid[#1 1.1, #2 1.1] & @@ BoundingRegion[R]];
S = BoundaryMeshRegion[
Join[MeshCoordinates[B], MeshCoordinates[R]],
Polygon[Join[
Join @@ MeshCells[B, 2, "Multicells" -> True][[All, 1]],
Join @@ MeshCells[R, 2, "Multicells" -> True][[All, 1]] + MeshCellCount[B, 0]
]
],
PlotTheme -> "Wireframe"
]


In order to obtain a tet mesh, you can discretize S.

 DiscretizeRegion[S, PlotTheme -> "Wireframe"]


• Thanks for that idea. I have tried it. It works if there is only 1 pore. If i do it with more than 1 pore though i get a solid without holes. Furthermore one of the pores is exactly on the boundary, so i get the following error: BoundaryMeshRegion::binsect: The boundary curves self-intersect or cross each other in BoundaryMeshRegion – N.Schl Jul 7 '18 at 17:02
• Try the newly edited version. It adds 10 percent of spacing to the bounding region. – Henrik Schumacher Jul 7 '18 at 17:34
• i already did something similar for testing. The thing is i cant enlarge the region, because i want to use this as specimen (RVE=representative volume element) for a finite element simulation. If i have extra space between the pores and the boundaries to make BoundaryMeshRegion[] work, it might change the response in the simulation. – N.Schl Jul 7 '18 at 17:50
• I would rather bother about pores touching the boundary box in FEM as this would lead to obtuse tets. – Henrik Schumacher Jul 7 '18 at 18:30
• As long as proper boundary conditions are given why should that be a problem? – N.Schl Jul 7 '18 at 19:02