occ.get_entities_in_bounding_box very imprecise
I create 2d surfaces from lists of points using the OpenCascade kernel. I try to extract parts of the geometry using occ.get_entities_in_bounding_box
but have trouble with limited accuracy. For surfaces I directly added (e.g. using occ.add_rectangle
) there is no such problem.
The issue seems to be related to the size of the bounding box of the entities, which is far too big for the first case. Here is a mwe:
import gmsh
occ = gmsh.model.occ
gmsh.initialize()
points = [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]]
pts = [occ.addPoint(x[0], x[1], x[2]) for x in points]
pts.append(pts[0]) # for closed loop
lines = []
for i in range(len(pts) - 1):
lines.append(occ.addLine(pts[i], pts[i+1]))
surf = occ.addSurfaceFilling(occ.addCurveLoop(lines))
print(occ.get_bounding_box(2, surf)) # output: (-0.6000001000000232, -0.6000000999999665, -1e-07, 1.6000000999999429, 1.600000100000033, 1e-07)
eps=1e-6
print(occ.get_entities_in_bounding_box(0-eps, 0-eps, 0-eps, 1+eps, 1+eps, 0+eps, dim=2)) # output: []
surf2 = occ.addRectangle(0, 0, 0, 1, 1)
print(occ.get_bounding_box(2, surf2)) # output: (-1e-07, -1e-07, -1e-07, 1.0000001, 1.0000001, 1e-07)
print(occ.get_entities_in_bounding_box(0-eps, 0-eps, 0-eps, 1+eps, 1+eps, 0+eps, dim=2)) # output: [(2, 2)]
# occ.synchronize()
# gmsh.fltk.run()
gmsh.finalize()
I'm using gmsh v.4.8.4 on Windows 10, Python 3.9.1.