diff --git a/src/BOPTools/BOPTools_AlgoTools.cdl b/src/BOPTools/BOPTools_AlgoTools.cdl index 5641d6cb5d..e5e88810cd 100644 --- a/src/BOPTools/BOPTools_AlgoTools.cdl +++ b/src/BOPTools/BOPTools_AlgoTools.cdl @@ -310,12 +310,7 @@ is --- in terms of BRepCheck_InvalidPointOnCurve. --- --fields - - CorrectPoint (myclass; - thePnt:Pnt from gp; - thePL:Plane from Geom; - theNewPnt:out Pnt from gp); - + --copy from BOPTools_AlgoTools.cdl MakeNewVertex (myclass; aP1 : Pnt from gp; @@ -434,19 +429,6 @@ is --- Returns TRUE if PaveBlock lays on the face , i.e --- the is IN or ON in 2D of - - GetProjectPoint(myclass; - aF : Face from TopoDS; - aPF : Pnt from gp; - aF1 : Face from TopoDS; - aPF1 : out Pnt from gp; - aDNF1 : out Dir from gp; - theContext : out Context from BOPInt) - returns Boolean from Standard; - ---Purpose: - --- Computes projection of the point on the face . - --- Returns TRUE if projection is done. - IsMicroEdge(myclass; theEdge : Edge from TopoDS; theContext : Context from BOPInt) diff --git a/src/BOPTools/BOPTools_AlgoTools.cxx b/src/BOPTools/BOPTools_AlgoTools.cxx index 070c5ad026..6ac8976439 100644 --- a/src/BOPTools/BOPTools_AlgoTools.cxx +++ b/src/BOPTools/BOPTools_AlgoTools.cxx @@ -27,13 +27,19 @@ #include #include #include +#include +#include +#include +#include // #include #include +#include #include #include #include #include +#include // #include // @@ -53,21 +59,17 @@ // #include // +#include +#include +#include #include #include // #include #include // -#include -#include -#include -#include -#include -#include -#include -#include #include +// static Standard_Real AngleWithRef(const gp_Dir& theD1, @@ -85,7 +87,24 @@ static TopAbs_Orientation Orientation(const TopoDS_Edge& anE, const TopoDS_Face& aF); - +static + void GetFaceDir(const TopoDS_Edge& aE, + const TopoDS_Face& aF, + const gp_Pnt& aP, + const Standard_Real aT, + const gp_Dir& aDTgt, + gp_Dir& aDN, + gp_Dir& aDB, + Handle(BOPInt_Context)& theContext); +static + Standard_Boolean FindPointInFace(const TopoDS_Edge& aE, + const TopoDS_Face& aF, + const gp_Pnt& aP, + const Standard_Real aT, + gp_Dir& aDB, + gp_Pnt& aPOut, + Handle(BOPInt_Context)& theContext, + const GeomAdaptor_Surface& aGAS); //======================================================================= // function: MakeConnexityBlocks @@ -731,31 +750,24 @@ static { Standard_Real aT, aT1, aT2, aAngle, aTwoPI, aAngleMin; gp_Pnt aPn1, aPn2, aPx; + gp_Dir aDN1, aDN2, aDBF, aDBF2, aDTF; gp_Vec aVTgt; - gp_Dir aDN1, aDN2; + TopAbs_Orientation aOr; Handle(Geom_Curve)aC3D; BOPTools_ListIteratorOfListOfCoupleOfShape aIt; // aAngleMin=100.; aTwoPI=M_PI+M_PI; aC3D =BRep_Tool::Curve(theE1, aT1, aT2); - //BRep_Tool::Range(theE1, aT1, aT2); aT=BOPTools_AlgoTools2D::IntermediatePoint(aT1, aT2); aC3D->D0(aT, aPx); - // Ref - BOPTools_AlgoTools2D::EdgeTangent(theE1, aT, aVTgt); - gp_Dir aDTtgt(aVTgt); - aDTtgt.Reverse(); - Handle(Geom_Plane) aPL; - aPL = new Geom_Plane(aPx, aDTtgt); - // N1 - BOPTools_AlgoTools3D::GetApproxNormalToFaceOnEdge(theE1, theF1, aT, aPn1, aDN1, theContext); // - gp_Pnt aPFx, aPF2x; - CorrectPoint(aPn1, aPL, aPFx); - gp_Vec aVBF (aPx, aPFx ); - gp_Dir aDTF; - gp_Dir aDBF (aVBF); + BOPTools_AlgoTools2D::EdgeTangent(theE1, aT, aVTgt); + gp_Dir aDTgt(aVTgt), aDTgt2; + aOr = theE1.Orientation(); + // + GetFaceDir(theE1, theF1, aPx, aT, aDTgt, aDN1, aDBF, theContext); + // aDTF=aDN1^aDBF; // aIt.Initialize(theLCSOff); @@ -764,28 +776,24 @@ static const TopoDS_Edge& aE2=(*(TopoDS_Edge*)(&aCS.Shape1())); const TopoDS_Face& aF2=(*(TopoDS_Face*)(&aCS.Shape2())); // - /*if (aF2==theF1) { - aAngle=M_PI; - } - else if (aF2.IsSame(theF1)) { - aAngle=aTwoPI; - } - else {*/ - if (!theE1.IsEqual(aE2) || - !GetProjectPoint(theF1, aPn1, aF2, aPn2, aDN2, theContext)) { - BOPTools_AlgoTools3D::GetApproxNormalToFaceOnEdge (aE2, aF2, aT, aPn2, aDN2, theContext); - } - CorrectPoint(aPn2, aPL, aPF2x); - gp_Vec aVBF2(aPx, aPF2x); - gp_Dir aDBF2(aVBF2); + aDTgt2 = (aE2.Orientation()==aOr) ? aDTgt : aDTgt.Reversed(); + GetFaceDir(aE2, aF2, aPx, aT, aDTgt2, aDN2, aDBF2, theContext); //Angle aAngle=AngleWithRef(aDBF, aDBF2, aDTF); // if(aAngle<0.) { aAngle=aTwoPI+aAngle; } - //} - + // + if (aAngleAxis().IsParallel(aCS1->Axis(), Precision::Angular())) { - return bRet; - } - // - aR = aCS->Radius(); - aR1 = aCS1->Radius(); - dR = fabs(aR - aR1); - // - if (dR < Precision::Angular()) { - return bRet; - } - - gp_Lin aL(aCS->Axis()), aL1(aCS1->Axis()); - if (Abs(aL.Distance(aL1) - dR) < Precision::Confusion()) { - GeomAPI_ProjectPointOnSurf& aProjector=aContext->ProjPS(aF1); - aProjector.Perform(aPF); - if (!aProjector.IsDone()) { - return bRet; - } - aDMin = aProjector.LowerDistance(); - if (aDMin > dR) { - return bRet; - } - aProjector.LowerDistanceParameters(aU, aV); - Handle(Geom_Surface) aS = BRep_Tool::Surface(aF1); - BOPTools_AlgoTools3D::GetNormalToSurface (aS, aU, aV, aDNF1); - aS->D0(aU, aV, aPF1); - bRet = !bRet; - } - return bRet; -} - //======================================================================= //function : IsMicroEdge //purpose : @@ -1812,77 +1737,120 @@ Standard_Real fsqrt(Standard_Real val) return bRet; } -/* //======================================================================= -//function : AreFacesSameDomain -//purpose : +//function : GetFaceDir +//purpose : Get binormal direction for the face in the point aP //======================================================================= - Standard_Boolean BOPTools_AlgoTools::AreFacesSameDomain(const TopoDS_Face& theF1, - const TopoDS_Face& theF2, - Handle(BOPInt_Context)& theContext) - { - Standard_Boolean bFlag; - - Standard_Integer aNbE1, aNbE2; - Standard_Real aTolF1, aTolF2, aTol; - gp_Pnt2d aP2D; - gp_Pnt aP; - TopoDS_Face aF1, aF2; - TopExp_Explorer aExp; - BOPCol_MapOfShape aME1, aME2; - BOPCol_MapIteratorOfMapOfShape aIt; + void GetFaceDir(const TopoDS_Edge& aE, + const TopoDS_Face& aF, + const gp_Pnt& aP, + const Standard_Real aT, + const gp_Dir& aDTgt, + gp_Dir& aDN, + gp_Dir& aDB, + Handle(BOPInt_Context)& theContext) +{ + BOPTools_AlgoTools3D::GetNormalToFaceOnEdge(aE, aF, aT, aDN); + if (aF.Orientation()==TopAbs_REVERSED){ + aDN.Reverse(); + } + aDB = aDN^aDTgt; // - bFlag=Standard_False; - // - aF1=theF1; - aF1.Orientation(TopAbs_FORWARD); - aF2=theF2; - aF2.Orientation(TopAbs_FORWARD); - // - // 1 - aExp.Init(aF1, TopAbs_EDGE); - for (; aExp.More(); aExp.Next()) { - const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&aExp.Current())); - if (!BRep_Tool::Degenerated(aE)) { - aME1.Add(aE); + Handle(Geom_Surface) aS = BRep_Tool::Surface(aF); + GeomAdaptor_Surface aGAS(aS); + if (aGAS.GetType()!=GeomAbs_Plane) { + gp_Pnt aPx; + if (!FindPointInFace(aE, aF, aP, aT, aDB, aPx, theContext, aGAS)) { + gp_Pnt2d aPx2D; + Handle(Geom_Plane) aPL; + GeomAPI_ProjectPointOnSurf aProj; + // + BOPTools_AlgoTools3D::PointNearEdge(aE, aF, aT, aPx2D, aPx, theContext); + aPL = new Geom_Plane(aP, aDTgt); + aProj.Init(aPx, aPL); + aPx = aProj.NearestPoint(); + gp_Vec aVec(aP, aPx); + aDB.SetXYZ(aVec.XYZ()); } } - // - aExp.Init(aF2, TopAbs_EDGE); - for (; aExp.More(); aExp.Next()) { - const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&aExp.Current())); - if (!BRep_Tool::Degenerated(aE)) { - if (!aME1.Contains(aE)) { - return bFlag; - } - aME2.Add(aE); - } - } - // - aNbE1=aME1.Extent(); - aNbE2=aME2.Extent(); - // - if(!aNbE1 || !aNbE2){ - return bFlag; - } - // - if(aNbE1!=aNbE2) { - return bFlag; - } - // - // 2 - aTolF1=BRep_Tool::Tolerance(aF1); - aTolF2=BRep_Tool::Tolerance(aF2); - aTol=aTolF1+aTolF2; - // - aIt.Initialize(aME1); - for (; aIt.More(); aIt.Next()) { - const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&aIt.Key())); - BOPTools_AlgoTools3D::PointNearEdge(aE, aF1, aP2D, aP); - bFlag=theContext->IsValidPointForFace(aP, aF2, aTol); - break; - } - // - return bFlag; } -*/ + +//======================================================================= +//function : FindPointInFace +//purpose : Find a point in the face in direction of +//======================================================================= + Standard_Boolean FindPointInFace(const TopoDS_Edge& aE, + const TopoDS_Face& aF, + const gp_Pnt& aP, + const Standard_Real aT, + gp_Dir& aDB, + gp_Pnt& aPOut, + Handle(BOPInt_Context)& theContext, + const GeomAdaptor_Surface& aGAS) +{ + Standard_Integer aNbItMax; + Standard_Real aDt, aDtMin, aTolE, aTolF, aDist; + Standard_Boolean bRet; + gp_Pnt aP1; + // + bRet = Standard_False; + aTolE = BRep_Tool::Tolerance(aE); + aTolF = BRep_Tool::Tolerance(aF); + aDt = 2*(aTolE+aTolF); + // + aDtMin=5.e-4; + if (aDt < aDtMin) { + Standard_Real aR; + GeomAbs_SurfaceType aSType=aGAS.GetType(); + switch (aSType) { + case GeomAbs_Cylinder: + aR = aGAS.Cylinder().Radius(); + break; + case GeomAbs_Cone: + aR = aGAS.Cone().RefRadius(); + break; + case GeomAbs_Sphere: + aR = aGAS.Sphere().Radius(); + break; + case GeomAbs_Torus: + aR = aGAS.Torus().MinorRadius(); + break; + case GeomAbs_SurfaceOfRevolution: + aR=1.; + break; + default: + aR=0.001; + } + if (aR < 0.01) { + aDtMin=5.e-6; + } + else if (aR > 100.) { + aDtMin*=10; + } + if (aDt < aDtMin) { + aDt=aDtMin; + } + } + // + GeomAPI_ProjectPointOnSurf& aProj=theContext->ProjPS(aF); + aNbItMax = 15; + // + do { + aP1.SetCoord(aP.X()+aDt*aDB.X(), + aP.Y()+aDt*aDB.Y(), + aP.Z()+aDt*aDB.Z()); + // + aProj.Perform(aP1); + if (!aProj.IsDone()) { + return bRet; + } + aPOut = aProj.NearestPoint(); + aDist = aProj.LowerDistance(); + // + gp_Vec aV(aP, aPOut); + aDB.SetXYZ(aV.XYZ()); + } while (aDist>Precision::Angular() && --aNbItMax); + // + bRet = aDist < Precision::Angular(); + return bRet; +} diff --git a/src/BOPTools/BOPTools_AlgoTools_2.cxx b/src/BOPTools/BOPTools_AlgoTools_2.cxx index 29cf9b16e4..db27bb58d0 100644 --- a/src/BOPTools/BOPTools_AlgoTools_2.cxx +++ b/src/BOPTools/BOPTools_AlgoTools_2.cxx @@ -19,6 +19,8 @@ #include +#include + #include #include #include diff --git a/tests/boolean/bopcommon_complex/J1 b/tests/boolean/bopcommon_complex/J1 index 7c455c3608..fe368bff81 100644 --- a/tests/boolean/bopcommon_complex/J1 +++ b/tests/boolean/bopcommon_complex/J1 @@ -4,4 +4,4 @@ restore [locate_data_file b148] b bop a b bopcommon result -set square empty +set square 0.000550102 diff --git a/tests/bugs/modalg_2/bug20285_10 b/tests/bugs/modalg_2/bug20285_10 index e8baf098f8..3fb5ca9901 100755 --- a/tests/bugs/modalg_2/bug20285_10 +++ b/tests/bugs/modalg_2/bug20285_10 @@ -1,5 +1,3 @@ -puts "TODO OCC11111 ALL: Error : Result shape is WRONG" - puts "============" puts "OCC20285" puts "============" @@ -25,17 +23,17 @@ puts "Start boolean operation ..." boptuc result puts "Finish boolean operation ..." -set square 37856.9 +set square 37981.1 -set nb_v_good 15 -set nb_e_good 22 +set nb_v_good 13 +set nb_e_good 20 set nb_w_good 9 set nb_f_good 9 set nb_sh_good 1 set nb_sol_good 1 set nb_compsol_good 0 set nb_compound_good 1 -set nb_shape_good 58 +set nb_shape_good 54 set 2dviewer 0 diff --git a/tests/bugs/modalg_2/bug20285_6 b/tests/bugs/modalg_2/bug20285_6 index 4c0c5e31dd..7ae36c8e39 100755 --- a/tests/bugs/modalg_2/bug20285_6 +++ b/tests/bugs/modalg_2/bug20285_6 @@ -1,6 +1,3 @@ -puts "TODO OCC11111 ALL: Error : The length of result shape is" -puts "TODO OCC11111 ALL: Error : Result shape is WRONG" - puts "============" puts "OCC20285" puts "============" @@ -26,17 +23,17 @@ puts "Start boolean operation ..." bopsection result puts "Finish boolean operation ..." -set length 750.952 +set length 479.562 -set nb_v_good 8 -set nb_e_good 7 +set nb_v_good 5 +set nb_e_good 5 set nb_w_good 0 set nb_f_good 0 set nb_sh_good 0 set nb_sol_good 0 set nb_compsol_good 0 set nb_compound_good 1 -set nb_shape_good 16 +set nb_shape_good 11 set 2dviewer 0 diff --git a/tests/bugs/modalg_2/bug20285_7 b/tests/bugs/modalg_2/bug20285_7 index 7b383b071a..8073b020b1 100755 --- a/tests/bugs/modalg_2/bug20285_7 +++ b/tests/bugs/modalg_2/bug20285_7 @@ -1,6 +1,3 @@ -puts "TODO OCC11111 ALL: Error : The square of result shape is" -puts "TODO OCC11111 ALL: Error : Result shape is WRONG" - puts "============" puts "OCC20285" puts "============" @@ -26,17 +23,17 @@ puts "Start boolean operation ..." bopcommon result puts "Finish boolean operation ..." -set square 17577 +set square 14969 -set nb_v_good 8 -set nb_e_good 12 -set nb_w_good 6 -set nb_f_good 6 +set nb_v_good 6 +set nb_e_good 9 +set nb_w_good 5 +set nb_f_good 5 set nb_sh_good 1 set nb_sol_good 1 set nb_compsol_good 0 set nb_compound_good 1 -set nb_shape_good 35 +set nb_shape_good 28 set 2dviewer 0 diff --git a/tests/bugs/modalg_2/bug20285_8 b/tests/bugs/modalg_2/bug20285_8 index 36825b68ce..ca6c01ac27 100755 --- a/tests/bugs/modalg_2/bug20285_8 +++ b/tests/bugs/modalg_2/bug20285_8 @@ -1,6 +1,3 @@ -puts "TODO OCC11111 ALL: Error : The square of result shape is" -puts "TODO OCC11111 ALL: Error : Result shape is WRONG" - puts "============" puts "OCC20285" puts "============" @@ -26,17 +23,17 @@ puts "Start boolean operation ..." bopfuse result puts "Finish boolean operation ..." -set square 113140 +set square 389776 -set nb_v_good 18 -set nb_e_good 28 -set nb_w_good 11 -set nb_f_good 11 +set nb_v_good 47 +set nb_e_good 71 +set nb_w_good 26 +set nb_f_good 26 set nb_sh_good 1 set nb_sol_good 1 set nb_compsol_good 0 set nb_compound_good 1 -set nb_shape_good 71 +set nb_shape_good 173 set 2dviewer 0 diff --git a/tests/bugs/modalg_2/bug20285_9 b/tests/bugs/modalg_2/bug20285_9 index 6c71942dc1..46750992cc 100755 --- a/tests/bugs/modalg_2/bug20285_9 +++ b/tests/bugs/modalg_2/bug20285_9 @@ -1,6 +1,3 @@ -puts "TODO OCC11111 ALL: Error : The square of result shape is" -puts "TODO OCC11111 ALL: Error : Result shape is WRONG" - puts "============" puts "OCC20285" puts "============" @@ -26,17 +23,17 @@ puts "Start boolean operation ..." bopcut result puts "Finish boolean operation ..." -set square 92859.7 +set square 366764 -set nb_v_good 13 -set nb_e_good 19 -set nb_w_good 8 -set nb_f_good 8 +set nb_v_good 40 +set nb_e_good 60 +set nb_w_good 22 +set nb_f_good 22 set nb_sh_good 1 set nb_sol_good 1 set nb_compsol_good 0 set nb_compound_good 1 -set nb_shape_good 51 +set nb_shape_good 147 set 2dviewer 0 diff --git a/tests/bugs/modalg_5/bug23853_1 b/tests/bugs/modalg_5/bug23853_1 new file mode 100644 index 0000000000..d378d25990 --- /dev/null +++ b/tests/bugs/modalg_5/bug23853_1 @@ -0,0 +1,17 @@ +puts "============" +puts "OCC23853" +puts "============" +puts "" +###################################################### +# BOP regression (2) - BRepAlgoAPI_Cut +###################################################### + +restore [locate_data_file bug23853_cylinder.brep] s1 +restore [locate_data_file bug23853_pipe.brep] s2 + +bop s1 s2 +boptuc result + +set square 4122.75 +set 2dviewer 0 + diff --git a/tests/bugs/modalg_5/bug23853_2 b/tests/bugs/modalg_5/bug23853_2 new file mode 100644 index 0000000000..b4180d1412 --- /dev/null +++ b/tests/bugs/modalg_5/bug23853_2 @@ -0,0 +1,17 @@ +puts "============" +puts "OCC23853" +puts "============" +puts "" +###################################################### +# BOP regression (2) - BRepAlgoAPI_Cut +###################################################### + +restore [locate_data_file bug23853_cylinder.brep] s1 +restore [locate_data_file bug23853_pipe.brep] s2 + +bop s1 s2 +bopcut result + +set square 17590.6 +set 2dviewer 0 + diff --git a/tests/bugs/modalg_5/bug23853_3 b/tests/bugs/modalg_5/bug23853_3 new file mode 100644 index 0000000000..0e43652272 --- /dev/null +++ b/tests/bugs/modalg_5/bug23853_3 @@ -0,0 +1,17 @@ +puts "============" +puts "OCC23853" +puts "============" +puts "" +###################################################### +# BOP regression (2) - BRepAlgoAPI_Cut +###################################################### + +restore [locate_data_file bug23853_cylinder.brep] s1 +restore [locate_data_file bug23853_pipe.brep] s2 + +bop s1 s2 +bopfuse result + +set square 17766.2 +set 2dviewer 0 + diff --git a/tests/bugs/modalg_5/bug23853_4 b/tests/bugs/modalg_5/bug23853_4 new file mode 100644 index 0000000000..2e28488999 --- /dev/null +++ b/tests/bugs/modalg_5/bug23853_4 @@ -0,0 +1,17 @@ +puts "============" +puts "OCC23853" +puts "============" +puts "" +###################################################### +# BOP regression (2) - BRepAlgoAPI_Cut +###################################################### + +restore [locate_data_file bug23853_cylinder.brep] s1 +restore [locate_data_file bug23853_pipe.brep] s2 + +bop s1 s2 +bopcommon result + +set square 3947.09 +set 2dviewer 0 +