From fda01cadb20462e97c3d74dd72cd3d7550294041 Mon Sep 17 00:00:00 2001 From: ifv Date: Mon, 2 Feb 2015 15:58:21 +0300 Subject: [PATCH] Commit for 2d offset algorithm --- src/BRep/BRep_Tool.cxx | 96 +- src/BRepFill/BRepFill_TrimEdgeTool.cxx | 349 +++-- src/BRepLib/BRepLib.cxx | 1593 +++++++++++----------- src/BRepLib/BRepLib_FindSurface.cxx | 175 ++- src/BRepMAT2d/BRepMAT2d_Explorer.cxx | 294 ++-- src/Bisector/Bisector_Bisec.cxx | 569 ++++---- src/Bisector/Bisector_BisecCC.cxx | 486 +++---- src/Bisector/Bisector_Inter.cxx | 54 +- src/MAT2d/MAT2d_Tool2d.cxx | 637 +++++---- tests/bugs/modalg_5/bug22831 | 4 - tests/de/iges_1/K3 | 2 +- tests/de/iges_2/B8 | 2 +- tests/de/iges_2/E6 | 4 +- tests/de/iges_2/G1 | 1 - tests/mesh/data/standard/J1 | 2 +- tests/offset/wire_closed_inside_0_075/C7 | 16 +- 16 files changed, 2439 insertions(+), 1845 deletions(-) diff --git a/src/BRep/BRep_Tool.cxx b/src/BRep/BRep_Tool.cxx index 298da55047..af654bfee7 100644 --- a/src/BRep/BRep_Tool.cxx +++ b/src/BRep/BRep_Tool.cxx @@ -5,8 +5,8 @@ // // This file is part of Open CASCADE Technology software library. // -// This library is free software; you can redistribute it and / or modify it -// under the terms of the GNU Lesser General Public version 2.1 as published +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published // by the Free Software Foundation, with special exception defined in the file // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT // distribution for complete text of the license and disclaimer of any warranty. @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -52,6 +53,10 @@ #include #include +#include +#include +#include + //modified by NIZNHY-PKV Fri Oct 17 14:13:29 2008f static Standard_Boolean IsPlane(const Handle(Geom_Surface)& aS); @@ -314,40 +319,42 @@ Handle(Geom2d_Curve) BRep_Tool::CurveOnSurface(const TopoDS_Edge& E, GP = Handle(Geom_Plane)::DownCast(S); //fin modif du 21-05-97 - if (!GP.IsNull()) { - + if (!GP.IsNull()) + { Handle(GeomAdaptor_HCurve) HC; Handle(GeomAdaptor_HSurface) HS; HC = new GeomAdaptor_HCurve(); HS = new GeomAdaptor_HSurface(); - TopLoc_Location LC; + TopLoc_Location aCurveLocation; Standard_Real f, l;// for those who call with (u,u). - Handle(Geom_Curve) C3d = - BRep_Tool::Curve(E,/*LC,*/f,l); // transforming plane instead of curve - // we can loose scale factor of Curve transformation (eap 13 May 2002) + Handle(Geom_Curve) C3d = BRep_Tool::Curve(E, aCurveLocation, f, l); - LC = L/*.Predivided(LC)*/; + if (C3d.IsNull()) + { + return nullPCurve; + } - if (C3d.IsNull()) return nullPCurve; + aCurveLocation = L.Predivided(aCurveLocation); Handle(Geom_Plane) Plane = GP; - if (!LC.IsIdentity()) { - const gp_Trsf& T = LC.Transformation(); + if (!aCurveLocation.IsIdentity()) + { + const gp_Trsf& T = aCurveLocation.Transformation(); Handle(Geom_Geometry) GPT = GP->Transformed(T); Plane = *((Handle(Geom_Plane)*)&GPT); } GeomAdaptor_Surface& GAS = HS->ChangeSurface(); GAS.Load(Plane); - + Handle(Geom_Curve) ProjOnPlane = GeomProjLib::ProjectOnPlane(new Geom_TrimmedCurve(C3d,f,l), Plane, Plane->Position().Direction(), Standard_True); - + GeomAdaptor_Curve& GAC = HC->ChangeCurve(); GAC.Load(ProjOnPlane); @@ -1139,6 +1146,12 @@ Standard_Boolean BRep_Tool::HasContinuity(const TopoDS_Edge& E) gp_Pnt BRep_Tool::Pnt(const TopoDS_Vertex& V) { Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape()); + + if (TV.IsNull()) + { + Standard_NullObject::Raise("BRep_Tool:: TopoDS_Vertex hasn't gp_Pnt"); + } + gp_Pnt P = TV->Pnt(); P.Transform(V.Location().Transformation()); return P; @@ -1151,7 +1164,14 @@ gp_Pnt BRep_Tool::Pnt(const TopoDS_Vertex& V) Standard_Real BRep_Tool::Tolerance(const TopoDS_Vertex& V) { - Standard_Real p = (*((Handle(BRep_TVertex)*)&V.TShape()))->Tolerance(); + Handle(BRep_TVertex)& aTVert = *((Handle(BRep_TVertex)*)&V.TShape()); + + if (aTVert.IsNull()) + { + Standard_NullObject::Raise("BRep_Tool:: TopoDS_Vertex hasn't gp_Pnt"); + } + + Standard_Real p = aTVert->Tolerance(); Standard_Real pMin = Precision::Confusion(); if (p > pMin) return p; else return pMin; @@ -1431,24 +1451,43 @@ gp_Pnt2d BRep_Tool::Parameters(const TopoDS_Vertex& V, } //======================================================================= //function : IsClosed -//purpose : Returns if S if flaged Closed, if S is a -// Solid,Shell or Compound returns is S has no free boundaries. +//purpose : //======================================================================= -Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Shape& S) +Standard_Boolean BRep_Tool::IsClosed (const TopoDS_Shape& theShape) { - if (S.ShapeType() == TopAbs_SHELL || S.ShapeType() == TopAbs_SOLID || - S.ShapeType() == TopAbs_COMPOUND) { - TopTools_MapOfShape M; - TopExp_Explorer exp; - for (exp.Init(S,TopAbs_EDGE); exp.More(); exp.Next()) { -// for (TopExp_Explorer exp(S,TopAbs_EDGE); exp.More(); exp.Next()) { + if (theShape.ShapeType() == TopAbs_SHELL || theShape.ShapeType() == TopAbs_SOLID) + { + NCollection_Map aMap (101, new NCollection_IncAllocator); + TopExp_Explorer exp (theShape.Oriented(TopAbs_FORWARD), TopAbs_EDGE); + Standard_Boolean hasBound = Standard_False; + for (; exp.More(); exp.Next()) + { const TopoDS_Edge& E = TopoDS::Edge(exp.Current()); - if (BRep_Tool::Degenerated(E)) continue; - if (!M.Add(E)) M.Remove(E); + if (BRep_Tool::Degenerated(E) || E.Orientation() == TopAbs_INTERNAL || E.Orientation() == TopAbs_EXTERNAL) + continue; + hasBound = Standard_True; + if (!aMap.Add(E)) + aMap.Remove(E); } - if ( M.IsEmpty()) return 1; + return hasBound && aMap.IsEmpty(); } - return (S.Closed()); + else if (theShape.ShapeType() == TopAbs_WIRE) + { + NCollection_Map aMap (101, new NCollection_IncAllocator); + TopExp_Explorer exp (theShape.Oriented(TopAbs_FORWARD), TopAbs_VERTEX); + Standard_Boolean hasBound = Standard_False; + for (; exp.More(); exp.Next()) + { + const TopoDS_Shape& V = exp.Current(); + if (V.Orientation() == TopAbs_INTERNAL || V.Orientation() == TopAbs_EXTERNAL) + continue; + hasBound = Standard_True; + if (!aMap.Add(V)) + aMap.Remove(V); + } + return hasBound && aMap.IsEmpty(); + } + return theShape.Closed(); } //modified by NIZNHY-PKV Fri Oct 17 14:09:58 2008 f @@ -1480,3 +1519,4 @@ Standard_Boolean IsPlane(const Handle(Geom_Surface)& aS) // return bRet; } + diff --git a/src/BRepFill/BRepFill_TrimEdgeTool.cxx b/src/BRepFill/BRepFill_TrimEdgeTool.cxx index 4619cee0b8..186bbf1a09 100644 --- a/src/BRepFill/BRepFill_TrimEdgeTool.cxx +++ b/src/BRepFill/BRepFill_TrimEdgeTool.cxx @@ -5,8 +5,8 @@ // // This file is part of Open CASCADE Technology software library. // -// This library is free software; you can redistribute it and / or modify it -// under the terms of the GNU Lesser General Public version 2.1 as published +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published // by the Free Software Foundation, with special exception defined in the file // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT // distribution for complete text of the license and disclaimer of any warranty. @@ -31,13 +31,17 @@ #include #include #include - +#include #include - +#ifdef DEB +//#define DRAW #ifdef DRAW #include #include static Standard_Boolean Affich = Standard_False; +static Standard_Boolean AffichInt = Standard_False; +static Standard_Integer intind = 0; +#endif #endif @@ -47,7 +51,7 @@ static Standard_Boolean Affich = Standard_False; //======================================================================= static void SimpleExpression (const Bisector_Bisec& B, - Handle(Geom2d_Curve)& Bis) + Handle(Geom2d_Curve)& Bis) { Bis = B.Value(); @@ -60,8 +64,8 @@ static void SimpleExpression (const Bisector_Bisec& B, if (BT == STANDARD_TYPE(Bisector_BisecAna)) { Bis = Handle(Bisector_BisecAna)::DownCast(BasBis)->Geom2dCurve(); Bis = new Geom2d_TrimmedCurve (Bis, - TrBis->FirstParameter(), - TrBis->LastParameter()); + TrBis->FirstParameter(), + TrBis->LastParameter()); } } } @@ -83,18 +87,18 @@ BRepFill_TrimEdgeTool::BRepFill_TrimEdgeTool() //======================================================================= BRepFill_TrimEdgeTool::BRepFill_TrimEdgeTool -(const Bisector_Bisec& Bisec, - const Handle(Geom2d_Geometry)& S1, - const Handle(Geom2d_Geometry)& S2, - const Standard_Real Offset) : + (const Bisector_Bisec& Bisec, + const Handle(Geom2d_Geometry)& S1, + const Handle(Geom2d_Geometry)& S2, + const Standard_Real Offset) : myOffset(Offset), -myBisec(Bisec) + myBisec(Bisec) { isPoint1 = (S1->DynamicType() == STANDARD_TYPE(Geom2d_CartesianPoint)); isPoint2 = (S2->DynamicType() == STANDARD_TYPE(Geom2d_CartesianPoint)); -// return geometries of shapes. -// Standard_Real f,l; + // return geometries of shapes. + // Standard_Real f,l; if (isPoint1) { myP1 = Handle(Geom2d_Point)::DownCast(S1)->Pnt2d(); } @@ -102,10 +106,10 @@ myBisec(Bisec) myC1 = Handle(Geom2d_Curve)::DownCast(S1); #ifdef DRAW if ( Affich) { -//POP pour NT + //POP pour NT char* myC1name = "myC1"; DrawTrSurf::Set(myC1name,myC1); -// DrawTrSurf::Set("myC1",myC1); + // DrawTrSurf::Set("myC1",myC1); } #endif } @@ -118,7 +122,7 @@ myBisec(Bisec) if ( Affich) { char* myC2name = "myC2"; DrawTrSurf::Set(myC2name,myC2); -// DrawTrSurf::Set("myC2",myC2); + // DrawTrSurf::Set("myC2",myC2); } #endif } @@ -128,8 +132,8 @@ myBisec(Bisec) myBis = Geom2dAdaptor_Curve(Bis); #ifdef DRAW if ( Affich) { - char* myBisname = "myBis"; - DrawTrSurf::Set(myBisname,Bis); + char* myBisname = "myBis"; + DrawTrSurf::Set(myBisname,Bis); } #endif @@ -150,8 +154,8 @@ static void Bubble(TColgp_SequenceOfPnt& Seq) gp_Pnt P1 = Seq.Value(i); gp_Pnt P2 = Seq.Value(i+1); if (P2.X() 0) { for ( Standard_Integer i = 1; i <= NbPoints; i++) { U1 = Intersector.Point(i).ParamOnSecond(); @@ -194,11 +198,11 @@ static void EvalParameters(const Geom2dAdaptor_Curve& Bis, P = gp_Pnt(U1,U2,0.); Params.Append(P); } - + } - + NbSegments = Intersector.NbSegments(); - + if (NbSegments > 0) { IntRes2d_IntersectionSegment Seg; for ( Standard_Integer i = 1; i <= NbSegments; i++) { @@ -206,20 +210,20 @@ static void EvalParameters(const Geom2dAdaptor_Curve& Bis, U1 = Seg.FirstPoint().ParamOnSecond(); Standard_Real Ulast = Seg.LastPoint().ParamOnSecond(); if ( Abs(U1 - CBis.FirstParameter()) <= Tol && - Abs(Ulast - CBis.LastParameter()) <= Tol ) { - P = gp_Pnt(U1,Seg.FirstPoint().ParamOnFirst(),0.); - Params.Append(P); - P = gp_Pnt(Ulast,Seg.LastPoint().ParamOnFirst(),0.); - Params.Append(P); + Abs(Ulast - CBis.LastParameter()) <= Tol ) { + P = gp_Pnt(U1,Seg.FirstPoint().ParamOnFirst(),0.); + Params.Append(P); + P = gp_Pnt(Ulast,Seg.LastPoint().ParamOnFirst(),0.); + Params.Append(P); } else { - U1 += Seg.LastPoint().ParamOnSecond(); - U1 /= 2.; - U2 = Seg.FirstPoint().ParamOnFirst(); - U2 += Seg.LastPoint().ParamOnFirst(); - U2 /= 2.; - P = gp_Pnt(U1,U2,0.); - Params.Append(P); + U1 += Seg.LastPoint().ParamOnSecond(); + U1 /= 2.; + U2 = Seg.FirstPoint().ParamOnFirst(); + U2 += Seg.LastPoint().ParamOnFirst(); + U2 /= 2.; + P = gp_Pnt(U1,U2,0.); + Params.Append(P); } } } @@ -227,15 +231,15 @@ static void EvalParameters(const Geom2dAdaptor_Curve& Bis, // Order the sequence by growing parameter on the bissectrice. Bubble( Params); } - + static void EvalParametersBis(const Geom2dAdaptor_Curve& Bis, - const Geom2dAdaptor_Curve& AC, - TColgp_SequenceOfPnt& Params, - const Standard_Real Tol) + const Geom2dAdaptor_Curve& AC, + TColgp_SequenceOfPnt& Params, + const Standard_Real Tol) { Geom2dInt_GInter Intersector; Standard_Real TolC = Tol; - + Geom2dAdaptor_Curve CBis(Bis); Geom2dAdaptor_Curve CAC (AC); @@ -248,9 +252,9 @@ static void EvalParametersBis(const Geom2dAdaptor_Curve& Bis, if ( !Intersector.IsDone()) { StdFail_NotDone::Raise("BRepFill_TrimSurfaceTool::IntersectWith"); } - + NbPoints = Intersector.NbPoints(); - + if (NbPoints > 0) { for ( Standard_Integer i = 1; i <= NbPoints; i++) { U1 = Intersector.Point(i).ParamOnSecond(); @@ -258,11 +262,11 @@ static void EvalParametersBis(const Geom2dAdaptor_Curve& Bis, P = gp_Pnt(U1,U2,0.); Params.Append(P); } - + } - + NbSegments = Intersector.NbSegments(); - + if (NbSegments > 0) { IntRes2d_IntersectionSegment Seg; for ( Standard_Integer i = 1; i <= NbSegments; i++) { @@ -270,20 +274,20 @@ static void EvalParametersBis(const Geom2dAdaptor_Curve& Bis, U1 = Seg.FirstPoint().ParamOnSecond(); Standard_Real Ulast = Seg.LastPoint().ParamOnSecond(); if ( Abs(U1 - CBis.FirstParameter()) <= Tol && - Abs(Ulast - CBis.LastParameter()) <= Tol ) { - P = gp_Pnt(U1,Seg.FirstPoint().ParamOnFirst(),0.); - Params.Append(P); - P = gp_Pnt(Ulast,Seg.LastPoint().ParamOnFirst(),0.); - Params.Append(P); + Abs(Ulast - CBis.LastParameter()) <= Tol ) { + P = gp_Pnt(U1,Seg.FirstPoint().ParamOnFirst(),0.); + Params.Append(P); + P = gp_Pnt(Ulast,Seg.LastPoint().ParamOnFirst(),0.); + Params.Append(P); } else { - U1 += Seg.LastPoint().ParamOnSecond(); - U1 /= 2.; - U2 = Seg.FirstPoint().ParamOnFirst(); - U2 += Seg.LastPoint().ParamOnFirst(); - U2 /= 2.; - P = gp_Pnt(U1,U2,0.); - Params.Append(P); + U1 += Seg.LastPoint().ParamOnSecond(); + U1 /= 2.; + U2 = Seg.FirstPoint().ParamOnFirst(); + U2 += Seg.LastPoint().ParamOnFirst(); + U2 /= 2.; + P = gp_Pnt(U1,U2,0.); + Params.Append(P); } } } @@ -299,8 +303,8 @@ static void EvalParametersBis(const Geom2dAdaptor_Curve& Bis, //======================================================================= void BRepFill_TrimEdgeTool::IntersectWith(const TopoDS_Edge& Edge1, - const TopoDS_Edge& Edge2, - TColgp_SequenceOfPnt& Params) + const TopoDS_Edge& Edge2, + TColgp_SequenceOfPnt& Params) { Params.Clear(); @@ -318,27 +322,28 @@ void BRepFill_TrimEdgeTool::IntersectWith(const TopoDS_Edge& Edge1, Geom2dAdaptor_Curve AC2(C2,f,l); #ifdef DRAW - if ( Affich) { + if ( AffichInt) { f = AC1.FirstParameter(); l = AC1.LastParameter(); - char* CURVE1name = "CURVE1"; - DrawTrSurf::Set(CURVE1name, new Geom2d_TrimmedCurve(C1,f,l)); + char name[32]; + sprintf(name,"C1_%d", ++intind); + DrawTrSurf::Set(name, new Geom2d_TrimmedCurve(C1,f,l)); f = AC2.FirstParameter(); l = AC2.LastParameter(); - char* CURVE2name = "CURVE2"; - DrawTrSurf::Set(CURVE2name, new Geom2d_TrimmedCurve(C2,f,l)); + sprintf(name,"C2_%d", intind); + DrawTrSurf::Set(name, new Geom2d_TrimmedCurve(C2,f,l)); f = myBis.FirstParameter(); l = myBis.LastParameter(); - char* bisname = "BIS"; - DrawTrSurf::Set(bisname, new Geom2d_TrimmedCurve(myBis.Curve(),f,l)); - char* Edge1name = "E1"; - DBRep::Set(Edge1name, Edge1); - char* Edge2name = "E2"; - DBRep::Set(Edge2name, Edge2); + sprintf(name,"BIS%d", intind); + DrawTrSurf::Set(name, new Geom2d_TrimmedCurve(myBis.Curve(),f,l)); + sprintf(name,"E1_%d", intind); + DBRep::Set(name, Edge1); + sprintf(name,"E2_%d", intind); + DBRep::Set(name, Edge2); } #endif - + // Calculate intersection TColgp_SequenceOfPnt Points2; gp_Pnt PSeq; @@ -347,36 +352,94 @@ void BRepFill_TrimEdgeTool::IntersectWith(const TopoDS_Edge& Edge1, EvalParameters (myBis,AC2,Points2); + Standard_Integer SeanceDeRattrapage=0; Standard_Real TolInit= 1.e-9; Standard_Integer nn = 7; if((AC1.GetType() != GeomAbs_Circle && AC1.GetType() != GeomAbs_Line) || - (AC2.GetType() != GeomAbs_Circle && AC2.GetType() != GeomAbs_Line)) { + (AC2.GetType() != GeomAbs_Circle && AC2.GetType() != GeomAbs_Line)) { - TolInit = 1.e-8; - nn = 6; + TolInit = 1.e-8; + nn = 6; } - + + if(Params.IsEmpty() && Points2.IsEmpty()) + { + //Check, may be there are no intersections at all + // for case myBis == Line + if(myBis.GetType() == GeomAbs_Line) + { + Standard_Real dmax = TolInit; + Standard_Integer n = 0; + while(n < nn) + { + dmax *= 10.0; + ++n; + } + dmax *= dmax; + // + gp_Lin2d anL = myBis.Line(); + Standard_Boolean isFar1 = Standard_True; + Standard_Boolean isFar2 = Standard_True; + gp_Pnt2d aP; + // + Standard_Real d = RealLast(); + AC1.D0(AC1.FirstParameter(), aP); + Standard_Real par = ElCLib::Parameter(anL, aP); + if(par >= myBis.FirstParameter() && par <= myBis.LastParameter()) + { + d = anL.SquareDistance(aP); + } + AC1.D0(AC1.LastParameter(), aP); + par = ElCLib::Parameter(anL, aP); + if(par >= myBis.FirstParameter() && par <= myBis.LastParameter()) + { + d = Min(anL.SquareDistance(aP), d); + } + isFar1 = d > dmax; + // + d = RealLast(); + AC2.D0(AC2.FirstParameter(), aP); + par = ElCLib::Parameter(anL, aP); + if(par >= myBis.FirstParameter() && par <= myBis.LastParameter()) + { + d = anL.SquareDistance(aP); + } + AC2.D0(AC2.LastParameter(), aP); + par = ElCLib::Parameter(anL, aP); + if(par >= myBis.FirstParameter() && par <= myBis.LastParameter()) + { + d = Min(anL.SquareDistance(aP), d); + } + isFar2 = d > dmax; + // + if(isFar1 && isFar2) + { + return; + } + } + } + while ( SeanceDeRattrapage < nn // TolInit <= 0.01 - && ( Points2.Length() != Params.Length() || - (Points2.Length() == 0 && Params.Length() == 0) ) ) { + && ( Points2.Length() != Params.Length() || + (Points2.Length() == 0 && Params.Length() == 0) ) ) { -#ifdef DEB - cout << "BRepFill_TrimEdgeTool: incoherent intersection. Try with a greater tolerance" << endl; +#ifdef OCCT_DEBUG + cout << "BRepFill_TrimEdgeTool: incoherent intersection. Try with a greater tolerance" << endl; #endif - Params.Clear(); - Points2.Clear(); - - TolInit*=10.0; - - EvalParametersBis(myBis,AC1,Params,TolInit); - EvalParametersBis(myBis,AC2,Points2,TolInit); - SeanceDeRattrapage++; + Params.Clear(); + Points2.Clear(); + + TolInit*=10.0; + + EvalParametersBis(myBis,AC1,Params,TolInit); + EvalParametersBis(myBis,AC2,Points2,TolInit); + SeanceDeRattrapage++; } -#ifdef DEB +#ifdef OCCT_DEBUG if(SeanceDeRattrapage != 0) cout << "SeanceDeRattrapage = " << SeanceDeRattrapage << endl; if(SeanceDeRattrapage == nn) { cout << "BRepFill_TrimEdgeTool: incoherent intersection" << endl; @@ -387,7 +450,7 @@ void BRepFill_TrimEdgeTool::IntersectWith(const TopoDS_Edge& Edge1, if(Params.Length() == 0 && Points2.Length() == 1) { //cout << "Params.Length() == 0 && Points2.Length() == 1" << endl; - Standard_Real dmin; + Standard_Real dmin, dmax = 0.25*myOffset*myOffset; Standard_Real tBis = Points2(1).X(); gp_Pnt2d PBis = myBis.Value(tBis); @@ -395,19 +458,26 @@ void BRepFill_TrimEdgeTool::IntersectWith(const TopoDS_Edge& Edge1, gp_Pnt2d PC = AC1.Value(t); dmin = PC.SquareDistance(PBis); gp_Pnt P(tBis, t, 0.); - Params.Append(P); + if(dmin < dmax) + { + Params.Append(P); + } t = AC1.LastParameter(); PC = AC1.Value(t); - if(dmin > PC.SquareDistance(PBis)) { + Standard_Real dmin1 = PC.SquareDistance(PBis); + if(dmin > dmin1 && dmin1 < dmax ) { P.SetY(t); - Params.SetValue(1,P); + if(Params.IsEmpty()) + Params.Append(P); + else + Params.SetValue(1,P); } } else if(Params.Length() == 1 && Points2.Length() == 0) { //cout << "Params.Length() == 1 && Points2.Length() == 0" << endl; - Standard_Real dmin; + Standard_Real dmin, dmax = 0.25*myOffset*myOffset; Standard_Real tBis = Params(1).X(); gp_Pnt2d PBis = myBis.Value(tBis); @@ -415,13 +485,20 @@ void BRepFill_TrimEdgeTool::IntersectWith(const TopoDS_Edge& Edge1, gp_Pnt2d PC = AC2.Value(t); dmin = PC.SquareDistance(PBis); gp_Pnt P(tBis, t, 0.); - Points2.Append(P); + if(dmin < dmax) + { + Points2.Append(P); + } t = AC2.LastParameter(); PC = AC2.Value(t); - if(dmin > PC.SquareDistance(PBis)) { + Standard_Real dmin1 = PC.SquareDistance(PBis); + if(dmin > dmin1 && dmin1 < dmax ) { P.SetY(t); - Points2.SetValue(1,P); + if(Points2.IsEmpty()) + Points2.Append(P); + else + Points2.SetValue(1,P); } } @@ -452,18 +529,18 @@ void BRepFill_TrimEdgeTool::IntersectWith(const TopoDS_Edge& Edge1, Standard_Real P1xP2x=Abs( P1.X() - P2.X()); if ( P1xP2x > Tol ) { -#ifdef DEB +#ifdef OCCT_DEBUG cout << "BRepFill_TrimEdgeTool: no same parameter on the bissectrice" << endl; #endif if(P1xP2x>TolInit) { -#ifdef DEB - cout << "BRepFill_TrimEdgeTool: Continue somehow" << endl; +#ifdef OCCT_DEBUG + cout << "BRepFill_TrimEdgeTool: Continue somehow" << endl; #endif - i++; + i++; } else { - if ( P1.X() < P2.X()) Params.Remove(i); - else Points2.Remove(i); + if ( P1.X() < P2.X()) Params.Remove(i); + else Points2.Remove(i); } } else i++; @@ -492,10 +569,10 @@ void BRepFill_TrimEdgeTool::IntersectWith(const TopoDS_Edge& Edge1, //======================================================================= void BRepFill_TrimEdgeTool::AddOrConfuse(const Standard_Boolean Start, - const TopoDS_Edge& Edge1, - const TopoDS_Edge& Edge2, - TColgp_SequenceOfPnt& Params) -const + const TopoDS_Edge& Edge1, + const TopoDS_Edge& Edge2, + TColgp_SequenceOfPnt& Params) + const { Standard_Boolean ToProj = Standard_True; gp_Pnt2d PBis; @@ -521,9 +598,9 @@ const else P = AC1.Value(Params.Last ().Y()); ToProj = !PBis.IsEqual(P,Tol); } - + if (ToProj) { -#ifdef DEB +#ifdef OCCT_DEBUG cout << " project extremity bissectrice on parallel."< 0) { Dist = Projector.LowerDistance(); } -// Modified by Sergey KHROMOV - Fri Sep 27 11:43:43 2002 Begin -// else { -// gp_Pnt2d PF = myC1->Value(myC1->FirstParameter()); -// gp_Pnt2d PL = myC1->Value(myC1->LastParameter()); -// Dist = Min (P.Distance(PF),P.Distance(PL)); -// } - -// Check of distances between P and first and last point of the first curve -// should be performed in any case, despite of the results of projection. + // Modified by Sergey KHROMOV - Fri Sep 27 11:43:43 2002 Begin + // else { + // gp_Pnt2d PF = myC1->Value(myC1->FirstParameter()); + // gp_Pnt2d PL = myC1->Value(myC1->LastParameter()); + // Dist = Min (P.Distance(PF),P.Distance(PL)); + // } + + // Check of distances between P and first and last point of the first curve + // should be performed in any case, despite of the results of projection. gp_Pnt2d PF = myC1->Value(myC1->FirstParameter()); gp_Pnt2d PL = myC1->Value(myC1->LastParameter()); Standard_Real aDistMin = Min (P.Distance(PF),P.Distance(PL)); if (Dist > aDistMin) Dist = aDistMin; -// Modified by Sergey KHROMOV - Fri Sep 27 11:43:44 2002 End + // Modified by Sergey KHROMOV - Fri Sep 27 11:43:44 2002 End } - -// return (Dist < Abs(myOffset); -// return (Dist < Abs(myOffset) + Precision::Confusion()); + + // return (Dist < Abs(myOffset); + // return (Dist < Abs(myOffset) + Precision::Confusion()); return (Dist < Abs(myOffset) - Precision::Confusion()); } diff --git a/src/BRepLib/BRepLib.cxx b/src/BRepLib/BRepLib.cxx index c169450687..844501b2b0 100644 --- a/src/BRepLib/BRepLib.cxx +++ b/src/BRepLib/BRepLib.cxx @@ -5,8 +5,8 @@ // // This file is part of Open CASCADE Technology software library. // -// This library is free software; you can redistribute it and / or modify it -// under the terms of the GNU Lesser General Public version 2.1 as published +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published // by the Free Software Foundation, with special exception defined in the file // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT // distribution for complete text of the license and disclaimer of any warranty. @@ -134,14 +134,14 @@ const Handle(Geom_Plane)& BRepLib::Plane() //======================================================================= Standard_Boolean BRepLib::CheckSameRange(const TopoDS_Edge& AnEdge, - const Standard_Real Tolerance) + const Standard_Real Tolerance) { Standard_Boolean IsSameRange = Standard_True, - first_time_in = Standard_True ; + first_time_in = Standard_True ; BRep_ListIteratorOfListOfCurveRepresentation an_Iterator ((*((Handle(BRep_TEdge)*)&AnEdge.TShape()))->ChangeCurves()); - + Standard_Real first, last; Standard_Real current_first =0., current_last =0. ; Handle(BRep_GCurve) geometric_representation_ptr ; @@ -150,115 +150,115 @@ Standard_Boolean BRepLib::CheckSameRange(const TopoDS_Edge& AnEdge, geometric_representation_ptr = Handle(BRep_GCurve)::DownCast(an_Iterator.Value()); if (!geometric_representation_ptr.IsNull()) { - - first = geometric_representation_ptr->First(); - last = geometric_representation_ptr->Last(); - if (first_time_in ) { - current_first = first ; - current_last = last ; - first_time_in = Standard_False ; - } - else { - IsSameRange = (Abs(current_first - first) <= Tolerance) - && (Abs(current_last -last) <= Tolerance ) ; - } + + first = geometric_representation_ptr->First(); + last = geometric_representation_ptr->Last(); + if (first_time_in ) { + current_first = first ; + current_last = last ; + first_time_in = Standard_False ; + } + else { + IsSameRange = (Abs(current_first - first) <= Tolerance) + && (Abs(current_last -last) <= Tolerance ) ; } + } an_Iterator.Next() ; } return IsSameRange ; } - + //======================================================================= //function : SameRange //purpose : //======================================================================= void BRepLib::SameRange(const TopoDS_Edge& AnEdge, - const Standard_Real Tolerance) + const Standard_Real Tolerance) { BRep_ListIteratorOfListOfCurveRepresentation an_Iterator ((*((Handle(BRep_TEdge)*)&AnEdge.TShape()))->ChangeCurves()); - + Handle(Geom2d_Curve) Curve2dPtr, Curve2dPtr2, NewCurve2dPtr, NewCurve2dPtr2; TopLoc_Location LocalLoc ; Standard_Boolean first_time_in = Standard_True, - has_curve, - has_closed_curve ; + has_curve, + has_closed_curve ; Handle(BRep_GCurve) geometric_representation_ptr ; Standard_Real first, - current_first, - last, - current_last ; + current_first, + last, + current_last ; const Handle(Geom_Curve) C = BRep_Tool::Curve(AnEdge, - LocalLoc, - current_first, - current_last); + LocalLoc, + current_first, + current_last); if (!C.IsNull()) { first_time_in = Standard_False ; } - + while (an_Iterator.More()) { geometric_representation_ptr = Handle(BRep_GCurve)::DownCast(an_Iterator.Value()); if (! geometric_representation_ptr.IsNull()) { has_closed_curve = - has_curve = Standard_False ; + has_curve = Standard_False ; first = geometric_representation_ptr->First(); last = geometric_representation_ptr->Last(); if (geometric_representation_ptr->IsCurveOnSurface()) { - Curve2dPtr = geometric_representation_ptr->PCurve() ; - has_curve = Standard_True ; + Curve2dPtr = geometric_representation_ptr->PCurve() ; + has_curve = Standard_True ; } if (geometric_representation_ptr->IsCurveOnClosedSurface()) { - Curve2dPtr2 = geometric_representation_ptr->PCurve2() ; - has_closed_curve = Standard_True ; + Curve2dPtr2 = geometric_representation_ptr->PCurve2() ; + has_closed_curve = Standard_True ; } if (has_curve || has_closed_curve) { - if (first_time_in) { - current_first = first ; - current_last = last ; - first_time_in = Standard_False ; + if (first_time_in) { + current_first = first ; + current_last = last ; + first_time_in = Standard_False ; } - + if (Abs(first - current_first) > Precision::Confusion() || - Abs(last - current_last) > Precision::Confusion() ) - { - if (has_curve) - { - GeomLib::SameRange(Tolerance, - Curve2dPtr, - geometric_representation_ptr->First(), - geometric_representation_ptr->Last(), - current_first, - current_last, - NewCurve2dPtr); - geometric_representation_ptr->PCurve(NewCurve2dPtr) ; - } - if (has_closed_curve) - { - GeomLib::SameRange(Tolerance, - Curve2dPtr2, - geometric_representation_ptr->First(), - geometric_representation_ptr->Last(), - current_first, - current_last, - NewCurve2dPtr2); - geometric_representation_ptr->PCurve2(NewCurve2dPtr2) ; - } - } + Abs(last - current_last) > Precision::Confusion() ) + { + if (has_curve) + { + GeomLib::SameRange(Tolerance, + Curve2dPtr, + geometric_representation_ptr->First(), + geometric_representation_ptr->Last(), + current_first, + current_last, + NewCurve2dPtr); + geometric_representation_ptr->PCurve(NewCurve2dPtr) ; + } + if (has_closed_curve) + { + GeomLib::SameRange(Tolerance, + Curve2dPtr2, + geometric_representation_ptr->First(), + geometric_representation_ptr->Last(), + current_first, + current_last, + NewCurve2dPtr2); + geometric_representation_ptr->PCurve2(NewCurve2dPtr2) ; + } + } } } an_Iterator.Next() ; } BRep_Builder B; B.Range(TopoDS::Edge(AnEdge), - current_first, - current_last) ; + current_first, + current_last) ; B.SameRange(AnEdge, - Standard_True) ; + Standard_True) ; } //======================================================================= @@ -267,7 +267,7 @@ void BRepLib::SameRange(const TopoDS_Edge& AnEdge, //======================================================================= static Standard_Integer evaluateMaxSegment(const Standard_Integer aMaxSegment, - const Adaptor3d_CurveOnSurface& aCurveOnSurface) + const Adaptor3d_CurveOnSurface& aCurveOnSurface) { if (aMaxSegment != 0) return aMaxSegment; @@ -275,7 +275,7 @@ static Standard_Integer evaluateMaxSegment(const Standard_Integer aMaxSegment, Handle(Adaptor2d_HCurve2d) aCurv2d = aCurveOnSurface.GetCurve(); Standard_Real aNbSKnots = 0, aNbC2dKnots = 0; - + if (aSurf->GetType() == GeomAbs_BSplineSurface) { Handle(Geom_BSplineSurface) aBSpline = aSurf->BSpline(); aNbSKnots = Max(aBSpline->NbUKnots(), aBSpline->NbVKnots()); @@ -293,22 +293,22 @@ static Standard_Integer evaluateMaxSegment(const Standard_Integer aMaxSegment, //======================================================================= Standard_Boolean BRepLib::BuildCurve3d(const TopoDS_Edge& AnEdge, - const Standard_Real Tolerance, - const GeomAbs_Shape Continuity, - const Standard_Integer MaxDegree, - const Standard_Integer MaxSegment) + const Standard_Real Tolerance, + const GeomAbs_Shape Continuity, + const Standard_Integer MaxDegree, + const Standard_Integer MaxSegment) { Standard_Integer //ErrorCode, -// ReturnCode = 0, - ii, -// num_knots, - jj; + // ReturnCode = 0, + ii, + // num_knots, + jj; TopLoc_Location LocalLoc,L[2],LC; Standard_Real f,l,fc,lc, first[2], last[2], - tolerance, - max_deviation, - average_deviation ; + tolerance, + max_deviation, + average_deviation ; Handle(Geom2d_Curve) Curve2dPtr, Curve2dArray[2] ; Handle(Geom_Surface) SurfacePtr, SurfaceArray[2] ; @@ -319,17 +319,17 @@ Standard_Boolean BRepLib::BuildCurve3d(const TopoDS_Edge& AnEdge, const Handle(Geom_Curve) C = BRep_Tool::Curve(AnEdge,LocalLoc,f,l); if (!C.IsNull()) return Standard_True; -// -// this should not exists but UpdateEdge makes funny things -// if the edge is not same range -// + // + // this should not exists but UpdateEdge makes funny things + // if the edge is not same range + // if (! CheckSameRange(AnEdge, - Precision::Confusion())) { - SameRange(AnEdge, - Tolerance) ; + Precision::Confusion())) { + SameRange(AnEdge, + Tolerance) ; } - + // search a curve on a plane Handle(Geom_Surface) S; @@ -362,8 +362,8 @@ Standard_Boolean BRepLib::BuildCurve3d(const TopoDS_Edge& AnEdge, BRep_Builder B; Standard_Boolean is_closed ; - is_closed = AnEdge.Closed() ; - + is_closed = AnEdge.Closed() ; + B.UpdateEdge(AnEdge,C3d,LocalLoc,0.0e0); BRep_Tool::Range(AnEdge, S, LC, First, Last); B.Range(AnEdge, First, Last); //Do not forget 3D range.(PRO6412) @@ -380,49 +380,49 @@ Standard_Boolean BRepLib::BuildCurve3d(const TopoDS_Edge& AnEdge, if (!BRep_Tool::Degenerated(AnEdge)) { jj = 0 ; for (ii = 0 ; ii < 3 ; ii++ ) { - BRep_Tool::CurveOnSurface(TopoDS::Edge(AnEdge), - Curve2dPtr, - SurfacePtr, - LocalLoc, - fc, - lc, - ii) ; - - if (!Curve2dPtr.IsNull() && jj < 2){ - Curve2dArray[jj] = Curve2dPtr ; - SurfaceArray[jj] = SurfacePtr ; - L[jj] = LocalLoc ; - first[jj] = fc ; - last[jj] = lc ; - jj += 1 ; - } + BRep_Tool::CurveOnSurface(TopoDS::Edge(AnEdge), + Curve2dPtr, + SurfacePtr, + LocalLoc, + fc, + lc, + ii) ; + + if (!Curve2dPtr.IsNull() && jj < 2){ + Curve2dArray[jj] = Curve2dPtr ; + SurfaceArray[jj] = SurfacePtr ; + L[jj] = LocalLoc ; + first[jj] = fc ; + last[jj] = lc ; + jj += 1 ; + } } f = first[0] ; l = last[0] ; Curve2dPtr = Curve2dArray[0] ; SurfacePtr = SurfaceArray[0] ; - + Geom2dAdaptor_Curve AnAdaptor3dCurve2d (Curve2dPtr, f, l) ; GeomAdaptor_Surface AnAdaptor3dSurface (SurfacePtr) ; Handle(Geom2dAdaptor_HCurve) AnAdaptor3dCurve2dPtr = - new Geom2dAdaptor_HCurve(AnAdaptor3dCurve2d) ; + new Geom2dAdaptor_HCurve(AnAdaptor3dCurve2d) ; Handle(GeomAdaptor_HSurface) AnAdaptor3dSurfacePtr = - new GeomAdaptor_HSurface (AnAdaptor3dSurface) ; + new GeomAdaptor_HSurface (AnAdaptor3dSurface) ; Adaptor3d_CurveOnSurface CurveOnSurface( AnAdaptor3dCurve2dPtr, - AnAdaptor3dSurfacePtr) ; - + AnAdaptor3dSurfacePtr) ; + Handle(Geom_Curve) NewCurvePtr ; GeomLib::BuildCurve3d(Tolerance, - CurveOnSurface, - f, - l, - NewCurvePtr, - max_deviation, - average_deviation, - Continuity, - MaxDegree, - evaluateMaxSegment(MaxSegment,CurveOnSurface)) ; + CurveOnSurface, + f, + l, + NewCurvePtr, + max_deviation, + average_deviation, + Continuity, + MaxDegree, + evaluateMaxSegment(MaxSegment,CurveOnSurface)) ; BRep_Builder B; tolerance = BRep_Tool::Tolerance(AnEdge) ; //Patch @@ -433,24 +433,24 @@ Standard_Boolean BRepLib::BuildCurve3d(const TopoDS_Edge& AnEdge, Standard_Boolean is_closed ; is_closed = AnEdge.Closed() ; B.UpdateEdge(TopoDS::Edge(AnEdge), - NewCurvePtr, - L[0], - max_deviation) ; + NewCurvePtr, + L[0], + max_deviation) ; TopoDS_Edge E = AnEdge ; E.Closed(is_closed) ; if (jj == 1 ) { -// -// if there is only one curve on surface attached to the edge -// than it can be qualified sameparameter -// - B.SameParameter(TopoDS::Edge(AnEdge), - Standard_True) ; + // + // if there is only one curve on surface attached to the edge + // than it can be qualified sameparameter + // + B.SameParameter(TopoDS::Edge(AnEdge), + Standard_True) ; } } else { return Standard_False ; } - + } return Standard_True; } @@ -463,7 +463,7 @@ Standard_Boolean BRepLib::BuildCurves3d(const TopoDS_Shape& S) { return BRepLib::BuildCurves3d(S, - 1.0e-5) ; + 1.0e-5) ; } //======================================================================= @@ -472,22 +472,22 @@ Standard_Boolean BRepLib::BuildCurves3d(const TopoDS_Shape& S) //======================================================================= Standard_Boolean BRepLib::BuildCurves3d(const TopoDS_Shape& S, - const Standard_Real Tolerance, - const GeomAbs_Shape Continuity, - const Standard_Integer MaxDegree, - const Standard_Integer MaxSegment) + const Standard_Real Tolerance, + const GeomAbs_Shape Continuity, + const Standard_Integer MaxDegree, + const Standard_Integer MaxSegment) { Standard_Boolean boolean_value, - ok = Standard_True; + ok = Standard_True; TopTools_MapOfShape a_counter ; TopExp_Explorer ex(S,TopAbs_EDGE); while (ex.More()) { if (a_counter.Add(ex.Current())) { boolean_value = - BuildCurve3d(TopoDS::Edge(ex.Current()), - Tolerance, Continuity, - MaxDegree, MaxSegment); + BuildCurve3d(TopoDS::Edge(ex.Current()), + Tolerance, Continuity, + MaxDegree, MaxSegment); ok = ok && boolean_value ; } ex.Next(); @@ -500,216 +500,216 @@ Standard_Boolean BRepLib::BuildCurves3d(const TopoDS_Shape& S, //======================================================================= Standard_Boolean BRepLib::UpdateEdgeTol(const TopoDS_Edge& AnEdge, - const Standard_Real MinToleranceRequested, - const Standard_Real MaxToleranceToCheck) - { - - Standard_Integer curve_on_surface_index, - curve_index, - not_done, - has_closed_curve, - has_curve, - jj, - ii, - geom_reference_curve_flag = 0, - max_sampling_points = 90, - min_sampling_points = 30 ; - - Standard_Real factor = 100.0e0, - // sampling_array[2], - safe_factor = 1.4e0, - current_last, - current_first, - max_distance, - coded_edge_tolerance, - edge_tolerance = 0.0e0 ; - Handle(TColStd_HArray1OfReal) parameters_ptr ; - Handle(BRep_GCurve) geometric_representation_ptr ; - - if (BRep_Tool::Degenerated(AnEdge)) return Standard_False ; - coded_edge_tolerance = BRep_Tool::Tolerance(AnEdge) ; - if (coded_edge_tolerance > MaxToleranceToCheck) return Standard_False ; - - const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&AnEdge.TShape()); - BRep_ListOfCurveRepresentation& list_curve_rep = TE->ChangeCurves() ; - BRep_ListIteratorOfListOfCurveRepresentation an_iterator(list_curve_rep), - second_iterator(list_curve_rep) ; - Handle(Geom2d_Curve) curve2d_ptr, new_curve2d_ptr; - Handle(Geom_Surface) surface_ptr ; - TopLoc_Location local_location ; - GCPnts_QuasiUniformDeflection a_sampler ; - GeomAdaptor_Curve geom_reference_curve ; - Adaptor3d_CurveOnSurface curve_on_surface_reference ; - Handle(Geom_Curve) C = BRep_Tool::Curve(AnEdge, - local_location, - current_first, - current_last); - curve_on_surface_index = -1 ; - if (!C.IsNull()) { - if (! local_location.IsIdentity()) { - C = Handle(Geom_Curve):: - DownCast(C-> Transformed(local_location.Transformation()) ) ; - } - geom_reference_curve.Load(C) ; - geom_reference_curve_flag = 1 ; - a_sampler.Initialize(geom_reference_curve, - MinToleranceRequested * factor, - current_first, - current_last) ; + const Standard_Real MinToleranceRequested, + const Standard_Real MaxToleranceToCheck) +{ + + Standard_Integer curve_on_surface_index, + curve_index, + not_done, + has_closed_curve, + has_curve, + jj, + ii, + geom_reference_curve_flag = 0, + max_sampling_points = 90, + min_sampling_points = 30 ; + + Standard_Real factor = 100.0e0, + // sampling_array[2], + safe_factor = 1.4e0, + current_last, + current_first, + max_distance, + coded_edge_tolerance, + edge_tolerance = 0.0e0 ; + Handle(TColStd_HArray1OfReal) parameters_ptr ; + Handle(BRep_GCurve) geometric_representation_ptr ; + + if (BRep_Tool::Degenerated(AnEdge)) return Standard_False ; + coded_edge_tolerance = BRep_Tool::Tolerance(AnEdge) ; + if (coded_edge_tolerance > MaxToleranceToCheck) return Standard_False ; + + const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&AnEdge.TShape()); + BRep_ListOfCurveRepresentation& list_curve_rep = TE->ChangeCurves() ; + BRep_ListIteratorOfListOfCurveRepresentation an_iterator(list_curve_rep), + second_iterator(list_curve_rep) ; + Handle(Geom2d_Curve) curve2d_ptr, new_curve2d_ptr; + Handle(Geom_Surface) surface_ptr ; + TopLoc_Location local_location ; + GCPnts_QuasiUniformDeflection a_sampler ; + GeomAdaptor_Curve geom_reference_curve ; + Adaptor3d_CurveOnSurface curve_on_surface_reference ; + Handle(Geom_Curve) C = BRep_Tool::Curve(AnEdge, + local_location, + current_first, + current_last); + curve_on_surface_index = -1 ; + if (!C.IsNull()) { + if (! local_location.IsIdentity()) { + C = Handle(Geom_Curve):: + DownCast(C-> Transformed(local_location.Transformation()) ) ; } - else { - not_done = 1 ; - curve_on_surface_index = 0 ; - - while (not_done && an_iterator.More()) { - geometric_representation_ptr = - Handle(BRep_GCurve)::DownCast(second_iterator.Value()); - if (!geometric_representation_ptr.IsNull() - && geometric_representation_ptr->IsCurveOnSurface()) { - curve2d_ptr = geometric_representation_ptr->PCurve() ; - local_location = geometric_representation_ptr->Location() ; - current_first = geometric_representation_ptr->First(); - //first = geometric_representation_ptr->First(); - current_last = geometric_representation_ptr->Last(); - // must be inverted - // - if (! local_location.IsIdentity() ) { - surface_ptr = Handle(Geom_Surface):: - DownCast( geometric_representation_ptr->Surface()-> - Transformed(local_location.Transformation()) ) ; - } - else { - surface_ptr = - geometric_representation_ptr->Surface() ; - } - not_done = 0 ; - } - curve_on_surface_index += 1 ; + geom_reference_curve.Load(C) ; + geom_reference_curve_flag = 1 ; + a_sampler.Initialize(geom_reference_curve, + MinToleranceRequested * factor, + current_first, + current_last) ; + } + else { + not_done = 1 ; + curve_on_surface_index = 0 ; + + while (not_done && an_iterator.More()) { + geometric_representation_ptr = + Handle(BRep_GCurve)::DownCast(second_iterator.Value()); + if (!geometric_representation_ptr.IsNull() + && geometric_representation_ptr->IsCurveOnSurface()) { + curve2d_ptr = geometric_representation_ptr->PCurve() ; + local_location = geometric_representation_ptr->Location() ; + current_first = geometric_representation_ptr->First(); + //first = geometric_representation_ptr->First(); + current_last = geometric_representation_ptr->Last(); + // must be inverted + // + if (! local_location.IsIdentity() ) { + surface_ptr = Handle(Geom_Surface):: + DownCast( geometric_representation_ptr->Surface()-> + Transformed(local_location.Transformation()) ) ; + } + else { + surface_ptr = + geometric_representation_ptr->Surface() ; + } + not_done = 0 ; } - Geom2dAdaptor_Curve AnAdaptor3dCurve2d (curve2d_ptr) ; - GeomAdaptor_Surface AnAdaptor3dSurface (surface_ptr) ; - Handle(Geom2dAdaptor_HCurve) AnAdaptor3dCurve2dPtr = - new Geom2dAdaptor_HCurve(AnAdaptor3dCurve2d) ; - Handle(GeomAdaptor_HSurface) AnAdaptor3dSurfacePtr = - new GeomAdaptor_HSurface (AnAdaptor3dSurface) ; - curve_on_surface_reference.Load( AnAdaptor3dCurve2dPtr) ; - curve_on_surface_reference.Load( AnAdaptor3dSurfacePtr) ; - a_sampler.Initialize(curve_on_surface_reference, - MinToleranceRequested * factor, - current_first, - current_last) ; - } - TColStd_Array1OfReal sampling_parameters(1,a_sampler.NbPoints()) ; - for (ii = 1 ; ii <= a_sampler.NbPoints() ; ii++) { - sampling_parameters(ii) = a_sampler.Parameter(ii) ; - } - if (a_sampler.NbPoints() < min_sampling_points) { - GeomLib::DensifyArray1OfReal(min_sampling_points, - sampling_parameters, - parameters_ptr) ; - } - else if (a_sampler.NbPoints() > max_sampling_points) { - GeomLib::RemovePointsFromArray(max_sampling_points, - sampling_parameters, - parameters_ptr) ; + curve_on_surface_index += 1 ; } - else { - jj = 1 ; - parameters_ptr = - new TColStd_HArray1OfReal(1,sampling_parameters.Length()) ; - for (ii = sampling_parameters.Lower() ; ii <= sampling_parameters.Upper() ; ii++) { - parameters_ptr->ChangeArray1()(jj) = - sampling_parameters(ii) ; - jj +=1 ; - } + Geom2dAdaptor_Curve AnAdaptor3dCurve2d (curve2d_ptr) ; + GeomAdaptor_Surface AnAdaptor3dSurface (surface_ptr) ; + Handle(Geom2dAdaptor_HCurve) AnAdaptor3dCurve2dPtr = + new Geom2dAdaptor_HCurve(AnAdaptor3dCurve2d) ; + Handle(GeomAdaptor_HSurface) AnAdaptor3dSurfacePtr = + new GeomAdaptor_HSurface (AnAdaptor3dSurface) ; + curve_on_surface_reference.Load( AnAdaptor3dCurve2dPtr) ; + curve_on_surface_reference.Load( AnAdaptor3dSurfacePtr) ; + a_sampler.Initialize(curve_on_surface_reference, + MinToleranceRequested * factor, + current_first, + current_last) ; + } + TColStd_Array1OfReal sampling_parameters(1,a_sampler.NbPoints()) ; + for (ii = 1 ; ii <= a_sampler.NbPoints() ; ii++) { + sampling_parameters(ii) = a_sampler.Parameter(ii) ; + } + if (a_sampler.NbPoints() < min_sampling_points) { + GeomLib::DensifyArray1OfReal(min_sampling_points, + sampling_parameters, + parameters_ptr) ; + } + else if (a_sampler.NbPoints() > max_sampling_points) { + GeomLib::RemovePointsFromArray(max_sampling_points, + sampling_parameters, + parameters_ptr) ; + } + else { + jj = 1 ; + parameters_ptr = + new TColStd_HArray1OfReal(1,sampling_parameters.Length()) ; + for (ii = sampling_parameters.Lower() ; ii <= sampling_parameters.Upper() ; ii++) { + parameters_ptr->ChangeArray1()(jj) = + sampling_parameters(ii) ; + jj +=1 ; } - - curve_index = 0 ; + } + + curve_index = 0 ; + + while (second_iterator.More()) { + geometric_representation_ptr = + Handle(BRep_GCurve)::DownCast(second_iterator.Value()); + if (! geometric_representation_ptr.IsNull() && + curve_index != curve_on_surface_index) { + has_closed_curve = + has_curve = Standard_False ; + // first = geometric_representation_ptr->First(); + // last = geometric_representation_ptr->Last(); + local_location = geometric_representation_ptr->Location() ; + if (geometric_representation_ptr->IsCurveOnSurface()) { + curve2d_ptr = geometric_representation_ptr->PCurve() ; + has_curve = Standard_True ; + } + if (geometric_representation_ptr->IsCurveOnClosedSurface()) { + curve2d_ptr = geometric_representation_ptr->PCurve2() ; + has_closed_curve = Standard_True ; + } + + if (has_curve || + has_closed_curve) { + if (! local_location.IsIdentity() ) { + surface_ptr = Handle(Geom_Surface):: + DownCast( geometric_representation_ptr->Surface()-> + Transformed(local_location.Transformation()) ) ; + } + else { + surface_ptr = + geometric_representation_ptr->Surface() ; + } + Geom2dAdaptor_Curve an_adaptor_curve2d (curve2d_ptr) ; + GeomAdaptor_Surface an_adaptor_surface(surface_ptr) ; + Handle(Geom2dAdaptor_HCurve) an_adaptor_curve2d_ptr = + new Geom2dAdaptor_HCurve(an_adaptor_curve2d) ; + Handle(GeomAdaptor_HSurface) an_adaptor_surface_ptr = + new GeomAdaptor_HSurface (an_adaptor_surface) ; + Adaptor3d_CurveOnSurface a_curve_on_surface(an_adaptor_curve2d_ptr, + an_adaptor_surface_ptr) ; + + if (BRep_Tool::SameParameter(AnEdge)) { + + GeomLib::EvalMaxParametricDistance(a_curve_on_surface, + geom_reference_curve, + MinToleranceRequested, + parameters_ptr->Array1(), + max_distance) ; + } + else if (geom_reference_curve_flag) { + GeomLib::EvalMaxDistanceAlongParameter(a_curve_on_surface, + geom_reference_curve, + MinToleranceRequested, + parameters_ptr->Array1(), + max_distance) ; + } + else { + + GeomLib::EvalMaxDistanceAlongParameter(a_curve_on_surface, + curve_on_surface_reference, + MinToleranceRequested, + parameters_ptr->Array1(), + max_distance) ; + } + max_distance *= safe_factor ; + edge_tolerance = Max(max_distance, edge_tolerance) ; + } - while (second_iterator.More()) { - geometric_representation_ptr = - Handle(BRep_GCurve)::DownCast(second_iterator.Value()); - if (! geometric_representation_ptr.IsNull() && - curve_index != curve_on_surface_index) { - has_closed_curve = - has_curve = Standard_False ; -// first = geometric_representation_ptr->First(); -// last = geometric_representation_ptr->Last(); - local_location = geometric_representation_ptr->Location() ; - if (geometric_representation_ptr->IsCurveOnSurface()) { - curve2d_ptr = geometric_representation_ptr->PCurve() ; - has_curve = Standard_True ; - } - if (geometric_representation_ptr->IsCurveOnClosedSurface()) { - curve2d_ptr = geometric_representation_ptr->PCurve2() ; - has_closed_curve = Standard_True ; - } - - if (has_curve || - has_closed_curve) { - if (! local_location.IsIdentity() ) { - surface_ptr = Handle(Geom_Surface):: - DownCast( geometric_representation_ptr->Surface()-> - Transformed(local_location.Transformation()) ) ; - } - else { - surface_ptr = - geometric_representation_ptr->Surface() ; - } - Geom2dAdaptor_Curve an_adaptor_curve2d (curve2d_ptr) ; - GeomAdaptor_Surface an_adaptor_surface(surface_ptr) ; - Handle(Geom2dAdaptor_HCurve) an_adaptor_curve2d_ptr = - new Geom2dAdaptor_HCurve(an_adaptor_curve2d) ; - Handle(GeomAdaptor_HSurface) an_adaptor_surface_ptr = - new GeomAdaptor_HSurface (an_adaptor_surface) ; - Adaptor3d_CurveOnSurface a_curve_on_surface(an_adaptor_curve2d_ptr, - an_adaptor_surface_ptr) ; - - if (BRep_Tool::SameParameter(AnEdge)) { - - GeomLib::EvalMaxParametricDistance(a_curve_on_surface, - geom_reference_curve, - MinToleranceRequested, - parameters_ptr->Array1(), - max_distance) ; - } - else if (geom_reference_curve_flag) { - GeomLib::EvalMaxDistanceAlongParameter(a_curve_on_surface, - geom_reference_curve, - MinToleranceRequested, - parameters_ptr->Array1(), - max_distance) ; - } - else { - - GeomLib::EvalMaxDistanceAlongParameter(a_curve_on_surface, - curve_on_surface_reference, - MinToleranceRequested, - parameters_ptr->Array1(), - max_distance) ; - } - max_distance *= safe_factor ; - edge_tolerance = Max(max_distance, edge_tolerance) ; - } - - } - curve_index += 1 ; - second_iterator.Next() ; } - - TE->Tolerance(edge_tolerance); - return Standard_True ; - + curve_index += 1 ; + second_iterator.Next() ; } + + TE->Tolerance(edge_tolerance); + return Standard_True ; + +} //======================================================================= //function : UpdateEdgeTolerance //purpose : //======================================================================= Standard_Boolean BRepLib::UpdateEdgeTolerance(const TopoDS_Shape& S, - const Standard_Real MinToleranceRequested, - const Standard_Real MaxToleranceToCheck) + const Standard_Real MinToleranceRequested, + const Standard_Real MaxToleranceToCheck) { TopExp_Explorer ex(S,TopAbs_EDGE); TopTools_MapOfShape a_counter ; @@ -720,11 +720,11 @@ Standard_Boolean BRepLib::UpdateEdgeTolerance(const TopoDS_Shape& S, while (ex.More()) { if (a_counter.Add(ex.Current())) { local_flag = - BRepLib::UpdateEdgeTol(TopoDS::Edge(ex.Current()), - MinToleranceRequested, - MaxToleranceToCheck) ; + BRepLib::UpdateEdgeTol(TopoDS::Edge(ex.Current()), + MinToleranceRequested, + MaxToleranceToCheck) ; if (local_flag && ! return_status) { - return_status = Standard_True ; + return_status = Standard_True ; } } ex.Next(); @@ -738,7 +738,7 @@ Standard_Boolean BRepLib::UpdateEdgeTolerance(const TopoDS_Shape& S, //======================================================================= static void SetEdgeTol(const TopoDS_Edge& E, - const TopoDS_Face& F) + const TopoDS_Face& F) { TopLoc_Location L; const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L); @@ -763,7 +763,7 @@ static void SetEdgeTol(const TopoDS_Edge& E, Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve(); Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface(); - + TopLoc_Location LC; Standard_Real First, Last; GeomAdaptor_Curve& GAC = HC->ChangeCurve(); @@ -772,11 +772,11 @@ static void SetEdgeTol(const TopoDS_Edge& E, if (!LC.IsIdentity()) { GP = Handle(Geom_Plane)::DownCast( - GP->Transformed(LC.Transformation())); + GP->Transformed(LC.Transformation())); } GeomAdaptor_Surface& GAS = HS->ChangeSurface(); GAS.Load(GP); - + ProjLib_ProjectedCurve Proj(HS,HC); Handle(Geom2d_Curve) pc = Geom2dAdaptor::MakeCurve(Proj); @@ -790,7 +790,13 @@ static void SetEdgeTol(const TopoDS_Edge& E, gp_Pnt Pc3d = HC->Value(u); gp_Pnt2d p2d = pc->Value(u); gp_Pnt Pcons = ElSLib::Value(p2d.X(),p2d.Y(),pln); + Standard_Real eps = Max(Pc3d.XYZ().SquareModulus(), Pcons.XYZ().SquareModulus()); + eps = Epsilon(eps); Standard_Real temp = Pc3d.SquareDistance(Pcons); + if(temp <= eps) + { + temp = 0.; + } if(temp > d2) d2 = temp; } d2 = 1.5*sqrt(d2); @@ -802,8 +808,8 @@ static void SetEdgeTol(const TopoDS_Edge& E, //purpose : //======================================================================= void BRepLib::SameParameter(const TopoDS_Shape& S, - const Standard_Real Tolerance, - const Standard_Boolean forced) + const Standard_Real Tolerance, + const Standard_Boolean forced) { TopExp_Explorer ex(S,TopAbs_EDGE); TopTools_MapOfShape Done; @@ -812,8 +818,8 @@ void BRepLib::SameParameter(const TopoDS_Shape& S, while (ex.More()) { if (Done.Add(ex.Current())) { if (forced) { - brB.SameRange(TopoDS::Edge(ex.Current()), Standard_False); - brB.SameParameter(TopoDS::Edge(ex.Current()), Standard_False); + brB.SameRange(TopoDS::Edge(ex.Current()), Standard_False); + brB.SameParameter(TopoDS::Edge(ex.Current()), Standard_False); } BRepLib::SameParameter(TopoDS::Edge(ex.Current()),Tolerance); } @@ -843,10 +849,10 @@ void BRepLib::SameParameter(const TopoDS_Shape& S, // for vertex extremities it is required to find something else //================================================================ static Standard_Boolean EvalTol(const Handle(Geom2d_Curve)& pc, - const Handle(Geom_Surface)& s, - const GeomAdaptor_Curve& gac, - const Standard_Real tol, - Standard_Real& tolbail) + const Handle(Geom_Surface)& s, + const GeomAdaptor_Curve& gac, + const Standard_Real tol, + Standard_Real& tolbail) { Standard_Integer ok = 0; Standard_Real f = gac.FirstParameter(); @@ -872,33 +878,30 @@ static Standard_Boolean EvalTol(const Handle(Geom2d_Curve)& pc, } static Standard_Real ComputeTol(const Handle(Adaptor3d_HCurve)& c3d, - const Handle(Adaptor2d_HCurve2d)& c2d, - const Handle(Adaptor3d_HSurface)& surf, - const Standard_Integer nbp) + const Handle(Adaptor2d_HCurve2d)& c2d, + const Handle(Adaptor3d_HSurface)& surf, + const Standard_Integer nbp) { TColStd_Array1OfReal dist(1,nbp+10); dist.Init(-1.); - Adaptor3d_CurveOnSurface cons(c2d,surf); Standard_Real d2 = 0.; - Standard_Integer nn = nbp; - Standard_Real unsurnn = 1./nn; Standard_Real first = c3d->FirstParameter(); Standard_Real last = c3d->LastParameter(); Standard_Integer i = 0; - for(i = 0; i <= nn; i++){ - Standard_Real t = unsurnn*i; - Standard_Real u = first*(1.-t) + last*t; + for(i = 0; i <= nbp; i++){ + const Standard_Real t = IntToReal(i)/IntToReal(nbp); + const Standard_Real u = first*(1.-t) + last*t; gp_Pnt Pc3d = c3d->Value(u); gp_Pnt Pcons = cons.Value(u); if (Precision::IsInfinite(Pcons.X()) || - Precision::IsInfinite(Pcons.Y()) || - Precision::IsInfinite(Pcons.Z())) { - d2=Precision::Infinite(); - break; + Precision::IsInfinite(Pcons.Y()) || + Precision::IsInfinite(Pcons.Z())) { + d2=Precision::Infinite(); + break; } Standard_Real temp = Pc3d.SquareDistance(Pcons); @@ -922,25 +925,23 @@ static Standard_Real ComputeTol(const Handle(Adaptor3d_HCurve)& c3d, else N2++; } - if( N1 > N2 && N2 != 0 ) N3 = 100*N2/(N1+N2); - if( N3 < 10 && N3 != 0 ) { - ana = Standard_True; - for( i = 1; i<= nbp+10; i++) - if( dist(i) > 0 && dist(i) < 1.0 ) - if( dist(i) > D2 ) D2 = dist(i); - } + if( N1 > N2 && N2 != 0 ) N3 = 100*N2/(N1+N2); + if( N3 < 10 && N3 != 0 ) { + ana = Standard_True; + for( i = 1; i<= nbp+10; i++) + if( dist(i) > 0 && dist(i) < 1.0 ) + if( dist(i) > D2 ) D2 = dist(i); + } - //d2 = 1.5*sqrt(d2); - d2 = (!ana) ? 1.5*sqrt(d2) : 1.5*sqrt(D2); - if(d2<1.e-7) d2 = 1.e-7; + //d2 = 1.5*sqrt(d2); + d2 = (!ana) ? 1.5*sqrt(d2) : 1.5*sqrt(D2); + if(d2<1.e-7) d2 = 1.e-7; - return d2; + return d2; } - - void BRepLib::SameParameter(const TopoDS_Edge& AnEdge, - const Standard_Real Tolerance) + const Standard_Real Tolerance) { if (BRep_Tool::SameParameter(AnEdge)) return; @@ -959,7 +960,7 @@ void BRepLib::SameParameter(const TopoDS_Edge& AnEdge, const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &AnEdge.TShape()); BRep_ListOfCurveRepresentation& CList = TE->ChangeCurves(); BRep_ListIteratorOfListOfCurveRepresentation It(CList); - + Standard_Boolean NotDone = Standard_True; while (NotDone && It.More()) { @@ -980,10 +981,10 @@ void BRepLib::SameParameter(const TopoDS_Edge& AnEdge, Standard_Boolean m_TrimmedPeriodical = Standard_False; Handle(Standard_Type) TheType = C3d->DynamicType(); if( TheType == STANDARD_TYPE(Geom_TrimmedCurve)) - { - const Handle(Geom_Curve)& gtC = (*((Handle(Geom_TrimmedCurve)*)&C3d))->BasisCurve(); - m_TrimmedPeriodical = gtC->IsPeriodic(); - } + { + const Handle(Geom_Curve)& gtC = (*((Handle(Geom_TrimmedCurve)*)&C3d))->BasisCurve(); + m_TrimmedPeriodical = gtC->IsPeriodic(); + } // modified by NIZHNY-OCC486 Tue Aug 27 17:15:17 2002 . BRep_Builder B; @@ -994,10 +995,10 @@ void BRepLib::SameParameter(const TopoDS_Edge& AnEdge, //if (Udeb > f3d) f3d = Udeb; //if (l3d > Ufin) l3d = Ufin; if(!m_TrimmedPeriodical) - { - if (Udeb > f3d) f3d = Udeb; - if (l3d > Ufin) l3d = Ufin; - } + { + if (Udeb > f3d) f3d = Udeb; + if (l3d > Ufin) l3d = Ufin; + } // modified by NIZHNY-OCC486 Tue Aug 27 17:17:55 2002 . } if(!L3d.IsIdentity()){ @@ -1008,9 +1009,9 @@ void BRepLib::SameParameter(const TopoDS_Edge& AnEdge, Standard_Boolean IsSameP = 1; Standard_Real maxdist = 0.; -// Modified by skv - Thu Jun 3 12:39:19 2004 OCC5898 Begin + // Modified by skv - Thu Jun 3 12:39:19 2004 OCC5898 Begin Standard_Real anEdgeTol = BRep_Tool::Tolerance(AnEdge); -// Modified by skv - Thu Jun 3 12:39:20 2004 OCC5898 End + // Modified by skv - Thu Jun 3 12:39:20 2004 OCC5898 End Standard_Boolean SameRange = BRep_Tool::SameRange(AnEdge); Standard_Boolean YaPCu = Standard_False; It.Initialize(CList); @@ -1027,252 +1028,253 @@ void BRepLib::SameParameter(const TopoDS_Edge& AnEdge, TopLoc_Location PCLoc = GCurve->Location(); S = GCurve->Surface(); if (!PCLoc.IsIdentity() ) { - S = Handle(Geom_Surface)::DownCast(S->Transformed(PCLoc.Transformation())); + S = Handle(Geom_Surface)::DownCast(S->Transformed(PCLoc.Transformation())); } + GAS.Load(S); if (GCurve->IsCurveOnClosedSurface()) { - PC[1] = GCurve->PCurve2(); + PC[1] = GCurve->PCurve2(); } - + // Eval tol2d to compute SameRange Standard_Real UResol = Max(GAS.UResolution(Tolerance), Precision::PConfusion()); Standard_Real VResol = Max(GAS.VResolution(Tolerance), Precision::PConfusion()); Standard_Real Tol2d = Min(UResol, VResol); for(Standard_Integer i = 0; i < 2; i++){ - Handle(Geom2d_Curve) curPC = PC[i]; - Standard_Boolean updatepc = 0; - if(curPC.IsNull()) break; - if(!SameRange){ - GeomLib::SameRange(Tol2d, - PC[i],GCurve->First(),GCurve->Last(), - f3d,l3d,curPC); - - updatepc = (curPC != PC[i]); - - } - Standard_Boolean goodpc = 1; - GAC2d.Load(curPC,f3d,l3d); - - Standard_Real error = ComputeTol(HC, HC2d, HS, NCONTROL); - - if(GAC2d.GetType() == GeomAbs_BSplineCurve && - GAC2d.Continuity() == GeomAbs_C0) { - Handle(Geom2d_BSplineCurve) bs2d = GAC2d.BSpline(); - Handle(Geom2d_BSplineCurve) bs2dsov = bs2d; - Standard_Real fC0 = bs2d->FirstParameter(), lC0 = bs2d->LastParameter(); - Standard_Boolean repar = Standard_True; - gp_Pnt2d OriginPoint; - bs2d->D0(fC0, OriginPoint); - Geom2dConvert::C0BSplineToC1BSplineCurve(bs2d, Tol2d); - isBSP = Standard_True; - - if(bs2d->IsPeriodic()) { // -------- IFV, Jan 2000 - gp_Pnt2d NewOriginPoint; - bs2d->D0(bs2d->FirstParameter(), NewOriginPoint); - if(Abs(OriginPoint.X() - NewOriginPoint.X()) > Precision::PConfusion() || - Abs(OriginPoint.Y() - NewOriginPoint.Y()) > Precision::PConfusion() ) { - - TColStd_Array1OfReal Knotbs2d (1, bs2d->NbKnots()); - bs2d->Knots(Knotbs2d); - - for(Standard_Integer Index = 1; Index <= bs2d->NbKnots(); Index++) { - bs2d->D0(Knotbs2d(Index), NewOriginPoint); - if(Abs(OriginPoint.X() - NewOriginPoint.X()) > Precision::PConfusion() || - Abs(OriginPoint.Y() - NewOriginPoint.Y()) > Precision::PConfusion() ) continue; - - bs2d->SetOrigin(Index); - break; - } - } - } - - if(bs2d->Continuity() == GeomAbs_C0) { - Standard_Real tolbail; - if(EvalTol(curPC,S,GAC,Tolerance,tolbail)){ - bs2d = bs2dsov; - Standard_Real UResbail = GAS.UResolution(tolbail); - Standard_Real VResbail = GAS.VResolution(tolbail); - Standard_Real Tol2dbail = Min(UResbail,VResbail); - bs2d->D0(bs2d->FirstParameter(), OriginPoint); - - Standard_Integer nbp = bs2d->NbPoles(); - TColgp_Array1OfPnt2d poles(1,nbp); - bs2d->Poles(poles); - gp_Pnt2d p = poles(1), p1; - Standard_Real d = Precision::Infinite(); - for(Standard_Integer ip = 2; ip <= nbp; ip++) { - p1 = poles(ip); - d = Min(d,p.SquareDistance(p1)); - p = p1; - } - d = sqrt(d)*.1; - - Tol2dbail = Max(Min(Tol2dbail,d),Tol2d); - - Geom2dConvert::C0BSplineToC1BSplineCurve(bs2d,Tol2dbail); - - if(bs2d->IsPeriodic()) { // -------- IFV, Jan 2000 - gp_Pnt2d NewOriginPoint; - bs2d->D0(bs2d->FirstParameter(), NewOriginPoint); - if(Abs(OriginPoint.X() - NewOriginPoint.X()) > Precision::PConfusion() || - Abs(OriginPoint.Y() - NewOriginPoint.Y()) > Precision::PConfusion() ) { - - TColStd_Array1OfReal Knotbs2d (1, bs2d->NbKnots()); - bs2d->Knots(Knotbs2d); - - for(Standard_Integer Index = 1; Index <= bs2d->NbKnots(); Index++) { - bs2d->D0(Knotbs2d(Index), NewOriginPoint); - if(Abs(OriginPoint.X() - NewOriginPoint.X()) > Precision::PConfusion() || - Abs(OriginPoint.Y() - NewOriginPoint.Y()) > Precision::PConfusion() ) continue; - - bs2d->SetOrigin(Index); - break; - } - } - } - - - if(bs2d->Continuity() == GeomAbs_C0) { - goodpc = 1; - bs2d = bs2dsov; - repar = Standard_False; - } - } - else goodpc = 0; - } - - if(goodpc){ - if(repar) { - Standard_Integer NbKnots = bs2d->NbKnots(); - TColStd_Array1OfReal Knots(1,NbKnots); - bs2d->Knots(Knots); - // BSplCLib::Reparametrize(f3d,l3d,Knots); - BSplCLib::Reparametrize(fC0,lC0,Knots); - bs2d->SetKnots(Knots); - GAC2d.Load(bs2d,f3d,l3d); - curPC = bs2d; - Standard_Boolean updatepcsov = updatepc; - updatepc = Standard_True; - - Standard_Real error1 = ComputeTol(HC, HC2d, HS, NCONTROL); - if(error1 > error) { - bs2d = bs2dsov; - GAC2d.Load(bs2d,f3d,l3d); - curPC = bs2d; - updatepc = updatepcsov; - isANA = Standard_True; - } - else { - error = error1; - } - } - - //check, if new BSpline "good" or not --------- IFV, Jan of 2000 - GeomAbs_Shape cont = bs2d->Continuity(); - Standard_Boolean IsBad = Standard_False; - - if(cont > GeomAbs_C0 && error > Max(1.e-3,Tolerance)) { - Standard_Integer NbKnots = bs2d->NbKnots(); - TColStd_Array1OfReal Knots(1,NbKnots); - bs2d->Knots(Knots); - Standard_Real critratio = 10.; - Standard_Real dtprev = Knots(2) - Knots(1), dtratio = 1.; - Standard_Real dtmin = dtprev; - Standard_Real dtcur; - for(Standard_Integer j = 2; j < NbKnots; j++) { - dtcur = Knots(j+1) - Knots(j); - dtmin = Min(dtmin, dtcur); - - if(IsBad) continue; - - if(dtcur > dtprev) dtratio = dtcur/dtprev; - else dtratio = dtprev/dtcur; - if(dtratio > critratio) {IsBad = Standard_True;} - dtprev = dtcur; - - } - if(IsBad) { - // To avoid failures in Approx_CurvilinearParameter - bs2d->Resolution(Max(1.e-3,Tolerance), dtcur); - if(dtmin < dtcur) IsBad = Standard_False; - } - } - - - if(IsBad ) { //if BSpline "bad", try to reparametrize it - // by its curve length - -// GeomAbs_Shape cont = bs2d->Continuity(); - if(cont > GeomAbs_C2) cont = GeomAbs_C2; - Standard_Integer maxdeg = bs2d->Degree(); - if(maxdeg == 1) maxdeg = 14; - Approx_CurvilinearParameter AppCurPar(HC2d, HS, Max(1.e-3,Tolerance), - cont, maxdeg, 10); - if(AppCurPar.IsDone() || AppCurPar.HasResult()) { - bs2d = AppCurPar.Curve2d1(); - GAC2d.Load(bs2d,f3d,l3d); - curPC = bs2d; - - if(Abs(bs2d->FirstParameter() - fC0) > Tol2d || - Abs(bs2d->LastParameter() - lC0) > Tol2d ) { - Standard_Integer NbKnots = bs2d->NbKnots(); - TColStd_Array1OfReal Knots(1,NbKnots); - bs2d->Knots(Knots); -// BSplCLib::Reparametrize(f3d,l3d,Knots); - BSplCLib::Reparametrize(fC0,lC0,Knots); - bs2d->SetKnots(Knots); - GAC2d.Load(bs2d,f3d,l3d); - curPC = bs2d; - - } - } - } - - - } - } - - - if(goodpc){ -// Approx_SameParameter SameP(HC,HC2d,HS,Tolerance); - Standard_Real aTol = (isANA && isBSP) ? 1.e-7 : Tolerance; - Approx_SameParameter SameP(HC,HC2d,HS,aTol); - - if (SameP.IsSameParameter()) { - maxdist = Max(maxdist,SameP.TolReached()); - if(updatepc){ - if (i == 0) GCurve->PCurve(curPC); - else GCurve->PCurve2(curPC); - } - } - else if (SameP.IsDone()) { - Standard_Real tolreached = SameP.TolReached(); - if(tolreached < error) { - curPC = SameP.Curve2d(); - updatepc = Standard_True; - maxdist = Max(maxdist,tolreached); - } - else { - maxdist = Max(maxdist, error); - } - if(updatepc){ - if (i == 0) GCurve->PCurve(curPC); - else GCurve->PCurve2(curPC); - } - } - else IsSameP = 0; - - } - else IsSameP = 0; - -// Modified by skv - Thu Jun 3 12:39:19 2004 OCC5898 Begin - if (!IsSameP) { - if (anEdgeTol > error) { - maxdist = Max(maxdist, anEdgeTol); - IsSameP = Standard_True; - } - } -// Modified by skv - Thu Jun 3 12:39:20 2004 OCC5898 End + Handle(Geom2d_Curve) curPC = PC[i]; + Standard_Boolean updatepc = 0; + if(curPC.IsNull()) break; + if(!SameRange){ + GeomLib::SameRange(Tol2d, + PC[i],GCurve->First(),GCurve->Last(), + f3d,l3d,curPC); + + updatepc = (curPC != PC[i]); + + } + Standard_Boolean goodpc = 1; + GAC2d.Load(curPC,f3d,l3d); + + Standard_Real error = ComputeTol(HC, HC2d, HS, NCONTROL); + + if(GAC2d.GetType() == GeomAbs_BSplineCurve && + GAC2d.Continuity() == GeomAbs_C0) { + Handle(Geom2d_BSplineCurve) bs2d = GAC2d.BSpline(); + Handle(Geom2d_BSplineCurve) bs2dsov = bs2d; + Standard_Real fC0 = bs2d->FirstParameter(), lC0 = bs2d->LastParameter(); + Standard_Boolean repar = Standard_True; + gp_Pnt2d OriginPoint; + bs2d->D0(fC0, OriginPoint); + Geom2dConvert::C0BSplineToC1BSplineCurve(bs2d, Tol2d); + isBSP = Standard_True; + + if(bs2d->IsPeriodic()) { // -------- IFV, Jan 2000 + gp_Pnt2d NewOriginPoint; + bs2d->D0(bs2d->FirstParameter(), NewOriginPoint); + if(Abs(OriginPoint.X() - NewOriginPoint.X()) > Precision::PConfusion() || + Abs(OriginPoint.Y() - NewOriginPoint.Y()) > Precision::PConfusion() ) { + + TColStd_Array1OfReal Knotbs2d (1, bs2d->NbKnots()); + bs2d->Knots(Knotbs2d); + + for(Standard_Integer Index = 1; Index <= bs2d->NbKnots(); Index++) { + bs2d->D0(Knotbs2d(Index), NewOriginPoint); + if(Abs(OriginPoint.X() - NewOriginPoint.X()) > Precision::PConfusion() || + Abs(OriginPoint.Y() - NewOriginPoint.Y()) > Precision::PConfusion() ) continue; + + bs2d->SetOrigin(Index); + break; + } + } + } + + if(bs2d->Continuity() == GeomAbs_C0) { + Standard_Real tolbail; + if(EvalTol(curPC,S,GAC,Tolerance,tolbail)){ + bs2d = bs2dsov; + Standard_Real UResbail = GAS.UResolution(tolbail); + Standard_Real VResbail = GAS.VResolution(tolbail); + Standard_Real Tol2dbail = Min(UResbail,VResbail); + bs2d->D0(bs2d->FirstParameter(), OriginPoint); + + Standard_Integer nbp = bs2d->NbPoles(); + TColgp_Array1OfPnt2d poles(1,nbp); + bs2d->Poles(poles); + gp_Pnt2d p = poles(1), p1; + Standard_Real d = Precision::Infinite(); + for(Standard_Integer ip = 2; ip <= nbp; ip++) { + p1 = poles(ip); + d = Min(d,p.SquareDistance(p1)); + p = p1; + } + d = sqrt(d)*.1; + + Tol2dbail = Max(Min(Tol2dbail,d),Tol2d); + + Geom2dConvert::C0BSplineToC1BSplineCurve(bs2d,Tol2dbail); + + if(bs2d->IsPeriodic()) { // -------- IFV, Jan 2000 + gp_Pnt2d NewOriginPoint; + bs2d->D0(bs2d->FirstParameter(), NewOriginPoint); + if(Abs(OriginPoint.X() - NewOriginPoint.X()) > Precision::PConfusion() || + Abs(OriginPoint.Y() - NewOriginPoint.Y()) > Precision::PConfusion() ) { + + TColStd_Array1OfReal Knotbs2d (1, bs2d->NbKnots()); + bs2d->Knots(Knotbs2d); + + for(Standard_Integer Index = 1; Index <= bs2d->NbKnots(); Index++) { + bs2d->D0(Knotbs2d(Index), NewOriginPoint); + if(Abs(OriginPoint.X() - NewOriginPoint.X()) > Precision::PConfusion() || + Abs(OriginPoint.Y() - NewOriginPoint.Y()) > Precision::PConfusion() ) continue; + + bs2d->SetOrigin(Index); + break; + } + } + } + + + if(bs2d->Continuity() == GeomAbs_C0) { + goodpc = 1; + bs2d = bs2dsov; + repar = Standard_False; + } + } + else goodpc = 0; + } + + if(goodpc){ + if(repar) { + Standard_Integer NbKnots = bs2d->NbKnots(); + TColStd_Array1OfReal Knots(1,NbKnots); + bs2d->Knots(Knots); + // BSplCLib::Reparametrize(f3d,l3d,Knots); + BSplCLib::Reparametrize(fC0,lC0,Knots); + bs2d->SetKnots(Knots); + GAC2d.Load(bs2d,f3d,l3d); + curPC = bs2d; + Standard_Boolean updatepcsov = updatepc; + updatepc = Standard_True; + + Standard_Real error1 = ComputeTol(HC, HC2d, HS, NCONTROL); + if(error1 > error) { + bs2d = bs2dsov; + GAC2d.Load(bs2d,f3d,l3d); + curPC = bs2d; + updatepc = updatepcsov; + isANA = Standard_True; + } + else { + error = error1; + } + } + + //check, if new BSpline "good" or not --------- IFV, Jan of 2000 + GeomAbs_Shape cont = bs2d->Continuity(); + Standard_Boolean IsBad = Standard_False; + + if(cont > GeomAbs_C0 && error > Max(1.e-3,Tolerance)) { + Standard_Integer NbKnots = bs2d->NbKnots(); + TColStd_Array1OfReal Knots(1,NbKnots); + bs2d->Knots(Knots); + Standard_Real critratio = 10.; + Standard_Real dtprev = Knots(2) - Knots(1), dtratio = 1.; + Standard_Real dtmin = dtprev; + Standard_Real dtcur; + for(Standard_Integer j = 2; j < NbKnots; j++) { + dtcur = Knots(j+1) - Knots(j); + dtmin = Min(dtmin, dtcur); + + if(IsBad) continue; + + if(dtcur > dtprev) dtratio = dtcur/dtprev; + else dtratio = dtprev/dtcur; + if(dtratio > critratio) {IsBad = Standard_True;} + dtprev = dtcur; + + } + if(IsBad) { + // To avoid failures in Approx_CurvilinearParameter + bs2d->Resolution(Max(1.e-3,Tolerance), dtcur); + if(dtmin < dtcur) IsBad = Standard_False; + } + } + + + if(IsBad ) { //if BSpline "bad", try to reparametrize it + // by its curve length + + // GeomAbs_Shape cont = bs2d->Continuity(); + if(cont > GeomAbs_C2) cont = GeomAbs_C2; + Standard_Integer maxdeg = bs2d->Degree(); + if(maxdeg == 1) maxdeg = 14; + Approx_CurvilinearParameter AppCurPar(HC2d, HS, Max(1.e-3,Tolerance), + cont, maxdeg, 10); + if(AppCurPar.IsDone() || AppCurPar.HasResult()) { + bs2d = AppCurPar.Curve2d1(); + GAC2d.Load(bs2d,f3d,l3d); + curPC = bs2d; + + if(Abs(bs2d->FirstParameter() - fC0) > Tol2d || + Abs(bs2d->LastParameter() - lC0) > Tol2d ) { + Standard_Integer NbKnots = bs2d->NbKnots(); + TColStd_Array1OfReal Knots(1,NbKnots); + bs2d->Knots(Knots); + // BSplCLib::Reparametrize(f3d,l3d,Knots); + BSplCLib::Reparametrize(fC0,lC0,Knots); + bs2d->SetKnots(Knots); + GAC2d.Load(bs2d,f3d,l3d); + curPC = bs2d; + + } + } + } + + + } + } + + + if(goodpc){ + // Approx_SameParameter SameP(HC,HC2d,HS,Tolerance); + Standard_Real aTol = (isANA && isBSP) ? 1.e-7 : Tolerance; + Approx_SameParameter SameP(HC,HC2d,HS,aTol); + + if (SameP.IsSameParameter()) { + maxdist = Max(maxdist,SameP.TolReached()); + if(updatepc){ + if (i == 0) GCurve->PCurve(curPC); + else GCurve->PCurve2(curPC); + } + } + else if (SameP.IsDone()) { + Standard_Real tolreached = SameP.TolReached(); + if(tolreached < error) { + curPC = SameP.Curve2d(); + updatepc = Standard_True; + maxdist = Max(maxdist,tolreached); + } + else { + maxdist = Max(maxdist, error); + } + if(updatepc){ + if (i == 0) GCurve->PCurve(curPC); + else GCurve->PCurve2(curPC); + } + } + else IsSameP = 0; + + } + else IsSameP = 0; + + // Modified by skv - Thu Jun 3 12:39:19 2004 OCC5898 Begin + if (!IsSameP) { + if (anEdgeTol > error) { + maxdist = Max(maxdist, anEdgeTol); + IsSameP = Standard_True; + } + } + // Modified by skv - Thu Jun 3 12:39:20 2004 OCC5898 End } } It.Next() ; @@ -1291,9 +1293,9 @@ void BRepLib::SameParameter(const TopoDS_Edge& AnEdge, TopoDS_Vertex V1,V2; TopExp::Vertices(AnEdge,V1,V2); if (!V1.IsNull()) - B.UpdateVertex(V1,maxdist); + B.UpdateVertex(V1,maxdist); if (!V2.IsNull()) - B.UpdateVertex(V2,maxdist); + B.UpdateVertex(V2,maxdist); TE->Modified(Standard_True); TE->Tolerance(maxdist); } @@ -1306,11 +1308,11 @@ void BRepLib::SameParameter(const TopoDS_Edge& AnEdge, //purpose : //======================================================================= void BRepLib::UpdateTolerances(const TopoDS_Shape& aShape, - const Standard_Boolean verifyTolerance) + const Standard_Boolean verifyTolerance) { -// Harmonize tolerances -// with rule Tolerance(VERTEX)>=Tolerance(EDGE)>=Tolerance(FACE) + // Harmonize tolerances + // with rule Tolerance(VERTEX)>=Tolerance(EDGE)>=Tolerance(FACE) BRep_Builder B; Standard_Real tol=0; if (verifyTolerance) { @@ -1324,47 +1326,47 @@ void BRepLib::UpdateTolerances(const TopoDS_Shape& aShape, const TopoDS_Face& curf=TopoDS::Face(ex.Current()); S = BRep_Tool::Surface(curf, l); if (!S.IsNull()) { - aB.SetVoid(); - BRepBndLib::Add(curf,aB); - if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) { - S = (*((Handle(Geom_RectangularTrimmedSurface)*)&S))->BasisSurface(); - } - GeomAdaptor_Surface AS(S); - switch (AS.GetType()) { - case GeomAbs_Plane: - case GeomAbs_Cylinder: - case GeomAbs_Cone: - { - tol=Precision::Confusion(); - break; - } - case GeomAbs_Sphere: - case GeomAbs_Torus: - { - tol=Precision::Confusion()*2; - break; - } - default: - tol=Precision::Confusion()*4; - } - if (!aB.IsWhole()) { - aB.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); - dMax=1.; - if (!aB.IsOpenXmin() && !aB.IsOpenXmax()) dMax=aXmax-aXmin; - if (!aB.IsOpenYmin() && !aB.IsOpenYmax()) aYmin=aYmax-aYmin; - if (!aB.IsOpenZmin() && !aB.IsOpenZmax()) aZmin=aZmax-aZmin; - if (aYmin>dMax) dMax=aYmin; - if (aZmin>dMax) dMax=aZmin; - tol=tol*dMax; - // Do not process tolerances > 1. - if (tol>1.) tol=0.99; - } - const Handle(BRep_TFace)& Tf = *((Handle(BRep_TFace)*)&curf.TShape()); - Tf->Tolerance(tol); + aB.SetVoid(); + BRepBndLib::Add(curf,aB); + if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) { + S = (*((Handle(Geom_RectangularTrimmedSurface)*)&S))->BasisSurface(); + } + GeomAdaptor_Surface AS(S); + switch (AS.GetType()) { + case GeomAbs_Plane: + case GeomAbs_Cylinder: + case GeomAbs_Cone: + { + tol=Precision::Confusion(); + break; + } + case GeomAbs_Sphere: + case GeomAbs_Torus: + { + tol=Precision::Confusion()*2; + break; + } + default: + tol=Precision::Confusion()*4; + } + if (!aB.IsWhole()) { + aB.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); + dMax=1.; + if (!aB.IsOpenXmin() && !aB.IsOpenXmax()) dMax=aXmax-aXmin; + if (!aB.IsOpenYmin() && !aB.IsOpenYmax()) aYmin=aYmax-aYmin; + if (!aB.IsOpenZmin() && !aB.IsOpenZmax()) aZmin=aZmax-aZmin; + if (aYmin>dMax) dMax=aYmin; + if (aZmin>dMax) dMax=aZmin; + tol=tol*dMax; + // Do not process tolerances > 1. + if (tol>1.) tol=0.99; + } + const Handle(BRep_TFace)& Tf = *((Handle(BRep_TFace)*)&curf.TShape()); + Tf->Tolerance(tol); } } } - + //Process edges TopTools_IndexedDataMapOfShapeListOfShape parents; TopExp::MapShapesAndAncestors(aShape, TopAbs_EDGE, TopAbs_FACE, parents); @@ -1403,37 +1405,37 @@ void BRepLib::UpdateTolerances(const TopoDS_Shape& aShape, BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); const TopLoc_Location& Eloc = E.Location(); while (itcr.More()) { - // For each CurveRepresentation, check the provided parameter - const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); - const TopLoc_Location& loc = cr->Location(); - TopLoc_Location L = (Eloc * loc); - if (cr->IsCurve3D()) { - const Handle(Geom_Curve)& C = cr->Curve3D(); - if (!C.IsNull()) { // edge non degenerated - p3d = C->Value(par); - p3d.Transform(L.Transformation()); - box.Add(p3d); - } - } - else if (cr->IsCurveOnSurface()) { - const Handle(Geom_Surface)& Su = cr->Surface(); - const Handle(Geom2d_Curve)& PC = cr->PCurve(); - Handle(Geom2d_Curve) PC2; - if (cr->IsCurveOnClosedSurface()) { - PC2 = cr->PCurve2(); - } - gp_Pnt2d p2d = PC->Value(par); - p3d = Su->Value(p2d.X(),p2d.Y()); - p3d.Transform(L.Transformation()); - box.Add(p3d); - if (!PC2.IsNull()) { - p2d = PC2->Value(par); - p3d = Su->Value(p2d.X(),p2d.Y()); - p3d.Transform(L.Transformation()); - box.Add(p3d); - } - } - itcr.Next(); + // For each CurveRepresentation, check the provided parameter + const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); + const TopLoc_Location& loc = cr->Location(); + TopLoc_Location L = (Eloc * loc); + if (cr->IsCurve3D()) { + const Handle(Geom_Curve)& C = cr->Curve3D(); + if (!C.IsNull()) { // edge non degenerated + p3d = C->Value(par); + p3d.Transform(L.Transformation()); + box.Add(p3d); + } + } + else if (cr->IsCurveOnSurface()) { + const Handle(Geom_Surface)& Su = cr->Surface(); + const Handle(Geom2d_Curve)& PC = cr->PCurve(); + Handle(Geom2d_Curve) PC2; + if (cr->IsCurveOnClosedSurface()) { + PC2 = cr->PCurve2(); + } + gp_Pnt2d p2d = PC->Value(par); + p3d = Su->Value(p2d.X(),p2d.Y()); + p3d.Transform(L.Transformation()); + box.Add(p3d); + if (!PC2.IsNull()) { + p2d = PC2->Value(par); + p3d = Su->Value(p2d.X(),p2d.Y()); + p3d.Transform(L.Transformation()); + box.Add(p3d); + } + } + itcr.Next(); } } Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; @@ -1446,13 +1448,13 @@ void BRepLib::UpdateTolerances(const TopoDS_Shape& aShape, // Attention to sharing of the vertex by other shapes const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*)&V.TShape()); if (Initialized.Add(TV)) - TV->Tolerance(tol); + TV->Tolerance(tol); else - B.UpdateVertex(V, tol); + B.UpdateVertex(V, tol); } else { - // Update can only increase tolerance, so if the edge has a greater - // tolerance than its faces it is not concerned + // Update can only increase tolerance, so if the edge has a greater + // tolerance than its faces it is not concerned B.UpdateVertex(V, tol); } } @@ -1464,7 +1466,7 @@ void BRepLib::UpdateTolerances(const TopoDS_Shape& aShape, //======================================================================= Standard_Boolean BRepLib::OrientClosedSolid(TopoDS_Solid& solid) { -// Set material inside the solid + // Set material inside the solid BRepClass3d_SolidClassifier where(solid); where.PerformInfinitePoint(Precision::Confusion()); if (where.State()==TopAbs_IN) { @@ -1483,11 +1485,21 @@ Standard_Boolean BRepLib::OrientClosedSolid(TopoDS_Solid& solid) //======================================================================= static Standard_Boolean tgtfaces(const TopoDS_Edge& Ed, - const TopoDS_Face& F1, - const TopoDS_Face& F2, - const Standard_Real ta, - const Standard_Boolean couture) + const TopoDS_Face& F1, + const TopoDS_Face& F2, + const Standard_Real ta, + const Standard_Boolean couture) { + // Check if pcurves exist on both faces of edge + Standard_Real aFirst,aLast; + Handle(Geom2d_Curve) aCurve; + aCurve = BRep_Tool::CurveOnSurface(Ed,F1,aFirst,aLast); + if(aCurve.IsNull()) + return Standard_False; + aCurve = BRep_Tool::CurveOnSurface(Ed,F2,aFirst,aLast); + if(aCurve.IsNull()) + return Standard_False; + Standard_Real u; TopoDS_Edge E = Ed; BRepAdaptor_Surface aBAS1(F1,Standard_False); @@ -1513,7 +1525,7 @@ static Standard_Boolean tgtfaces(const TopoDS_Edge& Ed, BRep_Tool::Range(E,f,l); Extrema_LocateExtPC ext; Standard_Boolean IsInitialized = Standard_False; - + eps = (l - f)/100.; f += eps; // to avoid calculations on l -= eps; // points of pointed squares. @@ -1548,28 +1560,28 @@ static Standard_Boolean tgtfaces(const TopoDS_Edge& Ed, if (Nok &&(ang > ta)) { // Refine by projection if (! IsInitialized ) { - ext.Initialize(C2,f,l,Precision::PConfusion()); - IsInitialized = Standard_True; + ext.Initialize(C2,f,l,Precision::PConfusion()); + IsInitialized = Standard_True; } ext.Perform(pp1,u); if(ext.IsDone() && ext.IsMin()){ - Extrema_POnCurv poc = ext.Point(); - Standard_Real v = poc.Parameter(); - - HC2d2->D0(v,p); - p.Coord(uu,vv); - HS2->D1(p.X(), p.Y(), pp2, du, dv); - d2 = (du.Crossed(dv)); - norm = d2.Magnitude(); - if (norm> 1.e-12) d2 /= norm; - else Nok = Standard_False; - if(rev2) d2.Reverse(); - if (Nok) ang = d1.Angle(d2); + Extrema_POnCurv poc = ext.Point(); + Standard_Real v = poc.Parameter(); + + HC2d2->D0(v,p); + p.Coord(uu,vv); + HS2->D1(p.X(), p.Y(), pp2, du, dv); + d2 = (du.Crossed(dv)); + norm = d2.Magnitude(); + if (norm> 1.e-12) d2 /= norm; + else Nok = Standard_False; + if(rev2) d2.Reverse(); + if (Nok) ang = d1.Angle(d2); } } if(ang >= angmax) angmax = ang; } - + return (angmax<=ta); } @@ -1582,7 +1594,7 @@ static Standard_Boolean tgtfaces(const TopoDS_Edge& Ed, //======================================================================= void BRepLib::EncodeRegularity(const TopoDS_Shape& S, - const Standard_Real TolAng) + const Standard_Real TolAng) { BRep_Builder B; TopTools_IndexedDataMapOfShapeListOfShape M; @@ -1598,30 +1610,30 @@ void BRepLib::EncodeRegularity(const TopoDS_Shape& S, for(It.Initialize(M.FindFromIndex(i));It.More() && !found;It.Next()){ if(F1.IsNull()) { F1 = TopoDS::Face(It.Value()); } else { - if(!F1.IsSame(TopoDS::Face(It.Value()))){ - found = Standard_True; - F2 = TopoDS::Face(It.Value()); - } + if(!F1.IsSame(TopoDS::Face(It.Value()))){ + found = Standard_True; + F2 = TopoDS::Face(It.Value()); + } } } if (!found && !F1.IsNull()){//is it a sewing edge? TopAbs_Orientation orE = E.Orientation(); TopoDS_Edge curE; for(Ex.Init(F1,TopAbs_EDGE);Ex.More() && !found;Ex.Next()){ - curE= TopoDS::Edge(Ex.Current()); - if(E.IsSame(curE) && orE != curE.Orientation()) { - found = Standard_True; - couture = Standard_True; - F2 = F1; - } + curE= TopoDS::Edge(Ex.Current()); + if(E.IsSame(curE) && orE != curE.Orientation()) { + found = Standard_True; + couture = Standard_True; + F2 = F1; + } } } if(found){ if(BRep_Tool::Continuity(E,F1,F2)<=GeomAbs_C0){ try { - if(tgtfaces(E, F1, F2, TolAng, couture)){ - B.Continuity(E,F1,F2,GeomAbs_G1); + if(tgtfaces(E, F1, F2, TolAng, couture)){ + B.Continuity(E,F1,F2,GeomAbs_G1); } } catch(Standard_Failure) @@ -1638,9 +1650,9 @@ void BRepLib::EncodeRegularity(const TopoDS_Shape& S, //======================================================================= void BRepLib::EncodeRegularity(TopoDS_Edge& E, - const TopoDS_Face& F1, - const TopoDS_Face& F2, - const Standard_Real TolAng) + const TopoDS_Face& F1, + const TopoDS_Face& F2, + const Standard_Real TolAng) { BRep_Builder B; if(BRep_Tool::Continuity(E,F1,F2)<=GeomAbs_C0){ @@ -1652,7 +1664,7 @@ void BRepLib::EncodeRegularity(TopoDS_Edge& E, catch(Standard_Failure) { } - } + } } //======================================================================= @@ -1661,7 +1673,7 @@ void BRepLib::EncodeRegularity(TopoDS_Edge& E, //======================================================================= void BRepLib::SortFaces (const TopoDS_Shape& Sh, - TopTools_ListOfShape& LF) + TopTools_ListOfShape& LF) { LF.Clear(); TopTools_ListOfShape LTri,LPlan,LCyl,LCon,LSphere,LTor,LOther; @@ -1674,37 +1686,37 @@ void BRepLib::SortFaces (const TopoDS_Shape& Sh, S = BRep_Tool::Surface(F, l); if (!S.IsNull()) { if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) { - S = (*((Handle(Geom_RectangularTrimmedSurface)*)&S))->BasisSurface(); + S = (*((Handle(Geom_RectangularTrimmedSurface)*)&S))->BasisSurface(); } GeomAdaptor_Surface AS(S); switch (AS.GetType()) { case GeomAbs_Plane: - { - LPlan.Append(F); - break; - } + { + LPlan.Append(F); + break; + } case GeomAbs_Cylinder: - { - LCyl.Append(F); - break; - } + { + LCyl.Append(F); + break; + } case GeomAbs_Cone: - { - LCon.Append(F); - break; - } + { + LCon.Append(F); + break; + } case GeomAbs_Sphere: - { - LSphere.Append(F); - break; - } + { + LSphere.Append(F); + break; + } case GeomAbs_Torus: - { - LTor.Append(F); - break; - } + { + LTor.Append(F); + break; + } default: - LOther.Append(F); + LOther.Append(F); } } else LTri.Append(F); @@ -1719,57 +1731,56 @@ void BRepLib::SortFaces (const TopoDS_Shape& Sh, //======================================================================= void BRepLib::ReverseSortFaces (const TopoDS_Shape& Sh, - TopTools_ListOfShape& LF) + TopTools_ListOfShape& LF) { LF.Clear(); TopTools_ListOfShape LTri,LPlan,LCyl,LCon,LSphere,LTor,LOther; TopExp_Explorer exp(Sh,TopAbs_FACE); TopLoc_Location l; Handle(Geom_Surface) S; - + for (; exp.More(); exp.Next()) { const TopoDS_Face& F = TopoDS::Face(exp.Current()); S = BRep_Tool::Surface(F, l); if (!S.IsNull()) { if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) { - S = (*((Handle(Geom_RectangularTrimmedSurface)*)&S))->BasisSurface(); + S = (*((Handle(Geom_RectangularTrimmedSurface)*)&S))->BasisSurface(); } GeomAdaptor_Surface AS(S); switch (AS.GetType()) { case GeomAbs_Plane: - { - LPlan.Append(F); - break; - } + { + LPlan.Append(F); + break; + } case GeomAbs_Cylinder: - { - LCyl.Append(F); - break; - } + { + LCyl.Append(F); + break; + } case GeomAbs_Cone: - { - LCon.Append(F); - break; - } + { + LCon.Append(F); + break; + } case GeomAbs_Sphere: - { - LSphere.Append(F); - break; - } + { + LSphere.Append(F); + break; + } case GeomAbs_Torus: - { - LTor.Append(F); - break; - } + { + LTor.Append(F); + break; + } default: - LOther.Append(F); + LOther.Append(F); } } else LTri.Append(F); } LF.Append(LTri); LF.Append(LOther); LF.Append(LTor ); LF.Append(LSphere); LF.Append(LCon); LF.Append(LCyl ); LF.Append(LPlan); - -} +} diff --git a/src/BRepLib/BRepLib_FindSurface.cxx b/src/BRepLib/BRepLib_FindSurface.cxx index 552a7c36f9..24a372304c 100644 --- a/src/BRepLib/BRepLib_FindSurface.cxx +++ b/src/BRepLib/BRepLib_FindSurface.cxx @@ -19,7 +19,9 @@ #include #include #include -#include +//#include +#include +#include #include #include @@ -45,6 +47,8 @@ #include #include #include +#include +#include #include #include @@ -58,7 +62,7 @@ //purpose : //======================================================================= static Standard_Real Controle(const TColgp_SequenceOfPnt& thePoints, - const Handle(Geom_Plane)& thePlane) + const Handle(Geom_Plane)& thePlane) { Standard_Real dfMaxDist=0.; Standard_Real a,b,c,d, dist; @@ -79,9 +83,9 @@ static Standard_Real Controle(const TColgp_SequenceOfPnt& thePoints, // the first vertex of theEdge2 in parametric space of theFace //======================================================================= inline static Standard_Boolean Is2DConnected(const TopoDS_Edge& theEdge1, - const TopoDS_Edge& theEdge2, - const Handle(Geom_Surface)& theSurface, - const TopLoc_Location& theLocation) + const TopoDS_Edge& theEdge2, + const Handle(Geom_Surface)& theSurface, + const TopLoc_Location& theLocation) { Standard_Real f,l; //TopLoc_Location aLoc; @@ -110,8 +114,8 @@ inline static Standard_Boolean Is2DConnected(const TopoDS_Edge& theEdge1, //======================================================================= static Standard_Boolean Is2DClosed(const TopoDS_Shape& theShape, - const Handle(Geom_Surface)& theSurface, - const TopLoc_Location& theLocation) + const Handle(Geom_Surface)& theSurface, + const TopLoc_Location& theLocation) { try { @@ -164,9 +168,9 @@ BRepLib_FindSurface::BRepLib_FindSurface() //purpose : //======================================================================= BRepLib_FindSurface::BRepLib_FindSurface(const TopoDS_Shape& S, - const Standard_Real Tol, - const Standard_Boolean OnlyPlane, - const Standard_Boolean OnlyClosed) + const Standard_Real Tol, + const Standard_Boolean OnlyPlane, + const Standard_Boolean OnlyClosed) { Init(S,Tol,OnlyPlane,OnlyClosed); } @@ -175,9 +179,9 @@ BRepLib_FindSurface::BRepLib_FindSurface(const TopoDS_Shape& S, //purpose : //======================================================================= void BRepLib_FindSurface::Init(const TopoDS_Shape& S, - const Standard_Real Tol, - const Standard_Boolean OnlyPlane, - const Standard_Boolean OnlyClosed) + const Standard_Real Tol, + const Standard_Boolean OnlyPlane, + const Standard_Boolean OnlyClosed) { myTolerance = Tol; myTolReached = 0.; @@ -331,27 +335,15 @@ void BRepLib_FindSurface::Init(const TopoDS_Shape& S, continue; else { - const Standard_Integer aNbPolMax = 200; - Standard_Integer incr = 1; - if(iNbPol > aNbPolMax) - { - Standard_Integer nb = iNbPol; - while(nb > aNbPolMax) - { - incr++; - nb = (iNbPol-1) / incr; - } - } Handle(TColgp_HArray1OfPnt) aPoles = new (TColgp_HArray1OfPnt) (1, iNbPol); GC->Poles(aPoles->ChangeArray1()); gp_Pnt aPolePrev = aPoles->Value(1), aPoleNext; Standard_Real dfDistPrev = 0., dfDistNext; - Standard_Integer iPol; - for (iPol = 1; iPol <= iNbPol; iPol += incr) + for (Standard_Integer iPol=1; iPol<=iNbPol; iPol++) { - if (iPol <= iNbPol - incr) + if (iPolValue(iPol+incr); + aPoleNext = aPoles->Value(iPol+1); dfDistNext = aPolePrev.Distance(aPoleNext); } else @@ -436,50 +428,115 @@ void BRepLib_FindSurface::Init(const TopoDS_Shape& S, aMat(1,1)+=w*p.X()*p.X(); aMat(1,2)+=w*p.X()*p.Y(); aMat(1,3)+=w*p.X()*p.Z(); - aMat(2,1)+=w*p.Y()*p.X(); + // aMat(2,2)+=w*p.Y()*p.Y(); aMat(2,3)+=w*p.Y()*p.Z(); - aMat(3,1)+=w*p.Z()*p.X(); - aMat(3,2)+=w*p.Z()*p.Y(); + // aMat(3,3)+=w*p.Z()*p.Z(); - aVec(1) -= w*p.X(); - aVec(2) -= w*p.Y(); - aVec(3) -= w*p.Z(); } - - // Solve the system of equations to get plane coefficients - math_Gauss aSolver(aMat); - Standard_Boolean isSolved = aSolver.IsDone(); - // - // let us be more tolerant (occ415) - Standard_Real dfDist = RealLast(); - Handle(Geom_Plane) aPlane; + aMat(2,1) = aMat(1,2); + aMat(3,1) = aMat(1,3); + aMat(3,2) = aMat(2,3); // - if (isSolved) { - aSolver.Solve(aVec); - if (aVec.Norm2() anE) + { + anEMin = anE; + isol = i; + } + if(anEMax < anE) + { + anEMax = anE; + } + } + + if(isol == 0) + { isSolved = Standard_False; } + else + { + Standard_Real eps = Epsilon(anEMax); + if(anEMin <= eps) + { + anEignval.Vector(isol, aVec); + } + else + { + //try using vector product of other axes + Standard_Integer ind[2] = {0,0}; + for(i = 1; i <= 3; ++i) + { + if(i == isol) + { + continue; + } + if(ind[0] == 0) + { + ind[0] = i; + continue; + } + if(ind[1] == 0) + { + ind[1] = i; + continue; + } + } + math_Vector aVec1(1, 3, 0.), aVec2(1, 3, 0.); + anEignval.Vector(ind[0], aVec1); + anEignval.Vector(ind[1], aVec2); + gp_Vec aV1(aVec1(1), aVec1(2), aVec1(3)); + gp_Vec aV2(aVec2(1), aVec2(2), aVec2(3)); + gp_Vec aN = aV1^ aV2; + aVec(1) = aN.X(); + aVec(2) = aN.Y(); + aVec(3) = aN.Z(); + } + if (aVec.Norm2() < gp::Resolution()) { + isSolved = Standard_False; + } + } } + + // + // let us be more tolerant (occ415) + Standard_Real dfDist = RealLast(); + Handle(Geom_Plane) aPlane; // if (isSolved) { - aPlane = new Geom_Plane(aBaryCenter,gp_Dir(aVec(1),aVec(2),aVec(3))); + //Plane normal can have two directions, direction is chosen + //according to direction of eigenvector + gp_Vec anN(aVec(1), aVec(2), aVec(3)); + aPlane = new Geom_Plane(aBaryCenter,anN); dfDist = Controle (aPoints, aPlane); } // if (!isSolved || myTolerance < dfDist) { gp_Pnt aFirstPnt=aPoints(1); for (iPoint=2; iPoint<=aPoints.Length(); iPoint++) { - const gp_Pnt& aNextPnt = aPoints(iPoint); - gp_Vec aDir(aFirstPnt, aNextPnt); + gp_Vec aDir(aFirstPnt,aPoints(iPoint)); Standard_Real dfSide=aDir.Magnitude(); if (dfSide dfSide*myTolerance) { - Handle(Geom_Plane) aPlane2 = new Geom_Plane(aFirstPnt, aCross); + Handle(Geom_Plane) aPlane2 = new Geom_Plane(aBaryCenter, aCross); Standard_Real dfDist2 = Controle (aPoints, aPlane2); if (dfDist2 < myTolerance) { myTolReached = dfDist2; @@ -504,6 +561,23 @@ void BRepLib_FindSurface::Init(const TopoDS_Shape& S, //myTolReached = dfDist; //XXt mySurface = aPlane; + //If S is wire, try to orient surface according to orientation of wire. + if(S.ShapeType() == TopAbs_WIRE && S.Closed()) + { + // + TopoDS_Wire aW = TopoDS::Wire(S); + TopoDS_Face aTmpFace = BRepLib_MakeFace(mySurface, Precision::Confusion()); + BRep_Builder BB; + BB.Add(aTmpFace, aW); + BRepTopAdaptor_FClass2d FClass(aTmpFace, 0.); + if ( FClass.PerformInfinitePoint() == TopAbs_IN ) + { + gp_Dir aN = aPlane->Position().Direction(); + aN.Reverse(); + mySurface = new Geom_Plane(aPlane->Position().Location(), aN); + } + + } } //XXf myTolReached = dfDist; @@ -558,4 +632,3 @@ TopLoc_Location BRepLib_FindSurface::Location() const return myLocation; } - diff --git a/src/BRepMAT2d/BRepMAT2d_Explorer.cxx b/src/BRepMAT2d/BRepMAT2d_Explorer.cxx index 7b855db0ff..327717bf09 100644 --- a/src/BRepMAT2d/BRepMAT2d_Explorer.cxx +++ b/src/BRepMAT2d/BRepMAT2d_Explorer.cxx @@ -5,8 +5,8 @@ // // This file is part of Open CASCADE Technology software library. // -// This library is free software; you can redistribute it and / or modify it -// under the terms of the GNU Lesser General Public version 2.1 as published +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published // by the Free Software Foundation, with special exception defined in the file // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT // distribution for complete text of the license and disclaimer of any warranty. @@ -39,14 +39,27 @@ #include #include #include - +#include +#include +#include +#include +#include +#include +#include +#include +#include +// // Modified by Sergey KHROMOV - Thu Dec 5 10:38:14 2002 Begin static TopoDS_Edge MakeEdge(const Handle(Geom2d_Curve) &theCurve, - const TopoDS_Face &theFace, - const TopoDS_Vertex &theVFirst, - const TopoDS_Vertex &theVLast); + const TopoDS_Face &theFace, + const TopoDS_Vertex &theVFirst, + const TopoDS_Vertex &theVLast); // Modified by Sergey KHROMOV - Thu Dec 5 10:38:16 2002 End - +// +static GeomAbs_CurveType GetCurveType(const Handle(Geom2d_Curve)& theC2d); +static void AdjustCurveEnd(Handle(Geom2d_BoundedCurve)& theC2d, const gp_Pnt2d theP, + const Standard_Boolean isFirst); +// //======================================================================= //function : BRepMAT2d_Explorer //purpose : @@ -79,7 +92,7 @@ void BRepMAT2d_Explorer::Perform(const TopoDS_Face& aFace) TopoDS_Face F = TopoDS::Face(aFace); F.Orientation(TopAbs_FORWARD); TopExp_Explorer Exp (F,TopAbs_WIRE); -// Modified by Sergey KHROMOV - Tue Nov 26 16:10:37 2002 Begin + // Modified by Sergey KHROMOV - Tue Nov 26 16:10:37 2002 Begin Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F); TopoDS_Face aNewF = BRepBuilderAPI_MakeFace(aSurf, Precision::Confusion()); @@ -91,8 +104,8 @@ void BRepMAT2d_Explorer::Perform(const TopoDS_Face& aFace) BRepLib::BuildCurves3d(aNewF); myModifShapes.Add(aFace, aNewF); -// CheckConnection(); -// Modified by Sergey KHROMOV - Tue Nov 26 16:10:38 2002 End + // CheckConnection(); + // Modified by Sergey KHROMOV - Tue Nov 26 16:10:38 2002 End } //======================================================================= @@ -101,43 +114,43 @@ void BRepMAT2d_Explorer::Perform(const TopoDS_Face& aFace) //======================================================================= void BRepMAT2d_Explorer::Add(const TopoDS_Wire& Spine, - const TopoDS_Face& aFace, - TopoDS_Face& aNewFace) + const TopoDS_Face& aFace, + TopoDS_Face& aNewFace) { -// Modified by Sergey KHROMOV - Tue Nov 26 14:25:46 2002 Begin -// This method is totally rewroted to include check -// of connection and creation of a new spine. + // Modified by Sergey KHROMOV - Tue Nov 26 14:25:46 2002 Begin + // This method is totally rewroted to include check + // of connection and creation of a new spine. NewContour(); myIsClosed(currentContour) = (Spine.Closed()) ? Standard_True : Standard_False; -// Modified by skv - Wed Jun 23 12:23:01 2004 Integration Begin -// Taking into account side of bisecting loci construction. -// TopoDS_Wire aWFwd = TopoDS::Wire(Spine.Oriented(TopAbs_FORWARD)); -// BRepTools_WireExplorer anExp(aWFwd, aFace); + // Modified by skv - Wed Jun 23 12:23:01 2004 Integration Begin + // Taking into account side of bisecting loci construction. + // TopoDS_Wire aWFwd = TopoDS::Wire(Spine.Oriented(TopAbs_FORWARD)); + // BRepTools_WireExplorer anExp(aWFwd, aFace); BRepTools_WireExplorer anExp(Spine, aFace); -// Modified by skv - Wed Jun 23 12:23:02 2004 Integration End + // Modified by skv - Wed Jun 23 12:23:02 2004 Integration End TopTools_IndexedDataMapOfShapeShape anOldNewE; if (!anExp.More()) return; TopoDS_Edge aFirstEdge = anExp.Current(); + TopoDS_Edge aPrevEdge = aFirstEdge; Standard_Real UFirst,ULast, aD; - Handle(Geom2d_BSplineCurve) BCurve; Handle(Geom2d_Curve) C2d; Handle(Geom2d_TrimmedCurve) CT2d; Handle(Geom2d_TrimmedCurve) aFirstCurve; gp_Pnt2d aPFirst; gp_Pnt2d aPLast; gp_Pnt2d aPCurFirst; -// Modified by skv - Mon Jul 11 19:00:25 2005 Integration Begin -// Set the confusion tolerance in accordance with the further algo -// Standard_Real aTolConf = Precision::Confusion(); + // Modified by skv - Mon Jul 11 19:00:25 2005 Integration Begin + // Set the confusion tolerance in accordance with the further algo + // Standard_Real aTolConf = Precision::Confusion(); Standard_Real aTolConf = 1.e-8; -// Modified by skv - Mon Jul 11 19:00:25 2005 Integration End + // Modified by skv - Mon Jul 11 19:00:25 2005 Integration End Standard_Boolean isModif = Standard_False; -// Treatment of the first edge of a wire. + // Treatment of the first edge of a wire. anOldNewE.Add(aFirstEdge, aFirstEdge); C2d = BRep_Tool::CurveOnSurface (aFirstEdge, aFace, UFirst, ULast); CT2d = new Geom2d_TrimmedCurve(C2d,UFirst,ULast); @@ -152,7 +165,7 @@ void BRepMAT2d_Explorer::Add(const TopoDS_Wire& Spine, aFirstCurve = CT2d; anExp.Next(); -// Treatment of the next edges: + // Treatment of the next edges: for (; anExp.More(); anExp.Next()) { TopoDS_Edge anEdge = anExp.Current(); @@ -175,64 +188,111 @@ void BRepMAT2d_Explorer::Add(const TopoDS_Wire& Spine, // code should be rewritten. isModif = Standard_True; // - //modified by NIZNHY-PKV Tue Aug 7 09:14:03 2007f - //BCurve = Geom2dConvert::CurveToBSplineCurve(CT2d); - BCurve=Geom2dConvert::CurveToBSplineCurve(CT2d, Convert_QuasiAngular); - //modified by NIZNHY-PKV Tue Aug 7 09:14:07 2007t - - BCurve->SetPole(1, aPLast); - CT2d = new Geom2d_TrimmedCurve(BCurve, BCurve->FirstParameter(), - BCurve->LastParameter()); - - // Creation of new edge. - TopoDS_Edge aNewEdge; - TopoDS_Vertex aVf = TopExp::FirstVertex(anEdge); - TopoDS_Vertex aVl = TopExp::LastVertex(anEdge); - - if (anEdge.Orientation() == TopAbs_FORWARD) - aNewEdge = MakeEdge(CT2d, aNewFace, aVf, aVl); - else - aNewEdge = MakeEdge(CT2d->Reversed(), aNewFace, aVf, aVl); - - aNewEdge.Orientation(anEdge.Orientation()); + Standard_Integer aNbC = theCurves.Value(currentContour).Length(); + Handle(Geom2d_BoundedCurve) CPrev = + Handle(Geom2d_BoundedCurve)::DownCast(theCurves.ChangeValue(currentContour).ChangeValue(aNbC)); + // + GeomAbs_CurveType TCPrev = GetCurveType(CPrev); + GeomAbs_CurveType TCCurr = GetCurveType(CT2d); + // + if(TCCurr <= TCPrev) + { + AdjustCurveEnd(CT2d, aPLast, Standard_True); + // Creation of new edge. + TopoDS_Edge aNewEdge; + TopoDS_Vertex aVf = TopExp::FirstVertex(anEdge); + TopoDS_Vertex aVl = TopExp::LastVertex(anEdge); + + if (anEdge.Orientation() == TopAbs_FORWARD) + aNewEdge = MakeEdge(CT2d, aNewFace, aVf, aVl); + else + aNewEdge = MakeEdge(CT2d->Reversed(), aNewFace, aVf, aVl); + + aNewEdge.Orientation(anEdge.Orientation()); + + anOldNewE.ChangeFromKey(anEdge) = aNewEdge; + } + else + { + gp_Pnt2d aP = CT2d->Value(CT2d->FirstParameter()); + AdjustCurveEnd(CPrev, aP, Standard_False); + theCurves.ChangeValue(currentContour).ChangeValue(aNbC) = CPrev; + //Change previous edge + TopoDS_Edge aNewEdge; + TopoDS_Vertex aVf = TopExp::FirstVertex(aPrevEdge); + TopoDS_Vertex aVl = TopExp::LastVertex(aPrevEdge); + + if (aPrevEdge.Orientation() == TopAbs_FORWARD) + aNewEdge = MakeEdge(CPrev, aNewFace, aVf, aVl); + else + aNewEdge = MakeEdge(CPrev->Reversed(), aNewFace, aVf, aVl); + + aNewEdge.Orientation(aPrevEdge.Orientation()); + + anOldNewE.ChangeFromKey(aPrevEdge) = aNewEdge; + + } - anOldNewE.ChangeFromKey(anEdge) = aNewEdge; } aPLast = CT2d->Value(CT2d->LastParameter()); Add(CT2d); + aPrevEdge = anEdge; } // Check of the distance between the first and the last point of wire // if the wire is closed. - if (myIsClosed(currentContour) && aPLast.Distance(aPFirst) > aTolConf) { - isModif = Standard_True; - - - //modified by NIZNHY-PKV Tue Aug 7 09:20:08 2007f - //Handle(Geom2d_BSplineCurve) - //BCurve = Geom2dConvert::CurveToBSplineCurve(aFirstCurve); - BCurve = Geom2dConvert::CurveToBSplineCurve(aFirstCurve, Convert_QuasiAngular); - //modified by NIZNHY-PKV Tue Aug 7 09:20:11 2007t + if (myIsClosed(currentContour) && aPLast.Distance(aPFirst) > aTolConf) { + isModif = Standard_True; - BCurve->SetPole(1, aPLast); - aFirstCurve = new Geom2d_TrimmedCurve(BCurve, BCurve->FirstParameter(), - BCurve->LastParameter()); + // + Standard_Integer aNbC = theCurves.Value(currentContour).Length(); + Handle(Geom2d_BoundedCurve) CPrev = + Handle(Geom2d_BoundedCurve)::DownCast(theCurves.ChangeValue(currentContour).ChangeValue(aNbC)); + // + GeomAbs_CurveType TCPrev = GetCurveType(CPrev); + GeomAbs_CurveType TCCurr = GetCurveType(aFirstCurve); + // + if(TCCurr <= TCPrev) + { + AdjustCurveEnd(aFirstCurve, aPLast, Standard_True); theCurves.ChangeValue(currentContour).ChangeValue(1) = aFirstCurve; - - // Creation of new first edge. + // Creation of new edge. TopoDS_Edge aNewEdge; TopoDS_Vertex aVf = TopExp::FirstVertex(aFirstEdge); TopoDS_Vertex aVl = TopExp::LastVertex(aFirstEdge); if (aFirstEdge.Orientation() == TopAbs_FORWARD) - aNewEdge = MakeEdge(aFirstCurve, aNewFace, aVf, aVl); + aNewEdge = MakeEdge(aFirstCurve, aNewFace, aVf, aVl); else - aNewEdge = MakeEdge(aFirstCurve->Reversed(), aNewFace, aVf, aVl); + aNewEdge = MakeEdge(aFirstCurve->Reversed(), aNewFace, aVf, aVl); aNewEdge.Orientation(aFirstEdge.Orientation()); + anOldNewE.ChangeFromKey(aFirstEdge) = aNewEdge; } + else + { + gp_Pnt2d aP = aFirstCurve->Value(aFirstCurve->FirstParameter()); + AdjustCurveEnd(CPrev, aP, Standard_False); + theCurves.ChangeValue(currentContour).ChangeValue(aNbC) = CPrev; + //Change previous edge + TopoDS_Edge aNewEdge; + TopoDS_Vertex aVf = TopExp::FirstVertex(aPrevEdge); + TopoDS_Vertex aVl = TopExp::LastVertex(aPrevEdge); + + if (aPrevEdge.Orientation() == TopAbs_FORWARD) + aNewEdge = MakeEdge(CPrev, aNewFace, aVf, aVl); + else + aNewEdge = MakeEdge(CPrev->Reversed(), aNewFace, aVf, aVl); + + aNewEdge.Orientation(aPrevEdge.Orientation()); + + anOldNewE.ChangeFromKey(aPrevEdge) = aNewEdge; + + } + + } TopoDS_Wire aNewWire; BRep_Builder aBuilder; @@ -263,7 +323,7 @@ void BRepMAT2d_Explorer::Add(const TopoDS_Wire& Spine, aNewWire = Spine; aBuilder.Add(aNewFace, aNewWire); -// Modified by Sergey KHROMOV - Tue Nov 26 14:25:53 2002 End + // Modified by Sergey KHROMOV - Tue Nov 26 14:25:53 2002 End } //======================================================================= @@ -302,10 +362,10 @@ void BRepMAT2d_Explorer::Clear() { theCurves.Clear() ; currentContour = 0; -// Modified by Sergey KHROMOV - Wed Mar 6 16:07:55 2002 Begin + // Modified by Sergey KHROMOV - Wed Mar 6 16:07:55 2002 Begin myIsClosed.Clear(); myModifShapes.Clear(); -// Modified by Sergey KHROMOV - Wed Mar 6 16:07:55 2002 End + // Modified by Sergey KHROMOV - Wed Mar 6 16:07:55 2002 End } @@ -318,9 +378,9 @@ void BRepMAT2d_Explorer::NewContour() { TColGeom2d_SequenceOfCurve Contour; theCurves.Append(Contour); -// Modified by Sergey KHROMOV - Wed Mar 6 16:12:05 2002 Begin + // Modified by Sergey KHROMOV - Wed Mar 6 16:12:05 2002 Begin myIsClosed.Append(Standard_False); -// Modified by Sergey KHROMOV - Wed Mar 6 16:12:05 2002 End + // Modified by Sergey KHROMOV - Wed Mar 6 16:12:05 2002 End currentContour ++ ; } @@ -353,7 +413,7 @@ Standard_Integer BRepMAT2d_Explorer::NumberOfContours() const Standard_Integer BRepMAT2d_Explorer::NumberOfCurves (const Standard_Integer IndexContour) -const + const { return theCurves.Value(IndexContour).Length(); } @@ -421,7 +481,7 @@ TopoDS_Shape BRepMAT2d_Explorer::Shape() const const TColGeom2d_SequenceOfCurve& BRepMAT2d_Explorer::Contour (const Standard_Integer IC) -const + const { return theCurves.Value(IC); } @@ -434,7 +494,7 @@ const //======================================================================= Standard_Boolean BRepMAT2d_Explorer::IsModified - (const TopoDS_Shape &aShape) const + (const TopoDS_Shape &aShape) const { if (myModifShapes.Contains(aShape)) { const TopoDS_Shape &aNewShape = myModifShapes.FindFromKey(aShape); @@ -452,7 +512,7 @@ Standard_Boolean BRepMAT2d_Explorer::IsModified //======================================================================= TopoDS_Shape BRepMAT2d_Explorer::ModifiedShape - (const TopoDS_Shape &aShape) const + (const TopoDS_Shape &aShape) const { if (myModifShapes.Contains(aShape)) { const TopoDS_Shape &aNewShape = myModifShapes.FindFromKey(aShape); @@ -479,9 +539,9 @@ const TColStd_SequenceOfBoolean &BRepMAT2d_Explorer::GetIsClosed() const //======================================================================= TopoDS_Edge MakeEdge(const Handle(Geom2d_Curve) &theCurve, - const TopoDS_Face &theFace, - const TopoDS_Vertex &theVFirst, - const TopoDS_Vertex &theVLast) + const TopoDS_Face &theFace, + const TopoDS_Vertex &theVFirst, + const TopoDS_Vertex &theVLast) { TopoDS_Edge aNewEdge; BRep_Builder aBuilder; @@ -498,3 +558,85 @@ TopoDS_Edge MakeEdge(const Handle(Geom2d_Curve) &theCurve, return aNewEdge; } // Modified by Sergey KHROMOV - Wed Mar 6 17:40:14 2002 End +// +//======================================================================= +//function : GetCurveType +//purpose : Get curve type. +//======================================================================= + +GeomAbs_CurveType GetCurveType(const Handle(Geom2d_Curve)& theC2d) +{ + GeomAbs_CurveType aTypeCurve = GeomAbs_OtherCurve; + Handle(Standard_Type) TheType = theC2d->DynamicType(); + if ( TheType == STANDARD_TYPE(Geom2d_TrimmedCurve)) { + TheType = (*((Handle(Geom2d_TrimmedCurve)*)&theC2d))->BasisCurve()->DynamicType(); + } + + if ( TheType == STANDARD_TYPE(Geom2d_Circle)) { + aTypeCurve = GeomAbs_Circle; + } + else if ( TheType ==STANDARD_TYPE(Geom2d_Line)) { + aTypeCurve = GeomAbs_Line; + } + else if ( TheType == STANDARD_TYPE(Geom2d_Ellipse)) { + aTypeCurve = GeomAbs_Ellipse; + } + else if ( TheType == STANDARD_TYPE(Geom2d_Parabola)) { + aTypeCurve = GeomAbs_Parabola; + } + else if ( TheType == STANDARD_TYPE(Geom2d_Hyperbola)) { + aTypeCurve = GeomAbs_Hyperbola; + } + else if ( TheType == STANDARD_TYPE(Geom2d_BezierCurve)) { + aTypeCurve = GeomAbs_BezierCurve; + } + else if ( TheType == STANDARD_TYPE(Geom2d_BSplineCurve)) { + aTypeCurve = GeomAbs_BSplineCurve; + } + else { + aTypeCurve = GeomAbs_OtherCurve; + } + return aTypeCurve; +} +//======================================================================= +//function : AdjustCurveEnd +//purpose : +//======================================================================= +void AdjustCurveEnd(Handle(Geom2d_BoundedCurve)& theC2d, const gp_Pnt2d theP, + const Standard_Boolean isFirst) +{ + GeomAbs_CurveType aType = GetCurveType(theC2d); + if(aType == GeomAbs_Line) + { + //create new line + if(isFirst) + { + gp_Pnt2d aP = theC2d->Value(theC2d->LastParameter()); + theC2d = GCE2d_MakeSegment(theP, aP); + } + else + { + gp_Pnt2d aP = theC2d->Value(theC2d->FirstParameter()); + theC2d = GCE2d_MakeSegment(aP, theP); + } + } + else + { + //Convert to BSpline and adjust first pole + Handle(Geom2d_BSplineCurve) BCurve = + Geom2dConvert::CurveToBSplineCurve(theC2d, Convert_QuasiAngular); + if(isFirst) + { + BCurve->SetPole(1, theP); + theC2d = new Geom2d_TrimmedCurve(BCurve, BCurve->FirstParameter(), + BCurve->LastParameter()); + } + else + { + BCurve->SetPole(BCurve->NbPoles(), theP); + theC2d = new Geom2d_TrimmedCurve(BCurve, BCurve->FirstParameter(), + BCurve->LastParameter()); + } + } + +} diff --git a/src/Bisector/Bisector_Bisec.cxx b/src/Bisector/Bisector_Bisec.cxx index 6137b488f8..68da2eb3db 100644 --- a/src/Bisector/Bisector_Bisec.cxx +++ b/src/Bisector/Bisector_Bisec.cxx @@ -5,8 +5,8 @@ // // This file is part of Open CASCADE Technology software library. // -// This library is free software; you can redistribute it and / or modify it -// under the terms of the GNU Lesser General Public version 2.1 as published +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published // by the Free Software Foundation, with special exception defined in the file // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT // distribution for complete text of the license and disclaimer of any warranty. @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -31,21 +32,27 @@ #include #include #include +#include -/* +#ifdef DEB +//#define DRAW +#ifdef DRAW #include -static char tname[100]; -static Standard_CString name = tname ; +#pragma comment(lib, "TKDraw.lib") +static char name[100]; static Standard_Integer nbb = 0; -*/ +static Standard_Boolean Affich = Standard_False; +#endif +#endif + static Standard_Boolean IsMaxRC (const Handle(Geom2d_Curve)& C, - Standard_Real U, - Standard_Real& R); + Standard_Real U, + Standard_Real& R); static void ReplaceByLineIfIsToSmall (Handle(Geom2d_Curve)& Bis, - Standard_Real& UFirst, - Standard_Real& ULast); + Standard_Real& UFirst, + Standard_Real& ULast); //============================================================================= //function : Empty Constructor //============================================================================= @@ -66,48 +73,115 @@ Bisector_Bisec::Bisector_Bisec() //=========================================================================== void Bisector_Bisec::Perform(const Handle(Geom2d_Curve)& afirstcurve , - const Handle(Geom2d_Curve)& asecondcurve , - const gp_Pnt2d& apoint , - const gp_Vec2d& afirstvector , - const gp_Vec2d& asecondvector , - const Standard_Real adirection , - const Standard_Real tolerance , - const Standard_Boolean oncurve ) + const Handle(Geom2d_Curve)& asecondcurve , + const gp_Pnt2d& apoint , + const gp_Vec2d& afirstvector , + const gp_Vec2d& asecondvector , + const Standard_Real adirection , + const Standard_Real tolerance , + const Standard_Boolean oncurve ) { Handle(Standard_Type) Type1 = afirstcurve ->DynamicType(); Handle(Standard_Type) Type2 = asecondcurve->DynamicType(); Handle(Bisector_Curve) Bis; Standard_Real UFirst,ULast; - + //gp_XY ref1( -65.9325, -200.28055 ); + //gp_XY ref2(50.00154, -201.54198 ); + + //gp_XY p1 = afirstcurve->Value(afirstcurve->FirstParameter()).XY(); + //gp_XY p2 = afirstcurve->Value(afirstcurve->LastParameter()).XY(); + + //if(p1.IsEqual(ref1, 1.e-5) && p2.IsEqual(ref2,1.e-5)) + //{ + // cout << "111" << endl; + //} + + //p1 = asecondcurve->Value(asecondcurve->FirstParameter()).XY(); + //p2 = asecondcurve->Value(asecondcurve->LastParameter()).XY(); + + //if(p1.IsEqual(ref1, 1.e-5) && p2.IsEqual(ref2,1.e-5)) + //{ + // cout << "222" << endl; + //} + if (Type1 == STANDARD_TYPE(Geom2d_TrimmedCurve)) { Type1 = Handle(Geom2d_TrimmedCurve)::DownCast(afirstcurve) - ->BasisCurve()->DynamicType(); + ->BasisCurve()->DynamicType(); } if (Type2 == STANDARD_TYPE(Geom2d_TrimmedCurve)) { Type2 = Handle(Geom2d_TrimmedCurve)::DownCast(asecondcurve) - ->BasisCurve()->DynamicType(); + ->BasisCurve()->DynamicType(); + } + + Handle(Geom2d_Curve) afirstcurve1 = afirstcurve; + Handle(Geom2d_Curve) asecondcurve1 = asecondcurve; + + if(Type1 == STANDARD_TYPE(Geom2d_BSplineCurve)) + { + Handle(Geom2d_BSplineCurve) aBS; + if(afirstcurve->DynamicType() == STANDARD_TYPE(Geom2d_TrimmedCurve)) + { + aBS = Handle(Geom2d_BSplineCurve)::DownCast(Handle(Geom2d_TrimmedCurve)::DownCast(afirstcurve) + ->BasisCurve()); + } + else + { + aBS = Handle(Geom2d_BSplineCurve)::DownCast(afirstcurve); + } + if(aBS->Degree() == 1 && aBS->NbPoles() == 2) + { + if(aBS->Pole(1).Distance(aBS->Pole(2)) < 1.e-4) + { + afirstcurve1 = GCE2d_MakeSegment(aBS->Pole(1), aBS->Pole(2)); + Type1 = STANDARD_TYPE(Geom2d_Line); + } + } + } + + + if(Type2 == STANDARD_TYPE(Geom2d_BSplineCurve)) + { + Handle(Geom2d_BSplineCurve) aBS; + if(asecondcurve->DynamicType() == STANDARD_TYPE(Geom2d_TrimmedCurve)) + { + aBS = Handle(Geom2d_BSplineCurve)::DownCast(Handle(Geom2d_TrimmedCurve)::DownCast(asecondcurve) + ->BasisCurve()); + } + else + { + aBS = Handle(Geom2d_BSplineCurve)::DownCast(asecondcurve); + } + if(aBS->Degree() == 1 && aBS->NbPoles() == 2) + { + if(aBS->Pole(1).Distance(aBS->Pole(2)) < 1.e-4) + { + asecondcurve1 = GCE2d_MakeSegment(aBS->Pole(1), aBS->Pole(2)); + Type2 = STANDARD_TYPE(Geom2d_Line); + } + } } if ( (Type1 == STANDARD_TYPE(Geom2d_Circle) || Type1 == STANDARD_TYPE(Geom2d_Line)) && - (Type2 == STANDARD_TYPE(Geom2d_Circle) || Type2 == STANDARD_TYPE(Geom2d_Line)) ) { + (Type2 == STANDARD_TYPE(Geom2d_Circle) || Type2 == STANDARD_TYPE(Geom2d_Line)) ) + { //------------------------------------------------------------------ // Analytic Bissectrice. //------------------------------------------------------------------ - Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna(); - BisAna->Perform(afirstcurve , - asecondcurve , - apoint , - afirstvector , - asecondvector , - adirection , - tolerance , - oncurve ); - UFirst = BisAna->ParameterOfStartPoint(); - ULast = BisAna->ParameterOfEndPoint(); - Bis = BisAna; + Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna(); + BisAna->Perform(afirstcurve1 , + asecondcurve1 , + apoint , + afirstvector , + asecondvector , + adirection , + tolerance , + oncurve ); + UFirst = BisAna->ParameterOfStartPoint(); + ULast = BisAna->ParameterOfEndPoint(); + Bis = BisAna; } else { - Standard_Boolean IsLine = Standard_False; + Standard_Boolean IsLine = Standard_False; if (oncurve) { gp_Dir2d Fd(afirstvector); @@ -115,7 +189,7 @@ void Bisector_Bisec::Perform(const Handle(Geom2d_Curve)& afirstcurve , //if (Fd.Dot(Sd) < Precision::Angular() - 1.) { //if (Fd.Dot(Sd) < 10*Precision::Angular() - 1.) //patch if (Fd.Dot(Sd) < Sqrt(2.*Precision::Angular()) - 1.) - IsLine = Standard_True; + IsLine = Standard_True; } if (IsLine) { //------------------------------------------------------------------ @@ -125,7 +199,7 @@ void Bisector_Bisec::Perform(const Handle(Geom2d_Curve)& afirstcurve , Handle (Geom2d_CartesianPoint) PG = new Geom2d_CartesianPoint(apoint); Handle (Geom2d_Line) L = new Geom2d_Line (apoint,N); Handle (Geom2d_TrimmedCurve) - BisL = new Geom2d_TrimmedCurve (L,0,Precision::Infinite()); + BisL = new Geom2d_TrimmedCurve (L,0,Precision::Infinite()); Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna (); BisAna->Init(BisL); UFirst = BisAna->ParameterOfStartPoint(); @@ -137,58 +211,78 @@ void Bisector_Bisec::Perform(const Handle(Geom2d_Curve)& afirstcurve , // Bissectrice algo //------------------------------------------------------------------- Handle(Bisector_BisecCC) BisCC = new Bisector_BisecCC(); - BisCC -> Perform(asecondcurve, - afirstcurve , - adirection , - adirection , - apoint); + BisCC -> Perform(asecondcurve1, + afirstcurve1 , + adirection , + adirection , + apoint); if (BisCC -> IsEmpty()) { - // bissectrice is empty. a point is projected at the end of the guide curve. - // Construction of a false bissectrice. -// modified by NIZHNY-EAP Mon Feb 21 12:00:13 2000 ___BEGIN___ - gp_Dir2d dir1(afirstvector), dir2(asecondvector); - Standard_Real - Nx = - dir1.X() - dir2.X(), - Ny = - dir1.Y() - dir2.Y(); - if (Abs(Nx) <= gp::Resolution() && Abs(Ny) <= gp::Resolution()) { - Nx = - afirstvector.Y(); - Ny = afirstvector.X(); - } - //gp_Dir2d N ( - adirection*afirstvector.Y(), adirection*afirstvector.X()); - gp_Dir2d N ( adirection*Nx, adirection*Ny); -// modified by NIZHNY-EAP Mon Feb 21 12:00:19 2000 ___END___ - - Handle (Geom2d_CartesianPoint) PG = new Geom2d_CartesianPoint(apoint); - Handle (Geom2d_Line) L = new Geom2d_Line (apoint,N); - Handle (Geom2d_TrimmedCurve) - BisL = new Geom2d_TrimmedCurve (L,0,Precision::Infinite()); - Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna (); - BisAna->Init(BisL); - UFirst = BisAna->ParameterOfStartPoint(); - ULast = BisAna->ParameterOfEndPoint(); - Bis = BisAna; + // bissectrice is empty. a point is projected at the end of the guide curve. + // Construction of a false bissectrice. + // modified by NIZHNY-EAP Mon Feb 21 12:00:13 2000 ___BEGIN___ + gp_Pnt2d aP1 = afirstcurve1->Value(afirstcurve1->LastParameter()); + gp_Pnt2d aP2 = asecondcurve1->Value(asecondcurve1->FirstParameter()); + gp_Pnt2d aPm(.5*(aP1.XY()+aP2.XY())); + Standard_Real Nx, Ny; + if(aPm.Distance(apoint) > 10.*Precision::Confusion()) + { + Nx = apoint.X() - aPm.X(); + Ny = apoint.Y() - aPm.Y(); + if(adirection < 0) + { + Nx = -Nx; + Ny = -Ny; + } + } + else + { + gp_Dir2d dir1(afirstvector), dir2(asecondvector); + Nx = - dir1.X() - dir2.X(), + Ny = - dir1.Y() - dir2.Y(); + if (Abs(Nx) <= gp::Resolution() && Abs(Ny) <= gp::Resolution()) { + Nx = -afirstvector.Y(); + Ny = afirstvector.X(); + } + } + gp_Dir2d N ( adirection*Nx, adirection*Ny); + // modified by NIZHNY-EAP Mon Feb 21 12:00:19 2000 ___END___ + + Handle (Geom2d_CartesianPoint) PG = new Geom2d_CartesianPoint(apoint); + Handle (Geom2d_Line) L = new Geom2d_Line (apoint,N); + Handle (Geom2d_TrimmedCurve) + BisL = new Geom2d_TrimmedCurve (L,0,Precision::Infinite()); + Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna (); + BisAna->Init(BisL); + UFirst = BisAna->ParameterOfStartPoint(); + ULast = BisAna->ParameterOfEndPoint(); + Bis = BisAna; } else { - UFirst = BisCC->FirstParameter(); - ULast = BisCC->LastParameter (); - Bis = BisCC; - ReplaceByLineIfIsToSmall(Bis,UFirst,ULast); + UFirst = BisCC->FirstParameter(); + ULast = BisCC->LastParameter (); + Bis = BisCC; + ReplaceByLineIfIsToSmall(Bis,UFirst,ULast); } } } + UFirst = Max(UFirst, Bis->FirstParameter()); + ULast = Min(ULast, Bis->LastParameter()); thebisector = new Geom2d_TrimmedCurve(Bis,UFirst,ULast); - -/* - sprintf( name, "c1_%d", ++nbb ); - DrawTrSurf::Set( name, afirstcurve ); - sprintf( name, "c2_%d", nbb ); - DrawTrSurf::Set( name, asecondcurve ); - sprintf( name, "p%d", nbb ); - DrawTrSurf::Set( name, apoint ); - sprintf( name, "b%d", nbb ); - DrawTrSurf::Set( name, thebisector ); -*/ +#ifdef DRAW + if(Affich) + { + sprintf( name, "c1_%d", ++nbb ); + DrawTrSurf::Set( name, afirstcurve ); + sprintf( name, "c2_%d", nbb ); + DrawTrSurf::Set( name, asecondcurve ); + sprintf( name, "p%d", nbb ); + DrawTrSurf::Set( name, apoint ); + sprintf( name, "b%d", nbb ); + DrawTrSurf::Set( name, thebisector ); + } +#endif + } //=========================================================================== @@ -204,13 +298,13 @@ void Bisector_Bisec::Perform(const Handle(Geom2d_Curve)& afirstcurve , //=========================================================================== void Bisector_Bisec::Perform(const Handle(Geom2d_Curve)& afirstcurve , - const Handle(Geom2d_Point)& asecondpoint , - const gp_Pnt2d& apoint , - const gp_Vec2d& afirstvector , - const gp_Vec2d& asecondvector, - const Standard_Real adirection , - const Standard_Real tolerance , - const Standard_Boolean oncurve ) + const Handle(Geom2d_Point)& asecondpoint , + const gp_Pnt2d& apoint , + const gp_Vec2d& afirstvector , + const gp_Vec2d& asecondvector, + const Standard_Real adirection , + const Standard_Real tolerance , + const Standard_Boolean oncurve ) { //gp_Pnt2d SecondPnt = asecondpoint->Pnt2d(); @@ -220,7 +314,7 @@ void Bisector_Bisec::Perform(const Handle(Geom2d_Curve)& afirstcurve , if (Type1 == STANDARD_TYPE(Geom2d_TrimmedCurve)) { Type1 = Handle(Geom2d_TrimmedCurve)::DownCast(afirstcurve) - ->BasisCurve()->DynamicType(); + ->BasisCurve()->DynamicType(); } if ( Type1 == STANDARD_TYPE(Geom2d_Circle) || Type1 == STANDARD_TYPE(Geom2d_Line)) { @@ -229,13 +323,13 @@ void Bisector_Bisec::Perform(const Handle(Geom2d_Curve)& afirstcurve , //------------------------------------------------------------------ Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna(); BisAna -> Perform (afirstcurve , - asecondpoint , - apoint , - afirstvector , - asecondvector , - adirection , - tolerance , - oncurve ); + asecondpoint , + apoint , + afirstvector , + asecondvector , + adirection , + tolerance , + oncurve ); UFirst = BisAna->ParameterOfStartPoint(); ULast = BisAna->ParameterOfEndPoint(); Bis = BisAna; @@ -243,11 +337,11 @@ void Bisector_Bisec::Perform(const Handle(Geom2d_Curve)& afirstcurve , else { Standard_Boolean IsLine = Standard_False; Standard_Real RC = Precision::Infinite(); - + if (oncurve) { if (Bisector::IsConvex(afirstcurve,adirection) || - IsMaxRC(afirstcurve,afirstcurve->LastParameter(),RC)) { - IsLine = Standard_True; + IsMaxRC(afirstcurve,afirstcurve->LastParameter(),RC)) { + IsLine = Standard_True; } } if (IsLine) { @@ -269,66 +363,73 @@ void Bisector_Bisec::Perform(const Handle(Geom2d_Curve)& afirstcurve , //------------------------------------------------------------------- Handle(Bisector_BisecPC) BisPC = new Bisector_BisecPC(); Handle(Geom2d_Curve) afirstcurvereverse = afirstcurve->Reversed(); - + BisPC -> Perform(afirstcurvereverse , - asecondpoint->Pnt2d(), - - adirection ); -// Modified by Sergey KHROMOV - Thu Feb 21 16:49:54 2002 Begin + asecondpoint->Pnt2d(), + - adirection ); + // Modified by Sergey KHROMOV - Thu Feb 21 16:49:54 2002 Begin if (BisPC -> IsEmpty()) { - gp_Dir2d dir1(afirstvector), dir2(asecondvector); - Standard_Real - Nx = - dir1.X() - dir2.X(), - Ny = - dir1.Y() - dir2.Y(); - if (Abs(Nx) <= gp::Resolution() && Abs(Ny) <= gp::Resolution()) { - Nx = - afirstvector.Y(); - Ny = afirstvector.X(); - } -// gp_Dir2d N ( -adirection*afirstvector.Y(), adirection*afirstvector.X()); - gp_Dir2d N ( adirection*Nx, adirection*Ny); - Handle (Geom2d_Line) L = new Geom2d_Line (apoint,N); - Handle (Geom2d_TrimmedCurve) BisL = new Geom2d_TrimmedCurve(L,0,RC); - Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna (); - BisAna->Init(BisL); - UFirst = BisAna->ParameterOfStartPoint(); - ULast = BisAna->ParameterOfEndPoint(); - Bis = BisAna; + gp_Dir2d dir1(afirstvector), dir2(asecondvector); + Standard_Real + Nx = - dir1.X() - dir2.X(), + Ny = - dir1.Y() - dir2.Y(); + if (Abs(Nx) <= gp::Resolution() && Abs(Ny) <= gp::Resolution()) { + Nx = - afirstvector.Y(); + Ny = afirstvector.X(); + } + // gp_Dir2d N ( -adirection*afirstvector.Y(), adirection*afirstvector.X()); + gp_Dir2d N ( adirection*Nx, adirection*Ny); + Handle (Geom2d_Line) L = new Geom2d_Line (apoint,N); + Handle (Geom2d_TrimmedCurve) BisL = new Geom2d_TrimmedCurve(L,0,RC); + Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna (); + BisAna->Init(BisL); + UFirst = BisAna->ParameterOfStartPoint(); + ULast = BisAna->ParameterOfEndPoint(); + Bis = BisAna; } else { -// Modified by Sergey KHROMOV - Wed Mar 6 17:01:08 2002 End - UFirst = BisPC->Parameter(apoint); - ULast = BisPC->LastParameter(); - if(UFirst >= ULast) - { - //Standard_Real t = .9; - //UFirst = (1. - t) * BisPC->FirstParameter() + t * ULast; - //Extrapolate by line - //gp_Dir2d N ( -adirection*afirstvector.Y(), adirection*afirstvector.X()); - gp_Vec2d V( BisPC->Value(BisPC->FirstParameter()), BisPC->Value(ULast) ); - gp_Dir2d N( V ); - Handle (Geom2d_Line) L = new Geom2d_Line (apoint,N); - Handle (Geom2d_TrimmedCurve) BisL = new Geom2d_TrimmedCurve (L,0,RC); - Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna (); - BisAna->Init(BisL); - UFirst = BisAna->ParameterOfStartPoint(); - ULast = BisAna->ParameterOfEndPoint(); - Bis = BisAna; - } - else - Bis = BisPC; + // Modified by Sergey KHROMOV - Wed Mar 6 17:01:08 2002 End + UFirst = BisPC->Parameter(apoint); + ULast = BisPC->LastParameter(); + if(UFirst >= ULast) + { + //Standard_Real t = .9; + //UFirst = (1. - t) * BisPC->FirstParameter() + t * ULast; + //Extrapolate by line + //gp_Dir2d N ( -adirection*afirstvector.Y(), adirection*afirstvector.X()); + gp_Vec2d V( BisPC->Value(BisPC->FirstParameter()), BisPC->Value(ULast) ); + gp_Dir2d N( V ); + Handle (Geom2d_Line) L = new Geom2d_Line (apoint,N); + Handle (Geom2d_TrimmedCurve) BisL = new Geom2d_TrimmedCurve (L,0,RC); + Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna (); + BisAna->Init(BisL); + UFirst = BisAna->ParameterOfStartPoint(); + ULast = BisAna->ParameterOfEndPoint(); + Bis = BisAna; + } + else + Bis = BisPC; } } } + if(UFirst < Bis->FirstParameter()) + UFirst = Bis->FirstParameter(); + if(ULast > Bis->LastParameter()) + ULast = Bis->LastParameter(); thebisector = new Geom2d_TrimmedCurve(Bis,UFirst,ULast); -/* +#ifdef DRAW + if(Affich) + { sprintf( name, "c1_%d", ++nbb ); DrawTrSurf::Set( name, afirstcurve ); sprintf( name, "c2_%d", nbb ); - DrawTrSurf::Set( name, SecondPnt ); + DrawTrSurf::Set( name, asecondpoint->Pnt2d() ); sprintf( name, "p%d", nbb ); DrawTrSurf::Set( name, apoint ); sprintf( name, "b%d", nbb ); DrawTrSurf::Set( name, thebisector ); -*/ + } +#endif } //=========================================================================== @@ -344,13 +445,13 @@ void Bisector_Bisec::Perform(const Handle(Geom2d_Curve)& afirstcurve , //=========================================================================== void Bisector_Bisec::Perform(const Handle(Geom2d_Point)& afirstpoint , - const Handle(Geom2d_Curve)& asecondcurve , - const gp_Pnt2d& apoint , - const gp_Vec2d& afirstvector , - const gp_Vec2d& asecondvector, - const Standard_Real adirection , - const Standard_Real tolerance , - const Standard_Boolean oncurve ) + const Handle(Geom2d_Curve)& asecondcurve , + const gp_Pnt2d& apoint , + const gp_Vec2d& afirstvector , + const gp_Vec2d& asecondvector, + const Standard_Real adirection , + const Standard_Real tolerance , + const Standard_Boolean oncurve ) { //gp_Pnt2d FirstPnt = afirstpoint->Pnt2d(); @@ -358,38 +459,38 @@ void Bisector_Bisec::Perform(const Handle(Geom2d_Point)& afirstpoint , Handle(Bisector_Curve) Bis; Handle(Standard_Type) Type1 = asecondcurve ->DynamicType(); Standard_Real UFirst,ULast; - + if (Type1 == STANDARD_TYPE(Geom2d_TrimmedCurve)) { Type1 = Handle(Geom2d_TrimmedCurve)::DownCast(asecondcurve) - ->BasisCurve()->DynamicType(); + ->BasisCurve()->DynamicType(); } - + if ( Type1 == STANDARD_TYPE(Geom2d_Circle) || Type1 == STANDARD_TYPE(Geom2d_Line)) { //------------------------------------------------------------------ // Analytic Bissectrice. //------------------------------------------------------------------ Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna(); BisAna -> Perform (afirstpoint , - asecondcurve , - apoint , - afirstvector , - asecondvector , - adirection , - tolerance , - oncurve ); + asecondcurve , + apoint , + afirstvector , + asecondvector , + adirection , + tolerance , + oncurve ); UFirst = BisAna->ParameterOfStartPoint(); ULast = BisAna->ParameterOfEndPoint(); Bis = BisAna; } else { -// Standard_Real UPoint = 0.; + // Standard_Real UPoint = 0.; Standard_Boolean IsLine = Standard_False; Standard_Real RC = Precision::Infinite(); - + if (oncurve) { if (Bisector::IsConvex(asecondcurve, adirection) || - IsMaxRC(asecondcurve,asecondcurve->FirstParameter(),RC)) { - IsLine = Standard_True; + IsMaxRC(asecondcurve,asecondcurve->FirstParameter(),RC)) { + IsLine = Standard_True; } } if (IsLine) { @@ -411,62 +512,69 @@ void Bisector_Bisec::Perform(const Handle(Geom2d_Point)& afirstpoint , //------------------------------------------------------------------- Handle(Bisector_BisecPC) BisPC = new Bisector_BisecPC(); BisPC -> Perform(asecondcurve , - afirstpoint->Pnt2d(), - adirection ); -// Modified by Sergey KHROMOV - Thu Feb 21 16:49:54 2002 Begin + afirstpoint->Pnt2d(), + adirection ); + // Modified by Sergey KHROMOV - Thu Feb 21 16:49:54 2002 Begin if (BisPC -> IsEmpty()) { - gp_Dir2d dir1(afirstvector), dir2(asecondvector); - Standard_Real - Nx = - dir1.X() - dir2.X(), - Ny = - dir1.Y() - dir2.Y(); - if (Abs(Nx) <= gp::Resolution() && Abs(Ny) <= gp::Resolution()) { - Nx = - afirstvector.Y(); - Ny = afirstvector.X(); - } -// gp_Dir2d N ( -adirection*afirstvector.Y(), adirection*afirstvector.X()); - gp_Dir2d N ( adirection*Nx, adirection*Ny); - Handle (Geom2d_Line) L = new Geom2d_Line (apoint,N); - Handle (Geom2d_TrimmedCurve) BisL = new Geom2d_TrimmedCurve(L,0,RC); - Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna (); - BisAna->Init(BisL); - UFirst = BisAna->ParameterOfStartPoint(); - ULast = BisAna->ParameterOfEndPoint(); - Bis = BisAna; + gp_Dir2d dir1(afirstvector), dir2(asecondvector); + Standard_Real + Nx = - dir1.X() - dir2.X(), + Ny = - dir1.Y() - dir2.Y(); + if (Abs(Nx) <= gp::Resolution() && Abs(Ny) <= gp::Resolution()) { + Nx = - afirstvector.Y(); + Ny = afirstvector.X(); + } + // gp_Dir2d N ( -adirection*afirstvector.Y(), adirection*afirstvector.X()); + gp_Dir2d N ( adirection*Nx, adirection*Ny); + Handle (Geom2d_Line) L = new Geom2d_Line (apoint,N); + Handle (Geom2d_TrimmedCurve) BisL = new Geom2d_TrimmedCurve(L,0,RC); + Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna (); + BisAna->Init(BisL); + UFirst = BisAna->ParameterOfStartPoint(); + ULast = BisAna->ParameterOfEndPoint(); + Bis = BisAna; } else { -// Modified by Sergey KHROMOV - Thu Feb 21 16:49:58 2002 End - UFirst = BisPC->Parameter(apoint); - ULast = BisPC->LastParameter(); - if(UFirst >= ULast) - { - //Extrapolate by line - //gp_Dir2d N ( -adirection*afirstvector.Y(), adirection*afirstvector.X()); - gp_Vec2d V( BisPC->Value(BisPC->FirstParameter()), BisPC->Value(ULast) ); - gp_Dir2d N( V ); - Handle (Geom2d_Line) L = new Geom2d_Line (apoint,N); - Handle (Geom2d_TrimmedCurve) BisL = new Geom2d_TrimmedCurve (L,0,RC); - Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna (); - BisAna->Init(BisL); - UFirst = BisAna->ParameterOfStartPoint(); - ULast = BisAna->ParameterOfEndPoint(); - Bis = BisAna; - } - else - Bis = BisPC; + // Modified by Sergey KHROMOV - Thu Feb 21 16:49:58 2002 End + UFirst = BisPC->Parameter(apoint); + ULast = BisPC->LastParameter(); + if(UFirst >= ULast) + { + //Extrapolate by line + //gp_Dir2d N ( -adirection*afirstvector.Y(), adirection*afirstvector.X()); + gp_Vec2d V( BisPC->Value(BisPC->FirstParameter()), BisPC->Value(ULast) ); + gp_Dir2d N( V ); + Handle (Geom2d_Line) L = new Geom2d_Line (apoint,N); + Handle (Geom2d_TrimmedCurve) BisL = new Geom2d_TrimmedCurve (L,0,RC); + Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna (); + BisAna->Init(BisL); + UFirst = BisAna->ParameterOfStartPoint(); + ULast = BisAna->ParameterOfEndPoint(); + Bis = BisAna; + } + else + Bis = BisPC; } } } + + UFirst = Max(UFirst, Bis->FirstParameter()); + ULast = Min(ULast, Bis->LastParameter()); thebisector = new Geom2d_TrimmedCurve(Bis,UFirst,ULast); -/* +#ifdef DRAW + if(Affich) + { sprintf( name, "c1_%d", ++nbb ); - DrawTrSurf::Set( name, FirstPnt ); + DrawTrSurf::Set( name, afirstpoint->Pnt2d() ); sprintf( name, "c2_%d", nbb ); DrawTrSurf::Set( name, asecondcurve ); sprintf( name, "p%d", nbb ); DrawTrSurf::Set( name, apoint ); sprintf( name, "b%d", nbb ); DrawTrSurf::Set( name, thebisector ); -*/ + } +#endif + } //=========================================================================== @@ -481,29 +589,31 @@ void Bisector_Bisec::Perform(const Handle(Geom2d_Point)& afirstpoint , //=========================================================================== void Bisector_Bisec::Perform(const Handle(Geom2d_Point)& afirstpoint , - const Handle(Geom2d_Point)& asecondpoint , - const gp_Pnt2d& apoint , - const gp_Vec2d& afirstvector , - const gp_Vec2d& asecondvector, - const Standard_Real adirection , - const Standard_Real tolerance , - const Standard_Boolean oncurve ) + const Handle(Geom2d_Point)& asecondpoint , + const gp_Pnt2d& apoint , + const gp_Vec2d& afirstvector , + const gp_Vec2d& asecondvector, + const Standard_Real adirection , + const Standard_Real tolerance , + const Standard_Boolean oncurve ) { Handle(Bisector_BisecAna) Bis = new Bisector_BisecAna(); Bis -> Perform (afirstpoint , - asecondpoint , - apoint , - afirstvector , - asecondvector , - adirection , - tolerance , - oncurve ); + asecondpoint , + apoint , + afirstvector , + asecondvector , + adirection , + tolerance , + oncurve ); thebisector = new Geom2d_TrimmedCurve(Bis, - Bis->ParameterOfStartPoint(), - Bis->ParameterOfEndPoint()); + Bis->ParameterOfStartPoint(), + Bis->ParameterOfEndPoint()); -/* +#ifdef DRAW + if(Affich) + { sprintf( name, "c1_%d", ++nbb ); DrawTrSurf::Set( name, afirstpoint->Pnt2d() ); sprintf( name, "c2_%d", nbb ); @@ -512,7 +622,8 @@ void Bisector_Bisec::Perform(const Handle(Geom2d_Point)& afirstpoint , DrawTrSurf::Set( name, apoint ); sprintf( name, "b%d", nbb ); DrawTrSurf::Set( name, thebisector ); -*/ + } +#endif } //============================================================================= @@ -539,8 +650,8 @@ const Handle(Geom2d_TrimmedCurve)& Bisector_Bisec::ChangeValue() // replaced by a half-straight. //============================================================================= static void ReplaceByLineIfIsToSmall (Handle(Geom2d_Curve)& Bis, - Standard_Real& UFirst, - Standard_Real& ULast ) + Standard_Real& UFirst, + Standard_Real& ULast ) { if (Abs(ULast - UFirst) > 2.*Precision::PConfusion()*10.) return; //patch @@ -568,8 +679,8 @@ static void ReplaceByLineIfIsToSmall (Handle(Geom2d_Curve)& Bis, //purpose : //============================================================================= static Standard_Boolean IsMaxRC (const Handle(Geom2d_Curve)& C, - Standard_Real U, - Standard_Real& R) + Standard_Real U, + Standard_Real& R) { Standard_Real KF,KL; Standard_Real US = C->FirstParameter(); @@ -583,7 +694,7 @@ static Standard_Boolean IsMaxRC (const Handle(Geom2d_Curve)& C, Norm2 = D1.SquareMagnitude();; if (Norm2 < gp::Resolution()) { KF = 0.0;} else { KF = Abs(D1^D2)/(Norm2*sqrt(Norm2));} - + C->D2(UL,P,D1,D2); Norm2 = D1.SquareMagnitude();; if (Norm2 < gp::Resolution()) { KL = 0.0;} diff --git a/src/Bisector/Bisector_BisecCC.cxx b/src/Bisector/Bisector_BisecCC.cxx index 62bd97f129..165d4c5dfb 100644 --- a/src/Bisector/Bisector_BisecCC.cxx +++ b/src/Bisector/Bisector_BisecCC.cxx @@ -5,8 +5,8 @@ // // This file is part of Open CASCADE Technology software library. // -// This library is free software; you can redistribute it and / or modify it -// under the terms of the GNU Lesser General Public version 2.1 as published +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published // by the Free Software Foundation, with special exception defined in the file // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT // distribution for complete text of the license and disclaimer of any warranty. @@ -46,24 +46,24 @@ static Standard_Boolean ProjOnCurve (const gp_Pnt2d& P, - const Handle(Geom2d_Curve)& C, - Standard_Real& theParam); + const Handle(Geom2d_Curve)& C, + Standard_Real& theParam); static Standard_Real Curvature (const Handle(Geom2d_Curve)& C, - Standard_Real U, - Standard_Real Tol) ; + Standard_Real U, + Standard_Real Tol) ; static Standard_Boolean TestExtension (const Handle(Geom2d_Curve)& C1, - const Handle(Geom2d_Curve)& C2, - const Standard_Integer Start_End); + const Handle(Geom2d_Curve)& C2, + const Standard_Integer Start_End); static Standard_Boolean DiscretPar(const Standard_Real DU, - const Standard_Real EpsMin, - const Standard_Real EpsMax, - const Standard_Integer NbMin, - const Standard_Integer NbMax, - Standard_Real& Eps, - Standard_Integer& Nb); + const Standard_Real EpsMin, + const Standard_Real EpsMax, + const Standard_Integer NbMin, + const Standard_Integer NbMax, + Standard_Real& Eps, + Standard_Integer& Nb); //============================================================================= //function : @@ -80,11 +80,11 @@ Bisector_BisecCC::Bisector_BisecCC() //purpose : //============================================================================= Bisector_BisecCC::Bisector_BisecCC(const Handle(Geom2d_Curve)& Cu1, - const Handle(Geom2d_Curve)& Cu2, - const Standard_Real Side1, - const Standard_Real Side2, - const gp_Pnt2d& Origin, - const Standard_Real DistMax) + const Handle(Geom2d_Curve)& Cu2, + const Standard_Real Side1, + const Standard_Real Side2, + const gp_Pnt2d& Origin, + const Standard_Real DistMax) { Perform (Cu1,Cu2,Side1,Side2,Origin,DistMax); } @@ -94,11 +94,11 @@ Bisector_BisecCC::Bisector_BisecCC(const Handle(Geom2d_Curve)& Cu1, //purpose : //============================================================================= void Bisector_BisecCC::Perform(const Handle(Geom2d_Curve)& Cu1, - const Handle(Geom2d_Curve)& Cu2, - const Standard_Real Side1, - const Standard_Real Side2, - const gp_Pnt2d& Origin, - const Standard_Real DistMax) + const Handle(Geom2d_Curve)& Cu2, + const Standard_Real Side1, + const Standard_Real Side2, + const gp_Pnt2d& Origin, + const Standard_Real DistMax) { isEmpty = Standard_False; distMax = DistMax; @@ -122,7 +122,6 @@ void Bisector_BisecCC::Perform(const Handle(Geom2d_Curve)& Cu1, // Calculate first point of the polygon. //--------------------------------------------- Standard_Boolean isProjDone = ProjOnCurve (Origin,curve1, U); - P = ValueByInt (U,UC1,UC2,Dist); if(!isProjDone) { @@ -130,6 +129,20 @@ void Bisector_BisecCC::Perform(const Handle(Geom2d_Curve)& Cu1, return; } + P = ValueByInt (U,UC1,UC2,Dist); + if(Dist < Precision::Confusion()) + { + gp_Pnt2d aP1 = curve1->Value(UC1); + gp_Pnt2d aP2 = curve2->Value(UC2); + Standard_Real dp = (aP1.Distance(P)+aP2.Distance(P)); + Standard_Real dorig = (aP1.Distance(Origin)+aP2.Distance(Origin)); + if(dp < dorig) + { + isEmpty = Standard_True; + return; + } + } + if (Dist < Precision::Infinite()) { //---------------------------------------------------- // the parameter of the origin point gives a point @@ -164,7 +177,7 @@ void Bisector_BisecCC::Perform(const Handle(Geom2d_Curve)& Cu1, } } - if ( !myPolygon.Length() == 0) { + if ( myPolygon.Length() != 0 ) { SupLastParameter(); //---------------------------------------------- // Construction of the polygon of the bissectrice. @@ -363,11 +376,11 @@ Handle(Geom2d_Geometry) Bisector_BisecCC::Copy() const Handle(Bisector_BisecCC) Bisector_BisecCC::ChangeGuide() const { Handle(Bisector_BisecCC) C = new Bisector_BisecCC(); - + C -> Curve (1, curve2) ; C -> Curve (2, curve1); C -> Sign (1, sign2 ) ; C -> Sign (2, sign1 ); C -> IsConvex (1, isConvex2); C -> IsConvex (2, isConvex1); - + //------------------------------------------------------------------------- // Construction of the new polygon from the initial one. // inversion of PointOnBis and Calculation of new parameters on the bissectrice. @@ -380,8 +393,8 @@ Handle(Bisector_BisecCC) Bisector_BisecCC::ChangeGuide() const for (Standard_Integer i = myPolygon.Length(); i >=1; i--) { Bisector_PointOnBis P = myPolygon.Value(i); Bisector_PointOnBis NewP (P.ParamOnC2(), P.ParamOnC1(), - P.ParamOnC2(), P.Distance (), - P.Point()); + P.ParamOnC2(), P.Distance (), + P.Point()); Poly.Append (NewP); } } @@ -389,15 +402,15 @@ Handle(Bisector_BisecCC) Bisector_BisecCC::ChangeGuide() const for (Standard_Integer i = 1; i <= myPolygon.Length(); i ++) { Bisector_PointOnBis P = myPolygon.Value(i); Bisector_PointOnBis NewP (P.ParamOnC2(), P.ParamOnC1(), - P.ParamOnC2(), P.Distance (), - P.Point()); + P.ParamOnC2(), P.Distance (), + P.Point()); Poly.Append (NewP); } } C -> Polygon (Poly); C -> FirstParameter (Poly.First().ParamOnBis()); C -> LastParameter (Poly.Last() .ParamOnBis()); - + return C; } @@ -429,7 +442,7 @@ Standard_Boolean Bisector_BisecCC::IsCN (const Standard_Integer N) const //============================================================================= Standard_Real Bisector_BisecCC::FirstParameter() const { - return startIntervals.First(); + return startIntervals.First(); } //============================================================================= @@ -438,7 +451,7 @@ Standard_Real Bisector_BisecCC::FirstParameter() const //============================================================================= Standard_Real Bisector_BisecCC::LastParameter() const { - return endIntervals.Last(); + return endIntervals.Last(); } //============================================================================= @@ -475,7 +488,7 @@ Standard_Real Bisector_BisecCC::IntervalFirst(const Standard_Integer Index) cons { return startIntervals.Value(Index); } - + //============================================================================= //function : IntervalLast //purpose : @@ -510,7 +523,7 @@ Standard_Boolean Bisector_BisecCC::IsClosed() const { if (curve1->IsClosed()) { if (startIntervals.First() == curve1->FirstParameter() && - endIntervals .Last () == curve1->LastParameter () ) + endIntervals .Last () == curve1->LastParameter () ) return Standard_True; } return Standard_False; @@ -531,8 +544,8 @@ Standard_Boolean Bisector_BisecCC::IsPeriodic() const //purpose : //============================================================================= static Standard_Real Curvature (const Handle(Geom2d_Curve)& C, - Standard_Real U, - Standard_Real Tol) + Standard_Real U, + Standard_Real Tol) { Standard_Real K1; gp_Vec2d D1,D2; @@ -569,9 +582,9 @@ static Standard_Real Curvature (const Handle(Geom2d_Curve)& C, // //============================================================================= gp_Pnt2d Bisector_BisecCC::ValueAndDist (const Standard_Real U, - Standard_Real& U1, - Standard_Real& U2, - Standard_Real& Dist) const + Standard_Real& U1, + Standard_Real& U2, + Standard_Real& Dist) const { gp_Vec2d T; @@ -619,11 +632,11 @@ gp_Pnt2d Bisector_BisecCC::ValueAndDist (const Standard_Real U, //--------------------------------------------------------------- gp_Pnt2d P1; gp_Vec2d T1; - Standard_Real EpsH = 1.E-8; - Standard_Real EpsH100 = 1.E-6; + Standard_Real EpsH = 1.E-9; + Standard_Real EpsH100 = 1.E-7; curve1->D1 (U1,P1,T1); gp_Vec2d N1(T1.Y(), - T1.X()); - + if ((VMax - VMin) < Precision::PConfusion()) { U2 = VInit; } @@ -637,14 +650,14 @@ gp_Pnt2d Bisector_BisecCC::ValueAndDist (const Standard_Real U, else { math_BissecNewton SolNew (H,VMin - EpsH100,VMax + EpsH100,EpsH,10); if (SolNew.IsDone()) { - U2 = SolNew.Root(); + U2 = SolNew.Root(); } else { - math_FunctionRoot SolRoot (H,VInit,EpsH,VMin - EpsH100,VMax + EpsH100); - if (SolRoot.IsDone()) { - U2 = SolRoot.Root(); - } - else { Valid = Standard_False;} + math_FunctionRoot SolRoot (H,VInit,EpsH,VMin - EpsH100,VMax + EpsH100); + if (SolRoot.IsDone()) { + U2 = SolRoot.Root(); + } + else { Valid = Standard_False;} } } } @@ -667,8 +680,8 @@ gp_Pnt2d Bisector_BisecCC::ValueAndDist (const Standard_Real U, Valid = Standard_False; } else { - PBis = P1.Translated(- (0.5*SquareP2P1/N1P2P1)*N1); - Dist = P1.SquareDistance(PBis); + PBis = P1.Translated(- (0.5*SquareP2P1/N1P2P1)*N1); + Dist = P1.SquareDistance(PBis); } } @@ -691,20 +704,20 @@ gp_Pnt2d Bisector_BisecCC::ValueAndDist (const Standard_Real U, Geom2dAdaptor_Curve ANorLi(NorLi); //------------------------------------------------------------------------- Geom2dInt_GInter Intersect(ABisPC,ANorLi, - Precision::Confusion(),Precision::Confusion()); + Precision::Confusion(),Precision::Confusion()); //------------------------------------------------------------------------- if (Intersect.IsDone() && !Intersect.IsEmpty()) { for (Standard_Integer i = 1; i <= Intersect.NbPoints(); i++) { - if (Intersect.Point(i).ParamOnSecond()*sign1 < Precision::PConfusion()) { - P = Intersect.Point(i).Value(); - if (P.SquareDistance(P1) < DMin) { - DMin = P.SquareDistance(P1); - PBis = P; - U2 = BisPC->LinkBisCurve(Intersect.Point(i).ParamOnFirst()); - Dist = DMin; - } - } + if (Intersect.Point(i).ParamOnSecond()*sign1 < Precision::PConfusion()) { + P = Intersect.Point(i).Value(); + if (P.SquareDistance(P1) < DMin) { + DMin = P.SquareDistance(P1); + PBis = P; + U2 = BisPC->LinkBisCurve(Intersect.Point(i).ParamOnFirst()); + Dist = DMin; + } + } } } } @@ -725,9 +738,9 @@ gp_Pnt2d Bisector_BisecCC::ValueAndDist (const Standard_Real U, // normal at this point. //============================================================================= gp_Pnt2d Bisector_BisecCC::ValueByInt (const Standard_Real U, - Standard_Real& U1, - Standard_Real& U2, - Standard_Real& Dist) const + Standard_Real& U1, + Standard_Real& U2, + Standard_Real& Dist) const { //------------------------------------------------------------------ // Return point, tangent, normal on C1 at parameter U. @@ -738,7 +751,7 @@ gp_Pnt2d Bisector_BisecCC::ValueByInt (const Standard_Real U, gp_Vec2d Tan1,Tan2; curve1->D1(U1,P1,Tan1); gp_Vec2d N1( Tan1.Y(), - Tan1.X()); - + //-------------------------------------------------------------------------- // test confusion of P1 with extremity of curve2. //-------------------------------------------------------------------------- @@ -777,7 +790,7 @@ gp_Pnt2d Bisector_BisecCC::ValueByInt (const Standard_Real U, Standard_Integer NbSamples =20; Standard_Real UFirstOnC2 = curve2->FirstParameter(); Standard_Real ULastOnC2 = curve2->LastParameter(); - + if (!myPolygon.IsEmpty()){ if (sign1 == sign2) { ULastOnC2 = myPolygon.Last().ParamOnC2();} else { UFirstOnC2 = myPolygon.Last().ParamOnC2();} @@ -792,10 +805,10 @@ gp_Pnt2d Bisector_BisecCC::ValueByInt (const Standard_Real U, Bisector_FunctionH H (curve2,P1,sign1*sign2*Tan1); math_FunctionRoots SolRoot (H, - UFirstOnC2, - ULastOnC2 , - NbSamples, - EpsX,EpsH,EpsH); + UFirstOnC2, + ULastOnC2 , + NbSamples, + EpsX,EpsH,EpsH); if (SolRoot.IsDone()) { for (Standard_Integer j = 1; j <= SolRoot.NbSolutions(); j++) { USol = SolRoot.Value(j); @@ -806,60 +819,60 @@ gp_Pnt2d Bisector_BisecCC::ValueByInt (const Standard_Real U, // Test if the solution is at the proper side of the curves. if (N1P2P1*sign1 > 0 ) { - P = P1.Translated(- (0.5*SquareP2P1/N1P2P1)*N1); - DistPP1 = P1.SquareDistance(P); - if (DistPP1 < DMin) { - DMin = DistPP1; - PSol = P; - U2 = USol; - YaSol = Standard_True; - } + P = P1.Translated(- (0.5*SquareP2P1/N1P2P1)*N1); + DistPP1 = P1.SquareDistance(P); + if (DistPP1 < DMin) { + DMin = DistPP1; + PSol = P; + U2 = USol; + YaSol = Standard_True; + } } } } -/* + /* if (!YaSol) { - //-------------------------------------------------------------------- - // Construction de la bisectrice point courbe et de la droite passant - // par P1 et portee par la normale. - //-------------------------------------------------------------------- - Handle(Bisector_BisecPC) BisPC - = new Bisector_BisecPC(curve2,P1,sign2,2*distMax); - //------------------------------- - // Test si la bissectrice existe. - //------------------------------- - if (BisPC->IsEmpty()) { - Dist = Precision::Infinite(); - PSol = P1; - return PSol; - } - - Handle(Geom2d_Line) NorLi = new Geom2d_Line (P1,N1); - Geom2dAdaptor_Curve NorLiAd; - if (sign1 < 0.) {NorLiAd.Load(NorLi,0. ,distMax);} - else {NorLiAd.Load(NorLi,- distMax,0. );} + //-------------------------------------------------------------------- + // Construction de la bisectrice point courbe et de la droite passant + // par P1 et portee par la normale. + //-------------------------------------------------------------------- + Handle(Bisector_BisecPC) BisPC + = new Bisector_BisecPC(curve2,P1,sign2,2*distMax); + //------------------------------- + // Test si la bissectrice existe. + //------------------------------- + if (BisPC->IsEmpty()) { + Dist = Precision::Infinite(); + PSol = P1; + return PSol; + } - //------------------------------------------------------------------------- - Geom2dInt_GInter Intersect(BisPC,NorLiAd, - Precision::Confusion(),Precision::Confusion()); - //------------------------------------------------------------------------- - if (Intersect.IsDone() && !Intersect.IsEmpty()) { - for (Standard_Integer i = 1; i <= Intersect.NbPoints(); i++) { - if (Intersect.Point(i).ParamOnSecond()*sign1< Precision::PConfusion()) { - P = Intersect.Point(i).Value(); - DistPP1 = P.SquareDistance(P1); - if (DistPP1 < DMin) { - DMin = DistPP1; - PSol = P; - U2 = Intersect.Point(i).ParamOnFirst(); - YaSol = Standard_True; - } - } - } - } + Handle(Geom2d_Line) NorLi = new Geom2d_Line (P1,N1); + Geom2dAdaptor_Curve NorLiAd; + if (sign1 < 0.) {NorLiAd.Load(NorLi,0. ,distMax);} + else {NorLiAd.Load(NorLi,- distMax,0. );} + + //------------------------------------------------------------------------- + Geom2dInt_GInter Intersect(BisPC,NorLiAd, + Precision::Confusion(),Precision::Confusion()); + //------------------------------------------------------------------------- + if (Intersect.IsDone() && !Intersect.IsEmpty()) { + for (Standard_Integer i = 1; i <= Intersect.NbPoints(); i++) { + if (Intersect.Point(i).ParamOnSecond()*sign1< Precision::PConfusion()) { + P = Intersect.Point(i).Value(); + DistPP1 = P.SquareDistance(P1); + if (DistPP1 < DMin) { + DMin = DistPP1; + PSol = P; + U2 = Intersect.Point(i).ParamOnFirst(); + YaSol = Standard_True; + } + } } -*/ + } + } + */ if (YaSol) { Dist = DMin; @@ -869,7 +882,7 @@ gp_Pnt2d Bisector_BisecCC::ValueByInt (const Standard_Real U, P2 = curve2->Value(U2); gp_Vec2d PP1(P1.X() - PSol.X(),P1.Y() - PSol.Y()); gp_Vec2d PP2(P2.X() - PSol.X(),P2.Y() - PSol.Y()); - + //----------------------------------------------- // Dist = product of norms = distance at the square. //----------------------------------------------- @@ -878,18 +891,18 @@ gp_Pnt2d Bisector_BisecCC::ValueByInt (const Standard_Real U, } else { if ( !isConvex1 ) { - Standard_Real K1 = Curvature(curve1,U1,Precision::Confusion()); - if (K1 != 0.) { - if (Dist > 1/(K1*K1)) YaSol = Standard_False; - } + Standard_Real K1 = Curvature(curve1,U1,Precision::Confusion()); + if (K1 != 0.) { + if (Dist > 1/(K1*K1)) YaSol = Standard_False; + } } if (YaSol) { - if ( !isConvex2 ) { - Standard_Real K2 = Curvature(curve2,U2,Precision::Confusion()); - if (K2 != 0.) { - if (Dist > 1/(K2*K2)) YaSol = Standard_False; - } - } + if ( !isConvex2 ) { + Standard_Real K2 = Curvature(curve2,U2,Precision::Confusion()); + if (K2 != 0.) { + if (Dist > 1/(K2*K2)) YaSol = Standard_False; + } + } } } } @@ -905,7 +918,7 @@ gp_Pnt2d Bisector_BisecCC::ValueByInt (const Standard_Real U, //purpose : //============================================================================= void Bisector_BisecCC::D0(const Standard_Real U, - gp_Pnt2d& P) const + gp_Pnt2d& P) const { Standard_Real U1,U2,Dist; @@ -917,8 +930,8 @@ void Bisector_BisecCC::D0(const Standard_Real U, //purpose : //============================================================================= void Bisector_BisecCC::D1(const Standard_Real U, - gp_Pnt2d& P, - gp_Vec2d& V ) const + gp_Pnt2d& P, + gp_Vec2d& V ) const { V.SetCoord(0.,0.); gp_Vec2d V2,V3; @@ -930,9 +943,9 @@ void Bisector_BisecCC::D1(const Standard_Real U, //purpose : //============================================================================= void Bisector_BisecCC::D2(const Standard_Real U, - gp_Pnt2d& P, - gp_Vec2d& V1, - gp_Vec2d& V2) const + gp_Pnt2d& P, + gp_Vec2d& V1, + gp_Vec2d& V2) const { V1.SetCoord(0.,0.); V2.SetCoord(0.,0.); @@ -945,10 +958,10 @@ void Bisector_BisecCC::D2(const Standard_Real U, //purpose : //============================================================================= void Bisector_BisecCC::D3(const Standard_Real U, - gp_Pnt2d& P, - gp_Vec2d& V1, - gp_Vec2d& V2, - gp_Vec2d& V3) const + gp_Pnt2d& P, + gp_Vec2d& V1, + gp_Vec2d& V2, + gp_Vec2d& V3) const { V1.SetCoord(0.,0.); V2.SetCoord(0.,0.); @@ -961,7 +974,7 @@ void Bisector_BisecCC::D3(const Standard_Real U, //purpose : //============================================================================= gp_Vec2d Bisector_BisecCC::DN(const Standard_Real U, - const Standard_Integer N) const + const Standard_Integer N) const { gp_Pnt2d P; gp_Vec2d V1(0.,0.); @@ -969,12 +982,12 @@ gp_Vec2d Bisector_BisecCC::DN(const Standard_Real U, gp_Vec2d V3(0.,0.); Values (U,N,P,V1,V2,V3); switch (N) { - case 1 : return V1; - case 2 : return V2; - case 3 : return V3; - default: { - Standard_NotImplemented::Raise(); - } + case 1 : return V1; + case 2 : return V2; + case 3 : return V3; + default: { + Standard_NotImplemented::Raise(); + } } return V1; } @@ -1000,11 +1013,11 @@ gp_Vec2d Bisector_BisecCC::DN(const Standard_Real U, // //============================================================================= void Bisector_BisecCC::Values (const Standard_Real U, - const Standard_Integer N, - gp_Pnt2d& P, - gp_Vec2d& V1, - gp_Vec2d& V2, - gp_Vec2d& V3) const + const Standard_Integer N, + gp_Pnt2d& P, + gp_Vec2d& V1, + gp_Vec2d& V2, + gp_Vec2d& V3) const { V1 = gp_Vec2d(0.,0.); V2 = gp_Vec2d(0.,0.); @@ -1014,7 +1027,7 @@ void Bisector_BisecCC::Values (const Standard_Real U, // curve. //------------------------------------------------------------------------- Standard_Real U0,V0,Dist; - + //----------------------------------------------- // is the polygon reduced to a point or empty? //----------------------------------------------- @@ -1066,16 +1079,16 @@ void Bisector_BisecCC::Values (const Standard_Real U, TvvPuPv = Tvv.Dot(PuPv) ; TvTvv = Tv.Dot(Tvv) ; Standard_Real dHdu = 2*(TuPuPv*(TuuPuPv - TuTu)*TvTv + - TvPuPv*TuTv*TuTu -TuTuu*TvPuPv*TvPuPv); + TvPuPv*TuTv*TuTu -TuTuu*TvPuPv*TvPuPv); Standard_Real dHdv = 2*(TuPuPv*TuTv*TvTv + TvTvv*TuPuPv*TuPuPv - - TvPuPv*(TvvPuPv + TvTv)*TuTu); + TvPuPv*(TvvPuPv + TvTv)*TuTu); //----------------------------- // Calculate dF/du and dF/dv. //----------------------------- Standard_Real NorPuPv,NuPuPv,NorTv; Standard_Real A,B,dAdu,dAdv,dBdu,dBdv,BB; - + NorPuPv = Nor.Dot(PuPv); NuPuPv = Nu .Dot(PuPv); NorTv = Nor.Dot(Tv) ; @@ -1087,7 +1100,7 @@ void Bisector_BisecCC::Values (const Standard_Real U, dBdu = - NuPuPv ; dAdv = TvPuPv; dBdv = - NorTv; - + //--------------------------------------- // F(u,v) = Pu - (A(u,v)/B(u,v))*Nor(u) //---------------------------------------- @@ -1098,7 +1111,7 @@ void Bisector_BisecCC::Values (const Standard_Real U, else { gp_Vec2d dFdu = Tu - (dAdu/B - dBdu*A/BB)*Nor - (A/B)*Nu; gp_Vec2d dFdv = ( - dAdv/B + dBdv*A/BB)*Nor ; - + if (Abs(dHdv) > gp::Resolution()) { V1 = dFdu + dFdv*( - dHdu / dHdv ); } @@ -1115,10 +1128,10 @@ void Bisector_BisecCC::Values (const Standard_Real U, // by tangence of the curve. //============================================================================ gp_Pnt2d Bisector_BisecCC::Extension (const Standard_Real U, - Standard_Real& U1, - Standard_Real& U2, - Standard_Real& Dist, - gp_Vec2d& T ) const + Standard_Real& U1, + Standard_Real& U2, + Standard_Real& Dist, + gp_Vec2d& T ) const { Bisector_PointOnBis PRef; gp_Pnt2d P,P1,P2,PBis; @@ -1189,7 +1202,7 @@ gp_Pnt2d Bisector_BisecCC::Extension (const Standard_Real U, } if (T1.Dot(Tang) < 0.) Tang = - Tang; } - + T = Tang.Normalized(); PBis.SetCoord(P.X() + dU*T.X(),P.Y() + dU*T.Y()); Dist = P1.Distance(PBis); @@ -1201,12 +1214,12 @@ gp_Pnt2d Bisector_BisecCC::Extension (const Standard_Real U, // purpose : //============================================================================= static Standard_Boolean PointByInt(const Handle(Geom2d_Curve)& CA, - const Handle(Geom2d_Curve)& CB, - const Standard_Real SignA, - const Standard_Real SignB, - const Standard_Real UOnA, - Standard_Real& UOnB, - Standard_Real& Dist) + const Handle(Geom2d_Curve)& CB, + const Standard_Real SignA, + const Standard_Real SignB, + const Standard_Real UOnA, + Standard_Real& UOnB, + Standard_Real& Dist) { //------------------------------------------------------------------ // Return point,tangent, normal on CA with parameter UOnA. @@ -1218,7 +1231,7 @@ static Standard_Boolean PointByInt(const Handle(Geom2d_Curve)& CA, CA->D1(UOnA,P1,Tan1); gp_Vec2d N1(Tan1.Y(), - Tan1.X()); - + //-------------------------------------------------------------------------- // test of confusion of P1 with extremity of curve2. //-------------------------------------------------------------------------- @@ -1250,7 +1263,7 @@ static Standard_Boolean PointByInt(const Handle(Geom2d_Curve)& CA, Standard_Real DMin = Precision::Infinite(); Standard_Real UPC; Standard_Boolean YaSol = Standard_False; - //-------------------------------------------------------------------- + //-------------------------------------------------------------------- // Construction of the bisectrice point curve and of the straight line passing // through P1 and carried by the normal. //-------------------------------------------------------------------- @@ -1271,21 +1284,21 @@ static Standard_Boolean PointByInt(const Handle(Geom2d_Curve)& CA, Geom2dAdaptor_Curve ANorLi(NorLi); //------------------------------------------------------------------------- Geom2dInt_GInter Intersect(ABisPC,ANorLi, - Precision::Confusion(),Precision::Confusion()); + Precision::Confusion(),Precision::Confusion()); //------------------------------------------------------------------------- if (Intersect.IsDone() && !Intersect.IsEmpty()) { for (Standard_Integer i = 1; i <= Intersect.NbPoints(); i++) { if (Intersect.Point(i).ParamOnSecond()*SignA < Precision::PConfusion()) { - P = Intersect.Point(i).Value(); - if (P.SquareDistance(P1) < DMin) { - DMin = P.SquareDistance(P1); - PSol = P; - UPC = Intersect.Point(i).ParamOnFirst(); - UOnB = BisPC->LinkBisCurve(UPC); - Dist = DMin; - YaSol = Standard_True; - } + P = Intersect.Point(i).Value(); + if (P.SquareDistance(P1) < DMin) { + DMin = P.SquareDistance(P1); + PSol = P; + UPC = Intersect.Point(i).ParamOnFirst(); + UOnB = BisPC->LinkBisCurve(UPC); + Dist = DMin; + YaSol = Standard_True; + } } } } @@ -1294,27 +1307,38 @@ static Standard_Boolean PointByInt(const Handle(Geom2d_Curve)& CA, // Point found => Test distance curvature + Angular test //--------------------------------------------------------------- P2 = CB->Value(UOnB); + if(P1.SquareDistance(PSol) < 1.e-32) + { + YaSol = Standard_False; + return YaSol; + } + if(P2.SquareDistance(PSol) < 1.e-32) + { + YaSol = Standard_False; + return YaSol; + } + gp_Dir2d PP1Unit(P1.X() - PSol.X(),P1.Y() - PSol.Y()); gp_Dir2d PP2Unit(P2.X() - PSol.X(),P2.Y() - PSol.Y()); - + if (PP1Unit*PP2Unit > 1. - Precision::Angular()) { YaSol = Standard_False; } else { Dist = sqrt(Dist); if ( !IsConvexA ) { - Standard_Real K1 = Curvature(CA,UOnA,Precision::Confusion()); - if (K1 != 0.) { - if (Dist > Abs(1/K1)) YaSol = Standard_False; - } + Standard_Real K1 = Curvature(CA,UOnA,Precision::Confusion()); + if (K1 != 0.) { + if (Dist > Abs(1/K1)) YaSol = Standard_False; + } } if (YaSol) { - if ( !IsConvexB ) { - Standard_Real K2 = Curvature(CB,UOnB,Precision::Confusion()); - if (K2 != 0.) { - if (Dist > Abs(1/K2)) YaSol = Standard_False; - } - } + if ( !IsConvexB ) { + Standard_Real K2 = Curvature(CB,UOnB,Precision::Confusion()); + if (K2 != 0.) { + if (Dist > Abs(1/K2)) YaSol = Standard_False; + } + } } } } @@ -1426,20 +1450,20 @@ Standard_Real Bisector_BisecCC::Parameter(const gp_Pnt2d& P) const //============================================================================= //void Bisector_BisecCC::Dump(const Standard_Integer Deep, void Bisector_BisecCC::Dump(const Standard_Integer , - const Standard_Integer Offset) const + const Standard_Integer Offset) const { Indent (Offset); cout <<"Bisector_BisecCC :"< TolPar || - ((Dist1 < Precision::Infinite() && - Dist2 < Precision::Infinite() && - !PBis.IsEqual(PBisPrec,TolPnt)))) { - PBisPrec = PBis; - UMid = 0.5*( U22 + U11); - PBis = ValueByInt(UMid,UC1,UC2,DistMid); - if ((Dist1 < Precision::Infinite()) == (DistMid < Precision::Infinite())) { - U11 = UMid; - Dist1 = DistMid; - } - else { - U22 = UMid; - Dist2 = DistMid; - } + ((Dist1 < Precision::Infinite() && + Dist2 < Precision::Infinite() && + !PBis.IsEqual(PBisPrec,TolPnt)))) { + PBisPrec = PBis; + UMid = 0.5*( U22 + U11); + PBis = ValueByInt(UMid,UC1,UC2,DistMid); + if ((Dist1 < Precision::Infinite()) == (DistMid < Precision::Infinite())) { + U11 = UMid; + Dist1 = DistMid; + } + else { + U22 = UMid; + Dist2 = DistMid; + } } PBis = ValueByInt(U11,UC1,UC2,Dist1); if (Dist1 < Precision::Infinite()) { @@ -1628,8 +1652,8 @@ Standard_Real Bisector_BisecCC::SearchBound (const Standard_Real U1, // purpose : //============================================================================= static Standard_Boolean ProjOnCurve (const gp_Pnt2d& P, - const Handle(Geom2d_Curve)& C, - Standard_Real& theParam) + const Handle(Geom2d_Curve)& C, + Standard_Real& theParam) { //Standard_Real UOnCurve =0.; theParam = 0.0; @@ -1644,16 +1668,16 @@ static Standard_Boolean ProjOnCurve (const gp_Pnt2d& P, theParam = C->FirstParameter(); return Standard_True; } - + if (P.IsEqual(PL ,Precision::Confusion())) { theParam = C->LastParameter(); return Standard_True; } - + gp_Vec2d PPF(PF.X() - P.X(), PF.Y() - P.Y()); TF.Normalize(); - + if ( Abs (PPF.Dot(TF)) < Precision::Confusion()) { theParam = C->FirstParameter(); @@ -1667,8 +1691,8 @@ static Standard_Boolean ProjOnCurve (const gp_Pnt2d& P, return Standard_True; } Geom2dAPI_ProjectPointOnCurve Proj(P,C, - C->FirstParameter(), - C->LastParameter()); + C->FirstParameter(), + C->LastParameter()); if (Proj.NbPoints() > 0) { theParam = Proj.LowerDistanceParameter(); } @@ -1684,8 +1708,8 @@ static Standard_Boolean ProjOnCurve (const gp_Pnt2d& P, // purpose : //============================================================================= static Standard_Boolean TestExtension (const Handle(Geom2d_Curve)& C1, - const Handle(Geom2d_Curve)& C2, - const Standard_Integer Start_End) + const Handle(Geom2d_Curve)& C2, + const Standard_Integer Start_End) { gp_Pnt2d P1,P2; gp_Vec2d T1,T2; @@ -1708,7 +1732,7 @@ static Standard_Boolean TestExtension (const Handle(Geom2d_Curve)& C1, if (P1.IsEqual(P2,Precision::Confusion())) { T2.Normalize(); if (T1.Dot(T2) > 1.0 - Precision::Confusion()) { - Test = Standard_True; + Test = Standard_True; } } } @@ -1753,12 +1777,12 @@ void Bisector_BisecCC::ComputePointEnd () // purpose : //============================================================================= static Standard_Boolean DiscretPar(const Standard_Real DU, - const Standard_Real EpsMin, - const Standard_Real EpsMax, - const Standard_Integer NbMin, - const Standard_Integer NbMax, - Standard_Real& Eps, - Standard_Integer& Nb) + const Standard_Real EpsMin, + const Standard_Real EpsMax, + const Standard_Integer NbMin, + const Standard_Integer NbMax, + Standard_Real& Eps, + Standard_Integer& Nb) { if (DU <= NbMin*EpsMin) { Eps = DU/(NbMin + 1) ; diff --git a/src/Bisector/Bisector_Inter.cxx b/src/Bisector/Bisector_Inter.cxx index 8f25ee600a..4494cd0a44 100644 --- a/src/Bisector/Bisector_Inter.cxx +++ b/src/Bisector/Bisector_Inter.cxx @@ -5,8 +5,8 @@ // // This file is part of Open CASCADE Technology software library. // -// This library is free software; you can redistribute it and / or modify it -// under the terms of the GNU Lesser General Public version 2.1 as published +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published // by the Free Software Foundation, with special exception defined in the file // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT // distribution for complete text of the license and disclaimer of any warranty. @@ -33,14 +33,14 @@ #include #include #include - -#ifdef DRAW -#include -#include -#include -#endif #ifdef DEB +//#define DRAW +#ifdef DRAW +#include +static char name[100]; static Standard_Boolean Affich = Standard_False; +static Standard_Integer nbint = 0; +#endif #endif //=================================================================================== @@ -174,14 +174,14 @@ void Bisector_Inter::Perform(const Bisector_Bisec& C1, PMax,UMax,D2.LastTolerance()); if ((IB2 == 1 && Bis2->IsExtendAtStart()) || - (IB2 == Bis1->NbIntervals() && Bis2->IsExtendAtEnd()) ){ - //-------------------------------------------------------- - // Part corresponding to an extension is a segment. - //-------------------------------------------------------- - SBis2 [IB2] = ConstructSegment (PMin,PMax,UMin,UMax); + (IB2 == Bis1->NbIntervals() && Bis2->IsExtendAtEnd()) ){ + //-------------------------------------------------------- + // Part corresponding to an extension is a segment. + //-------------------------------------------------------- + SBis2 [IB2] = ConstructSegment (PMin,PMax,UMin,UMax); } else { - SBis2 [IB2] = Bis2; + SBis2 [IB2] = Bis2; } NB2++; } @@ -271,11 +271,11 @@ void Bisector_Inter::SinglePerform(const Handle(Geom2d_Curve)& CBis1, if (Type1 == STANDARD_TYPE(Geom2d_Line) && Type2 != STANDARD_TYPE(Geom2d_Line)) { TestBound(Handle(Geom2d_Line)::DownCast(Bis1), - D1,Bis2,D2,TolConf,Standard_False); + D1,Bis2,D2,TolConf,Standard_False); } else if (Type2 == STANDARD_TYPE(Geom2d_Line)&& Type1 != STANDARD_TYPE(Geom2d_Line)) { TestBound(Handle(Geom2d_Line)::DownCast(Bis2), - D2,Bis1,D1,TolConf,Standard_True); + D2,Bis1,D1,TolConf,Standard_True); } Geom2dInt_GInter Intersect; Geom2dAdaptor_Curve ABis1(Bis1); @@ -287,21 +287,17 @@ void Bisector_Inter::SinglePerform(const Handle(Geom2d_Curve)& CBis1, #ifdef DRAW if (Affich) { - Handle(DrawTrSurf_Curve2d) dr; - Draw_Color Couleur = Draw_bleu; - - dr = new DrawTrSurf_Curve2d(Bis1,Couleur,100); - dout << dr; - dr = new DrawTrSurf_Curve2d(Bis2,Couleur,100); - dout << dr; - if (IsDone() && !IsEmpty()) { + sprintf( name, "i1_%d", ++nbint); + DrawTrSurf::Set(name, Bis1); + sprintf( name, "i2_%d", nbint); + DrawTrSurf::Set(name, Bis2); + if (IsDone() && !IsEmpty()) { for (Standard_Integer k = 1; k <= NbPoints(); k++) { - gp_Pnt2d P = Point(k).Value(); - Handle(Draw_Marker2D) drp = new Draw_Marker2D(P,Draw_Plus,Draw_vert); - dout << drp; + gp_Pnt2d P = Point(k).Value(); + sprintf( name, "ip_%d_%d", nbint, k); + DrawTrSurf::Set(name, P); } } - dout.Flush(); } #endif } @@ -334,7 +330,7 @@ void Bisector_Inter::NeighbourPerform(const Handle(Bisector_BisecCC)& Bis1, // Change guiedline on Bis2. BisTemp = Bis2->ChangeGuide(); Guide = Bis2->Curve(2); -#ifdef DEB +#ifdef OCCT_DEBUG gp_Pnt2d P2S = Bis2->ValueAndDist(D2.FirstParameter(),U1,UMax,Dist); gp_Pnt2d P2E = Bis2->ValueAndDist(D2.LastParameter() ,U1,UMin,Dist); #else diff --git a/src/MAT2d/MAT2d_Tool2d.cxx b/src/MAT2d/MAT2d_Tool2d.cxx index 3eab062007..8826ec83de 100644 --- a/src/MAT2d/MAT2d_Tool2d.cxx +++ b/src/MAT2d/MAT2d_Tool2d.cxx @@ -5,8 +5,8 @@ // // This file is part of Open CASCADE Technology software library. // -// This library is free software; you can redistribute it and / or modify it -// under the terms of the GNU Lesser General Public version 2.1 as published +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published // by the Free Software Foundation, with special exception defined in the file // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT // distribution for complete text of the license and disclaimer of any warranty. @@ -16,6 +16,7 @@ #define Debug(expr) cout<<" MAT2d_Tool2d.cxx : expr :"< #include @@ -68,12 +69,14 @@ #include #ifdef DRAW - static Handle(DrawTrSurf_Curve2d) draw; +static Handle(DrawTrSurf_Curve2d) draw; +static Standard_Integer AffichBis = Standard_False; #endif #ifdef DEB - static void MAT2d_DrawCurve(const Handle(Geom2d_Curve)& aCurve, - const Standard_Integer Indice); - static Standard_Boolean Store = Standard_False; +static void MAT2d_DrawCurve(const Handle(Geom2d_Curve)& aCurve, + const Standard_Integer Indice); +static Standard_Boolean Store = Standard_False; +static Standard_Boolean AffichDist = Standard_False; #endif //===================================================================== @@ -81,15 +84,19 @@ //===================================================================== static IntRes2d_Domain Domain (const Handle(Geom2d_TrimmedCurve)& Bisector1, - const Standard_Real Tolerance); + const Standard_Real Tolerance); static Handle(Standard_Type) Type (const Handle(Geom2d_Geometry)& acurve); static Standard_Boolean AreNeighbours(const Standard_Integer IEdge1, - const Standard_Integer IEdge2, - const Standard_Integer NbEdge); + const Standard_Integer IEdge2, + const Standard_Integer NbEdge); static void SetTrim(Bisector_Bisec& Bis , Handle(Geom2d_Curve)& Line1); +static Standard_Boolean CheckEnds (const Handle(Geom2d_Geometry)& Elt , + const gp_Pnt2d& PCom , + const Standard_Real Distance, + const Standard_Real Tol); static Standard_Real MAT2d_TOLCONF = 1.e-7; @@ -100,6 +107,7 @@ static Standard_Real MAT2d_TOLCONF = 1.e-7; MAT2d_Tool2d::MAT2d_Tool2d() { theDirection = 1.; + //theJoinType = GeomAbs_Arc; //default theNumberOfBisectors = 0; theNumberOfVecs = 0; theNumberOfPnts = 0; @@ -118,10 +126,10 @@ void MAT2d_Tool2d::InitItems(const Handle(MAT2d_Circuit)& EquiCircuit) theNumberOfBisectors = 0; theNumberOfVecs = 0; theNumberOfPnts = 0; - + theCircuit = EquiCircuit; } - + //============================================================================= //function : Sense //purpose : @@ -132,6 +140,15 @@ void MAT2d_Tool2d::Sense(const MAT_Side aside) else theDirection = -1.; } +//============================================================================= +//function : SetJoinType +//purpose : +//============================================================================= +//void MAT2d_Tool2d::SetJoinType(const GeomAbs_JoinType aJoinType) +//{ +// theJoinType = aJoinType; +//} + //============================================================================= //function : NumberOfItems //purpose : @@ -155,7 +172,7 @@ Standard_Real MAT2d_Tool2d::ToleranceOfConfusion() const //purpose : //============================================================================= Standard_Integer MAT2d_Tool2d::FirstPoint(const Standard_Integer anitem, - Standard_Real& dist ) + Standard_Real& dist ) { Handle(Geom2d_Curve) curve; Handle(Geom2d_Point) point; @@ -165,7 +182,7 @@ Standard_Integer MAT2d_Tool2d::FirstPoint(const Standard_Integer anitem, gp_Pnt2d P1 = theCircuit->Connexion(anitem)->PointOnFirst(); gp_Pnt2d P2 = theCircuit->Connexion(anitem)->PointOnSecond(); theGeomPnts.Bind(theNumberOfPnts,gp_Pnt2d((P1.X() + P2.X())*0.5, - (P1.Y() + P2.Y())*0.5)); + (P1.Y() + P2.Y())*0.5)); dist = P1.Distance(P2)*0.5; return theNumberOfPnts; } @@ -194,7 +211,7 @@ Standard_Integer MAT2d_Tool2d::TangentBefore(const Standard_Integer anitem) Standard_Integer item; Handle(Geom2d_Curve) curve; theNumberOfVecs++; - + item = (anitem == theCircuit->NumberOfItems()) ? 1 : (anitem + 1); if (theCircuit->ConnexionOn(item)){ Standard_Real x1,y1,x2,y2; @@ -260,8 +277,8 @@ Standard_Integer MAT2d_Tool2d::Tangent(const Standard_Integer bisector) { theNumberOfVecs++; theGeomVecs.Bind(theNumberOfVecs,GeomBis(bisector).Value() - ->DN(GeomBis(bisector).Value() - ->LastParameter(),1)); + ->DN(GeomBis(bisector).Value() + ->LastParameter(),1)); return theNumberOfVecs; } @@ -279,8 +296,8 @@ void MAT2d_Tool2d::CreateBisector(const Handle(MAT_Bisector)& abisector) Standard_Integer edge1number = abisector->FirstEdge()->EdgeNumber(); Standard_Integer edge2number = abisector->SecondEdge()->EdgeNumber(); Standard_Boolean ontheline = AreNeighbours(edge1number, - edge2number, - NumberOfItems()); + edge2number, + NumberOfItems()); Standard_Boolean InitialNeighbour = ontheline; if(theCircuit->ConnexionOn(edge2number)) ontheline = Standard_False; @@ -311,49 +328,49 @@ void MAT2d_Tool2d::CreateBisector(const Handle(MAT_Bisector)& abisector) cout<<" Item 1 : "<Dump(1,1); + // elt1->Dump(1,1); cout<Dump(1,1); + // elt2->Dump(1,1); cout<IssuePoint()), - GeomVec (abisector->FirstVector()), - GeomVec (abisector->SecondVector()), - theDirection,tolerance,ontheline); + type2 != STANDARD_TYPE(Geom2d_CartesianPoint)) { + bisector.Perform(item1,item2, + GeomPnt (abisector->IssuePoint()), + GeomVec (abisector->FirstVector()), + GeomVec (abisector->SecondVector()), + theDirection,tolerance,ontheline); } else if(type1 == STANDARD_TYPE(Geom2d_CartesianPoint) && - type2 == STANDARD_TYPE(Geom2d_CartesianPoint)) { - point1 = Handle(Geom2d_Point)::DownCast(elt1); - point2 = Handle(Geom2d_Point)::DownCast(elt2); - bisector.Perform(point1,point2, - GeomPnt (abisector->IssuePoint()), - GeomVec (abisector->FirstVector()), - GeomVec (abisector->SecondVector()), - theDirection,tolerance,ontheline); + type2 == STANDARD_TYPE(Geom2d_CartesianPoint)) { + point1 = Handle(Geom2d_Point)::DownCast(elt1); + point2 = Handle(Geom2d_Point)::DownCast(elt2); + bisector.Perform(point1,point2, + GeomPnt (abisector->IssuePoint()), + GeomVec (abisector->FirstVector()), + GeomVec (abisector->SecondVector()), + theDirection,tolerance,ontheline); } else if(type1 == STANDARD_TYPE(Geom2d_CartesianPoint)) { point1 = Handle(Geom2d_Point)::DownCast(elt1); bisector.Perform(point1,item2, - GeomPnt (abisector->IssuePoint()), - GeomVec (abisector->FirstVector()), - GeomVec (abisector->SecondVector()), - theDirection,tolerance,ontheline); + GeomPnt (abisector->IssuePoint()), + GeomVec (abisector->FirstVector()), + GeomVec (abisector->SecondVector()), + theDirection,tolerance,ontheline); } else { point2 = Handle(Geom2d_Point)::DownCast(elt2); bisector.Perform(item1,point2, - GeomPnt (abisector->IssuePoint()), - GeomVec (abisector->FirstVector()), - GeomVec (abisector->SecondVector()), - theDirection,tolerance,ontheline); + GeomPnt (abisector->IssuePoint()), + GeomVec (abisector->FirstVector()), + GeomVec (abisector->SecondVector()), + theDirection,tolerance,ontheline); } //------------------------------ @@ -376,7 +393,7 @@ void MAT2d_Tool2d::CreateBisector(const Handle(MAT_Bisector)& abisector) Handle(Geom2d_Curve) BasisCurve; if (Type1 == STANDARD_TYPE(Bisector_BisecAna)) { BasisCurve = Handle(Bisector_BisecAna) - ::DownCast(bisector.Value()->BasisCurve())->Geom2dCurve(); + ::DownCast(bisector.Value()->BasisCurve())->Geom2dCurve(); #ifdef DRAW char *name = new char[100]; sprintf(name,"BISSEC_%d",abisector->BisectorNumber()); @@ -396,48 +413,47 @@ void MAT2d_Tool2d::CreateBisector(const Handle(MAT_Bisector)& abisector) // Cette restriction est necessaire a la logique de l algorithme. //============================================================================= void MAT2d_Tool2d::TrimBisec ( Bisector_Bisec& B1, - const Standard_Integer IndexEdge, - const Standard_Boolean InitialNeighbour, - const Standard_Integer StartOrEnd ) const + const Standard_Integer IndexEdge, + const Standard_Boolean InitialNeighbour, + const Standard_Integer StartOrEnd ) const { Handle(Geom2d_Curve) Curve; Handle(Geom2d_TrimmedCurve) LineSupportDomain,Line; Handle(Geom2d_Line) Line1,Line2; - + //gp_Vec2d Tan1,Tan2; gp_Pnt2d Ori; //PEdge; - Standard_Integer IPrec,INext; - IPrec = (IndexEdge == 1) ? theCircuit->NumberOfItems() : (IndexEdge - 1); + Standard_Integer INext; INext = (IndexEdge == theCircuit->NumberOfItems()) ? 1 : (IndexEdge + 1); - + Handle(Standard_Type) EdgeType = theCircuit->Value(IndexEdge)->DynamicType(); - + if (EdgeType != STANDARD_TYPE(Geom2d_CartesianPoint)) { if(!InitialNeighbour) { Curve = Handle(Geom2d_TrimmedCurve) - ::DownCast(theCircuit->Value(IndexEdge))->BasisCurve(); + ::DownCast(theCircuit->Value(IndexEdge))->BasisCurve(); EdgeType = Curve->DynamicType(); //------------------------------------------------------------------- // si l edge est liee a sa voisine precedente par une connexion. //------------------------------------------------------------------- if (theCircuit->ConnexionOn(IndexEdge) && StartOrEnd == 1){ - if (EdgeType == STANDARD_TYPE(Geom2d_Circle)) { - Ori = Handle(Geom2d_Circle)::DownCast(Curve)->Location(); - gp_Pnt2d P2 = theCircuit->Connexion(IndexEdge)->PointOnFirst(); - Line1 = new Geom2d_Line (Ori,gp_Dir2d(P2.X() - Ori.X(), - P2.Y() - Ori.Y())); - } + if (EdgeType == STANDARD_TYPE(Geom2d_Circle)) { + Ori = Handle(Geom2d_Circle)::DownCast(Curve)->Location(); + gp_Pnt2d P2 = theCircuit->Connexion(IndexEdge)->PointOnFirst(); + Line1 = new Geom2d_Line (Ori,gp_Dir2d(P2.X() - Ori.X(), + P2.Y() - Ori.Y())); + } } //----------------------------------------------------------------------- // Si l edge est liee a sa voisine suivante par une connexion. //----------------------------------------------------------------------- if (theCircuit->ConnexionOn(INext) && StartOrEnd == 2){ - if (EdgeType == STANDARD_TYPE(Geom2d_Circle)) { - Ori = Handle(Geom2d_Circle)::DownCast(Curve)->Location(); - gp_Pnt2d P2 = theCircuit->Connexion(INext)->PointOnSecond(); - Line2 = new Geom2d_Line (Ori,gp_Dir2d(P2.X() - Ori.X(), - P2.Y() - Ori.Y())); - } + if (EdgeType == STANDARD_TYPE(Geom2d_Circle)) { + Ori = Handle(Geom2d_Circle)::DownCast(Curve)->Location(); + gp_Pnt2d P2 = theCircuit->Connexion(INext)->PointOnSecond(); + Line2 = new Geom2d_Line (Ori,gp_Dir2d(P2.X() - Ori.X(), + P2.Y() - Ori.Y())); + } } if (Line1.IsNull() && Line2.IsNull()) return; @@ -446,12 +462,12 @@ void MAT2d_Tool2d::TrimBisec ( Bisector_Bisec& B1, // si elles existent. //----------------------------------------------------------------------- if (!Line1.IsNull()) { - Line = new Geom2d_TrimmedCurve(Line1,0.,Precision::Infinite()); - SetTrim(B1,Line); + Line = new Geom2d_TrimmedCurve(Line1,0.,Precision::Infinite()); + SetTrim(B1,Line); } if (!Line2.IsNull()) { - Line = new Geom2d_TrimmedCurve(Line2,0.,Precision::Infinite()); - SetTrim(B1,Line); + Line = new Geom2d_TrimmedCurve(Line2,0.,Precision::Infinite()); + SetTrim(B1,Line); } } } @@ -473,13 +489,13 @@ Standard_Boolean MAT2d_Tool2d::TrimBisector Handle(Geom2d_TrimmedCurve) bisector = Handle(Geom2d_TrimmedCurve) - ::DownCast(ChangeGeomBis(abisector->BisectorNumber()).ChangeValue()); - + ::DownCast(ChangeGeomBis(abisector->BisectorNumber()).ChangeValue()); + if(bisector->BasisCurve()->IsPeriodic() && param == Precision::Infinite()) { param = bisector->FirstParameter() + 2*M_PI; } if (param > bisector->BasisCurve()->LastParameter()) { - param = bisector->BasisCurve()->LastParameter(); + param = bisector->BasisCurve()->LastParameter(); } if(bisector->FirstParameter() == param) return Standard_False; @@ -493,17 +509,17 @@ Standard_Boolean MAT2d_Tool2d::TrimBisector //============================================================================= Standard_Boolean MAT2d_Tool2d::TrimBisector (const Handle(MAT_Bisector)& abisector, - const Standard_Integer apoint) + const Standard_Integer apoint) { Standard_Real Param; Handle(Geom2d_TrimmedCurve) Bisector = Handle(Geom2d_TrimmedCurve):: - DownCast(ChangeGeomBis(abisector->BisectorNumber()).ChangeValue()); + DownCast(ChangeGeomBis(abisector->BisectorNumber()).ChangeValue()); Handle(Bisector_Curve) Bis = Handle(Bisector_Curve):: DownCast(Bisector->BasisCurve()); -// Param = ParameterOnCurve(Bisector,theGeomPnts.Value(apoint)); + // Param = ParameterOnCurve(Bisector,theGeomPnts.Value(apoint)); Param = Bis->Parameter(GeomPnt (apoint)); if (Bisector->BasisCurve()->IsPeriodic()) { @@ -526,16 +542,15 @@ Standard_Boolean MAT2d_Tool2d::TrimBisector //purpose : //============================================================================= Standard_Boolean MAT2d_Tool2d::Projection (const Standard_Integer IEdge , - const gp_Pnt2d& PCom , - Standard_Real& Distance) - const + const gp_Pnt2d& PCom , + Standard_Real& Distance) + const { gp_Pnt2d PEdge; Handle(Geom2d_Geometry) Elt = theCircuit->Value(IEdge); Handle(Standard_Type) Type = Elt->DynamicType(); Handle(Geom2d_TrimmedCurve) Curve; Standard_Integer INext; - Standard_Real ParameterOnC; Standard_Real Eps = MAT2d_TOLCONF;//*10.; if (Type == STANDARD_TYPE(Geom2d_CartesianPoint)) { @@ -559,7 +574,7 @@ Standard_Boolean MAT2d_Tool2d::Projection (const Standard_Integer IEdge , if (theCircuit->ConnexionOn(INext)) { ParamMax = theCircuit->Connexion(INext)->ParameterOnFirst(); if (Curve->BasisCurve()->IsPeriodic()){ - ElCLib::AdjustPeriodic(0.,2*M_PI,Eps,ParamMin,ParamMax); + ElCLib::AdjustPeriodic(0.,2*M_PI,Eps,ParamMin,ParamMax); } } //--------------------------------------------------------------------- @@ -569,10 +584,10 @@ Standard_Boolean MAT2d_Tool2d::Projection (const Standard_Integer IEdge , GeomAbs_CurveType TypeC1 = C1.GetType(); if (TypeC1 == GeomAbs_Circle) { Standard_Real R = C1.Circle().Radius(); - Standard_Real EpsCirc = Eps; + Standard_Real EpsCirc = 100.*Eps; if ( R < 1.) EpsCirc = Eps/R; - if (!((ParamMax - ParamMin + 2*EpsCirc) < 2*M_PI)) { - ParamMax = ParamMax + EpsCirc; ParamMin = ParamMin - EpsCirc; + if (((ParamMax - ParamMin + 2*EpsCirc) < 2*M_PI)) { + ParamMax = ParamMax + EpsCirc; ParamMin = ParamMin - EpsCirc; } } else { @@ -583,17 +598,21 @@ Standard_Boolean MAT2d_Tool2d::Projection (const Standard_Integer IEdge , //----------------------------------------------------- Extrema_ExtPC2d Extremas(PCom,C1,ParamMin,ParamMax); if (Extremas.IsDone()){ - if (Extremas.NbExt() == 0 ) return Standard_False; // Pas de solution! + Distance = Precision::Infinite(); + if(Extremas.NbExt() < 1) + { + return Standard_False; + } for (Standard_Integer i = 1; i <= Extremas.NbExt(); i++) { - if (Extremas.SquareDistance(i) < Distance * Distance) { - ParameterOnC = Extremas.Point(i).Parameter(); - Distance = sqrt (Extremas.SquareDistance(i)); - } + if (Extremas.SquareDistance(i) < Distance) { + Distance = Extremas.SquareDistance(i); + } } + Distance = Sqrt(Distance); } else { if (TypeC1 == GeomAbs_Circle) { - Distance = C1.Circle().Radius(); + Distance = C1.Circle().Radius(); } } } @@ -605,12 +624,13 @@ Standard_Boolean MAT2d_Tool2d::Projection (const Standard_Integer IEdge , // purpose : //============================================================================= Standard_Boolean MAT2d_Tool2d::IsSameDistance ( - const Handle(MAT_Bisector)& BisectorOne, - const Handle(MAT_Bisector)& BisectorTwo, - const gp_Pnt2d& PCom, - Standard_Real& Distance) const + const Handle(MAT_Bisector)& BisectorOne, + const Handle(MAT_Bisector)& BisectorTwo, + const gp_Pnt2d& PCom, + Standard_Real& Distance) const { TColStd_Array1OfReal Dist(1,4); + const Standard_Real eps = 1.e-7; Standard_Integer IEdge1,IEdge2,IEdge3,IEdge4; IEdge1 = BisectorOne->FirstEdge() ->EdgeNumber(); @@ -618,34 +638,89 @@ Standard_Boolean MAT2d_Tool2d::IsSameDistance ( IEdge3 = BisectorTwo->FirstEdge() ->EdgeNumber(); IEdge4 = BisectorTwo->SecondEdge()->EdgeNumber(); - Projection(IEdge1,PCom,Dist(1)); - Projection(IEdge2,PCom,Dist(2)); + Standard_Boolean isDone1 = Projection(IEdge1,PCom,Dist(1)); + Standard_Boolean isDone2 = Projection(IEdge2,PCom,Dist(2)); + + if(isDone1) + { + if(!isDone2) + { + Handle(Geom2d_Geometry) Elt = theCircuit->Value(IEdge2); + Standard_Real Tol = Max(Precision::Confusion(), eps*Dist(1)); + if(CheckEnds (Elt, PCom, Dist(1), Tol)) + { + Dist(2) = Dist(1); + } + } + } + else + { + if(isDone2) + { + Handle(Geom2d_Geometry) Elt = theCircuit->Value(IEdge1); + Standard_Real Tol = Max(Precision::Confusion(), eps*Dist(2)); + if(CheckEnds (Elt, PCom, Dist(2), Tol)) + { + Dist(1) = Dist(2); + } + } + } + Standard_Boolean isDone3 = Standard_True, isDone4 = Standard_True; if (IEdge3 == IEdge1) Dist(3) = Dist(1); else if (IEdge3 == IEdge2) Dist(3) = Dist(2); - else Projection(IEdge3,PCom,Dist(3)); + else isDone3 = Projection(IEdge3,PCom,Dist(3)); if (IEdge4 == IEdge1) Dist(4) = Dist(1); else if (IEdge4 == IEdge2) Dist(4) = Dist(2); - else Projection(IEdge4,PCom,Dist(4)); + else isDone4 = Projection(IEdge4,PCom,Dist(4)); + // + if(isDone3) + { + if(!isDone4) + { + Handle(Geom2d_Geometry) Elt = theCircuit->Value(IEdge4); + Standard_Real Tol = Max(Precision::Confusion(), eps*Dist(3)); + if(CheckEnds (Elt, PCom, Dist(3), Tol)) + { + Dist(4) = Dist(3); + } + } + } + else + { + if(isDone4) + { + Handle(Geom2d_Geometry) Elt = theCircuit->Value(IEdge3); + Standard_Real Tol = Max(Precision::Confusion(), eps*Dist(4)); + if(CheckEnds (Elt, PCom, Dist(4), Tol)) + { + Dist(3) = Dist(4); + } + } + } + #ifdef DEB - Standard_Boolean Affich = Standard_False; - if (Affich) + + if (AffichDist) for (Standard_Integer j = 1; j <= 4;j++){ cout <<"Distance number : "< EpsDist) { - Distance = Precision::Infinite(); - return Standard_False; + Standard_Real EpsDist = MAT2d_TOLCONF*300. ; + Distance = Dist(1); + for (Standard_Integer i = 1; i <= 4; i++){ + //if (theJoinType == GeomAbs_Intersection && + // Precision::IsInfinite(Dist(i))) + // continue; + if (Abs(Dist(i) - Distance) > EpsDist) { + Distance = Precision::Infinite(); + return Standard_False; + } } - } - return Standard_True; + return Standard_True; } //============================================================================= @@ -653,9 +728,9 @@ Standard_Boolean MAT2d_Tool2d::IsSameDistance ( //purpose : //============================================================================= Standard_Real MAT2d_Tool2d::IntersectBisector ( - const Handle(MAT_Bisector)& BisectorOne, - const Handle(MAT_Bisector)& BisectorTwo, - Standard_Integer& IntPnt) + const Handle(MAT_Bisector)& BisectorOne, + const Handle(MAT_Bisector)& BisectorTwo, + Standard_Integer& IntPnt) { Standard_Real Tolerance = MAT2d_TOLCONF; Standard_Real Param1,Param2; @@ -666,11 +741,11 @@ Standard_Real MAT2d_Tool2d::IntersectBisector ( Handle(Geom2d_TrimmedCurve) Bisector1 = Handle(Geom2d_TrimmedCurve) - ::DownCast(ChangeGeomBis(BisectorOne->BisectorNumber()).ChangeValue()); + ::DownCast(ChangeGeomBis(BisectorOne->BisectorNumber()).ChangeValue()); Handle(Geom2d_TrimmedCurve) Bisector2 = Handle(Geom2d_TrimmedCurve) - ::DownCast(ChangeGeomBis(BisectorTwo->BisectorNumber()).ChangeValue()); + ::DownCast(ChangeGeomBis(BisectorTwo->BisectorNumber()).ChangeValue()); if(Bisector1.IsNull() || Bisector2.IsNull()) return Precision::Infinite(); @@ -684,17 +759,17 @@ Standard_Real MAT2d_Tool2d::IntersectBisector ( Standard_Integer IS2 = BisectorTwo->SecondEdge()->EdgeNumber(); Standard_Integer IF1 = BisectorOne->FirstEdge() ->EdgeNumber(); Standard_Integer IF2 = BisectorTwo->FirstEdge() ->EdgeNumber(); - + if (AreNeighbours(IF1,IS1,NumberOfItems()) && - AreNeighbours(IF2,IS2,NumberOfItems()) && - theCircuit->ConnexionOn(IS2) && - theCircuit->ConnexionOn(IS1) ) { - Handle(MAT2d_Connexion) C1,C2; - C1 = theCircuit->Connexion(IS1); - C2 = theCircuit->Connexion(IS2); - if (C2->IndexFirstLine() == C1->IndexSecondLine() && - C1->IndexFirstLine() == C2->IndexSecondLine() ) - return Precision::Infinite(); + AreNeighbours(IF2,IS2,NumberOfItems()) && + theCircuit->ConnexionOn(IS2) && + theCircuit->ConnexionOn(IS1) ) { + Handle(MAT2d_Connexion) C1,C2; + C1 = theCircuit->Connexion(IS1); + C2 = theCircuit->Connexion(IS2); + if (C2->IndexFirstLine() == C1->IndexSecondLine() && + C1->IndexFirstLine() == C2->IndexSecondLine() ) + return Precision::Infinite(); } // ----------------------------------------- @@ -704,24 +779,24 @@ Standard_Real MAT2d_Tool2d::IntersectBisector ( IntRes2d_Domain Domain2 = Domain(Bisector2,Tolerance); if (Domain1.LastParameter() - Domain1.FirstParameter() < Tolerance) - return Precision::Infinite(); + return Precision::Infinite(); if (Domain2.LastParameter() - Domain2.FirstParameter() < Tolerance) - return Precision::Infinite(); + return Precision::Infinite(); #ifdef DEB Standard_Boolean Affich = Standard_False; if (Affich) { cout<BisectorNumber()<< - " et de "<BisectorNumber()<BisectorNumber()<BasisCurve())->Dump(-1,1); + // (Bisector1->BasisCurve())->Dump(-1,1); cout<BasisCurve())->Dump(-1,1); + // (Bisector2->BasisCurve())->Dump(-1,1); cout<BisectorNumber()),Domain1, - GeomBis(BisectorTwo->BisectorNumber()),Domain2, - Tolerance,Tolerance,Standard_True); + GeomBis(BisectorTwo->BisectorNumber()),Domain2, + Tolerance,Tolerance,Standard_True); -// Geom2dInt_GInter Intersect; -// Intersect.Perform(Bisector1,Domain1,Bisector2,Domain2,Tolerance,Tolerance); + // Geom2dInt_GInter Intersect; + // Intersect.Perform(Bisector1,Domain1,Bisector2,Domain2,Tolerance,Tolerance); -// ------------------------------------------------------------------------- -// Exploitation du resultat de l intersection et selection du point solution -// equidistant des deux edges et le plus proche en parametre de l origine -// des bissectrices. -// ------------------------------------------------------------------------- + // ------------------------------------------------------------------------- + // Exploitation du resultat de l intersection et selection du point solution + // equidistant des deux edges et le plus proche en parametre de l origine + // des bissectrices. + // ------------------------------------------------------------------------- if(!Intersect.IsDone()) return Precision::Infinite(); @@ -767,30 +842,30 @@ Standard_Real MAT2d_Tool2d::IntersectBisector ( // equidistants des edges. // ---------------------------------------------------------------- if ((Segment.HasFirstPoint() && Segment.HasLastPoint())) { - gp_Pnt2d P1,P2; - Standard_Real SegmentLength; - P1 = Segment.FirstPoint().Value(); - P2 = Segment.LastPoint().Value(); - SegmentLength = P1.Distance(P2); - if (SegmentLength <= Tolerance) { - PointOnSegment = P1; - if(IsSameDistance(BisectorOne,BisectorTwo, - PointOnSegment,Distance)) - PointRetenu = Standard_True; - } - else if (SegmentLength <= MaxSegmentLength) { - gp_Dir2d Dir(P2.X()-P1.X(),P2.Y()-P1.Y()); - Standard_Real Dist = 0.; - while (Dist <= SegmentLength + Tolerance){ - PointOnSegment = P1.Translated(Dist*Dir); - if(IsSameDistance(BisectorOne,BisectorTwo, - PointOnSegment,Distance)) { - PointRetenu = Standard_True; - break; - } - Dist = Dist + Tolerance; - } - } + gp_Pnt2d P1,P2; + Standard_Real SegmentLength; + P1 = Segment.FirstPoint().Value(); + P2 = Segment.LastPoint().Value(); + SegmentLength = P1.Distance(P2); + if (SegmentLength <= Tolerance) { + PointOnSegment = P1; + if(IsSameDistance(BisectorOne,BisectorTwo, + PointOnSegment,Distance)) + PointRetenu = Standard_True; + } + else if (SegmentLength <= MaxSegmentLength) { + gp_Dir2d Dir(P2.X()-P1.X(),P2.Y()-P1.Y()); + Standard_Real Dist = 0.; + while (Dist <= SegmentLength + Tolerance){ + PointOnSegment = P1.Translated(Dist*Dir); + if(IsSameDistance(BisectorOne,BisectorTwo, + PointOnSegment,Distance)) { + PointRetenu = Standard_True; + break; + } + Dist = Dist + Tolerance; + } + } } // ---------------------------------------------------------------- @@ -798,17 +873,17 @@ Standard_Real MAT2d_Tool2d::IntersectBisector ( // parametre sur les bissectrices. // ---------------------------------------------------------------- if(PointRetenu) { - Parama = Handle(Bisector_Curve)::DownCast(Bisector1->BasisCurve()) - ->Parameter(PointOnSegment); - Paramb = Handle(Bisector_Curve)::DownCast(Bisector2->BasisCurve()) - ->Parameter(PointOnSegment); - if(Parama < Param1 && Paramb < Param2) { - Param1 = Parama; - Param2 = Paramb; - DistanceMini = Distance; - PointSolution = PointOnSegment; - SolutionValide = Standard_True; - } + Parama = Handle(Bisector_Curve)::DownCast(Bisector1->BasisCurve()) + ->Parameter(PointOnSegment); + Paramb = Handle(Bisector_Curve)::DownCast(Bisector2->BasisCurve()) + ->Parameter(PointOnSegment); + if(Parama < Param1 && Paramb < Param2) { + Param1 = Parama; + Param2 = Paramb; + DistanceMini = Distance; + PointSolution = PointOnSegment; + SolutionValide = Standard_True; + } } } } @@ -816,17 +891,17 @@ Standard_Real MAT2d_Tool2d::IntersectBisector ( if(Intersect.NbPoints() != 1) { for(Standard_Integer i=1; i<=Intersect.NbPoints(); i++) { if(IsSameDistance(BisectorOne,BisectorTwo, - Intersect.Point(i).Value(),Distance) && - Distance > Tolerance ) { - Parama = Intersect.Point(i).ParamOnFirst(); - Paramb = Intersect.Point(i).ParamOnSecond(); - if (Parama < Param1 && Paramb < Param2) { - Param1 = Parama; - Param2 = Paramb; - DistanceMini = Distance; - PointSolution = Intersect.Point(i).Value(); - SolutionValide = Standard_True; - } + Intersect.Point(i).Value(),Distance) && + Distance > Tolerance ) { + Parama = Intersect.Point(i).ParamOnFirst(); + Paramb = Intersect.Point(i).ParamOnSecond(); + if (Parama < Param1 && Paramb < Param2) { + Param1 = Parama; + Param2 = Paramb; + DistanceMini = Distance; + PointSolution = Intersect.Point(i).Value(); + SolutionValide = Standard_True; + } } } } @@ -835,7 +910,7 @@ Standard_Real MAT2d_Tool2d::IntersectBisector ( Param1 = Intersect.Point(1).ParamOnFirst(); Param2 = Intersect.Point(1).ParamOnSecond(); SolutionValide = IsSameDistance(BisectorOne,BisectorTwo, - PointSolution,DistanceMini); + PointSolution,DistanceMini); } if (!SolutionValide) return Precision::Infinite(); @@ -865,57 +940,86 @@ Standard_Real MAT2d_Tool2d::IntersectBisector ( IndexEdge2 = BisectorOne->SecondEdge()->EdgeNumber(); IndexEdge3 = BisectorTwo->FirstEdge() ->EdgeNumber(); IndexEdge4 = BisectorTwo->SecondEdge()->EdgeNumber(); - + if (theCircuit->ConnexionOn(IndexEdge2)){ // -------------------------------------- // BisectorOne est issue d une connexion. // -------------------------------------- - if (AreNeighbours(IndexEdge1,IndexEdge2,NumberOfItems()) && - AreNeighbours(IndexEdge3,IndexEdge4,NumberOfItems()) && - IndexEdge2 == IndexEdge3 ){ - ExtremiteControle = Standard_False; - Param1 = Param1 + Tolerance; + if (AreNeighbours(IndexEdge1,IndexEdge2,NumberOfItems()) && + AreNeighbours(IndexEdge3,IndexEdge4,NumberOfItems()) && + IndexEdge2 == IndexEdge3 ){ + ExtremiteControle = Standard_False; + Param1 = Param1 + Tolerance; } } - + if (theCircuit->ConnexionOn(IndexEdge4)){ - // -------------------------------------- - // BisectorTwo est issue d une connexion. - // -------------------------------------- + //-------------------------------------- + //BisectorTwo est issue d une connexion. + //-------------------------------------- if (AreNeighbours(IndexEdge1,IndexEdge2,NumberOfItems()) && - AreNeighbours(IndexEdge3,IndexEdge4,NumberOfItems()) && - IndexEdge2 == IndexEdge3 ){ - ExtremiteControle = Standard_False; - Param2 = Param2 + Tolerance; + AreNeighbours(IndexEdge3,IndexEdge4,NumberOfItems()) && + IndexEdge2 == IndexEdge3 ){ + ExtremiteControle = Standard_False; + Param2 = Param2 + Tolerance; } } - - if (ExtremiteControle) { - if(Bisector1->StartPoint().Distance(PointSolution) < Tolerance || - Bisector2->StartPoint().Distance(PointSolution) < Tolerance ) + + //if (ExtremiteControle) { + // if(Bisector1->StartPoint().Distance(PointSolution) < Tolerance || + // Bisector2->StartPoint().Distance(PointSolution) < Tolerance ) + // return Precision::Infinite(); + //} + + if(ExtremiteControle) + { + if(Bisector1->StartPoint().Distance(PointSolution) < Tolerance) + { +#ifdef DRAW + if(AffichBis) + { + DrawTrSurf::Set("Bis1", Bisector1); + DrawTrSurf::Set("Bis2", Bisector2); + } +#endif + return Precision::Infinite(); + } + if(Bisector2->StartPoint().Distance(PointSolution) < Tolerance) + { + +#ifdef DRAW + if(AffichBis) + { + DrawTrSurf::Set("Bis1", Bisector1); + DrawTrSurf::Set("Bis2", Bisector2); + } +#endif return Precision::Infinite(); + } } + + if(BisectorOne->SecondParameter() < Precision::Infinite() && - BisectorOne->SecondParameter() < Param1*(1. - Tolerance )) + BisectorOne->SecondParameter() < Param1*(1. - Tolerance )) return Precision::Infinite(); - + if(BisectorTwo->FirstParameter() < Precision::Infinite() && - BisectorTwo->FirstParameter() < Param2*(1.- Tolerance)) + BisectorTwo->FirstParameter() < Param2*(1.- Tolerance)) return Precision::Infinite(); BisectorOne->SecondParameter(Param1); BisectorTwo->FirstParameter (Param2); - + #ifdef DEB if (Affich) { cout<<" coordonnees : "< theNumberOfBisectors) return; @@ -966,7 +1070,7 @@ void MAT2d_Tool2d::Dump(const Standard_Integer bisector, //purpose : //============================================================================= const Bisector_Bisec& MAT2d_Tool2d::GeomBis (const Standard_Integer Index) - const + const { return theGeomBisectors.Find(Index); } @@ -986,7 +1090,7 @@ Bisector_Bisec& MAT2d_Tool2d::ChangeGeomBis(const Standard_Integer Index) //purpose : //============================================================================= Handle(Geom2d_Geometry) MAT2d_Tool2d::GeomElt(const Standard_Integer Index) - const + const { return theCircuit->Value(Index); } @@ -1024,7 +1128,7 @@ Handle(MAT2d_Circuit) MAT2d_Tool2d::Circuit()const //purpose : //============================================================================= void MAT2d_Tool2d::BisecFusion(const Standard_Integer I1, - const Standard_Integer I2) + const Standard_Integer I2) { Standard_Real DU,UL1,UF1; Handle(Geom2d_TrimmedCurve) Bisector1; @@ -1053,7 +1157,7 @@ void MAT2d_Tool2d::BisecFusion(const Standard_Integer I1, Handle(Bisector_BisecCC) BCC1 = Handle(Bisector_BisecCC)::DownCast(Bisector1->BasisCurve()); Bis.Perform(BCC1->Curve(2), BCC1->Curve(1), P2, VBid, VBid, - theDirection, Tolerance, Standard_False); + theDirection, Tolerance, Standard_False); Bisector1 = Handle(Geom2d_TrimmedCurve)::DownCast(Bis.Value()); BCC1 = Handle(Bisector_BisecCC) ::DownCast(Bisector1->BasisCurve()); @@ -1067,11 +1171,11 @@ void MAT2d_Tool2d::BisecFusion(const Standard_Integer I1, UF1 = UF1 - DU; Handle(Bisector_BisecAna) BAna = Handle(Bisector_BisecAna)::DownCast(Bisector1->BasisCurve()); -//---------------------------- uncomment if new method Bisector_BisecAna::SetTrim(f,l) is not used -// Handle(Geom2d_Curve) C2d = BAna->Geom2dCurve(); -// Handle(Geom2d_TrimmedCurve) trimC2d = new Geom2d_TrimmedCurve(C2d, UF1, UL1); -// BAna->Init(trimC2d); -//--------------------------- end + //---------------------------- uncomment if new method Bisector_BisecAna::SetTrim(f,l) is not used + // Handle(Geom2d_Curve) C2d = BAna->Geom2dCurve(); + // Handle(Geom2d_TrimmedCurve) trimC2d = new Geom2d_TrimmedCurve(C2d, UF1, UL1); + // BAna->Init(trimC2d); + //--------------------------- end BAna->SetTrim(UF1,UL1); // put comment if SetTrim(f,l) is not used Bisector1->SetTrim(UF1,UL1); @@ -1100,8 +1204,8 @@ static Handle(Standard_Type) Type(const Handle(Geom2d_Geometry)& aGeom) // consecutifs sur un contour ferme de NbEdge elements. //========================================================================== Standard_Boolean AreNeighbours(const Standard_Integer IEdge1, - const Standard_Integer IEdge2, - const Standard_Integer NbEdge) + const Standard_Integer IEdge2, + const Standard_Integer NbEdge) { if (Abs(IEdge1 - IEdge2) == 1) return Standard_True; else if (Abs(IEdge1 - IEdge2) == NbEdge -1) return Standard_True; @@ -1123,22 +1227,22 @@ void SetTrim(Bisector_Bisec& Bis, Handle(Geom2d_Curve)& Line1) IntRes2d_Domain Domain1 = Domain(Bisector,Tolerance); Standard_Real UB1 = Bisector->FirstParameter(); Standard_Real UB2 = Bisector->LastParameter(); - + gp_Pnt2d FirstPointBisector = Bisector->Value(UB1); Standard_Real UTrim = Precision::Infinite(); Geom2dAdaptor_Curve AdapBisector(Bisector); Geom2dAdaptor_Curve AdapLine1 (Line1); Intersect.Perform(AdapBisector, Domain1, - AdapLine1, Tolerance, Tolerance); + AdapLine1, Tolerance, Tolerance); if (Intersect.IsDone() && !Intersect.IsEmpty()) { for (Standard_Integer i = 1; i <= Intersect.NbPoints(); i++) { gp_Pnt2d PInt = Intersect.Point(i).Value(); Distance = FirstPointBisector.Distance(PInt); if (Distance > 10.*Tolerance && - Intersect.Point(i).ParamOnFirst() < UTrim ) { - UTrim = Intersect.Point(i).ParamOnFirst(); + Intersect.Point(i).ParamOnFirst() < UTrim ) { + UTrim = Intersect.Point(i).ParamOnFirst(); } } } @@ -1154,7 +1258,7 @@ void SetTrim(Bisector_Bisec& Bis, Handle(Geom2d_Curve)& Line1) //purpose : //========================================================================== IntRes2d_Domain Domain(const Handle(Geom2d_TrimmedCurve)& Bisector1, - const Standard_Real Tolerance) + const Standard_Real Tolerance) { Standard_Real Param1 = Bisector1->FirstParameter(); Standard_Real Param2 = Bisector1->LastParameter(); @@ -1164,7 +1268,7 @@ IntRes2d_Domain Domain(const Handle(Geom2d_TrimmedCurve)& Bisector1, Handle(Geom2d_Curve) BasisCurve; if (Type1 == STANDARD_TYPE(Bisector_BisecAna)) { BasisCurve = Handle(Bisector_BisecAna) - ::DownCast(Bisector1->BasisCurve())->Geom2dCurve(); + ::DownCast(Bisector1->BasisCurve())->Geom2dCurve(); Type1 = BasisCurve->DynamicType(); } gp_Parab2d gpParabola; @@ -1189,15 +1293,45 @@ IntRes2d_Domain Domain(const Handle(Geom2d_TrimmedCurve)& Bisector1, Param2 = (Val1 <= Val2 ? Val1:Val2); } } - + IntRes2d_Domain Domain1(Bisector1->Value(Param1),Param1,Tolerance, - Bisector1->Value(Param2),Param2,Tolerance); + Bisector1->Value(Param2),Param2,Tolerance); if(Bisector1->BasisCurve()->IsPeriodic()) { Domain1.SetEquivalentParameters(0.,2.*M_PI); } return Domain1; } +//============================================================================= +//function : Projection +//purpose : +//============================================================================= +Standard_Boolean CheckEnds (const Handle(Geom2d_Geometry)& Elt , + const gp_Pnt2d& PCom , + const Standard_Real Distance, + const Standard_Real Tol) + +{ + Handle(Standard_Type) Type = Elt->DynamicType(); + Handle(Geom2d_TrimmedCurve) Curve; + + if (Type == STANDARD_TYPE(Geom2d_CartesianPoint)) { + return Standard_False; + } + else { + Curve = Handle(Geom2d_TrimmedCurve)::DownCast(Elt); + gp_Pnt2d aPf = Curve->StartPoint(); + gp_Pnt2d aPl = Curve->EndPoint(); + Standard_Real df = PCom.Distance(aPf); + Standard_Real dl = PCom.Distance(aPl); + if(Abs(df - Distance) <= Tol) + return Standard_True; + if(Abs(dl - Distance) <= Tol) + return Standard_True; + } + return Standard_False; +} + #ifdef DEB //========================================================================== //function : MAT2d_DrawCurve @@ -1209,7 +1343,7 @@ IntRes2d_Domain Domain(const Handle(Geom2d_TrimmedCurve)& Bisector1, // Indice = 4 vert. //========================================================================== void MAT2d_DrawCurve(const Handle(Geom2d_Curve)& aCurve, - const Standard_Integer /*Indice*/) + const Standard_Integer /*Indice*/) { Handle(Standard_Type) type = aCurve->DynamicType(); Handle(Geom2d_Curve) curve,CurveDraw; @@ -1230,27 +1364,27 @@ void MAT2d_DrawCurve(const Handle(Geom2d_Curve)& aCurve, // PB de representation des courbes semi_infinies. if (aCurve->LastParameter() == Precision::Infinite()) { - + if (type == STANDARD_TYPE(Geom2d_Parabola)) { - gpParabola = Handle(Geom2d_Parabola)::DownCast(curve)->Parab2d(); - Focus = gpParabola.Focal(); - Standard_Real Val1 = Sqrt(Limit*Focus); - Standard_Real Val2 = Sqrt(Limit*Limit); - delta= (Val1 <= Val2 ? Val1:Val2); + gpParabola = Handle(Geom2d_Parabola)::DownCast(curve)->Parab2d(); + Focus = gpParabola.Focal(); + Standard_Real Val1 = Sqrt(Limit*Focus); + Standard_Real Val2 = Sqrt(Limit*Limit); + delta= (Val1 <= Val2 ? Val1:Val2); } else if (type == STANDARD_TYPE(Geom2d_Hyperbola)) { - gpHyperbola = Handle(Geom2d_Hyperbola)::DownCast(curve)->Hypr2d(); - Standard_Real Majr = gpHyperbola.MajorRadius(); - Standard_Real Minr = gpHyperbola.MinorRadius(); - Standard_Real Valu1 = Limit/Majr; - Standard_Real Valu2 = Limit/Minr; - Standard_Real Val1 = Log(Valu1+Sqrt(Valu1*Valu1-1)); - Standard_Real Val2 = Log(Valu2+Sqrt(Valu2*Valu2+1)); - delta = (Val1 <= Val2 ? Val1:Val2); + gpHyperbola = Handle(Geom2d_Hyperbola)::DownCast(curve)->Hypr2d(); + Standard_Real Majr = gpHyperbola.MajorRadius(); + Standard_Real Minr = gpHyperbola.MinorRadius(); + Standard_Real Valu1 = Limit/Majr; + Standard_Real Valu2 = Limit/Minr; + Standard_Real Val1 = Log(Valu1+Sqrt(Valu1*Valu1-1)); + Standard_Real Val2 = Log(Valu2+Sqrt(Valu2*Valu2+1)); + delta = (Val1 <= Val2 ? Val1:Val2); } CurveDraw = new Geom2d_TrimmedCurve(aCurve, - aCurve->FirstParameter(), - aCurve->FirstParameter() + delta); + aCurve->FirstParameter(), + aCurve->FirstParameter() + delta); } else { CurveDraw = aCurve; @@ -1262,6 +1396,7 @@ void MAT2d_DrawCurve(const Handle(Geom2d_Curve)& aCurve, } #ifdef DRAW + Standard_Integer Indice = 1; if (Indice == 1) Couleur = Draw_jaune; else if (Indice == 2) Couleur = Draw_bleu; else if (Indice == 3) Couleur = Draw_rouge; @@ -1274,8 +1409,8 @@ void MAT2d_DrawCurve(const Handle(Geom2d_Curve)& aCurve, else dr = new DrawTrSurf_Curve2d(CurveDraw,Couleur,500); - dout << dr; - dout.Flush(); + //dout << dr; + //dout.Flush(); #endif } diff --git a/tests/bugs/modalg_5/bug22831 b/tests/bugs/modalg_5/bug22831 index 9929eb05aa..ed76b72127 100644 --- a/tests/bugs/modalg_5/bug22831 +++ b/tests/bugs/modalg_5/bug22831 @@ -1,7 +1,3 @@ -puts "TODO DEBUG_OCC24121 Debian60-64 Windows: \\*\\* Exception \\*\\*.*" -puts "TODO DEBUG_OCC24121 Debian60-64 Windows: An exception was caught" -puts "TODO DEBUG_OCC24121 Debian60-64 Windows: TEST INCOMPLETE" - puts "============" puts "OCC22831" puts "============" diff --git a/tests/de/iges_1/K3 b/tests/de/iges_1/K3 index 7a72c762c7..d4bca5950e 100644 --- a/tests/de/iges_1/K3 +++ b/tests/de/iges_1/K3 @@ -11,7 +11,7 @@ CHECKSHAPE : Wires = 12 ( 18 ) Faces = 16 ( 16 ) Shells = 0 ( 0 ) NBSHAPES : Solid = 0 ( 0 ) Shell = 0 ( 0 ) Face = 5163 ( 5163 ) Summary = 68418 ( 68418 ) STATSHAPE : Solid = 0 ( 0 ) Shell = 0 ( 0 ) Face = 5163 ( 5163 ) FreeWire = 10 ( 10 ) FreeEdge = 283 ( 283 ) SharedEdge = 29071 ( 29075 ) TOLERANCE : MaxTol = 0.9874083984 ( 0.9875071265 ) AvgTol = 0.0111430941 ( 0.01115568387 ) -LABELS : N0Labels = 5392 ( 5458 ) N1Labels = 18 ( 4437 ) N2Labels = 0 ( 0 ) TotalLabels = 5410 ( 9895 ) NameLabels = 5392 ( 5458 ) ColorLabels = 5391 ( 9829 ) LayerLabels = 5391 ( 9829 ) +LABELS : N0Labels = 5392 ( 5458 ) N1Labels = 18 ( 4443 ) N2Labels = 0 ( 0 ) TotalLabels = 5410 ( 9901 ) NameLabels = 5392 ( 5458 ) ColorLabels = 5391 ( 9835 ) LayerLabels = 5391 ( 9835 ) PROPS : Centroid = 0 ( 0 ) Volume = 0 ( 0 ) Area = 0 ( 0 ) NCOLORS : NColors = 4 ( 4 ) COLORS : Colors = BLACK BLUE1 CYAN1 GREEN ( BLACK BLUE1 CYAN1 GREEN ) diff --git a/tests/de/iges_2/B8 b/tests/de/iges_2/B8 index 55d55ba04d..0b80d00922 100644 --- a/tests/de/iges_2/B8 +++ b/tests/de/iges_2/B8 @@ -14,7 +14,7 @@ CHECKSHAPE : Wires = 12 ( 17 ) Faces = 12 ( 11 ) Shells = 0 ( 0 ) NBSHAPES : Solid = 0 ( 0 ) Shell = 0 ( 0 ) Face = 4729 ( 4729 ) Summary = 63154 ( 63144 ) STATSHAPE : Solid = 0 ( 0 ) Shell = 0 ( 0 ) Face = 4729 ( 4729 ) FreeWire = 18 ( 18 ) FreeEdge = 452 ( 452 ) SharedEdge = 26794 ( 26793 ) TOLERANCE : MaxTol = 0.9804479161 ( 0.9805459497 ) AvgTol = 0.01153089029 ( 0.01154870945 ) -LABELS : N0Labels = 5089 ( 5165 ) N1Labels = 26 ( 3844 ) N2Labels = 0 ( 0 ) TotalLabels = 5115 ( 9009 ) NameLabels = 5089 ( 5165 ) ColorLabels = 5086 ( 8933 ) LayerLabels = 5086 ( 8933 ) +LABELS : N0Labels = 5089 ( 5165 ) N1Labels = 26 ( 3846 ) N2Labels = 0 ( 0 ) TotalLabels = 5115 ( 9011 ) NameLabels = 5089 ( 5165 ) ColorLabels = 5086 ( 8935 ) LayerLabels = 5086 ( 8935 ) PROPS : Centroid = 0 ( 0 ) Volume = 0 ( 0 ) Area = 0 ( 0 ) NCOLORS : NColors = 3 ( 3 ) COLORS : Colors = BLUE1 CYAN1 GREEN ( BLUE1 CYAN1 GREEN ) diff --git a/tests/de/iges_2/E6 b/tests/de/iges_2/E6 index 4abfc5305b..fc944857b5 100644 --- a/tests/de/iges_2/E6 +++ b/tests/de/iges_2/E6 @@ -14,8 +14,8 @@ TPSTAT : Faulties = 0 ( 0 ) Warnings = 6 ( 523 ) Summary = 6 ( 523 ) CHECKSHAPE : Wires = 0 ( 0 ) Faces = 0 ( 0 ) Shells = 0 ( 0 ) Solids = 0 ( 0 ) NBSHAPES : Solid = 0 ( 0 ) Shell = 0 ( 0 ) Face = 1177 ( 1177 ) Summary = 18232 ( 18230 ) STATSHAPE : Solid = 0 ( 0 ) Shell = 0 ( 0 ) Face = 1177 ( 1177 ) FreeWire = 5 ( 5 ) FreeEdge = 714 ( 714 ) SharedEdge = 7614 ( 7614 ) -TOLERANCE : MaxTol = 0.9436610236 ( 0.8261873283 ) AvgTol = 0.01104814106 ( 0.01076280021 ) -LABELS : N0Labels = 1884 ( 1885 ) N1Labels = 0 ( 1020 ) N2Labels = 0 ( 0 ) TotalLabels = 1884 ( 2905 ) NameLabels = 1884 ( 1885 ) ColorLabels = 1873 ( 2904 ) LayerLabels = 1873 ( 2904 ) +TOLERANCE : MaxTol = 0.9436610236 ( 0.8261873283 ) AvgTol = 0.01104814109 ( 0.0107628002 ) +LABELS : N0Labels = 1884 ( 1885 ) N1Labels = 0 ( 1019 ) N2Labels = 0 ( 0 ) TotalLabels = 1884 ( 2904 ) NameLabels = 1884 ( 1885 ) ColorLabels = 1873 ( 2903 ) LayerLabels = 1873 ( 2903 ) PROPS : Centroid = 0 ( 0 ) Volume = 0 ( 0 ) Area = 0 ( 0 ) NCOLORS : NColors = 7 ( 7 ) COLORS : Colors = BLACK BLUE1 CYAN1 GREEN RED WHITE YELLOW ( BLACK BLUE1 CYAN1 GREEN RED WHITE YELLOW ) diff --git a/tests/de/iges_2/G1 b/tests/de/iges_2/G1 index 95d049341d..8aebac7a67 100644 --- a/tests/de/iges_2/G1 +++ b/tests/de/iges_2/G1 @@ -1,6 +1,5 @@ # !!!! This file is generated automatically, do not edit manually! See end script puts "TODO CR23096 ALL: TPSTAT : Faulty" -puts "TODO CR23096 ALL: CHECKSHAPE : Faulty" puts "TODO CR23096 ALL: LABELS : Faulty" puts "TODO CR23096 Mandriva2010: Error : 2 differences with reference data found :" puts "TODO CR23096 Mandriva2010: STATSHAPE : Faulty" diff --git a/tests/mesh/data/standard/J1 b/tests/mesh/data/standard/J1 index b39110db37..69a06e7d79 100755 --- a/tests/mesh/data/standard/J1 +++ b/tests/mesh/data/standard/J1 @@ -1,3 +1,3 @@ set TheFileName shading_082.brep set bug_cross "OCC22687" -set nbcross(All) 16 +set nbcross(All) 0 diff --git a/tests/offset/wire_closed_inside_0_075/C7 b/tests/offset/wire_closed_inside_0_075/C7 index 066233d4ec..497da0a356 100644 --- a/tests/offset/wire_closed_inside_0_075/C7 +++ b/tests/offset/wire_closed_inside_0_075/C7 @@ -1,16 +1,6 @@ -set os "ALL" -if {[array get env os_type] != ""} { - set os $env(os_type) -} - -if { - [string compare $os "Debian40"] == 0 - || [string compare $os "Mandriva2008"] == 0 - } { - puts "TODO OCC23068 $os: Faulty shapes in variables faulty_1 to faulty_4" - puts "TODO OCC23068 $os: Error : The length of result shape is" - puts "TODO OCC23068 $os: Error : Result shape is WRONG" -} +puts "TODO OCC23068 ALL: Faulty shapes in variables faulty_1 to faulty_4" +puts "TODO OCC23068 ALL: Error : The length of the resulting shape is" +puts "TODO OCC23068 ALL: Error : The resulting shape is WRONG because it must contain" restore [locate_data_file offset_wire_038.brep] s -- 2.39.5