Skip to content

Commit ed0fa28

Browse files
committed
Update compute BoundaryBox with addOptimal
1 parent a3bd2ef commit ed0fa28

6 files changed

Lines changed: 98 additions & 96 deletions

File tree

src/Core/Geom/OCCHelper.cpp

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,38 +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);
10071006

1008-
if (analyzer.IsValid()) {
1009-
BRepBndLib::AddClose(shape, box);
1010-
} else {
1011-
BRepBndLib::AddOptimal(shape, box);
1012-
}
1013-
1014-
if (box.IsVoid())
1015-
{
1016-
BRepBndLib::Add(shape, box);
1017-
}
1018-
1019-
TopAbs_ShapeEnum type = shape.ShapeType();
1020-
if (type != TopAbs_FACE && type != TopAbs_EDGE && type != TopAbs_VERTEX)
1021-
{
1022-
// On teste si la box est plane
1023-
// Récupérer les coins min et max
1024-
gp_Pnt minCorner = box.CornerMin();
1025-
gp_Pnt maxCorner = box.CornerMax();
1026-
1027-
// Calculer les dimensions
1028-
double width = maxCorner.X() - minCorner.X();
1029-
double height = maxCorner.Y() - minCorner.Y();
1030-
double depth = maxCorner.Z() - minCorner.Z();
1031-
1032-
// Vérifier si l'une des dimensions est nulle ou quasi-nulle
1033-
double tolerance = 1e-7;
1034-
if (width < tolerance || height < tolerance || depth < tolerance) {
1035-
BRepBndLib::Add(shape, box);
1036-
}
1037-
}
1007+
BRepBndLib::AddOptimal(shape, box);
10381008
double xmin, ymin, zmin, xmax, ymax, zmax;
10391009
box.Get(xmin, ymin, zmin, xmax, ymax, zmax);
10401010
pmin.SetCoord(xmin, ymin, zmin);

test_link/test_bounding_box.py

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

test_link/test_issue262.py

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

test_link/test_order_join_curves.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import pyMagix3D as Mgx3D
22

3+
# Issue 228 : L'ordre des entités créées par la commande sectionByPlane peut varier d'une exécution à l'autre
4+
# Corrigé par le nouveau calcul de boite englobante
35
def test_order_join_curves():
46
ctx = Mgx3D.getStdContext()
57
ctx.clearSession() # Clean the session after the previous test

0 commit comments

Comments
 (0)