From: vro Date: Thu, 5 Sep 2019 08:23:30 +0000 (+0300) Subject: 0030704: Modeling Data, Bnd_OBB - Oriented bounding box gives a wrong result if a... X-Git-Tag: V7_4_0_beta~16 X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=f2c862db0760390b62210744315261d344fa04c7 0030704: Modeling Data, Bnd_OBB - Oriented bounding box gives a wrong result if a box is added to a void box Added protection on a void box to methods Bnd_OBB::Add() to escape taking into account "heap trash" coordinates of a void box. --- diff --git a/src/Bnd/Bnd_OBB.cxx b/src/Bnd/Bnd_OBB.cxx index 0120cfe1de..6fd3dc700e 100644 --- a/src/Bnd/Bnd_OBB.cxx +++ b/src/Bnd/Bnd_OBB.cxx @@ -973,11 +973,24 @@ Standard_Boolean Bnd_OBB::IsCompletelyInside(const Bnd_OBB& theOther) const // ======================================================================= void Bnd_OBB::Add(const gp_Pnt& theP) { - gp_Pnt aList[9]; - GetVertex(aList); - aList[8] = theP; - - ReBuild(TColgp_Array1OfPnt(aList[0], 0, 8)); + if (IsVoid()) + { + myCenter = theP.XYZ(); + myAxes[0] = gp::DX().XYZ(); + myAxes[1] = gp::DY().XYZ(); + myAxes[2] = gp::DZ().XYZ(); + myHDims[0] = 0.0; + myHDims[1] = 0.0; + myHDims[2] = 0.0; + myIsAABox = Standard_True; + } + else + { + gp_Pnt aList[9]; + GetVertex(aList); + aList[8] = theP; + ReBuild(TColgp_Array1OfPnt(aList[0], 0, 8)); + } } // ======================================================================= @@ -986,9 +999,26 @@ void Bnd_OBB::Add(const gp_Pnt& theP) // ======================================================================= void Bnd_OBB::Add(const Bnd_OBB& theOther) { - gp_Pnt aList[16]; - GetVertex(&aList[0]); - theOther.GetVertex(&aList[8]); - ReBuild(TColgp_Array1OfPnt(aList[0], 0, 15)); + if (!theOther.IsVoid()) + { + if (IsVoid()) + { + myCenter = theOther.myCenter; + myAxes[0] = theOther.myAxes[0]; + myAxes[1] = theOther.myAxes[1]; + myAxes[2] = theOther.myAxes[2]; + myHDims[0] = theOther.myHDims[0]; + myHDims[1] = theOther.myHDims[1]; + myHDims[2] = theOther.myHDims[2]; + myIsAABox = theOther.myIsAABox; + } + else + { + gp_Pnt aList[16]; + GetVertex(&aList[0]); + theOther.GetVertex(&aList[8]); + ReBuild(TColgp_Array1OfPnt(aList[0], 0, 15)); + } + } } diff --git a/src/QABugs/QABugs_20.cxx b/src/QABugs/QABugs_20.cxx index 996c7b8e1a..b9c898e43f 100644 --- a/src/QABugs/QABugs_20.cxx +++ b/src/QABugs/QABugs_20.cxx @@ -3239,6 +3239,38 @@ static Standard_Integer OCC30869 (Draw_Interpretor& theDI, Standard_Integer theA return 0; } +#include +static Standard_Integer OCC30704(Draw_Interpretor& di, Standard_Integer, const char**) +{ + // Make a shape somewhere far from (0, 0, 0). + BRepPrimAPI_MakeBox mkBox(gp_Pnt(100, 100, 100), 100, 100, 100); + const TopoDS_Shape& box = mkBox.Shape(); + + // Add a bounding box of a shape to a void bounding box. + Bnd_OBB aVoidBox, aBox; + BRepBndLib::AddOBB(box, aBox, Standard_False, Standard_False, Standard_False); + aVoidBox.Add(aBox); + + // Print the center point of the bounding box. + const gp_XYZ& center = aVoidBox.Center(); + di << center.X() << " " << center.Y() << " " << center.Z(); + return 0; +} +static Standard_Integer OCC30704_1(Draw_Interpretor& di, Standard_Integer, const char**) +{ + // A point. + gp_Pnt aP(100, 200, 300); + + // Add the point to a void bounding box. + Bnd_OBB aVoidBox; + aVoidBox.Add(aP); + + // Print the center point of the bounding box. + const gp_XYZ& center = aVoidBox.Center(); + di << center.X() << " " << center.Y() << " " << center.Z(); + return 0; +} + void QABugs::Commands_20(Draw_Interpretor& theCommands) { const char *group = "QABugs"; @@ -3296,5 +3328,8 @@ void QABugs::Commands_20(Draw_Interpretor& theCommands) { "Usage: OCC30869 wire", __FILE__, OCC30869, group); + theCommands.Add("OCC30704", "OCC30704", __FILE__, OCC30704, group); + theCommands.Add("OCC30704_1", "OCC30704_1", __FILE__, OCC30704_1, group); + return; } diff --git a/tests/bugs/moddata_3/bug30704 b/tests/bugs/moddata_3/bug30704 new file mode 100644 index 0000000000..244018eec2 --- /dev/null +++ b/tests/bugs/moddata_3/bug30704 @@ -0,0 +1,15 @@ +puts "============" +puts "0030704: Oriented bounding box (Bnd_OBB) gives a wrong result if a box is added to a void box" +puts "============" + +pload QAcommands + +set ret1 [OCC30704] +if { ${ret1} != "150 150 150" } { + puts "Error: add bounding box to void bounding box" +} + +set ret2 [OCC30704_1] +if { ${ret2} != "100 200 300" } { + puts "Error: add point to void bounding box" +}