From 55468283787fd50a14533eefd39991df4c6e9b37 Mon Sep 17 00:00:00 2001 From: aml Date: Wed, 16 Apr 2014 10:42:28 +0400 Subject: [PATCH] 0024513: Suspicious code highlighted by 0024510 Blend_Walking_1: value returned by TestArret() deleted. IntTools_EdgeFace: deleted redundant parameter ff2 and anIsProj2 associated with ff2, since ff2 = !ff1. Refactoring. ProjLib_ProjectedCurve: treatment of surface of revolution is symmetric for surface of revolution now. Refactoring. --- src/Blend/Blend_Walking_1.gxx | 246 +++++------ src/IntTools/IntTools_EdgeFace.cxx | 55 +-- src/ProjLib/ProjLib_ProjectedCurve.cxx | 549 +++++++++++++------------ 3 files changed, 443 insertions(+), 407 deletions(-) diff --git a/src/Blend/Blend_Walking_1.gxx b/src/Blend/Blend_Walking_1.gxx index c082938705..bf68fd9a43 100644 --- a/src/Blend/Blend_Walking_1.gxx +++ b/src/Blend/Blend_Walking_1.gxx @@ -165,14 +165,13 @@ void Blend_Walking::Perform(Blend_Function& Func, } -Standard_Boolean Blend_Walking::PerformFirstSection -(Blend_Function& Func, - const Standard_Real Pdep, - math_Vector& ParDep, - const Standard_Real Tolesp, - const Standard_Real TolGuide, - TopAbs_State& Pos1, - TopAbs_State& Pos2) +Standard_Boolean Blend_Walking::PerformFirstSection(Blend_Function& Func, + const Standard_Real Pdep, + math_Vector& ParDep, + const Standard_Real Tolesp, + const Standard_Real TolGuide, + TopAbs_State& Pos1, + TopAbs_State& Pos2) { iscomplete = Standard_False; comptra = Standard_False; @@ -182,116 +181,122 @@ Standard_Boolean Blend_Walking::PerformFirstSection Pos1 = Pos2 = TopAbs_UNKNOWN; - Blend_Status State; - param = Pdep; Func.Set(param); - math_Vector tolerance(1,4),infbound(1,4),supbound(1,4); - Func.GetTolerance(tolerance,tolesp); - Func.GetBounds(infbound,supbound); - math_FunctionSetRoot rsnld(Func,tolerance,30); - - rsnld.Perform(Func,ParDep,infbound,supbound); - - if (!rsnld.IsDone()) { + math_Vector tolerance(1, 4),infbound(1, 4),supbound(1, 4); + Func.GetTolerance(tolerance, tolesp); + Func.GetBounds(infbound, supbound); + math_FunctionSetRoot rsnld(Func, tolerance, 30); + + rsnld.Perform(Func, ParDep, infbound, supbound); + + if (!rsnld.IsDone()) + { return Standard_False; } rsnld.Root(sol); ParDep = sol; - Pos1 = domain1->Classify(gp_Pnt2d(sol(1),sol(2)), - Min(tolerance(1),tolerance(2)),0); - Pos2 = domain2->Classify(gp_Pnt2d(sol(3),sol(4)), - Min(tolerance(3),tolerance(4)),0); - if (Pos1 != TopAbs_IN || Pos2 != TopAbs_IN) { + Pos1 = domain1->Classify(gp_Pnt2d(sol(1), sol(2)), Min(tolerance(1), tolerance(2)), 0); + Pos2 = domain2->Classify(gp_Pnt2d(sol(3), sol(4)), Min(tolerance(3), tolerance(4)), 0); + if (Pos1 != TopAbs_IN || Pos2 != TopAbs_IN) + { return Standard_False; } - State = TestArret(Func, Blend_OK, Standard_False); -#ifdef DEB - if (Blend_GettraceDRAWSECT()){ - Drawsect(surf1,surf2,sol,param,Func); - } -#endif + TestArret(Func, Blend_OK, Standard_False); + #ifdef DEB + if (Blend_GettraceDRAWSECT()) + { + Drawsect(surf1, surf2, sol, param, Func); + } + #endif return Standard_True; } -Standard_Boolean Blend_Walking::PerformFirstSection - (Blend_Function& Func, - Blend_FuncInv& FuncInv, - const Standard_Real Pdep, - const Standard_Real Pmax, - const math_Vector& ParDep, - const Standard_Real Tolesp, - const Standard_Real TolGuide, - const Standard_Boolean RecOnS1, - const Standard_Boolean RecOnS2, - Standard_Real& Psol, - math_Vector& ParSol) +Standard_Boolean Blend_Walking::PerformFirstSection (Blend_Function& Func, + Blend_FuncInv& FuncInv, + const Standard_Real Pdep, + const Standard_Real Pmax, + const math_Vector& ParDep, + const Standard_Real Tolesp, + const Standard_Real TolGuide, + const Standard_Boolean RecOnS1, + const Standard_Boolean RecOnS2, + Standard_Real& Psol, + math_Vector& ParSol) { iscomplete = Standard_False; comptra = Standard_False; line = new TheLine (); - Standard_Real w1,w2, extrapol; - Standard_Boolean recad1,recad2; + Standard_Real w1, w2, extrapol; + Standard_Boolean recad1, recad2; tolesp = Abs(Tolesp); tolgui = Abs(TolGuide); - if (Pmax-Pdep >= 0.) { + if (Pmax - Pdep >= 0.0) + { sens = 1.; } - else { + else + { sens = -1.; } - extrapol = Abs(Pmax-Pdep)/50; // 2% + extrapol = Abs(Pmax - Pdep) / 50.0; // 2% Blend_Status State; param = Pdep; Func.Set(param); - math_Vector tolerance(1,4),infbound(1,4),supbound(1,4); - math_Vector solrst1(1,4),solrst2(1,4); - TheExtremity Ext1,Ext2; + math_Vector tolerance(1, 4),infbound(1, 4),supbound(1, 4); + math_Vector solrst1(1, 4),solrst2(1, 4); + TheExtremity Ext1, Ext2; Standard_Integer Index1 = 0, Index2 = 0, nbarc; Standard_Boolean Isvtx1 = Standard_False, Isvtx2 = Standard_False; - TheVertex Vtx1,Vtx2; + TheVertex Vtx1, Vtx2; gp_Pnt2d p2d; - Func.GetTolerance(tolerance,tolesp); - Func.GetBounds(infbound,supbound); - math_FunctionSetRoot rsnld(Func,tolerance,30); + Func.GetTolerance(tolerance, tolesp); + Func.GetBounds(infbound, supbound); + math_FunctionSetRoot rsnld(Func, tolerance, 30); - rsnld.Perform(Func,ParDep,infbound,supbound); - - if (!rsnld.IsDone()) { + rsnld.Perform(Func, ParDep, infbound, supbound); + + if (!rsnld.IsDone()) + { return Standard_False; } rsnld.Root(sol); w1 = w2 = Pmax; - recad1 = RecOnS1 && Recadre(FuncInv,Standard_True, - sol,solrst1,Index1,Isvtx1,Vtx1, extrapol); - if (recad1) { + recad1 = RecOnS1 && Recadre(FuncInv, Standard_True, sol, solrst1, + Index1, Isvtx1, Vtx1, extrapol); + if (recad1) + { w1 = solrst1(2); } - recad2 = RecOnS2 && Recadre(FuncInv,Standard_False, - sol,solrst2,Index2,Isvtx2,Vtx2, extrapol); - if (recad2) { + recad2 = RecOnS2 && Recadre(FuncInv, Standard_False, sol, solrst2, + Index2, Isvtx2, Vtx2, extrapol); + if (recad2) + { w2 = solrst2(2); } - if (!recad1 && !recad2) { + if (!recad1 && !recad2) + { return Standard_False; } - if (recad1 && recad2) { - if (Abs(w1-w2) <= tolgui) { + if (recad1 && recad2) + { + if (Abs(w1 - w2) <= tolgui) + { //sol sur 1 et 2 a la fois State = Blend_OnRst12; param = w1; @@ -300,70 +305,78 @@ Standard_Boolean Blend_Walking::PerformFirstSection ParSol(3) = solrst1(3); ParSol(4) = solrst1(4); } - else if (sens*(w2-w1) < 0.) { // on garde le plus grand + else if (sens * (w2 - w1) < 0.0) + { // on garde le plus grand //sol sur 1 State = Blend_OnRst1; param = w1; recdomain1->Init(); nbarc = 1; - while (nbarc < Index1) { - nbarc++; - recdomain1->Next(); + while (nbarc < Index1) + { + nbarc++; + recdomain1->Next(); } - p2d = TheArcTool::Value(recdomain1->Value(),solrst1(1)); + p2d = TheArcTool::Value(recdomain1->Value(), solrst1(1)); ParSol(1) = p2d.X(); ParSol(2) = p2d.Y(); ParSol(3) = solrst1(3); ParSol(4) = solrst1(4); } - else { + else + { //sol sur 2 State = Blend_OnRst2; param = w2; recdomain2->Init(); nbarc = 1; - while (nbarc < Index2) { - nbarc++; - recdomain2->Next(); + while (nbarc < Index2) + { + nbarc++; + recdomain2->Next(); } - p2d = TheArcTool::Value(recdomain2->Value(),solrst2(1)); + p2d = TheArcTool::Value(recdomain2->Value(), solrst2(1)); ParSol(1) = solrst2(3); ParSol(2) = solrst2(4); ParSol(3) = p2d.X(); ParSol(4) = p2d.Y(); } } - else if (recad1) { + else if (recad1) + { // sol sur 1 State = Blend_OnRst1; param = w1; recdomain1->Init(); nbarc = 1; - while (nbarc < Index1) { + while (nbarc < Index1) + { nbarc++; recdomain1->Next(); } - p2d = TheArcTool::Value(recdomain1->Value(),solrst1(1)); + p2d = TheArcTool::Value(recdomain1->Value(), solrst1(1)); ParSol(1) = p2d.X(); ParSol(2) = p2d.Y(); ParSol(3) = solrst1(3); ParSol(4) = solrst1(4); } - else { //if (recad2) { + else + { //if (recad2) { //sol sur 2 State = Blend_OnRst2; param = w2; recdomain2->Init(); nbarc = 1; - while (nbarc < Index2) { + while (nbarc < Index2) + { nbarc++; recdomain2->Next(); } - p2d = TheArcTool::Value(recdomain2->Value(),solrst2(1)); + p2d = TheArcTool::Value(recdomain2->Value(), solrst2(1)); ParSol(1) = solrst2(3); ParSol(2) = solrst2(4); ParSol(3) = p2d.X(); @@ -374,46 +387,44 @@ Standard_Boolean Blend_Walking::PerformFirstSection sol = ParSol; Func.Set(param); State = TestArret(Func, State, Standard_False); - switch (State) { - case Blend_OnRst1 : + switch (State) + { + case Blend_OnRst1: { -#ifdef DEB - if (Blend_GettraceDRAWSECT()){ - Drawsect(surf1,surf2,sol,param,Func); - } -#endif - MakeExtremity(Ext1,Standard_True,Index1, - solrst1(1),Isvtx1,Vtx1); - Ext2.SetValue(previousP.PointOnS2(), - sol(3),sol(4),tolesp); + #ifdef DEB + if (Blend_GettraceDRAWSECT()) + { + Drawsect(surf1, surf2, sol, param, Func); + } + #endif + MakeExtremity(Ext1, Standard_True, Index1, solrst1(1), Isvtx1, Vtx1); + Ext2.SetValue(previousP.PointOnS2(), sol(3), sol(4), tolesp); } break; - - case Blend_OnRst2 : + + case Blend_OnRst2: { -#ifdef DEB - if (Blend_GettraceDRAWSECT()){ - Drawsect(surf1,surf2,sol,param,Func); - } -#endif - Ext1.SetValue(previousP.PointOnS1(), - sol(1),sol(2),tolesp); - MakeExtremity(Ext2,Standard_False,Index2, - solrst2(1),Isvtx2,Vtx2); + #ifdef DEB + if (Blend_GettraceDRAWSECT()) + { + Drawsect(surf1, surf2, sol, param, Func); + } + #endif + Ext1.SetValue(previousP.PointOnS1(), sol(1), sol(2), tolesp); + MakeExtremity(Ext2, Standard_False, Index2, solrst2(1), Isvtx2, Vtx2); } break; - + case Blend_OnRst12 : { -#ifdef DEB - if (Blend_GettraceDRAWSECT()){ - Drawsect(surf1,surf2,sol,param,Func); + #ifdef DEB + if (Blend_GettraceDRAWSECT()) + { + Drawsect(surf1, surf2, sol, param, Func); } -#endif - MakeExtremity(Ext1,Standard_True,Index1, - solrst1(1),Isvtx1,Vtx1); - MakeExtremity(Ext2,Standard_False,Index2, - solrst2(1),Isvtx2,Vtx2); + #endif + MakeExtremity(Ext1, Standard_True , Index1, solrst1(1), Isvtx1, Vtx1); + MakeExtremity(Ext2, Standard_False, Index2, solrst2(1), Isvtx2, Vtx2); } break; default: @@ -421,11 +432,13 @@ Standard_Boolean Blend_Walking::PerformFirstSection Standard_Failure::Raise("Blend_Walking::PerformFirstSection : echec"); } } - if (sens < 0.) { - line->SetEndPoints(Ext1,Ext2); + if (sens < 0.0) + { + line->SetEndPoints(Ext1, Ext2); } - else { - line->SetStartPoints(Ext1,Ext2); + else + { + line->SetStartPoints(Ext1, Ext2); } return Standard_True; } @@ -570,4 +583,3 @@ void Blend_Walking::Check(const Standard_Boolean C) { check = C; } - diff --git a/src/IntTools/IntTools_EdgeFace.cxx b/src/IntTools/IntTools_EdgeFace.cxx index 80c13cb6d3..9ac4a71d9c 100644 --- a/src/IntTools/IntTools_EdgeFace.cxx +++ b/src/IntTools/IntTools_EdgeFace.cxx @@ -400,40 +400,41 @@ void IntTools_EdgeFace::Prepare() //function : FindProjectableRoot //purpose : //======================================================================= -void IntTools_EdgeFace::FindProjectableRoot - (const Standard_Real tt1, - const Standard_Real tt2, - const Standard_Integer ff1, - const Standard_Integer ff2, - Standard_Real& tRoot) + void IntTools_EdgeFace::FindProjectableRoot (const Standard_Real tt1, + const Standard_Real tt2, + const Standard_Integer ff1, + const Standard_Integer /*ff2*/, + Standard_Real& tRoot) { Standard_Real tm, t1, t2, aEpsT; - Standard_Integer anIsProj1, anIsProj2, anIsProjm; - aEpsT=0.5*myEpsT; - // + Standard_Integer anIsProj1, anIsProjm; + aEpsT = 0.5 * myEpsT; + // Root is inside [tt1, tt2] - t1=tt1; - t2=tt2; - anIsProj1=ff1; - anIsProj2=ff2; - - for(;;) { - if (fabs(t1-t2) < aEpsT) { - tRoot=(anIsProj1) ? t1 : t2; + t1 = tt1; + t2 = tt2; + anIsProj1 = ff1; + + for(;;) + { + if (fabs(t1 - t2) < aEpsT) + { + tRoot = (anIsProj1) ? t1 : t2; return; } - tm=.5*(t1+t2); - anIsProjm=IsProjectable(tm); - - if (anIsProjm != anIsProj1) { - t2=tm; - anIsProj2=anIsProjm; + tm = 0.5 * (t1 + t2); + anIsProjm = IsProjectable(tm); + + if (anIsProjm != anIsProj1) + { + t2 = tm; } - else { - t1=tm; - anIsProj1=anIsProjm; + else + { + t1 = tm; + anIsProj1 = anIsProjm; } - } + } // for(;;) } //======================================================================= //function : IsProjectable diff --git a/src/ProjLib/ProjLib_ProjectedCurve.cxx b/src/ProjLib/ProjLib_ProjectedCurve.cxx index 6be1457708..cbdd84ae92 100644 --- a/src/ProjLib/ProjLib_ProjectedCurve.cxx +++ b/src/ProjLib/ProjLib_ProjectedCurve.cxx @@ -329,360 +329,383 @@ void ProjLib_ProjectedCurve::Load(const Handle(Adaptor3d_HCurve)& C) myCurve = C; Standard_Real FirstPar = C->FirstParameter(); Standard_Real LastPar = C->LastParameter(); - GeomAbs_SurfaceType SType = mySurface->GetType(); + GeomAbs_SurfaceType SType = mySurface->GetType(); GeomAbs_CurveType CType = myCurve->GetType(); - switch (SType) { - + switch (SType) + { case GeomAbs_Plane: { - ProjLib_Plane P(mySurface->Plane()); - Project(P,myCurve); - myResult = P; + ProjLib_Plane P(mySurface->Plane()); + Project(P,myCurve); + myResult = P; } break; case GeomAbs_Cylinder: { - ProjLib_Cylinder P(mySurface->Cylinder()); - Project(P,myCurve); - myResult = P; + ProjLib_Cylinder P(mySurface->Cylinder()); + Project(P,myCurve); + myResult = P; } break; case GeomAbs_Cone: { - ProjLib_Cone P(mySurface->Cone()); - Project(P,myCurve); - myResult = P; + ProjLib_Cone P(mySurface->Cone()); + Project(P,myCurve); + myResult = P; } break; case GeomAbs_Sphere: { - ProjLib_Sphere P(mySurface->Sphere()); - Project(P,myCurve); - if ( P.IsDone()) { - // on met dans la pseudo-periode ( car Sphere n'est pas - // periodique en V !) - P.SetInBounds(myCurve->FirstParameter()); - } - myResult = P; + ProjLib_Sphere P(mySurface->Sphere()); + Project(P,myCurve); + if ( P.IsDone()) + { + // on met dans la pseudo-periode ( car Sphere n'est pas + // periodique en V !) + P.SetInBounds(myCurve->FirstParameter()); + } + myResult = P; } break; case GeomAbs_Torus: { - ProjLib_Torus P(mySurface->Torus()); - Project(P,myCurve); - myResult = P; + ProjLib_Torus P(mySurface->Torus()); + Project(P,myCurve); + myResult = P; } break; case GeomAbs_BezierSurface: case GeomAbs_BSplineSurface: { - - Standard_Boolean IsTrimmed[2] = {Standard_False, Standard_False}; + Standard_Boolean IsTrimmed[2] = {Standard_False, Standard_False}; Standard_Integer SingularCase[2]; - Standard_Real f, l, dt; - const Standard_Real eps = 0.01; - f = myCurve->FirstParameter(); - l = myCurve->LastParameter(); - dt = (l-f)*eps; - - Standard_Real U1=0.,U2=0.,V1=0.,V2=0; - const Adaptor3d_Surface& S = mySurface->Surface(); - U1 = S.FirstUParameter(); - U2 = S.LastUParameter(); - V1 = S.FirstVParameter(); - V2 = S.LastVParameter(); - - if(IsoIsDeg(S, U1, GeomAbs_IsoU, 0., myTolerance) ) { - //Surface has pole at U = Umin - gp_Pnt Pole = mySurface->Value(U1, V1); - TrimC3d(myCurve, IsTrimmed, dt, Pole, SingularCase, 1); - } - - if(IsoIsDeg(S, U2, GeomAbs_IsoU, 0., myTolerance) ) { - //Surface has pole at U = Umax - gp_Pnt Pole = mySurface->Value(U2, V1); - TrimC3d(myCurve, IsTrimmed, dt, Pole, SingularCase, 2); - } - - if(IsoIsDeg(S, V1, GeomAbs_IsoV, 0., myTolerance) ) { - //Surface has pole at V = Vmin - gp_Pnt Pole = mySurface->Value(U1, V1); - TrimC3d(myCurve, IsTrimmed, dt, Pole, SingularCase, 3); - } - - if(IsoIsDeg(S, V2, GeomAbs_IsoV, 0., myTolerance) ) { - //Surface has pole at V = Vmax - gp_Pnt Pole = mySurface->Value(U1, V2); - TrimC3d(myCurve, IsTrimmed, dt, Pole, SingularCase, 4); - } - - ProjLib_ComputeApproxOnPolarSurface polar(myCurve, - mySurface, - myTolerance); - - Handle(Geom2d_BSplineCurve) aRes = polar.BSpline(); - - if(IsTrimmed[0] || IsTrimmed[1]) { - if(IsTrimmed[0]) { - //Add segment before start of curve - f = myCurve->FirstParameter(); - ExtendC2d(aRes, f, -dt, U1, U2, V1, V2, 0, SingularCase[0]); - } - if(IsTrimmed[1]) { - //Add segment after end of curve - l = myCurve->LastParameter(); - ExtendC2d(aRes, l, dt, U1, U2, V1, V2, 1, SingularCase[1]); - } + Standard_Real f, l, dt; + const Standard_Real eps = 0.01; + f = myCurve->FirstParameter(); + l = myCurve->LastParameter(); + dt = (l - f) * eps; + + Standard_Real U1 = 0.0, U2=0.0, V1=0.0, V2=0.0; + const Adaptor3d_Surface& S = mySurface->Surface(); + U1 = S.FirstUParameter(); + U2 = S.LastUParameter(); + V1 = S.FirstVParameter(); + V2 = S.LastVParameter(); + + if(IsoIsDeg(S, U1, GeomAbs_IsoU, 0., myTolerance)) + { + //Surface has pole at U = Umin + gp_Pnt Pole = mySurface->Value(U1, V1); + TrimC3d(myCurve, IsTrimmed, dt, Pole, SingularCase, 1); + } + + if(IsoIsDeg(S, U2, GeomAbs_IsoU, 0., myTolerance)) + { + //Surface has pole at U = Umax + gp_Pnt Pole = mySurface->Value(U2, V1); + TrimC3d(myCurve, IsTrimmed, dt, Pole, SingularCase, 2); + } + + if(IsoIsDeg(S, V1, GeomAbs_IsoV, 0., myTolerance)) + { + //Surface has pole at V = Vmin + gp_Pnt Pole = mySurface->Value(U1, V1); + TrimC3d(myCurve, IsTrimmed, dt, Pole, SingularCase, 3); + } + + if(IsoIsDeg(S, V2, GeomAbs_IsoV, 0., myTolerance)) + { + //Surface has pole at V = Vmax + gp_Pnt Pole = mySurface->Value(U1, V2); + TrimC3d(myCurve, IsTrimmed, dt, Pole, SingularCase, 4); + } + + ProjLib_ComputeApproxOnPolarSurface polar(myCurve, mySurface, myTolerance); + + Handle(Geom2d_BSplineCurve) aRes = polar.BSpline(); + + if(IsTrimmed[0] || IsTrimmed[1]) + { + if(IsTrimmed[0]) + { + //Add segment before start of curve + f = myCurve->FirstParameter(); + ExtendC2d(aRes, f, -dt, U1, U2, V1, V2, 0, SingularCase[0]); + } + if(IsTrimmed[1]) + { + //Add segment after end of curve + l = myCurve->LastParameter(); + ExtendC2d(aRes, l, dt, U1, U2, V1, V2, 1, SingularCase[1]); + } Handle(Geom2d_Curve) NewCurve2d; GeomLib::SameRange(Precision::PConfusion(), aRes, aRes->FirstParameter(), aRes->LastParameter(), - FirstPar, LastPar, - NewCurve2d); + FirstPar, LastPar, NewCurve2d); aRes = Handle(Geom2d_BSplineCurve)::DownCast(NewCurve2d); } - myResult.SetBSpline(aRes); - myResult.Done(); - myResult.SetType(GeomAbs_BSplineCurve); + myResult.SetBSpline(aRes); + myResult.Done(); + myResult.SetType(GeomAbs_BSplineCurve); } break; default: { - Standard_Boolean IsTrimmed[2] = {Standard_False, Standard_False}; - Standard_Real Vsingular[2] = { 0.0 , 0.0 }; //for surfaces of revolution - Standard_Real f = 0., l = 0., dt = 0.; - const Standard_Real eps = 0.01; - - if(mySurface->GetType() == GeomAbs_SurfaceOfRevolution) { - //Check possible singularity - - gp_Pnt P = mySurface->AxeOfRevolution().Location(); - gp_Dir N = mySurface->AxeOfRevolution().Direction(); - - gp_Lin L(P, N); - - f = myCurve->FirstParameter(); - l = myCurve->LastParameter(); - dt = (l-f)*eps; - - P = myCurve->Value(f); - if(L.Distance(P) < Precision::Confusion()) { - IsTrimmed[0] = Standard_True; - f = f+dt; - myCurve = myCurve->Trim(f, l, Precision::Confusion()); + Standard_Boolean IsTrimmed[2] = {Standard_False, Standard_False}; + Standard_Real Vsingular[2] = {0.0 , 0.0}; //for surfaces of revolution + Standard_Real f = 0.0, l = 0.0, dt = 0.0; + const Standard_Real eps = 0.01; + + if(mySurface->GetType() == GeomAbs_SurfaceOfRevolution) + { + //Check possible singularity + + gp_Pnt P = mySurface->AxeOfRevolution().Location(); + gp_Dir N = mySurface->AxeOfRevolution().Direction(); + + gp_Lin L(P, N); + + f = myCurve->FirstParameter(); + l = myCurve->LastParameter(); + dt = (l - f) * eps; + + P = myCurve->Value(f); + if(L.Distance(P) < Precision::Confusion()) + { + IsTrimmed[0] = Standard_True; + f = f + dt; + myCurve = myCurve->Trim(f, l, Precision::Confusion()); Vsingular[0] = ElCLib::Parameter(L, P); //SingularCase[0] = 3; - } - - P = myCurve->Value(l); - if(L.Distance(P) < Precision::Confusion()) { - IsTrimmed[1] = Standard_True; - l = l-dt; - myCurve = myCurve->Trim(f, l, Precision::Confusion()); + } + + P = myCurve->Value(l); + if(L.Distance(P) < Precision::Confusion()) + { + IsTrimmed[1] = Standard_True; + l = l - dt; + myCurve = myCurve->Trim(f, l, Precision::Confusion()); Vsingular[1] = ElCLib::Parameter(L, P); - //SingularCase[1] = 3; - } - } - - ProjLib_CompProjectedCurve Projector(mySurface,myCurve, - myTolerance,myTolerance); - Handle(ProjLib_HCompProjectedCurve) HProjector = - new ProjLib_HCompProjectedCurve(); - HProjector->Set(Projector); - - // Normalement, dans le cadre de ProjLib, le resultat - // doit etre une et une seule courbe !!! - // De plus, cette courbe ne doit pas etre Single point - Standard_Integer NbCurves = Projector.NbCurves(); - Standard_Real Udeb = 0.,Ufin = 0.; - if (NbCurves > 0) { - Projector.Bounds(1,Udeb,Ufin); - } - else { - StdFail_NotDone::Raise("ProjLib CompProjectedCurve Not Done"); - } - // Approximons cette courbe algorithmique. - Standard_Boolean Only3d = Standard_False; - Standard_Boolean Only2d = Standard_True; - GeomAbs_Shape Continuity = GeomAbs_C1; - Standard_Integer MaxDegree = 14; - Standard_Integer MaxSeg = 16; - - Approx_CurveOnSurface appr(HProjector, mySurface, Udeb, Ufin, - myTolerance, - Continuity, MaxDegree, MaxSeg, - Only3d, Only2d); - - Handle(Geom2d_BSplineCurve) aRes = appr.Curve2d(); - - if(IsTrimmed[0] || IsTrimmed[1]) { - // Treatment only for surface of revolution - Standard_Real u1, u2, v1, v2; - u1 = mySurface->FirstUParameter(); - u2 = mySurface->LastUParameter(); - v1 = mySurface->FirstVParameter(); - v2 = mySurface->LastVParameter(); - - if(IsTrimmed[0]) { - //Add segment before start of curve - ExtendC2d(aRes, f, -dt, u1, u2, Vsingular[0], v2, 0, 3); - } - if(IsTrimmed[1]) { - //Add segment after end of curve - ExtendC2d(aRes, l, dt, u1, u2, Vsingular[1], v2, 1, 3); - } + //SingularCase[1] = 4; + } + } + + ProjLib_CompProjectedCurve Projector(mySurface,myCurve, myTolerance, myTolerance); + Handle(ProjLib_HCompProjectedCurve) HProjector = new ProjLib_HCompProjectedCurve(); + HProjector->Set(Projector); + + // Normalement, dans le cadre de ProjLib, le resultat + // doit etre une et une seule courbe !!! + // De plus, cette courbe ne doit pas etre Single point + Standard_Integer NbCurves = Projector.NbCurves(); + Standard_Real Udeb = 0.0,Ufin = 0.0; + if (NbCurves > 0) + { + Projector.Bounds(1, Udeb, Ufin); + } + else + { + StdFail_NotDone::Raise("ProjLib CompProjectedCurve Not Done"); + } + // Approximons cette courbe algorithmique. + Standard_Boolean Only3d = Standard_False; + Standard_Boolean Only2d = Standard_True; + GeomAbs_Shape Continuity = GeomAbs_C1; + Standard_Integer MaxDegree = 14; + Standard_Integer MaxSeg = 16; + + Approx_CurveOnSurface appr(HProjector, mySurface, Udeb, Ufin, + myTolerance, Continuity, MaxDegree, MaxSeg, + Only3d, Only2d); + + Handle(Geom2d_BSplineCurve) aRes = appr.Curve2d(); + + if(IsTrimmed[0] || IsTrimmed[1]) + { + // Treatment only for surface of revolution + Standard_Real u1, u2, v1, v2; + u1 = mySurface->FirstUParameter(); + u2 = mySurface->LastUParameter(); + v1 = mySurface->FirstVParameter(); + v2 = mySurface->LastVParameter(); + + if(IsTrimmed[0]) + { + //Add segment before start of curve + ExtendC2d(aRes, f, -dt, u1, u2, Vsingular[0], v2, 0, 3); + } + if(IsTrimmed[1]) + { + //Add segment after end of curve + ExtendC2d(aRes, l, dt, u1, u2, v1, Vsingular[1], 1, 4); + } Handle(Geom2d_Curve) NewCurve2d; GeomLib::SameRange(Precision::PConfusion(), aRes, aRes->FirstParameter(), aRes->LastParameter(), - FirstPar, LastPar, - NewCurve2d); + FirstPar, LastPar, NewCurve2d); aRes = Handle(Geom2d_BSplineCurve)::DownCast(NewCurve2d); - } - - myResult.SetBSpline(aRes); - myResult.Done(); - myResult.SetType(GeomAbs_BSplineCurve); + } + + myResult.SetBSpline(aRes); + myResult.Done(); + myResult.SetType(GeomAbs_BSplineCurve); } } - if ( !myResult.IsDone()) { + if ( !myResult.IsDone()) + { ProjLib_ComputeApprox Comp( myCurve, mySurface, myTolerance); myResult.Done(); - + // set the type - if ( SType == GeomAbs_Plane && CType == GeomAbs_BezierCurve) { + if ( SType == GeomAbs_Plane && CType == GeomAbs_BezierCurve) + { myResult.SetType(GeomAbs_BezierCurve); myResult.SetBezier(Comp.Bezier()) ; } - else { + else + { myResult.SetType(GeomAbs_BSplineCurve); myResult.SetBSpline(Comp.BSpline()) ; } // set the periodicity flag - if ( SType == GeomAbs_Plane && - CType == GeomAbs_BSplineCurve && - myCurve->IsPeriodic() ) { + if (SType == GeomAbs_Plane && + CType == GeomAbs_BSplineCurve && + myCurve->IsPeriodic() ) + { myResult.SetPeriodic(); } myTolerance = Comp.Tolerance(); } - else { + else + { // On remet arbitrairement la tol atteinte a une valeur // petite en attendant mieux. dub lbo 11/03/97 myTolerance = Min(myTolerance,Precision::Confusion()); // Translate the projected curve to keep the first point // In the canonical boundaries of periodic surfaces. - if (mySurface->IsUPeriodic()) { + if (mySurface->IsUPeriodic()) + { // xf Standard_Real aT1, aT2, aU1, aU2, aUPeriod, aUr, aUm, aUmid, dUm, dUr; GeomAbs_CurveType aTypeR; ProjLib_Projector aResult; // - aT1=myCurve->FirstParameter(); - aT2=myCurve->LastParameter(); - aU1=mySurface->FirstUParameter(); - aU2=mySurface->LastUParameter(); - aUPeriod=mySurface->UPeriod(); + aT1 = myCurve->FirstParameter(); + aT2 = myCurve->LastParameter(); + aU1 = mySurface->FirstUParameter(); + aU2 = mySurface->LastUParameter(); + aUPeriod = mySurface->UPeriod(); // - aTypeR=myResult.GetType(); - if ((aU2-aU1)<(aUPeriod-myTolerance) && aTypeR == GeomAbs_Line) { - aResult=myResult; - aResult.UFrame(aT1, aT2, aU1, aUPeriod); - // - gp_Lin2d &aLr = (gp_Lin2d &) aResult.Line(); - aUr=aLr.Location().X(); - gp_Lin2d &aLm = (gp_Lin2d &) myResult.Line(); - aUm=aLm.Location().X(); - // - aUmid=0.5*(aU2+aU1); - dUm=fabs(aUm-aUmid); - dUr=fabs(aUr-aUmid); - if (dUrFirstParameter(), - myCurve->LastParameter(), - mySurface->FirstUParameter(), - mySurface->UPeriod()); + myCurve->LastParameter(), + mySurface->FirstUParameter(), + mySurface->UPeriod()); */ //xt // Modified by skv - Wed Aug 11 15:45:58 2004 OCC6272 Begin // Correct the U isoline in periodical surface // to be inside restriction boundaries. - if (myResult.GetType() == GeomAbs_Line) { - gp_Lin2d &aLine = (gp_Lin2d &) myResult.Line(); - - Standard_Real aPeriod = mySurface->UPeriod(); - Standard_Real aFUPar = mySurface->FirstUParameter(); - Standard_Real aLUPar = mySurface->LastUParameter(); - - // Check if the parametric range is lower then the period. - if (aLUPar - aFUPar < aPeriod - myTolerance) { - Standard_Real aU = aLine.Location().X(); - - if (Abs(aU + aPeriod - aFUPar) < myTolerance || - Abs(aU - aPeriod - aFUPar) < myTolerance) { - gp_Pnt2d aNewLoc(aFUPar, aLine.Location().Y()); - - aLine.SetLocation(aNewLoc); - } else if (Abs(aU + aPeriod - aLUPar) < myTolerance || - Abs(aU - aPeriod - aLUPar) < myTolerance) { - gp_Pnt2d aNewLoc(aLUPar, aLine.Location().Y()); - - aLine.SetLocation(aNewLoc); - } - } + if (myResult.GetType() == GeomAbs_Line) + { + gp_Lin2d &aLine = (gp_Lin2d &) myResult.Line(); + + Standard_Real aPeriod = mySurface->UPeriod(); + Standard_Real aFUPar = mySurface->FirstUParameter(); + Standard_Real aLUPar = mySurface->LastUParameter(); + + // Check if the parametric range is lower then the period. + if (aLUPar - aFUPar < aPeriod - myTolerance) + { + Standard_Real aU = aLine.Location().X(); + + if (Abs(aU + aPeriod - aFUPar) < myTolerance || + Abs(aU - aPeriod - aFUPar) < myTolerance) + { + gp_Pnt2d aNewLoc(aFUPar, aLine.Location().Y()); + + aLine.SetLocation(aNewLoc); + } + else if (Abs(aU + aPeriod - aLUPar) < myTolerance || + Abs(aU - aPeriod - aLUPar) < myTolerance) + { + gp_Pnt2d aNewLoc(aLUPar, aLine.Location().Y()); + aLine.SetLocation(aNewLoc); + } + } } } -// Modified by skv - Wed Aug 11 15:45:58 2004 OCC6272 End - - if (mySurface->IsVPeriodic()) { - myResult.VFrame(myCurve->FirstParameter(), - myCurve->LastParameter(), - mySurface->FirstVParameter(), - mySurface->VPeriod()); -// Modified by skv - Wed Aug 11 15:45:58 2004 OCC6272 Begin -// Correct the V isoline in a periodical surface -// to be inside restriction boundaries. - if (myResult.GetType() == GeomAbs_Line) { - gp_Lin2d &aLine = (gp_Lin2d &) myResult.Line(); - - Standard_Real aPeriod = mySurface->VPeriod(); - Standard_Real aFVPar = mySurface->FirstVParameter(); - Standard_Real aLVPar = mySurface->LastVParameter(); - - // Check if the parametric range is lower then the period. - if (aLVPar - aFVPar < aPeriod - myTolerance) { - Standard_Real aV = aLine.Location().Y(); - - if (Abs(aV + aPeriod - aFVPar) < myTolerance || - Abs(aV - aPeriod - aFVPar) < myTolerance) { - gp_Pnt2d aNewLoc(aLine.Location().X(), aFVPar); - - aLine.SetLocation(aNewLoc); - } else if (Abs(aV + aPeriod - aLVPar) < myTolerance || - Abs(aV - aPeriod - aLVPar) < myTolerance) { - gp_Pnt2d aNewLoc(aLine.Location().X(), aLVPar); - - aLine.SetLocation(aNewLoc); - } - } + // Modified by skv - Wed Aug 11 15:45:58 2004 OCC6272 End + + if (mySurface->IsVPeriodic()) + { + myResult.VFrame(myCurve->FirstParameter(), myCurve->LastParameter(), + mySurface->FirstVParameter(), mySurface->VPeriod()); + // Modified by skv - Wed Aug 11 15:45:58 2004 OCC6272 Begin + // Correct the V isoline in a periodical surface + // to be inside restriction boundaries. + if (myResult.GetType() == GeomAbs_Line) + { + gp_Lin2d &aLine = (gp_Lin2d &) myResult.Line(); + + Standard_Real aPeriod = mySurface->VPeriod(); + Standard_Real aFVPar = mySurface->FirstVParameter(); + Standard_Real aLVPar = mySurface->LastVParameter(); + + // Check if the parametric range is lower then the period. + if (aLVPar - aFVPar < aPeriod - myTolerance) + { + Standard_Real aV = aLine.Location().Y(); + + if (Abs(aV + aPeriod - aFVPar) < myTolerance || + Abs(aV - aPeriod - aFVPar) < myTolerance) + { + gp_Pnt2d aNewLoc(aLine.Location().X(), aFVPar); + aLine.SetLocation(aNewLoc); + } + else if (Abs(aV + aPeriod - aLVPar) < myTolerance || + Abs(aV - aPeriod - aLVPar) < myTolerance) + { + gp_Pnt2d aNewLoc(aLine.Location().X(), aLVPar); + aLine.SetLocation(aNewLoc); + } + } } } -// Modified by skv - Wed Aug 11 15:45:58 2004 OCC6272 End + // Modified by skv - Wed Aug 11 15:45:58 2004 OCC6272 End } } -- 2.39.5