diff --git a/src/BOPAlgo/BOPAlgo_WireSplitter_1.cxx b/src/BOPAlgo/BOPAlgo_WireSplitter_1.cxx index c7084476cb..4712d72b93 100644 --- a/src/BOPAlgo/BOPAlgo_WireSplitter_1.cxx +++ b/src/BOPAlgo/BOPAlgo_WireSplitter_1.cxx @@ -134,7 +134,7 @@ static //purpose : //======================================================================= void BOPAlgo_WireSplitter::SplitBlock(const TopoDS_Face& myFace, - BOPTools_ConnexityBlock& aCB) + BOPTools_ConnexityBlock& aCB) { Standard_Boolean bNothingToDo; Standard_Integer aIx, aNb, i, aCntIn, aCntOut; @@ -336,20 +336,20 @@ void Path (const GeomAdaptor_Surface& aGAS, { Standard_Integer i, j, aNb, aNbj; - Standard_Real aTol, anAngleIn, anAngleOut, anAngle, aMinAngle; - Standard_Real aTol2D, aTol2D2; - Standard_Real aTol2, aD2, aTwoPI; + Standard_Real anAngleIn, anAngleOut, anAngle, aMinAngle; + Standard_Real aTol2D, aTol2D2, aD2, aTwoPI; Standard_Boolean anIsSameV2d, anIsSameV, anIsFound, anIsOut, anIsNotPassed; + Standard_Boolean bIsClosed, bRecomputeAngle; TopoDS_Vertex aVa, aVb; TopoDS_Edge aEOuta; BOPAlgo_ListIteratorOfListOfEdgeInfo anIt; + BOPCol_SequenceOfReal aRecomputedAngles; // aVa = aVFirst; aEOuta = aEFirst; BOPAlgo_EdgeInfo* anEdgeInfo = &aEIFirst; // aTwoPI = M_PI + M_PI; - aTol=1.e-7; // // append block // @@ -376,27 +376,27 @@ void Path (const GeomAdaptor_Surface& aGAS, gp_Pnt2d aPb=Coord2d(aVb, aEOuta, myFace); - const BOPAlgo_ListOfEdgeInfo& aLEInfoVb=mySmartMap.FindFromKey(aVb); + const BOPAlgo_ListOfEdgeInfo& aLEInfo=mySmartMap.FindFromKey(aVb); // - aTol=2.*Tolerance2D(aVb, aGAS); - aTol2=10.*aTol*aTol; - - TopoDS_Vertex aV1, aV2; - TopExp::Vertices(aEOuta, aV1, aV2); - Standard_Boolean bIsClosedEdge = aV1.IsNull() || aV2.IsNull() || aV1.IsSame(aV2); - Standard_Boolean bIsDegenerated = BRep_Tool::Degenerated(aEOuta); - Standard_Boolean bIsSeam = BRep_Tool::IsClosed(aEOuta, myFace); - - anIt.Initialize(aLEInfoVb); - for (; anIt.More(); anIt.Next()) { - const BOPAlgo_EdgeInfo& anEI = anIt.Value(); - const TopoDS_Edge& aE = anEI.Edge(); - bIsDegenerated = bIsDegenerated || BRep_Tool::Degenerated(aE); - bIsSeam = bIsSeam || BRep_Tool::IsClosed(aE, myFace); - aV1.Nullify(); - aV2.Nullify(); - TopExp::Vertices(aE, aV1, aV2); - bIsClosedEdge = bIsClosedEdge || aV1.IsNull() || aV2.IsNull() || aV1.IsSame(aV2); + aTol2D = 2.*Tolerance2D(aVb, aGAS); + aTol2D2 = aTol2D * aTol2D; + // + bIsClosed = BRep_Tool::Degenerated(aEOuta) || + BRep_Tool::IsClosed(aEOuta, myFace) || aVa.IsSame(aVb); + if (!bIsClosed) { + TopoDS_Vertex aV1, aV2; + // + anIt.Initialize(aLEInfo); + for (; anIt.More() && !bIsClosed; anIt.Next()) { + const BOPAlgo_EdgeInfo& anEI = anIt.Value(); + const TopoDS_Edge& aE = anEI.Edge(); + // + bIsClosed = BRep_Tool::Degenerated(aE) || BRep_Tool::IsClosed(aE, myFace); + if (!bIsClosed) { + TopExp::Vertices(aE, aV1, aV2); + bIsClosed = aV1.IsNull() || aV2.IsNull() || aV1.IsSame(aV2); + } + } } // aNb=aLS.Length(); @@ -411,24 +411,21 @@ void Path (const GeomAdaptor_Surface& aGAS, aBuf.Append(aEPrev); - anIsSameV=aVPrev.IsSame(aVb); - anIsSameV2d=Standard_False; - + anIsSameV = aVPrev.IsSame(aVb); + anIsSameV2d = anIsSameV; if (anIsSameV) { - anIsSameV2d = Standard_True; - // - aD2=aPaPrev.SquareDistance(aPb); - anIsSameV2d =aD2 aTolU) || - (vdist > aTolV)) { - anIsSameV2d = Standard_False; + if(bIsClosed) { + aD2 = aPaPrev.SquareDistance(aPb); + anIsSameV2d = aD2 < aTol2D2; + if (anIsSameV2d) { + Standard_Real udist = fabs(aPaPrev.X() - aPb.X()); + Standard_Real vdist = fabs(aPaPrev.Y() - aPb.Y()); + Standard_Real aTolU = 2.*UTolerance2D(aVb, aGAS); + Standard_Real aTolV = 2.*VTolerance2D(aVb, aGAS); + // + if((udist > aTolU) || (vdist > aTolV)) { + anIsSameV2d = Standard_False; + } } } }//if (anIsSameV) { @@ -481,26 +478,17 @@ void Path (const GeomAdaptor_Surface& aGAS, } } // - aTol2D=2.*Tolerance2D(aVb, aGAS); - aTol2D2=1000.*aTol2D*aTol2D;//100.*aTol2D*aTol2D; - // - // anAngleIn in Vb from edge aEOuta - const BOPAlgo_ListOfEdgeInfo& aLEInfo=mySmartMap.FindFromKey(aVb); - // - anAngleIn=AngleIn(aEOuta, aLEInfo); - BOPCol_SequenceOfReal aRecomputedAngles; - - Standard_Boolean bRecomputeAngle = + aRecomputedAngles.Clear(); + bRecomputeAngle = RecomputeAngles(aLEInfo, myFace, aPb, aVb, aGAS, aEOuta, - (bIsDegenerated || bIsSeam || bIsClosedEdge), - aTol2D, aRecomputedAngles); - + bIsClosed, aTol2D, aRecomputedAngles); // // aEOutb BOPAlgo_EdgeInfo *pEdgeInfo=NULL; // - aMinAngle=100.; - anIsFound=Standard_False; + anAngleIn = AngleIn(aEOuta, aLEInfo); + aMinAngle = 100.; + anIsFound = Standard_False; Standard_Integer aCurIndexE = 0; anIt.Initialize(aLEInfo); for (; anIt.More(); anIt.Next()) { @@ -532,17 +520,19 @@ void Path (const GeomAdaptor_Surface& aGAS, if (aE.IsSame(aEOuta)) { anAngle = aTwoPI; } else { - // Look for minimal angle and make the choice. - gp_Pnt2d aP2Dx; - // - aP2Dx=Coord2dVf(aE, myFace); - // - aD2=aP2Dx.SquareDistance(aPb); - if (aD2 > aTol2D2){ - continue; + //check 2d distance + if (bIsClosed) { + gp_Pnt2d aP2Dx; + // + aP2Dx = Coord2dVf(aE, myFace); + // + aD2 = aP2Dx.SquareDistance(aPb); + if (aD2 > aTol2D2){ + continue; + } } // - // + // Look for minimal angle and make the choice. anAngleOut=anEI.Angle(); // if(bRecomputeAngle) { diff --git a/src/BRepFeat/BRepFeat.cxx b/src/BRepFeat/BRepFeat.cxx index 30c652d825..ff32b5b4ad 100644 --- a/src/BRepFeat/BRepFeat.cxx +++ b/src/BRepFeat/BRepFeat.cxx @@ -68,7 +68,7 @@ //======================================================================= void BRepFeat::SampleEdges(const TopoDS_Shape& theShape, - TColgp_SequenceOfPnt& theSeq) + TColgp_SequenceOfPnt& theSeq) { LocOpe::SampleEdges(theShape,theSeq); } @@ -81,7 +81,7 @@ void BRepFeat::SampleEdges(const TopoDS_Shape& theShape, //======================================================================= void BRepFeat::Barycenter(const TopoDS_Shape& S, - gp_Pnt& B) + gp_Pnt& B) { TopTools_MapOfShape theMap; TopExp_Explorer exp(S,TopAbs_EDGE); @@ -100,9 +100,9 @@ void BRepFeat::Barycenter(const TopoDS_Shape& S, C = BRep_Tool::Curve(edg,Loc,f,l); C = Handle(Geom_Curve)::DownCast(C->Transformed(Loc.Transformation())); for (i=1;iValue(prm).XYZ(); - nbp++; + prm = ((NECHANTBARYC-i)*f + i*l)/NECHANTBARYC; + Bar += C->Value(prm).XYZ(); + nbp++; } } } @@ -125,7 +125,7 @@ void BRepFeat::Barycenter(const TopoDS_Shape& S, //======================================================================= Standard_Real BRepFeat::ParametricBarycenter(const TopoDS_Shape& S, - const Handle(Geom_Curve)& CC) + const Handle(Geom_Curve)& CC) { TopTools_MapOfShape theMap; TopExp_Explorer exp(S,TopAbs_EDGE); @@ -147,24 +147,24 @@ Standard_Real BRepFeat::ParametricBarycenter(const TopoDS_Shape& S, C = BRep_Tool::Curve(edg,Loc,f,l); C = Handle(Geom_Curve)::DownCast(C->Transformed(Loc.Transformation())); for (i=1;iValue(prm); - // On projette sur CC - extpc.Perform(pone); - if (extpc.IsDone() && extpc.NbExt() >= 1) { - Standard_Real Dist2Min = extpc.SquareDistance(1); - Standard_Integer kmin = 1; - for (Standard_Integer k=2; k<=extpc.NbExt(); k++) { - Standard_Real Dist2 = extpc.SquareDistance(k); - if (Dist2 < Dist2Min) { - Dist2Min = Dist2; - kmin = k; - } - } - nbp++; - Standard_Real prmp = extpc.Point(kmin).Parameter(); - parbar += prmp; - } + prm = ((NECHANTBARYC-i)*f + i*l)/NECHANTBARYC; + gp_Pnt pone = C->Value(prm); + // On projette sur CC + extpc.Perform(pone); + if (extpc.IsDone() && extpc.NbExt() >= 1) { + Standard_Real Dist2Min = extpc.SquareDistance(1); + Standard_Integer kmin = 1; + for (Standard_Integer k=2; k<=extpc.NbExt(); k++) { + Standard_Real Dist2 = extpc.SquareDistance(k); + if (Dist2 < Dist2Min) { + Dist2Min = Dist2; + kmin = k; + } + } + nbp++; + Standard_Real prmp = extpc.Point(kmin).Parameter(); + parbar += prmp; + } } } } @@ -175,15 +175,15 @@ Standard_Real BRepFeat::ParametricBarycenter(const TopoDS_Shape& S, // On projette sur CC extpc.Perform(pone); if (extpc.IsDone() && extpc.NbExt() >= 1) { - Standard_Real Dist2Min = extpc.SquareDistance(1); - for (Standard_Integer k=2; k<=extpc.NbExt(); k++) { - Standard_Real Dist2 = extpc.SquareDistance(k); - if (Dist2 < Dist2Min) { - Dist2Min = Dist2; - } - } - nbp++; - } + Standard_Real Dist2Min = extpc.SquareDistance(1); + for (Standard_Integer k=2; k<=extpc.NbExt(); k++) { + Standard_Real Dist2 = extpc.SquareDistance(k); + if (Dist2 < Dist2Min) { + Dist2Min = Dist2; + } + } + nbp++; + } } } @@ -198,13 +198,13 @@ Standard_Real BRepFeat::ParametricBarycenter(const TopoDS_Shape& S, //======================================================================= void BRepFeat::ParametricMinMax(const TopoDS_Shape& S, - const Handle(Geom_Curve)& CC, - Standard_Real& prmin, - Standard_Real& prmax, - Standard_Real& prbmin, - Standard_Real& prbmax, - Standard_Boolean& flag, - const Standard_Boolean Ori) + const Handle(Geom_Curve)& CC, + Standard_Real& prmin, + Standard_Real& prmax, + Standard_Real& prbmin, + Standard_Real& prbmax, + Standard_Boolean& flag, + const Standard_Boolean Ori) { LocOpe_CSIntersector ASI(S); TColGeom_SequenceOfCurve scur; @@ -213,19 +213,19 @@ void BRepFeat::ParametricMinMax(const TopoDS_Shape& S, if(ASI.IsDone() && ASI.NbPoints(1) >=1) { if (!Ori) { prmin = Min(ASI.Point(1,1).Parameter(), - ASI.Point(1, ASI.NbPoints(1)).Parameter()); + ASI.Point(1, ASI.NbPoints(1)).Parameter()); prmax = Max(ASI.Point(1,1).Parameter(), - ASI.Point(1, ASI.NbPoints(1)).Parameter()); + ASI.Point(1, ASI.NbPoints(1)).Parameter()); } else { TopAbs_Orientation Ori = ASI.Point(1,1).Orientation(); if (Ori == TopAbs_FORWARD) { - prmin = ASI.Point(1,1).Parameter(); - prmax = ASI.Point(1, ASI.NbPoints(1)).Parameter(); + prmin = ASI.Point(1,1).Parameter(); + prmax = ASI.Point(1, ASI.NbPoints(1)).Parameter(); } else { - prmax = ASI.Point(1,1).Parameter(); - prmin = ASI.Point(1, ASI.NbPoints(1)).Parameter(); + prmax = ASI.Point(1,1).Parameter(); + prmin = ASI.Point(1, ASI.NbPoints(1)).Parameter(); } } flag = Standard_True; @@ -257,28 +257,28 @@ void BRepFeat::ParametricMinMax(const TopoDS_Shape& S, C = BRep_Tool::Curve(edg,Loc,f,l); C = Handle(Geom_Curve)::DownCast(C->Transformed(Loc.Transformation())); for (i=1;iValue(prm); - // On projette sur CC - extpc.Perform(pone); - if (extpc.IsDone() && extpc.NbExt() >= 1) { - Standard_Real Dist2Min = extpc.SquareDistance(1); - Standard_Integer kmin = 1; - for (Standard_Integer k=2; k<=extpc.NbExt(); k++) { - Standard_Real Dist2 = extpc.SquareDistance(k); - if (Dist2 < Dist2Min) { - Dist2Min = Dist2; - kmin = k; - } - } - Standard_Real prmp = extpc.Point(kmin).Parameter(); - if (prmp <= prbmin) { - prbmin = prmp; - } - if (prmp >= prbmax) { - prbmax = prmp; - } - } + prm = ((NECHANTBARYC-i)*f + i*l)/NECHANTBARYC; + gp_Pnt pone = C->Value(prm); + // On projette sur CC + extpc.Perform(pone); + if (extpc.IsDone() && extpc.NbExt() >= 1) { + Standard_Real Dist2Min = extpc.SquareDistance(1); + Standard_Integer kmin = 1; + for (Standard_Integer k=2; k<=extpc.NbExt(); k++) { + Standard_Real Dist2 = extpc.SquareDistance(k); + if (Dist2 < Dist2Min) { + Dist2Min = Dist2; + kmin = k; + } + } + Standard_Real prmp = extpc.Point(kmin).Parameter(); + if (prmp <= prbmin) { + prbmin = prmp; + } + if (prmp >= prbmax) { + prbmax = prmp; + } + } } } } @@ -289,23 +289,23 @@ void BRepFeat::ParametricMinMax(const TopoDS_Shape& S, // On projette sur CC extpc.Perform(pone); if (extpc.IsDone() && extpc.NbExt() >= 1) { - Standard_Real Dist2Min = extpc.SquareDistance(1); - Standard_Integer kmin = 1; - for (Standard_Integer k=2; k<=extpc.NbExt(); k++) { - Standard_Real Dist2 = extpc.SquareDistance(k); - if (Dist2 < Dist2Min) { - Dist2Min = Dist2; - kmin = k; - } - } - Standard_Real prmp = extpc.Point(kmin).Parameter(); - if (prmp <= prbmin) { - prbmin = prmp; - } - if (prmp >= prbmax) { - prbmax = prmp; - } - } + Standard_Real Dist2Min = extpc.SquareDistance(1); + Standard_Integer kmin = 1; + for (Standard_Integer k=2; k<=extpc.NbExt(); k++) { + Standard_Real Dist2 = extpc.SquareDistance(k); + if (Dist2 < Dist2Min) { + Dist2Min = Dist2; + kmin = k; + } + } + Standard_Real prmp = extpc.Point(kmin).Parameter(); + if (prmp <= prbmin) { + prbmin = prmp; + } + if (prmp >= prbmax) { + prbmax = prmp; + } + } } } } @@ -319,7 +319,7 @@ void BRepFeat::ParametricMinMax(const TopoDS_Shape& S, //======================================================================= static Standard_Boolean IsIn (BRepTopAdaptor_FClass2d& FC, - Geom2dAdaptor_Curve AC) + Geom2dAdaptor_Curve AC) { Standard_Real Def = 100*Precision::Confusion(); GCPnts_QuasiUniformDeflection QU(AC,Def); @@ -343,12 +343,12 @@ static Standard_Boolean IsIn (BRepTopAdaptor_FClass2d& FC, //--------------- static void PutInBoundsU (Standard_Real umin, - Standard_Real umax, - Standard_Real eps, - Standard_Real period, - Standard_Real f, - Standard_Real l, - Handle(Geom2d_Curve)& C2d) + Standard_Real umax, + Standard_Real eps, + Standard_Real period, + Standard_Real f, + Standard_Real l, + Handle(Geom2d_Curve)& C2d) { gp_Pnt2d Pf = C2d->Value(f); gp_Pnt2d Pl = C2d->Value(l); @@ -389,12 +389,12 @@ static void PutInBoundsU (Standard_Real umin, //--------------- static void PutInBoundsV (Standard_Real vmin, - Standard_Real vmax, - Standard_Real eps, - Standard_Real period, - Standard_Real f, - Standard_Real l, - Handle(Geom2d_Curve)& C2d) + Standard_Real vmax, + Standard_Real eps, + Standard_Real period, + Standard_Real f, + Standard_Real l, + Handle(Geom2d_Curve)& C2d) { gp_Pnt2d Pf = C2d->Value(f); gp_Pnt2d Pl = C2d->Value(l); @@ -433,7 +433,7 @@ static void PutInBoundsV (Standard_Real vmin, Standard_Boolean BRepFeat::IsInside(const TopoDS_Face& F1, - const TopoDS_Face& F2) + const TopoDS_Face& F2) { TopExp_Explorer exp; exp.Init(F1, TopAbs_EDGE); @@ -457,7 +457,7 @@ Standard_Boolean BRepFeat::IsInside(const TopoDS_Face& F1, TopoDS_Shape aLocalShape = F2.Oriented(TopAbs_FORWARD); BRepTopAdaptor_FClass2d FC (TopoDS::Face(aLocalShape),Precision::Confusion()); // BRepTopAdaptor_FClass2d FC (TopoDS::Face(F2.Oriented(TopAbs_FORWARD)), -// Precision::Confusion()); +// Precision::Confusion()); for(; exp.More(); exp.Next()) { Standard_Real f1,l1; Handle(Geom_Curve) C0 = BRep_Tool::Curve(TopoDS::Edge(exp.Current()),f1,l1); @@ -486,7 +486,7 @@ Standard_Boolean BRepFeat::IsInside(const TopoDS_Face& F1, void BRepFeat::FaceUntil(const TopoDS_Shape& Sbase, - TopoDS_Face& FUntil) + TopoDS_Face& FUntil) { Bnd_Box B; BRepBndLib::Add(Sbase,B); @@ -512,11 +512,11 @@ void BRepFeat::FaceUntil(const TopoDS_Shape& Sbase, } else if (styp == STANDARD_TYPE(Geom_CylindricalSurface)) { str = new Geom_RectangularTrimmedSurface - (s, 0., 2.*M_PI, bnd, -bnd, Standard_True, Standard_True); + (s, bnd, -bnd, Standard_False, Standard_True); } else if (styp == STANDARD_TYPE(Geom_ConicalSurface)) { str = new Geom_RectangularTrimmedSurface - (s, 0., 2.*M_PI, bnd, -bnd, Standard_True, Standard_True); + (s, bnd, -bnd, Standard_False, Standard_True); } else { FUntil.Nullify(); @@ -534,8 +534,8 @@ void BRepFeat::FaceUntil(const TopoDS_Shape& Sbase, //======================================================================= TopoDS_Solid BRepFeat::Tool(const TopoDS_Shape& SRef, - const TopoDS_Face& Fac, - const TopAbs_Orientation Orf) + const TopoDS_Face& Fac, + const TopAbs_Orientation Orf) { TopTools_ListOfShape lfaces; // for (TopExp_Explorer exp(SRef,TopAbs_FACE); exp.More(); exp.Next()) { @@ -601,9 +601,9 @@ TopoDS_Solid BRepFeat::Tool(const TopoDS_Shape& SRef, //function : Print //purpose : Print the error Description of a StatusError on a stream. //======================================================================= - + Standard_OStream& BRepFeat::Print(const BRepFeat_StatusError se, - Standard_OStream& s) + Standard_OStream& s) { switch(se) { case BRepFeat_OK : diff --git a/src/IntTools/IntTools_EdgeEdge.cxx b/src/IntTools/IntTools_EdgeEdge.cxx index fe5920f170..ed5c7f86b4 100644 --- a/src/IntTools/IntTools_EdgeEdge.cxx +++ b/src/IntTools/IntTools_EdgeEdge.cxx @@ -135,10 +135,14 @@ void IntTools_EdgeEdge::Prepare() aDt = (aT2 - aT1) / 10.; aT = aT1; aBAC.D1(aT, aP, aV1); - while (aT <= aT2) { + while (aT < aT2) { aT += aDt; aBAC.D1(aT, aP, aV2); - aC += aV1.Angle(aV2); + if (aV1.Magnitude() > gp::Resolution() && + aV2.Magnitude() > gp::Resolution()) { + gp_Dir aD1(aV1), aD2(aV2); + aC += aD1.Angle(aD2); + } aV1 = aV2; } } diff --git a/tests/bugs/modalg_5/bug24558 b/tests/bugs/modalg_5/bug24558 new file mode 100644 index 0000000000..dc896c9c53 --- /dev/null +++ b/tests/bugs/modalg_5/bug24558 @@ -0,0 +1,34 @@ +puts "=========" +puts "OCC24558" +puts "=========" +puts "" +########################################################### +# Boolean operation can not create all results solids which should be built. +########################################################### + +restore [locate_data_file bug24558_Box.brep] b1 +restore [locate_data_file bug24558_Surface_1.brep] s1 +restore [locate_data_file bug24558_Surface_2.brep] s2 +restore [locate_data_file bug24558_Surface_3.brep] s3 +restore [locate_data_file bug24558_Surface_4.brep] s4 + +bclearobjects +bcleartools +baddobjects b1 s1 s2 s3 s4 + +bfillds +bbuild result + +set square 134338 + +set nb_v_good 109 +set nb_e_good 189 +set nb_w_good 95 +set nb_f_good 88 +set nb_sh_good 11 +set nb_sol_good 5 +set nb_compsol_good 0 +set nb_compound_good 1 +set nb_shape_good 498 + +set 2dviewer 1