Testing if a face is completely enclosed by a solid

What is the best way to do this? I am using BRepAlgo_Section with the faces of the solid (if there are section edges then it's not completely enclosed) and BRepAlgo_Cut (remove the solid from the face and check for empty result) but I have cases where neither of these works correctly. Any suggestions would be very much appreciated... Thanks...

Forum supervisor's picture

Dear Wayne,
We would be pleased to get data (shapes) of all not working cases.
These data will be used only for analysis purpose.

wayne606's picture

What is the best way to send the shape data? I am loading some of it from a STEP file and could send you a subset, together with a test program.

Are those routines the ones I should be using in general? Both section and cut compute a lot of data that may not be necessary for a simple yes or no query.


Forum supervisor's picture

You can attach to your post shapes (may be in stp format) which were used as input parameters in Section and Cut algorithms and gave incorrect result (from your point of view).

AP's picture

If OpenCascade Doesnt already have this function.

in topology:

if yo have a boundary and a point and you need to know if the point is inside or outside the boundary, you draw a line starting from the point out into any direction such that the line begins from the point, if you intersect that line with the boundary and you count the number of intersections, if the count is odd the point is inside, if the count is even the point is outside.

think of a circle and a point located outside, if a line starting from that outside point intersects the circle, it will always intersect the circle twice unless the curve is exactly tangent to the circle, but if the point is inside it will only intersect once.

try it on paper, no matter how wiggly or laberinth like your boundary is, the test always works.
and the neet thing is that it also applies to surfaces, so if your inside or outside a surface.

the Pseudo code would be something like:

get the bounding box of the solid
get the bounding box of your surface and check if it is inside the bounding box of the solid, this way you limit the search space.

if this test is not satisfied than you stop, if else continue

then get the wire of the surface face, which should be the boundary of the surface, for as many edges do a point abscissca on each edge with say count = length/tolerance amount of points per edge.

load all the points to a list as you build them

then iterate thorugh the points
for each point make a line starting from the current point facing any of the orthonormal directions(gp:DX() or gp::DY or gp::DZ()) and make it a very large number almost infinite.

intersect the line with the solid, count the number of intersections.
if the number is odd the point is inside the shape, if the number is even the point is outside the shape.

check all the points using that test, if all points satisfy the test of being inside then most likely your shape is inside.

you can setup the number of points as a tolerance.

to further optimize the code, check the curvature of each edge in the wire , if the edge is linear than you just intersect the linear edge with the solid, if there is no intersection its inside if the edge is curved then execute the point abscissa and run the point inclusion test.

this is a basic topology problem ( check the films of charles ray eames, there is one on topology, which shows in an animated form this concept of even and odd intersections defining the inclusion or exclusion of a point in a space)

Hope this helps.



wayne606's picture

Thanks Alex, I ended up doing something like this (I tested the tesselation of the face for enclosure in the solid, after some initial checks). The surface may extend outside the region even though the bounding wire does not... I could optimize it somewhat because the solid shape I was concerned with was an infinite convex prism (e.g. the region bounded by a screen selection).