X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=blobdiff_plain;f=src%2FProjLib%2FProjLib_ComputeApproxOnPolarSurface.cxx;h=02179dc8732ce382e51d1e77ac57387097c3ddbd;hp=5e005f85e7b0710aebfdf8e85c9ccfbc4b64c724;hb=eafb234bf120f005d1a52abc75384d33d2de1721;hpb=d3f26155b57e86aabd1f1adfb51008fc16a062bd diff --git a/src/ProjLib/ProjLib_ComputeApproxOnPolarSurface.cxx b/src/ProjLib/ProjLib_ComputeApproxOnPolarSurface.cxx index 5e005f85e7..02179dc873 100755 --- a/src/ProjLib/ProjLib_ComputeApproxOnPolarSurface.cxx +++ b/src/ProjLib/ProjLib_ComputeApproxOnPolarSurface.cxx @@ -119,7 +119,7 @@ static gp_Pnt2d Function_Value(const Standard_Real U, if((Type != GeomAbs_BSplineSurface) && (Type != GeomAbs_BezierSurface) && (Type != GeomAbs_OffsetSurface) ) { - Standard_Real S, T; + Standard_Real S = 0., T = 0.; switch (Type) { // case GeomAbs_Plane: // { @@ -199,34 +199,38 @@ static gp_Pnt2d Function_Value(const Standard_Real U, if(Surf->IsVPeriodic() || Surf->IsVClosed()) { vperiod = Surf->LastVParameter() - Surf->FirstVParameter(); } - if(U0 < Uinf) + if(U0 < Uinf) { if(!uperiod) U0 = Uinf; else { decalU = int((Uinf - U0)/uperiod)+1; U0 += decalU*uperiod; } - if(U0 > Usup) + } + if(U0 > Usup) { if(!uperiod) U0 = Usup; else { decalU = -(int((U0 - Usup)/uperiod)+1); U0 += decalU*uperiod; } - if(V0 < Vinf) + } + if(V0 < Vinf) { if(!vperiod) V0 = Vinf; else { decalV = int((Vinf - V0)/vperiod)+1; V0 += decalV*vperiod; } - if(V0 > Vsup) + } + if(V0 > Vsup) { if(!vperiod) V0 = Vsup; else { decalV = -int((V0 - Vsup)/vperiod)-1; V0 += decalV*vperiod; } + } // The surface around U0 is reduced Standard_Real uLittle = (Usup - Uinf)/10, vLittle = (Vsup - Vinf)/10; @@ -707,6 +711,14 @@ Handle(Adaptor2d_HCurve2d) Standard_Real TolU = Surf->UResolution(Tol3d), TolV = Surf->VResolution(Tol3d); Standard_Real DistTol3d = 100.0*Tol3d; + Standard_Real uperiod = 0., vperiod = 0.; + if(Surf->IsUPeriodic() || Surf->IsUClosed()) + uperiod = Surf->LastUParameter() - Surf->FirstUParameter(); + + if(Surf->IsVPeriodic() || Surf->IsVClosed()) + vperiod = Surf->LastVParameter() - Surf->FirstVParameter(); + + // NO myTol is Tol2d !!!! //Standard_Real TolU = myTolerance, TolV = myTolerance; //Standard_Real Tol3d = 100*myTolerance; // At random Balthazar. @@ -726,7 +738,9 @@ Handle(Adaptor2d_HCurve2d) Mult.Init(1); Mult(1) = Mult(NbOfPnts) = 2; - Standard_Real Vinf, Vsup; + Standard_Real Uinf, Usup, Vinf, Vsup; + Uinf = Surf->Surface().FirstUParameter(); + Usup = Surf->Surface().LastUParameter(); Vinf = Surf->Surface().FirstVParameter(); Vsup = Surf->Surface().LastVParameter(); GeomAbs_SurfaceType Type = Surf->GetType(); @@ -749,44 +763,46 @@ Handle(Adaptor2d_HCurve2d) case GeomAbs_Cylinder: { // Standard_Real Sloc, Tloc; - Standard_Real Sloc; - Standard_Integer usens = 0; - gp_Cylinder Cylinder = Surf->Cylinder(); - ElSLib::Parameters( Cylinder, Pts(1), S, T); - Pts2d(1).SetCoord(S,T); - for ( i = 2 ; i <= NbOfPnts ; i++) { - Sloc = S; - ElSLib::Parameters( Cylinder, Pts(i), S, T); - if(Abs(Sloc - S) > M_PI) - if(Sloc > S) - usens++; - else - usens--; - Pts2d(i).SetCoord(S+usens*2*M_PI,T); - } - myProjIsDone = Standard_True; - break; + Standard_Real Sloc; + Standard_Integer usens = 0; + gp_Cylinder Cylinder = Surf->Cylinder(); + ElSLib::Parameters( Cylinder, Pts(1), S, T); + Pts2d(1).SetCoord(S,T); + for ( i = 2 ; i <= NbOfPnts ; i++) { + Sloc = S; + ElSLib::Parameters( Cylinder, Pts(i), S, T); + if(Abs(Sloc - S) > M_PI) { + if(Sloc > S) + usens++; + else + usens--; + } + Pts2d(i).SetCoord(S+usens*2*M_PI,T); + } + myProjIsDone = Standard_True; + break; } case GeomAbs_Cone: { // Standard_Real Sloc, Tloc; - Standard_Real Sloc; - Standard_Integer usens = 0; - gp_Cone Cone = Surf->Cone(); - ElSLib::Parameters( Cone, Pts(1), S, T); - Pts2d(1).SetCoord(S,T); - for ( i = 2 ; i <= NbOfPnts ; i++) { - Sloc = S; - ElSLib::Parameters( Cone, Pts(i), S, T); - if(Abs(Sloc - S) > M_PI) - if(Sloc > S) - usens++; - else - usens--; - Pts2d(i).SetCoord(S+usens*2*M_PI,T); - } - myProjIsDone = Standard_True; - break; + Standard_Real Sloc; + Standard_Integer usens = 0; + gp_Cone Cone = Surf->Cone(); + ElSLib::Parameters( Cone, Pts(1), S, T); + Pts2d(1).SetCoord(S,T); + for ( i = 2 ; i <= NbOfPnts ; i++) { + Sloc = S; + ElSLib::Parameters( Cone, Pts(i), S, T); + if(Abs(Sloc - S) > M_PI) { + if(Sloc > S) + usens++; + else + usens--; + } + Pts2d(i).SetCoord(S+usens*2*M_PI,T); + } + myProjIsDone = Standard_True; + break; } case GeomAbs_Sphere: { @@ -799,11 +815,12 @@ Handle(Adaptor2d_HCurve2d) for ( i = 2 ; i <= NbOfPnts ; i++) { Sloc = S;Tloc = T; ElSLib::Parameters( Sphere, Pts(i), S, T); - if(1.6*M_PI < Abs(Sloc - S)) + if(1.6*M_PI < Abs(Sloc - S)) { if(Sloc > S) usens += 2; else usens -= 2; + } if(1.6*M_PI > Abs(Sloc - S) && Abs(Sloc - S) > 0.4*M_PI) { vparit = !vparit; if(Sloc > S) @@ -836,16 +853,18 @@ Handle(Adaptor2d_HCurve2d) for ( i = 2 ; i <= NbOfPnts ; i++) { Sloc = S; Tloc = T; ElSLib::Parameters( Torus, Pts(i), S, T); - if(Abs(Sloc - S) > M_PI) + if(Abs(Sloc - S) > M_PI) { if(Sloc > S) usens++; else usens--; - if(Abs(Tloc - T) > M_PI) + } + if(Abs(Tloc - T) > M_PI) { if(Tloc > T) vsens++; else vsens--; + } Pts2d(i).SetCoord(S+usens*2*M_PI,T+vsens*2*M_PI); } myProjIsDone = Standard_True; @@ -856,9 +875,6 @@ Handle(Adaptor2d_HCurve2d) } } else { - Standard_Real Uinf = Surf->Surface().FirstUParameter(); - Standard_Real Usup = Surf->Surface().LastUParameter(); - myProjIsDone = Standard_False; Standard_Real Dist2Min = 1.e+200, u = 0., v = 0.; gp_Pnt pntproj; @@ -1033,20 +1049,11 @@ Handle(Adaptor2d_HCurve2d) // (and store the result and each parameter in a sequence) Standard_Integer usens = 0, vsens = 0; // to know the position relatively to the period - Standard_Real U0 = u, V0 = v, U1 = u, V1 = v, uperiod =0, vperiod = 0; + Standard_Real U0 = u, V0 = v, U1 = u, V1 = v; // U0 and V0 are the points in the initialized period // (period with u and v), // U1 and V1 are the points for construction of poles - - if(Surf->IsUPeriodic() || Surf->IsUClosed()) { - uperiod = Surf->LastUParameter() - Surf->FirstUParameter(); - } - - if(Surf->IsVPeriodic() || Surf->IsVClosed()) { - vperiod = Surf->LastVParameter() - Surf->FirstVParameter(); - } - for ( i = 2 ; i <= NbOfPnts ; i++) if(myProjIsDone) { myProjIsDone = Standard_False; @@ -1161,7 +1168,7 @@ Handle(Adaptor2d_HCurve2d) if (Dist2Min < DistTol3d * DistTol3d) { //if (Dist2Min < Tol3d * Tol3d) { (ext.Point(GoodValue)).Parameter(u,v); - if(uperiod) + if(uperiod) { if((U0 - u) > (2*uperiod/3)) { usens++; } @@ -1169,7 +1176,8 @@ Handle(Adaptor2d_HCurve2d) if((u - U0) > (2*uperiod/3)) { usens--; } - if(vperiod) + } + if(vperiod) { if((V0 - v) > (vperiod/2)) { vsens++; } @@ -1177,6 +1185,7 @@ Handle(Adaptor2d_HCurve2d) if((v - V0) > (vperiod/2)) { vsens--; } + } U0 = u; V0 = v; U1 = U0 + usens*uperiod; V1 = V0 + vsens*vperiod; @@ -1192,6 +1201,34 @@ Handle(Adaptor2d_HCurve2d) // -- Pnts2d is transformed into Geom2d_BSplineCurve, with the help of Param and Mult if(myProjIsDone) { myBSpline = new Geom2d_BSplineCurve(Pts2d,Param,Mult,1); + //jgv: put the curve into parametric range + gp_Pnt2d MidPoint = myBSpline->Value(0.5*(myBSpline->FirstParameter() + myBSpline->LastParameter())); + Standard_Real TestU = MidPoint.X(), TestV = MidPoint.Y(); + Standard_Real sense = 0.; + if (uperiod) + { + if (TestU < Uinf - TolU) + sense = 1.; + else if (TestU > Usup + TolU) + sense = -1; + while (TestU < Uinf - TolU || TestU > Usup + TolU) + TestU += sense * uperiod; + } + if (vperiod) + { + sense = 0.; + if (TestV < Vinf - TolV) + sense = 1.; + else if (TestV > Vsup + TolV) + sense = -1.; + while (TestV < Vinf - TolV || TestV > Vsup + TolV) + TestV += sense * vperiod; + } + gp_Vec2d Offset(TestU - MidPoint.X(), TestV - MidPoint.Y()); + if (Abs(Offset.X()) > gp::Resolution() || + Abs(Offset.Y()) > gp::Resolution()) + myBSpline->Translate(Offset); + ////////////////////////////////////////// Geom2dAdaptor_Curve GAC(myBSpline); Handle(Adaptor2d_HCurve2d) IC2d = new Geom2dAdaptor_HCurve(GAC); #ifdef DEB