Skip to content

Commit c8561ef

Browse files
authored
issue#262 error in bounding box computation (#239)
Update compute BoundaryBox with addOptimal with third parameter useTriangulation==false
1 parent 5cc071c commit c8561ef

4 files changed

Lines changed: 97 additions & 46 deletions

File tree

src/Core/Geom/OCCHelper.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,16 +1003,8 @@ void OCCHelper::
10031003
computeBoundingBox(const TopoDS_Shape& shape, gp_Pnt& pmin, gp_Pnt& pmax)
10041004
{
10051005
Bnd_Box box;
1006-
BRepCheck_Analyzer analyzer(shape);
1007-
if (analyzer.IsValid()) {
1008-
BRepBndLib::AddClose(shape, box);
1009-
} else {
1010-
BRepBndLib::AddOptimal(shape, box);
1011-
}
1012-
1013-
if (box.IsVoid())
1014-
BRepBndLib::Add(shape, box);
10151006

1007+
BRepBndLib::AddOptimal(shape, box, false);
10161008
double xmin, ymin, zmin, xmax, ymax, zmax;
10171009
box.Get(xmin, ymin, zmin, xmax, ymax, zmax);
10181010
pmin.SetCoord(xmin, ymin, zmin);

test_link/test_bounding_box.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import math
2+
import os
3+
import pyMagix3D as Mgx3D
4+
import pytest
5+
6+
step_file_name = "mambo/Basic/B18.step"
7+
tol = 1e-7
8+
9+
def assertPoint(tm, name, x, y, z):
10+
p = tm.getCoord(name)
11+
assert math.isclose(p.getX(), x, rel_tol=tol)
12+
assert math.isclose(p.getY(), y, rel_tol=tol)
13+
assert math.isclose(p.getZ(), z, rel_tol=tol)
14+
15+
# Issue 225 : Le bloc créé par boite englobante d'un volume peut avoir de mauvaises dimensions
16+
def test_issue225(capfd):
17+
ctx = Mgx3D.getStdContext()
18+
ctx.clearSession() # Clean the session after the previous test
19+
gm = ctx.getGeomManager()
20+
tm = ctx.getTopoManager ()
21+
22+
magix3d_test_data_dir = os.environ['MAGIX3D_TEST_DATA_DIR']
23+
full_path = os.path.join(magix3d_test_data_dir, step_file_name)
24+
25+
ctx.setLengthUnit(Mgx3D.Unit.centimeter)
26+
gm.importSTEP(full_path)
27+
assert gm.getNbVolumes()==1
28+
tm.newFreeTopoOnGeometry("Vol0000")
29+
assert math.isclose(tm.getEdgeLength("Ar0002"), 0.1, abs_tol=tol) #0.1
30+
assert math.isclose(tm.getEdgeLength("Ar0007"), 0.1, abs_tol=1e-4) #0.10003610119179525
31+
assert math.isclose(tm.getEdgeLength("Ar0009"), 0.05, abs_tol=tol) #0.05000000000000623
32+
33+
# Issue 262 : Le bloc créé par boite englobante d'un volume peut avoir de mauvaises dimensions
34+
# la création d'un bloc sur une sphère crée un bloc plat
35+
def test_issue262():
36+
ctx = Mgx3D.getStdContext()
37+
ctx.clearSession() # Clean the session after the previous test
38+
gm = ctx.getGeomManager()
39+
tm = ctx.getTopoManager()
40+
# Création du volume Vol0000
41+
gm.newSphere (Mgx3D.Point(0, 0, 0), 1, Mgx3D.Portion.ENTIER)
42+
# Création d'un bloc topologique structuré sans projection (Vol0000)
43+
tm.newFreeTopoOnGeometry ("Vol0000")
44+
45+
assertPoint(tm, "Som0000", -1, -1, -1)
46+
assertPoint(tm, "Som0007", 1, 1, 1)
47+
48+
# Annulation de : Création d'un bloc topologique structuré sans projection (Vol0000)
49+
ctx.undo()
50+
# Création d'un bloc unitaire mis dans le groupe AAA
51+
ctx.getTopoManager().newFreeBoundedTopoInGroup ("AAA", 3, ["Vol0000"])
52+
53+
assertPoint(tm, "Som0000", -1, -1, -1)
54+
assertPoint(tm, "Som0007", 1, 1, 1)
55+
56+
def test_freeboundedtopoForPoints():
57+
ctx = Mgx3D.getStdContext()
58+
ctx.clearSession() # Clean the session after the previous test
59+
gm = ctx.getGeomManager ()
60+
tm = ctx.getTopoManager ()
61+
62+
gm.newVertex(Mgx3D.Point(-1.8, -.7, 1.2))
63+
gm.newVertex(Mgx3D.Point(-.7, .45, -.1))
64+
tm.newFreeBoundedTopoInGroup ("aaa", 3, ["Pt0000","Pt0001"])
65+
assertPoint(tm, "Som0007", -0.7, 0.45, 1.2)
66+
67+
def test_freeboundedtopoForSphere():
68+
ctx = Mgx3D.getStdContext()
69+
ctx.clearSession() # Clean the session after the previous test
70+
gm = ctx.getGeomManager ()
71+
tm = ctx.getTopoManager ()
72+
73+
gm.newSphere (Mgx3D.Point(0, 0, 0), 1, 150)
74+
tm.newFreeTopoOnGeometry ("Vol0000")
75+
assertPoint(tm, "Som0007", 1.0, 1.0, 1.0)
76+
77+
def test_freeboundedtopoForCylinder():
78+
ctx = Mgx3D.getStdContext()
79+
ctx.clearSession() # Clean the session after the previous test
80+
gm = ctx.getGeomManager ()
81+
tm = ctx.getTopoManager ()
82+
83+
gm.newCylinder (Mgx3D.Point(0, 0, 0), 1, Mgx3D.Vector(10, 0, 0), 360)
84+
tm.newFreeTopoOnGeometry ("Vol0000")
85+
assertPoint(tm, "Som0007", 10, 1.0, 1.0)
86+
87+
def test_bounding_box_with_scale():
88+
ctx = Mgx3D.getStdContext()
89+
ctx.clearSession() # Clean the session after the previous test
90+
gm = ctx.getGeomManager ()
91+
tm = ctx.getTopoManager ()
92+
93+
gm.newSphere (Mgx3D.Point(0, 0, 0), 1, 125)
94+
gm.scaleAll(10, 20, 10)
95+
tm.newFreeTopoOnGeometry ("Vol0000")
96+
assertPoint(tm, "Som0007", 10.0, 20.0, 10.0)

test_link/test_free_bounded_topo.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

test_link/test_issue225.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)