From bcd19756937566ff3087d7ce50dca3e9407263e1 Mon Sep 17 00:00:00 2001 From: aml Date: Thu, 8 Oct 2015 09:39:35 +0300 Subject: [PATCH] 0026560: BRepBndLib build too large bounding box in Z direction for planar spline edge. Poles bounding box for curve added for bezier and bspline curves. Method Poles() for Bezier curve added. Test case for issue CR26560 Function to compute subshape max tolerance has been added. Fixed bounding box expanding at Face/Face step of boolean operation. Test cases are updated to the new behavior. --- src/BOPAlgo/BOPAlgo_PaveFiller_6.cxx | 14 +++++- src/BRep/BRep_Tool.cxx | 38 ++++++++++++++ src/BRep/BRep_Tool.hxx | 8 ++- src/BndLib/BndLib_Add3dCurve.cxx | 74 +++++++++++++++++++++++++--- src/Geom/Geom_BezierCurve.cxx | 11 +++++ src/Geom/Geom_BezierCurve.hxx | 3 ++ tests/boolean/volumemaker/B7 | 2 + tests/boolean/volumemaker/B9 | 2 +- tests/boolean/volumemaker/C4 | 2 + tests/bugs/modalg_2/bug472_2 | 4 +- tests/bugs/modalg_2/bug472_3 | 3 ++ tests/bugs/modalg_4/bug697_2 | 2 +- tests/bugs/modalg_4/bug697_4 | 2 +- tests/bugs/modalg_4/bug697_7 | 2 +- tests/bugs/modalg_4/bug697_8 | 2 +- tests/bugs/moddata_2/bug23165 | 8 +-- tests/bugs/moddata_3/bug26560 | 37 ++++++++++++++ tests/de/iges_2/H9 | 2 +- 18 files changed, 194 insertions(+), 22 deletions(-) create mode 100755 tests/bugs/moddata_3/bug26560 diff --git a/src/BOPAlgo/BOPAlgo_PaveFiller_6.cxx b/src/BOPAlgo/BOPAlgo_PaveFiller_6.cxx index bf019a43fb..bab10df97b 100644 --- a/src/BOPAlgo/BOPAlgo_PaveFiller_6.cxx +++ b/src/BOPAlgo/BOPAlgo_PaveFiller_6.cxx @@ -296,13 +296,25 @@ void BOPAlgo_PaveFiller::PerformFF() aFF.Init(aNbCurves, aNbPoints); // // Curves + + // Fix bounding box expanding coefficient. + Standard_Real aBoxExpandValue = aTolR3D; + if (aNbCurves > 0) + { + // Modify geometric expanding coefficient by topology value, + // since this bounging box used in sharing (vertex or edge). + Standard_Real aMaxVertexTol = Max (BRep_Tool::MaxTolerance(aFaceFace.Face1(), TopAbs_VERTEX), + BRep_Tool::MaxTolerance(aFaceFace.Face2(), TopAbs_VERTEX)); + aBoxExpandValue += aMaxVertexTol; + } + BOPDS_VectorOfCurve& aVNC=aFF.ChangeCurves(); for (i=1; i<=aNbCurves; ++i) { Bnd_Box aBox; // const IntTools_Curve& aIC=aCvsX(i); const Handle(Geom_Curve)& aC3D= aIC.Curve(); - bValid=IntTools_Tools::CheckCurve(aC3D, aTolR3D, aBox); + bValid=IntTools_Tools::CheckCurve(aC3D, aBoxExpandValue, aBox); if (bValid) { BOPDS_Curve& aNC=aVNC.Append1(); aNC.SetCurve(aIC); diff --git a/src/BRep/BRep_Tool.cxx b/src/BRep/BRep_Tool.cxx index 101d93f106..8b8e2f62c3 100644 --- a/src/BRep/BRep_Tool.cxx +++ b/src/BRep/BRep_Tool.cxx @@ -1538,3 +1538,41 @@ Standard_Boolean IsPlane(const Handle(Geom_Surface)& aS) return bRet; } +//======================================================================= +//function : MaxTolerance +//purpose : +//======================================================================= +Standard_Real BRep_Tool::MaxTolerance (const TopoDS_Shape& theShape, + const TopAbs_ShapeEnum theSubShape) +{ + Standard_Real aTol = 0.0; + + // Explorer Shape-Subshape. + TopExp_Explorer anExpSS(theShape, theSubShape); + if (theSubShape == TopAbs_FACE) + { + for( ; anExpSS.More() ; anExpSS.Next() ) + { + const TopoDS_Shape& aCurrentSubShape = anExpSS.Current(); + aTol = Max(aTol, Tolerance(TopoDS::Face(aCurrentSubShape))); + } + } + else if (theSubShape == TopAbs_EDGE) + { + for( ; anExpSS.More() ; anExpSS.Next() ) + { + const TopoDS_Shape& aCurrentSubShape = anExpSS.Current(); + aTol = Max(aTol, Tolerance(TopoDS::Edge(aCurrentSubShape))); + } + } + else if (theSubShape == TopAbs_VERTEX) + { + for( ; anExpSS.More() ; anExpSS.Next() ) + { + const TopoDS_Shape& aCurrentSubShape = anExpSS.Current(); + aTol = Max(aTol, Tolerance(TopoDS::Vertex(aCurrentSubShape))); + } + } + + return aTol; +} diff --git a/src/BRep/BRep_Tool.hxx b/src/BRep/BRep_Tool.hxx index 103e60bfa7..cd2a32c9ad 100644 --- a/src/BRep/BRep_Tool.hxx +++ b/src/BRep/BRep_Tool.hxx @@ -1,4 +1,4 @@ -// Created on: 1993-07-07 +;// Created on: 1993-07-07 // Created by: Remi LEQUETTE // Copyright (c) 1993-1999 Matra Datavision // Copyright (c) 1999-2014 OPEN CASCADE SAS @@ -31,6 +31,7 @@ #include #include #include +#include class TopoDS_Shape; class TopoDS_Face; @@ -237,6 +238,11 @@ public: //! Returns the parameters of the vertex on the face. Standard_EXPORT static gp_Pnt2d Parameters (const TopoDS_Vertex& V, const TopoDS_Face& F); + //! Returns the maximum tolerance of input shape subshapes. + //@param theShape - Shape to search tolerance. + //@param theSubShape - Search subshape, only Face, Edge or Vertex are supported. + Standard_EXPORT static Standard_Real MaxTolerance (const TopoDS_Shape& theShape, const TopAbs_ShapeEnum theSubShape); + }; #endif // _BRep_Tool_HeaderFile diff --git a/src/BndLib/BndLib_Add3dCurve.cxx b/src/BndLib/BndLib_Add3dCurve.cxx index 20c47af293..45e16beb3d 100644 --- a/src/BndLib/BndLib_Add3dCurve.cxx +++ b/src/BndLib/BndLib_Add3dCurve.cxx @@ -33,6 +33,70 @@ #include #include +//======================================================================= +//function : reduceSplineBox +//purpose : This method intended to reduce box in case of +// bezier and bspline curve. +//======================================================================= +static void reduceSplineBox(const Adaptor3d_Curve& theCurve, + const Bnd_Box& theOrigBox, + Bnd_Box & theReducedBox) +{ + // Guaranteed bounding box based on poles of bspline. + Bnd_Box aPolesBox; + Standard_Real aPolesXMin, aPolesYMin, aPolesZMin, + aPolesXMax, aPolesYMax, aPolesZMax; + + if (theCurve.GetType() == GeomAbs_BSplineCurve) + { + Handle(Geom_BSplineCurve) aC = theCurve.BSpline(); + const TColgp_Array1OfPnt& aPoles = aC->Poles(); + + for(Standard_Integer anIdx = aPoles.Lower(); + anIdx <= aPoles.Upper(); + ++anIdx) + { + aPolesBox.Add(aPoles.Value(anIdx)); + } + } + if (theCurve.GetType() == GeomAbs_BezierCurve) + { + Handle(Geom_BezierCurve) aC = theCurve.Bezier(); + const TColgp_Array1OfPnt& aPoles = aC->Poles(); + + for(Standard_Integer anIdx = aPoles.Lower(); + anIdx <= aPoles.Upper(); + ++anIdx) + { + aPolesBox.Add(aPoles.Value(anIdx)); + } + } + + aPolesBox.Get(aPolesXMin, aPolesYMin, aPolesZMin, + aPolesXMax, aPolesYMax, aPolesZMax); + + Standard_Real x, y, z, X, Y, Z; + theOrigBox.Get(x, y, z, X, Y, Z); + + // Left bound. + if (aPolesXMin > x) + x = aPolesXMin; + if (aPolesYMin > y) + y = aPolesYMin; + if (aPolesZMin > z) + z = aPolesZMin; + + // Right bound. + if (aPolesXMax < X) + X = aPolesXMax; + if (aPolesYMax < Y) + Y = aPolesYMax; + if (aPolesZMax < Z) + Z = aPolesZMax; + + theReducedBox.Update(x, y, z, X, Y, Z); +} + //======================================================================= //function : Add //purpose : @@ -116,17 +180,13 @@ void BndLib_Add3dCurve::Add( const Adaptor3d_Curve& C, case GeomAbs_BezierCurve: { Handle(Geom_BezierCurve) Bz = C.Bezier(); - //OCC566(apo)-> Standard_Integer N = Bz->Degree(); GeomAdaptor_Curve GACurve(Bz); Bnd_Box B1; tol = FillBox(B1,GACurve,U1,U2,N); B1.Enlarge(weakness*tol); - Standard_Real x, y, z, X, Y, Z; - B1.Get(x, y, z, X, Y, Z); - B.Update(x, y, z, X, Y, Z); + reduceSplineBox(C, B1, B); B.Enlarge(Tol); - //<-OCC566(apo) break; } case GeomAbs_BSplineCurve: @@ -168,9 +228,7 @@ void BndLib_Add3dCurve::Add( const Adaptor3d_Curve& C, if (!B1.IsVoid()) { B1.Enlarge(weakness*tol); - Standard_Real x, y, z, X, Y, Z; - B1.Get(x, y, z, X, Y, Z); - B.Update(x, y, z, X, Y, Z); + reduceSplineBox(C, B1, B); B.Enlarge(Tol); } //<-OCC566(apo) diff --git a/src/Geom/Geom_BezierCurve.cxx b/src/Geom/Geom_BezierCurve.cxx index ec94e90911..aa8f2e2d47 100644 --- a/src/Geom/Geom_BezierCurve.cxx +++ b/src/Geom/Geom_BezierCurve.cxx @@ -732,6 +732,17 @@ void Geom_BezierCurve::Poles (TColgp_Array1OfPnt& P) const P = poles->Array1(); } + +//======================================================================= +//function : Poles +//purpose : +//======================================================================= + +const TColgp_Array1OfPnt& Geom_BezierCurve::Poles() const +{ + return poles->Array1(); +} + //======================================================================= //function : Weight //purpose : diff --git a/src/Geom/Geom_BezierCurve.hxx b/src/Geom/Geom_BezierCurve.hxx index 8d405832fe..add41c0dcb 100644 --- a/src/Geom/Geom_BezierCurve.hxx +++ b/src/Geom/Geom_BezierCurve.hxx @@ -292,6 +292,9 @@ public: //! //! Raised if the length of P is not equal to the number of poles. Standard_EXPORT void Poles (TColgp_Array1OfPnt& P) const; + + //! Returns all the poles of the curve. + Standard_EXPORT const TColgp_Array1OfPnt& Poles () const; //! Returns the weight of range Index. //! Raised if Index is not in the range [1, NbPoles] diff --git a/tests/boolean/volumemaker/B7 b/tests/boolean/volumemaker/B7 index a6e9633541..4f8d70b3e4 100644 --- a/tests/boolean/volumemaker/B7 +++ b/tests/boolean/volumemaker/B7 @@ -1,7 +1,9 @@ # test script on make volume operation # plane +puts "TODO OCC26560 ALL: Faulty shapes in variables faulty_1 to faulty_" puts "TODO OCC26020 ALL: Error: bopcheck failed" +puts "TODO OCC26560 ALL: Error : The area of the resulting shape is" # planar face plane pln_f1 18.855982726712998 17.500000000800412 0 -0.96152394764524818 -0.27472112788189063 0 diff --git a/tests/boolean/volumemaker/B9 b/tests/boolean/volumemaker/B9 index 4bedb2a818..6a4df26bb2 100644 --- a/tests/boolean/volumemaker/B9 +++ b/tests/boolean/volumemaker/B9 @@ -3,7 +3,7 @@ puts "TODO OCC26020 ALL: Faulty shapes in variables faulty_1 to faulty_" puts "TODO OCC26020 ALL: Error: bopcheck failed" -puts "TODO OCC26020 Linux: Error : The area of the resulting shape is" +puts "TODO OCC26020 ALL: Error : The area of the resulting shape is" # planar face plane pln_f1 32.294537607197917 1.8096910201742288e-014 -39.176406819310692 -0.77162458338772011 -6.6613381477509373e-016 -0.63607822027776384 diff --git a/tests/boolean/volumemaker/C4 b/tests/boolean/volumemaker/C4 index 35302436f3..4d27a2fbfb 100644 --- a/tests/boolean/volumemaker/C4 +++ b/tests/boolean/volumemaker/C4 @@ -1,6 +1,8 @@ # test script on make volume operation # cylinder plane +puts "TODO OCC26737 ALL: Faulty shapes in variables faulty_1 to faulty_" + # planar face plane pln_f1 0 515 1.1102230246251565e-015 0 -1 -1.1102230246251565e-016 erase pln_f1 diff --git a/tests/bugs/modalg_2/bug472_2 b/tests/bugs/modalg_2/bug472_2 index bb40ce531a..82ea21a1fd 100755 --- a/tests/bugs/modalg_2/bug472_2 +++ b/tests/bugs/modalg_2/bug472_2 @@ -1,4 +1,4 @@ -puts "TODO OCC25917 ALL: Error : The command is not valid. The square is" +puts "TODO OCC25917 ALL: Faulty shapes in variables faulty_1 to faulty_" if { [regexp {Debug mode} [dversion]] } { puts "TODO OCC25917 ALL: TEST INCOMPLETE" puts "TODO OCC25917 ALL: Tcl Exception" @@ -21,5 +21,5 @@ checkshape b2 bcommon result b1 b2 -set square 0 +set square 0.01 set 2dviewer 0 diff --git a/tests/bugs/modalg_2/bug472_3 b/tests/bugs/modalg_2/bug472_3 index db34c1aebe..9dc5992847 100755 --- a/tests/bugs/modalg_2/bug472_3 +++ b/tests/bugs/modalg_2/bug472_3 @@ -1,3 +1,6 @@ +puts "TODO OCC25917 ALL: Faulty shapes in variables faulty_1 to faulty_" +puts "TODO OCC25917 ALL: Error : The square of result shape is" +puts "TODO OCC25917 ALL: Error : Result shape is WRONG because it must contains" if { [regexp {Debug mode} [dversion]] } { puts "TODO OCC25917 ALL: TEST INCOMPLETE" puts "TODO OCC25917 ALL: Tcl Exception" diff --git a/tests/bugs/modalg_4/bug697_2 b/tests/bugs/modalg_4/bug697_2 index a4ca44f48c..04206198eb 100755 --- a/tests/bugs/modalg_4/bug697_2 +++ b/tests/bugs/modalg_4/bug697_2 @@ -1,5 +1,5 @@ puts "TODO OCC25829 ALL: Error : The square of result shape is" -puts "TODO OCC25829 Linux: Faulty shapes in variables faulty_1 to" +puts "TODO OCC25829 ALL: Faulty shapes in variables faulty_1 to" puts "============" puts "OCC697" diff --git a/tests/bugs/modalg_4/bug697_4 b/tests/bugs/modalg_4/bug697_4 index dde93e7f1e..5621debb59 100755 --- a/tests/bugs/modalg_4/bug697_4 +++ b/tests/bugs/modalg_4/bug697_4 @@ -1,5 +1,5 @@ puts "TODO OCC25829 ALL: Error : The square of result shape is" -puts "TODO OCC25829 Linux: Faulty shapes in variables faulty_1 to" +puts "TODO OCC25829 ALL: Faulty shapes in variables faulty_1 to" puts "============" puts "OCC697" diff --git a/tests/bugs/modalg_4/bug697_7 b/tests/bugs/modalg_4/bug697_7 index ace77912a0..dc277be079 100755 --- a/tests/bugs/modalg_4/bug697_7 +++ b/tests/bugs/modalg_4/bug697_7 @@ -1,5 +1,5 @@ puts "TODO OCC25829 ALL: Error : The square of result shape is" -puts "TODO OCC25829 Linux: Faulty shapes in variables faulty_1 to" +puts "TODO OCC25829 ALL: Faulty shapes in variables faulty_1 to" puts "============" puts "OCC697" diff --git a/tests/bugs/modalg_4/bug697_8 b/tests/bugs/modalg_4/bug697_8 index 0dc0e2d536..916774c0ad 100755 --- a/tests/bugs/modalg_4/bug697_8 +++ b/tests/bugs/modalg_4/bug697_8 @@ -1,5 +1,5 @@ puts "TODO OCC25829 ALL: Error : The square of result shape is" -puts "TODO OCC25829 Linux: Faulty shapes in variables faulty_1 to" +puts "TODO OCC25829 ALL: Faulty shapes in variables faulty_1 to" puts "============" puts "OCC697" diff --git a/tests/bugs/moddata_2/bug23165 b/tests/bugs/moddata_2/bug23165 index 5b05ca9aa1..47787eb750 100755 --- a/tests/bugs/moddata_2/bug23165 +++ b/tests/bugs/moddata_2/bug23165 @@ -54,8 +54,8 @@ if {$index > -1} { set e1_good_y1 -0.010622244944394899 set e1_good_z1 -3.0106222449443973 set e1_good_x2 -17.589377755055537 - set e1_good_y2 5.7106222251726582 - set e1_good_z2 -1.6146050638816589 + set e1_good_y2 5.700038816113608 + set e1_good_z2 -1.6251884728673096 set e1_x1_percent [GetPercent ${e1_x1} ${e1_good_x1}] set e1_y1_percent [GetPercent ${e1_y1} ${e1_good_y1}] @@ -110,8 +110,8 @@ set good_x1 -17.6105835090592 set good_y1 -4.7133570660117909 set good_z1 -4.3679100133425806 set good_x2 -17.589416490940806 -set good_y2 5.7105834892874094 -set good_z2 -1.6146437997669054 +set good_y2 5.7000000802283299 +set good_z2 -1.6252272087525899 set x1_percent [GetPercent ${x1} ${good_x1}] set y1_percent [GetPercent ${y1} ${good_y1}] diff --git a/tests/bugs/moddata_3/bug26560 b/tests/bugs/moddata_3/bug26560 new file mode 100755 index 0000000000..0c40031736 --- /dev/null +++ b/tests/bugs/moddata_3/bug26560 @@ -0,0 +1,37 @@ +puts "=========" +puts "OCC26560" +puts "=========" +puts "" +##################################################################### +## BRepBndLib build too large bounding box in Z direction for planar spline edge. +##################################################################### + +restore [locate_data_file bug26560_planarspline.brep] b1 + +set rr [bounding b1] +regexp { *([-0-9.+eE]+) +([-0-9.+eE]+) +([-0-9.+eE]+) +([-0-9.+eE]+) +([-0-9.+eE]+) +([-0-9.+eE]+)} $rr full v1_x v1_y v1_z v2_x v2_y v2_z + +set tol_abs 1.0e-4 +set tol_rel 0.0001 + +set expected_v1_x -277.03883383200952 +checkreal "v1_x" ${v1_x} ${expected_v1_x} ${tol_abs} ${tol_rel} + +set expected_v1_y -562.56241861670651 +checkreal "v1_y" ${v1_y} ${expected_v1_y} ${tol_abs} ${tol_rel} + +set expected_v1_z -9.9999999999999995e-08 +checkreal "v1_z" ${v1_z} ${expected_v1_z} ${tol_abs} ${tol_rel} + +set expected_v2_x 20.000000100000001 +checkreal "v2_x" ${v2_x} ${expected_v2_x} ${tol_abs} ${tol_rel} + +set expected_v2_y -221.27317426638498 +checkreal "v2_y" ${v2_y} ${expected_v2_y} ${tol_abs} ${tol_rel} + +set expected_v2_z 9.9999999999999995e-08 +checkreal "v2_z" ${v2_z} ${expected_v2_z} ${tol_abs} ${tol_rel} + +smallview +fit +set only_screen_axo 1 diff --git a/tests/de/iges_2/H9 b/tests/de/iges_2/H9 index 8c0e68f860..69b1f6d083 100755 --- a/tests/de/iges_2/H9 +++ b/tests/de/iges_2/H9 @@ -3,7 +3,7 @@ puts "TODO CR23096 ALL: NBSHAPES : Faulty" puts "TODO CR23096 ALL: TOLERANCE : Faulty" puts "TODO CR23096 ALL: LABELS : Faulty" puts "TODO CR23096 ALL: COLORS : Faulty" -puts "TODO CR25013 ALL: Error : 3 differences with reference data found" +puts "TODO CR25013 ALL: Error : 4 differences with reference data found" set LinuxDiff 4 set LinuxFaulties {STATSHAPE}