- // on regarde si on garde
- //
- if (aNbParts==1) {
- // if (Abs(fprm) < RealEpsilon() && Abs(lprm-2.*M_PI) < RealEpsilon()) {
- if (Abs(fprm) <= aRealEpsilon && Abs(lprm-2.*M_PI) <= aRealEpsilon) {
- IntTools_Curve aCurve;
- Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
- aCurve.SetCurve(aTC3D);
- fprm=aTC3D->FirstParameter();
- lprm=aTC3D->LastParameter ();
-
- if(myApprox1) {
- Handle (Geom2d_Curve) C2d;
- BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
- if(Tolpc>myTolReached2d || myTolReached2d==0) {
- myTolReached2d=Tolpc;
- }
- //
- aCurve.SetFirstCurve2d(C2d);
- }
- else { ////
- Handle(Geom2d_BSplineCurve) H1;
- aCurve.SetFirstCurve2d(H1);
- }
-
- if(myApprox2) {
- Handle (Geom2d_Curve) C2d;
- BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
- if(Tolpc>myTolReached2d || myTolReached2d==0) {
- myTolReached2d=Tolpc;
- }
- //
- aCurve.SetSecondCurve2d(C2d);
- }
- else {
- Handle(Geom2d_BSplineCurve) H1;
- aCurve.SetSecondCurve2d(H1);
- }
- mySeqOfCurve.Append(aCurve);
- break;
- }
- }
- //
- Standard_Real aTwoPIdiv17, u1, v1, u2, v2, Tol;
-
- aTwoPIdiv17=2.*M_PI/17.;
-
- for (j=0; j<=17; j++) {
- gp_Pnt ptref (newc->Value (j*aTwoPIdiv17));
- Tol = Precision::Confusion();
-
- Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
- ok = (dom1->Classify(gp_Pnt2d(u1,v1),Tol) != TopAbs_OUT);
- if(ok) {
- ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
- }
- if (ok) {
- IntTools_Curve aCurve;
- aCurve.SetCurve(newc);
- //==============================================
- if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {
-
- if(myApprox1) {
- Handle (Geom2d_Curve) C2d;
- BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
- if(Tolpc>myTolReached2d || myTolReached2d==0) {
- myTolReached2d=Tolpc;
- }
- //
- aCurve.SetFirstCurve2d(C2d);
- }
- else {
- Handle(Geom2d_BSplineCurve) H1;
- aCurve.SetFirstCurve2d(H1);
- }
-
- if(myApprox2) {
- Handle (Geom2d_Curve) C2d;
- BuildPCurves(fprm, lprm, Tolpc,myHS2->ChangeSurface().Surface(), newc, C2d);
- if(Tolpc>myTolReached2d || myTolReached2d==0) {
- myTolReached2d=Tolpc;
- }
- //
- aCurve.SetSecondCurve2d(C2d);
- }
-
- else {
- Handle(Geom2d_BSplineCurve) H1;
- aCurve.SetSecondCurve2d(H1);
- }
- }// end of if (typl == IntPatch_Circle || typl == IntPatch_Ellipse)
-
- else {
- Handle(Geom2d_BSplineCurve) H1;
- //
- aCurve.SetFirstCurve2d(H1);
- aCurve.SetSecondCurve2d(H1);
- }
- //==============================================
- //
- mySeqOfCurve.Append(aCurve);
- break;
-
- }// end of if (ok) {
- }// end of for (Standard_Integer j=0; j<=17; j++)
- }// end of else { on regarde si on garde
- }// for (i=1; i<=myLConstruct.NbParts(); i++)
- }// IntPatch_Circle: IntPatch_Ellipse:
- break;
-
+ // on regarde si on garde
+ //
+ if (aNbParts==1) {
+// if (Abs(fprm) < RealEpsilon() && Abs(lprm-2.*M_PI) < RealEpsilon()) {
+ if (Abs(fprm) <= aRealEpsilon && Abs(lprm-2.*M_PI) <= aRealEpsilon) {
+ IntTools_Curve aCurve;
+ Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
+ aCurve.SetCurve(aTC3D);
+ fprm=aTC3D->FirstParameter();
+ lprm=aTC3D->LastParameter ();
+
+ if(myApprox1) {
+ Handle (Geom2d_Curve) C2d;
+ BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
+ if(Tolpc>myTolReached2d || myTolReached2d==0) {
+ myTolReached2d=Tolpc;
+ }
+ //
+ aCurve.SetFirstCurve2d(C2d);
+ }
+ else { ////
+ Handle(Geom2d_BSplineCurve) H1;
+ aCurve.SetFirstCurve2d(H1);
+ }
+
+ if(myApprox2) {
+ Handle (Geom2d_Curve) C2d;
+ BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
+ if(Tolpc>myTolReached2d || myTolReached2d==0) {
+ myTolReached2d=Tolpc;
+ }
+ //
+ aCurve.SetSecondCurve2d(C2d);
+ }
+ else {
+ Handle(Geom2d_BSplineCurve) H1;
+ aCurve.SetSecondCurve2d(H1);
+ }
+ mySeqOfCurve.Append(aCurve);
+ break;
+ }
+ }
+ //
+ Standard_Real aTwoPIdiv17, u1, v1, u2, v2, Tol;
+
+ aTwoPIdiv17=2.*M_PI/17.;
+
+ for (j=0; j<=17; j++) {
+ gp_Pnt ptref (newc->Value (j*aTwoPIdiv17));
+ Tol = Precision::Confusion();
+
+ Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
+ ok = (dom1->Classify(gp_Pnt2d(u1,v1),Tol) != TopAbs_OUT);
+ if(ok) {
+ ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
+ }
+ if (ok) {
+ IntTools_Curve aCurve;
+ aCurve.SetCurve(newc);
+ //==============================================
+ if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {
+
+ if(myApprox1) {
+ Handle (Geom2d_Curve) C2d;
+ BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
+ if(Tolpc>myTolReached2d || myTolReached2d==0) {
+ myTolReached2d=Tolpc;
+ }
+ //
+ aCurve.SetFirstCurve2d(C2d);
+ }
+ else {
+ Handle(Geom2d_BSplineCurve) H1;
+ aCurve.SetFirstCurve2d(H1);
+ }
+
+ if(myApprox2) {
+ Handle (Geom2d_Curve) C2d;
+ BuildPCurves(fprm, lprm, Tolpc,myHS2->ChangeSurface().Surface(), newc, C2d);
+ if(Tolpc>myTolReached2d || myTolReached2d==0) {
+ myTolReached2d=Tolpc;
+ }
+ //
+ aCurve.SetSecondCurve2d(C2d);
+ }
+
+ else {
+ Handle(Geom2d_BSplineCurve) H1;
+ aCurve.SetSecondCurve2d(H1);
+ }
+ }// end of if (typl == IntPatch_Circle || typl == IntPatch_Ellipse)
+
+ else {
+ Handle(Geom2d_BSplineCurve) H1;
+ //
+ aCurve.SetFirstCurve2d(H1);
+ aCurve.SetSecondCurve2d(H1);
+ }
+ //==============================================
+ //
+ mySeqOfCurve.Append(aCurve);
+ break;
+
+ }// end of if (ok) {
+ }// end of for (Standard_Integer j=0; j<=17; j++)
+ }// end of else { on regarde si on garde
+ }// for (i=1; i<=myLConstruct.NbParts(); i++)
+ }// IntPatch_Circle: IntPatch_Ellipse:
+ break;
+
- myLConstruct.Part(i, fprm, lprm);
- Handle(IntPatch_WLine) WL =
- convert.MakeWLine(Handle(IntPatch_ALine):: DownCast(L),fprm,lprm);
-
- theapp3d.Perform(myHS1,myHS2,WL,Standard_True,myApprox1,myApprox2, 1, WL->NbPnts());
-
- if (!theapp3d.IsDone()) {
- //
- Handle(Geom2d_BSplineCurve) H1;
- Handle(Geom2d_BSplineCurve) H2;
-
- if(myApprox1) {
- H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
- }
-
- if(myApprox2) {
- H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
- }
- //
- mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
- }
-
- else {
- if(myApprox1 || myApprox2) {
- if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0) {
- myTolReached2d = theapp3d.TolReached2d();
- }
- }
-
- if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0) {
- myTolReached3d = theapp3d.TolReached3d();
- }
-
- Standard_Integer aNbMultiCurves, nbpoles;
- aNbMultiCurves=theapp3d.NbMultiCurves();
- for (j=1; j<=aNbMultiCurves; j++) {
- const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
- nbpoles = mbspc.NbPoles();
-
- TColgp_Array1OfPnt tpoles(1, nbpoles);
- mbspc.Curve(1, tpoles);
- Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
- mbspc.Knots(),
- mbspc.Multiplicities(),
- mbspc.Degree());
-
- GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
- Check.FixTangent(Standard_True,Standard_True);
- //
- IntTools_Curve aCurve;
- aCurve.SetCurve(BS);
-
- if(myApprox1) {
- TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
- mbspc.Curve(2,tpoles2d);
- Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
- mbspc.Knots(),
- mbspc.Multiplicities(),
- mbspc.Degree());
-
- GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
- newCheck.FixTangent(Standard_True,Standard_True);
- //
- aCurve.SetFirstCurve2d(BS2);
- }
- else {
- Handle(Geom2d_BSplineCurve) H1;
- aCurve.SetFirstCurve2d(H1);
- }
-
- if(myApprox2) {
- TColgp_Array1OfPnt2d tpoles2d(1, nbpoles);
- Standard_Integer TwoOrThree;
- TwoOrThree=myApprox1 ? 3 : 2;
- mbspc.Curve(TwoOrThree, tpoles2d);
- Handle(Geom2d_BSplineCurve) BS2 =new Geom2d_BSplineCurve(tpoles2d,
- mbspc.Knots(),
- mbspc.Multiplicities(),
- mbspc.Degree());
-
- GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
- newCheck.FixTangent(Standard_True,Standard_True);
- //
- aCurve.SetSecondCurve2d(BS2);
- }
- else {
- Handle(Geom2d_BSplineCurve) H2;
- aCurve.SetSecondCurve2d(H2);
- }
- //
- mySeqOfCurve.Append(aCurve);
-
- }// for (j=1; j<=aNbMultiCurves; j++) {
- }// else from if (!theapp3d.IsDone())
+ myLConstruct.Part(i, fprm, lprm);
+ Handle(IntPatch_WLine) WL =
+ convert.MakeWLine(Handle(IntPatch_ALine):: DownCast(L),fprm,lprm);
+
+ theapp3d.Perform(myHS1,myHS2,WL,Standard_True,myApprox1,myApprox2, 1, WL->NbPnts());
+
+ if (!theapp3d.IsDone()) {
+ //
+ Handle(Geom2d_BSplineCurve) H1;
+ Handle(Geom2d_BSplineCurve) H2;
+
+ if(myApprox1) {
+ H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
+ }
+
+ if(myApprox2) {
+ H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
+ }
+ //
+ mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
+ }
+
+ else {
+ if(myApprox1 || myApprox2) {
+ if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0) {
+ myTolReached2d = theapp3d.TolReached2d();
+ }
+ }
+
+ if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0) {
+ myTolReached3d = theapp3d.TolReached3d();
+ }
+
+ Standard_Integer aNbMultiCurves, nbpoles;
+ aNbMultiCurves=theapp3d.NbMultiCurves();
+ for (j=1; j<=aNbMultiCurves; j++) {
+ const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
+ nbpoles = mbspc.NbPoles();
+
+ TColgp_Array1OfPnt tpoles(1, nbpoles);
+ mbspc.Curve(1, tpoles);
+ Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
+ mbspc.Knots(),
+ mbspc.Multiplicities(),
+ mbspc.Degree());
+
+ GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
+ Check.FixTangent(Standard_True,Standard_True);
+ //
+ IntTools_Curve aCurve;
+ aCurve.SetCurve(BS);
+
+ if(myApprox1) {
+ TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
+ mbspc.Curve(2,tpoles2d);
+ Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
+ mbspc.Knots(),
+ mbspc.Multiplicities(),
+ mbspc.Degree());
+
+ GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
+ newCheck.FixTangent(Standard_True,Standard_True);
+ //
+ aCurve.SetFirstCurve2d(BS2);
+ }
+ else {
+ Handle(Geom2d_BSplineCurve) H1;
+ aCurve.SetFirstCurve2d(H1);
+ }
+
+ if(myApprox2) {
+ TColgp_Array1OfPnt2d tpoles2d(1, nbpoles);
+ Standard_Integer TwoOrThree;
+ TwoOrThree=myApprox1 ? 3 : 2;
+ mbspc.Curve(TwoOrThree, tpoles2d);
+ Handle(Geom2d_BSplineCurve) BS2 =new Geom2d_BSplineCurve(tpoles2d,
+ mbspc.Knots(),
+ mbspc.Multiplicities(),
+ mbspc.Degree());
+
+ GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
+ newCheck.FixTangent(Standard_True,Standard_True);
+ //
+ aCurve.SetSecondCurve2d(BS2);
+ }
+ else {
+ Handle(Geom2d_BSplineCurve) H2;
+ aCurve.SetSecondCurve2d(H2);
+ }
+ //
+ mySeqOfCurve.Append(aCurve);
+
+ }// for (j=1; j<=aNbMultiCurves; j++) {
+ }// else from if (!theapp3d.IsDone())
- if(myApprox2) {
- H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
- }
- //
- IntTools_Curve aIC(aBSp, H1, H2);
- mySeqOfCurve.Append(aIC);
- }
-
- else {
- if(myApprox1 || myApprox2 || (typs1==GeomAbs_Plane || typs2==GeomAbs_Plane)) {
- if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0.) {
- myTolReached2d = theapp3d.TolReached2d();
- }
- }
- if(typs1==GeomAbs_Plane || typs2==GeomAbs_Plane) {
- myTolReached3d = myTolReached2d;
- //
- if (typs1==GeomAbs_Torus || typs2==GeomAbs_Torus) {
- if (myTolReached3d<1.e-6) {
- myTolReached3d = theapp3d.TolReached3d();
- myTolReached3d=1.e-6;
- }
- }
- }
- else if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0.) {
- myTolReached3d = theapp3d.TolReached3d();
- }
-
- Standard_Integer aNbMultiCurves, nbpoles;
- aNbMultiCurves=theapp3d.NbMultiCurves();
- for (j=1; j<=aNbMultiCurves; j++) {
- if(typs1 == GeomAbs_Plane) {
- const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
- nbpoles = mbspc.NbPoles();
-
- TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
- TColgp_Array1OfPnt tpoles(1,nbpoles);
-
- mbspc.Curve(1,tpoles2d);
- const gp_Pln& Pln = myHS1->Surface().Plane();
- //
- Standard_Integer ik;
- for(ik = 1; ik<= nbpoles; ik++) {
- tpoles.SetValue(ik,
- ElSLib::Value(tpoles2d.Value(ik).X(),
- tpoles2d.Value(ik).Y(),
- Pln));
- }
- //
- Handle(Geom_BSplineCurve) BS =
- new Geom_BSplineCurve(tpoles,
- mbspc.Knots(),
- mbspc.Multiplicities(),
- mbspc.Degree());
- GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
- Check.FixTangent(Standard_True, Standard_True);
- //
- IntTools_Curve aCurve;
- aCurve.SetCurve(BS);
-
- if(myApprox1) {
- Handle(Geom2d_BSplineCurve) BS1 =
- new Geom2d_BSplineCurve(tpoles2d,
- mbspc.Knots(),
- mbspc.Multiplicities(),
- mbspc.Degree());
- GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
- Check1.FixTangent(Standard_True,Standard_True);
- //
- // ############################################
- if(!rejectSurface && !reApprox) {
- Standard_Boolean isValid = IsCurveValid(BS1);
- if(!isValid) {
- reApprox = Standard_True;
- goto reapprox;
- }
- }
- // ############################################
- aCurve.SetFirstCurve2d(BS1);
- }
- else {
- Handle(Geom2d_BSplineCurve) H1;
- aCurve.SetFirstCurve2d(H1);
- }
-
- if(myApprox2) {
- mbspc.Curve(2, tpoles2d);
-
- Handle(Geom2d_BSplineCurve) BS2 = new Geom2d_BSplineCurve(tpoles2d,
- mbspc.Knots(),
- mbspc.Multiplicities(),
- mbspc.Degree());
- GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
- newCheck.FixTangent(Standard_True,Standard_True);
-
- // ###########################################
- if(!rejectSurface && !reApprox) {
- Standard_Boolean isValid = IsCurveValid(BS2);
- if(!isValid) {
- reApprox = Standard_True;
- goto reapprox;
- }
- }
- // ###########################################
- //
- aCurve.SetSecondCurve2d(BS2);
- }
- else {
- Handle(Geom2d_BSplineCurve) H2;
- //
- aCurve.SetSecondCurve2d(H2);
- }
- //
- mySeqOfCurve.Append(aCurve);
+ if(myApprox2) {
+ H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
+ }
+ //
+ IntTools_Curve aIC(aBSp, H1, H2);
+ mySeqOfCurve.Append(aIC);
+ }
+
+ else {
+ if(myApprox1 || myApprox2 || (typs1==GeomAbs_Plane || typs2==GeomAbs_Plane)) {
+ if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0.) {
+ myTolReached2d = theapp3d.TolReached2d();
+ }
+ }
+ if(typs1==GeomAbs_Plane || typs2==GeomAbs_Plane) {
+ myTolReached3d = myTolReached2d;
+ //
+ if (typs1==GeomAbs_Torus || typs2==GeomAbs_Torus) {
+ if (myTolReached3d<1.e-6) {
+ myTolReached3d = theapp3d.TolReached3d();
+ myTolReached3d=1.e-6;
+ }
+ }
+ }
+ else if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0.) {
+ myTolReached3d = theapp3d.TolReached3d();
+ }
+
+ Standard_Integer aNbMultiCurves, nbpoles;
+ aNbMultiCurves=theapp3d.NbMultiCurves();
+ for (j=1; j<=aNbMultiCurves; j++) {
+ if(typs1 == GeomAbs_Plane) {
+ const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
+ nbpoles = mbspc.NbPoles();
+
+ TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
+ TColgp_Array1OfPnt tpoles(1,nbpoles);
+
+ mbspc.Curve(1,tpoles2d);
+ const gp_Pln& Pln = myHS1->Surface().Plane();
+ //
+ Standard_Integer ik;
+ for(ik = 1; ik<= nbpoles; ik++) {
+ tpoles.SetValue(ik,
+ ElSLib::Value(tpoles2d.Value(ik).X(),
+ tpoles2d.Value(ik).Y(),
+ Pln));
+ }
+ //
+ Handle(Geom_BSplineCurve) BS =
+ new Geom_BSplineCurve(tpoles,
+ mbspc.Knots(),
+ mbspc.Multiplicities(),
+ mbspc.Degree());
+ GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
+ Check.FixTangent(Standard_True, Standard_True);
+ //
+ IntTools_Curve aCurve;
+ aCurve.SetCurve(BS);
+
+ if(myApprox1) {
+ Handle(Geom2d_BSplineCurve) BS1 =
+ new Geom2d_BSplineCurve(tpoles2d,
+ mbspc.Knots(),
+ mbspc.Multiplicities(),
+ mbspc.Degree());
+ GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
+ Check1.FixTangent(Standard_True,Standard_True);
+ //
+ // ############################################
+ if(!rejectSurface && !reApprox) {
+ Standard_Boolean isValid = IsCurveValid(BS1);
+ if(!isValid) {
+ reApprox = Standard_True;
+ goto reapprox;
+ }
+ }
+ // ############################################
+ aCurve.SetFirstCurve2d(BS1);
+ }
+ else {
+ Handle(Geom2d_BSplineCurve) H1;
+ aCurve.SetFirstCurve2d(H1);
+ }
+
+ if(myApprox2) {
+ mbspc.Curve(2, tpoles2d);
+
+ Handle(Geom2d_BSplineCurve) BS2 = new Geom2d_BSplineCurve(tpoles2d,
+ mbspc.Knots(),
+ mbspc.Multiplicities(),
+ mbspc.Degree());
+ GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
+ newCheck.FixTangent(Standard_True,Standard_True);
+
+ // ###########################################
+ if(!rejectSurface && !reApprox) {
+ Standard_Boolean isValid = IsCurveValid(BS2);
+ if(!isValid) {
+ reApprox = Standard_True;
+ goto reapprox;
+ }
+ }
+ // ###########################################
+ //
+ aCurve.SetSecondCurve2d(BS2);
+ }
+ else {
+ Handle(Geom2d_BSplineCurve) H2;
+ //
+ aCurve.SetSecondCurve2d(H2);
+ }
+ //
+ mySeqOfCurve.Append(aCurve);
- if ( anExtrema.SquareDistance(i) > aCriteria * aCriteria )
- continue;
-
- Extrema_POnCurv P1, P2;
- anExtrema.Points( i, P1, P2 );
-
- Standard_Boolean bFoundResult = Standard_True;
- gp_Pnt2d pr1, pr2;
-
- Standard_Integer surfit = 0;
- for ( surfit = 0; surfit < 2; surfit++ ) {
- GeomAPI_ProjectPointOnSurf& aProjector =
- (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
-
- gp_Pnt aP3d = (surfit == 0) ? P1.Value() : P2.Value();
- aProjector.Perform(aP3d);
-
- if(!aProjector.IsDone())
- bFoundResult = Standard_False;
- else {
- if(aProjector.LowerDistance() > aCriteria) {
- bFoundResult = Standard_False;
- }
- else {
- Standard_Real foundU = 0, foundV = 0;
- aProjector.LowerDistanceParameters(foundU, foundV);
- if ( surfit == 0 )
- pr1 = gp_Pnt2d( foundU, foundV );
- else
- pr2 = gp_Pnt2d( foundU, foundV );
- }
- }
- }
- if ( bFoundResult ) {
- aSeqResultS1.Append( pr1 );
- aSeqResultS2.Append( pr2 );
- aSeqResultRad.Append( aCriteria );
-
- // torus is u and v periodic
- const Standard_Real twoPI = M_PI + M_PI;
- Standard_Real arr1tmp[2] = {pr1.X(), pr1.Y()};
- Standard_Real arr2tmp[2] = {pr2.X(), pr2.Y()};
-
- // iteration on period bounds
- for ( Standard_Integer k1 = 0; k1 < 2; k1++ ) {
- Standard_Real aBound = ( k1 == 0 ) ? 0 : twoPI;
- Standard_Real aShift = ( k1 == 0 ) ? twoPI : -twoPI;
-
- // iteration on surfaces
- for ( Standard_Integer k2 = 0; k2 < 2; k2++ ) {
- Standard_Real* arr1 = ( k2 == 0 ) ? arr1tmp : arr2tmp;
- Standard_Real* arr2 = ( k2 != 0 ) ? arr1tmp : arr2tmp;
- TColgp_SequenceOfPnt2d& aSeqS1 = ( k2 == 0 ) ? aSeqResultS1 : aSeqResultS2;
- TColgp_SequenceOfPnt2d& aSeqS2 = ( k2 != 0 ) ? aSeqResultS1 : aSeqResultS2;
-
- if (fabs(arr1[0] - aBound) < Precision::PConfusion()) {
- aSeqS1.Append( gp_Pnt2d( arr1[0] + aShift, arr1[1] ) );
- aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
- aSeqResultRad.Append( aCriteria );
- }
- if (fabs(arr1[1] - aBound) < Precision::PConfusion()) {
- aSeqS1.Append( gp_Pnt2d( arr1[0], arr1[1] + aShift) );
- aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
- aSeqResultRad.Append( aCriteria );
- }
- }
- } //
- }
+ if ( anExtrema.SquareDistance(i) > aCriteria * aCriteria )
+ continue;
+
+ Extrema_POnCurv P1, P2;
+ anExtrema.Points( i, P1, P2 );
+
+ Standard_Boolean bFoundResult = Standard_True;
+ gp_Pnt2d pr1, pr2;
+
+ Standard_Integer surfit = 0;
+ for ( surfit = 0; surfit < 2; surfit++ ) {
+ GeomAPI_ProjectPointOnSurf& aProjector =
+ (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
+
+ gp_Pnt aP3d = (surfit == 0) ? P1.Value() : P2.Value();
+ aProjector.Perform(aP3d);
+
+ if(!aProjector.IsDone())
+ bFoundResult = Standard_False;
+ else {
+ if(aProjector.LowerDistance() > aCriteria) {
+ bFoundResult = Standard_False;
+ }
+ else {
+ Standard_Real foundU = 0, foundV = 0;
+ aProjector.LowerDistanceParameters(foundU, foundV);
+ if ( surfit == 0 )
+ pr1 = gp_Pnt2d( foundU, foundV );
+ else
+ pr2 = gp_Pnt2d( foundU, foundV );
+ }
+ }
+ }
+ if ( bFoundResult ) {
+ aSeqResultS1.Append( pr1 );
+ aSeqResultS2.Append( pr2 );
+ aSeqResultRad.Append( aCriteria );
+
+ // torus is u and v periodic
+ const Standard_Real twoPI = M_PI + M_PI;
+ Standard_Real arr1tmp[2] = {pr1.X(), pr1.Y()};
+ Standard_Real arr2tmp[2] = {pr2.X(), pr2.Y()};
+
+ // iteration on period bounds
+ for ( Standard_Integer k1 = 0; k1 < 2; k1++ ) {
+ Standard_Real aBound = ( k1 == 0 ) ? 0 : twoPI;
+ Standard_Real aShift = ( k1 == 0 ) ? twoPI : -twoPI;
+
+ // iteration on surfaces
+ for ( Standard_Integer k2 = 0; k2 < 2; k2++ ) {
+ Standard_Real* arr1 = ( k2 == 0 ) ? arr1tmp : arr2tmp;
+ Standard_Real* arr2 = ( k2 != 0 ) ? arr1tmp : arr2tmp;
+ TColgp_SequenceOfPnt2d& aSeqS1 = ( k2 == 0 ) ? aSeqResultS1 : aSeqResultS2;
+ TColgp_SequenceOfPnt2d& aSeqS2 = ( k2 != 0 ) ? aSeqResultS1 : aSeqResultS2;
+
+ if (fabs(arr1[0] - aBound) < Precision::PConfusion()) {
+ aSeqS1.Append( gp_Pnt2d( arr1[0] + aShift, arr1[1] ) );
+ aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
+ aSeqResultRad.Append( aCriteria );
+ }
+ if (fabs(arr1[1] - aBound) < Precision::PConfusion()) {
+ aSeqS1.Append( gp_Pnt2d( arr1[0], arr1[1] + aShift) );
+ aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
+ aSeqResultRad.Append( aCriteria );
+ }
+ }
+ } //
+ }
- if(!isperiodic) {
- bIsPointOnBoundary=
- IsPointOnBoundary(aParameter, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
- if(bIsPointOnBoundary) {
- bIsUBoundary = (parit == 0);
- bIsFirstBoundary = bIsOnFirstBoundary;
- nbboundaries++;
- }
- }
- else {
- Standard_Real aPeriod = (parit == 0) ? aGASurface->UPeriod() : aGASurface->VPeriod();
- Standard_Real anoffset = 0.;
- Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
-
- bIsPointOnBoundary=
- IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
- if(bIsPointOnBoundary) {
- bIsUBoundary = (parit == 0);
- bIsFirstBoundary = bIsOnFirstBoundary;
- nbboundaries++;
- }
- else {
- //check neighbourhood of boundary
- Standard_Real anEpsilon = aResolution * 100.;
- Standard_Real aPart = ( aupperboundary - alowerboundary ) * 0.1;
- anEpsilon = ( anEpsilon > aPart ) ? aPart : anEpsilon;
-
- bIsNearBoundary = IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary,
- anEpsilon, bIsOnFirstBoundary);
-
- }
- }
- }
-
- // check if a point belong to a tangent zone. Begin
- for ( Standard_Integer zIt = 1; zIt <= aNbZone; zIt++ ) {
- gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
- Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
-
- Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
- const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
- Standard_Real nU1, nV1;
-
- if(surfit == 0)
- aNeighbourPoint.ParametersOnS1(nU1, nV1);
- else
- aNeighbourPoint.ParametersOnS2(nU1, nV1);
- gp_Pnt2d ap1(nU1, nV1);
- gp_Pnt2d ap2 = AdjustByNeighbour( ap1, gp_Pnt2d( U, V ), aGASurface );
-
-
- if ( IsInsideTanZone( ap2, aPZone, aZoneRadius, aGASurface ) ) {
- aZoneIndex = zIt;
- bIsNearBoundary = Standard_True;
- if ( theReachedTol3d < aZoneRadius ) {
- theReachedTol3d = aZoneRadius;
- }
- }
- }
- // check if a point belong to a tangent zone. End
- Standard_Boolean bComputeLineEnd = Standard_False;
-
- if(nbboundaries == 2) {
- //xf
- bComputeLineEnd = Standard_True;
- //xt
- }
- else if(nbboundaries == 1) {
- Standard_Boolean isperiodic = (bIsUBoundary) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
-
- if(isperiodic) {
- Standard_Real alowerboundary = (bIsUBoundary) ? umin : vmin;
- Standard_Real aupperboundary = (bIsUBoundary) ? umax : vmax;
- Standard_Real aPeriod = (bIsUBoundary) ? aGASurface->UPeriod() : aGASurface->VPeriod();
- Standard_Real aParameter = (bIsUBoundary) ? U : V;
- Standard_Real anoffset = 0.;
- Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
-
- Standard_Real adist = (bIsFirstBoundary) ? fabs(anAdjustPar - alowerboundary) : fabs(anAdjustPar - aupperboundary);
- Standard_Real anotherPar = (bIsFirstBoundary) ? (aupperboundary - adist) : (alowerboundary + adist);
- anotherPar += anoffset;
- Standard_Integer aneighbourpointindex = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
- const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex);
- Standard_Real nU1, nV1;
-
- if(surfit == 0)
- aNeighbourPoint.ParametersOnS1(nU1, nV1);
- else
- aNeighbourPoint.ParametersOnS2(nU1, nV1);
-
- Standard_Real adist1 = (bIsUBoundary) ? fabs(nU1 - U) : fabs(nV1 - V);
- Standard_Real adist2 = (bIsUBoundary) ? fabs(nU1 - anotherPar) : fabs(nV1 - anotherPar);
- bComputeLineEnd = Standard_True;
- Standard_Boolean bCheckAngle1 = Standard_False;
- Standard_Boolean bCheckAngle2 = Standard_False;
- gp_Vec2d aNewVec;
- Standard_Real anewU = (bIsUBoundary) ? anotherPar : U;
- Standard_Real anewV = (bIsUBoundary) ? V : anotherPar;
-
- if(((adist1 - adist2) > Precision::PConfusion()) &&
- (adist2 < (aPeriod / 4.))) {
- bCheckAngle1 = Standard_True;
- aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(anewU, anewV));
-
- if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
- aNewP.SetValue((surfit == 0), anewU, anewV);
- bCheckAngle1 = Standard_False;
- }
- }
- else if(adist1 < (aPeriod / 4.)) {
- bCheckAngle2 = Standard_True;
- aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(U, V));
-
- if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
- bCheckAngle2 = Standard_False;
- }
- }
-
- if(bCheckAngle1 || bCheckAngle2) {
- // assume there are at least two points in line (see "if" above)
- Standard_Integer anindexother = aneighbourpointindex;
-
- while((anindexother <= aListOfIndex.Last()) && (anindexother >= aListOfIndex.First())) {
- anindexother = (j == 0) ? (anindexother + 1) : (anindexother - 1);
- const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(anindexother);
- Standard_Real nU2, nV2;
-
- if(surfit == 0)
- aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
- else
- aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
- gp_Vec2d aVecOld(gp_Pnt2d(nU2, nV2), gp_Pnt2d(nU1, nV1));
-
- if(aVecOld.SquareMagnitude() <= (gp::Resolution() * gp::Resolution())) {
- continue;
- }
- else {
- Standard_Real anAngle = aNewVec.Angle(aVecOld);
-
- if((fabs(anAngle) < (M_PI * 0.25)) && (aNewVec.Dot(aVecOld) > 0.)) {
-
- if(bCheckAngle1) {
- Standard_Real U1, U2, V1, V2;
- IntSurf_PntOn2S atmppoint = aNewP;
- atmppoint.SetValue((surfit == 0), anewU, anewV);
- atmppoint.Parameters(U1, V1, U2, V2);
- gp_Pnt P1 = theSurface1->Value(U1, V1);
- gp_Pnt P2 = theSurface2->Value(U2, V2);
- gp_Pnt P0 = aPoint.Value();
-
- if(P0.IsEqual(P1, aTol) &&
- P0.IsEqual(P2, aTol) &&
- P1.IsEqual(P2, aTol)) {
- bComputeLineEnd = Standard_False;
- aNewP.SetValue((surfit == 0), anewU, anewV);
- }
- }
-
- if(bCheckAngle2) {
- bComputeLineEnd = Standard_False;
- }
- }
- break;
- }
- } // end while(anindexother...)
- }
- }
- }
- else if ( bIsNearBoundary ) {
- bComputeLineEnd = Standard_True;
- }
-
- if(bComputeLineEnd) {
-
- gp_Pnt2d anewpoint;
- Standard_Boolean found = Standard_False;
-
- if ( bIsNearBoundary ) {
- // re-compute point near natural boundary or near tangent zone
- Standard_Real u1, v1, u2, v2;
- aNewP.Parameters( u1, v1, u2, v2 );
- if(surfit == 0)
- anewpoint = gp_Pnt2d( u1, v1 );
- else
- anewpoint = gp_Pnt2d( u2, v2 );
-
- Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
- const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
- Standard_Real nU1, nV1;
-
- if(surfit == 0)
- aNeighbourPoint.ParametersOnS1(nU1, nV1);
- else
- aNeighbourPoint.ParametersOnS2(nU1, nV1);
- gp_Pnt2d ap1(nU1, nV1);
- gp_Pnt2d ap2;
-
-
- if ( aZoneIndex ) {
- // exclude point from a tangent zone
- anewpoint = AdjustByNeighbour( ap1, anewpoint, aGASurface );
- gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(aZoneIndex) : aTanZoneS2->Value(aZoneIndex);
- Standard_Real aZoneRadius = aTanZoneRadius->Value(aZoneIndex);
-
- if ( FindPoint(ap1, anewpoint, umin, umax, vmin, vmax,
- aPZone, aZoneRadius, aGASurface, ap2) ) {
- anewpoint = ap2;
- found = Standard_True;
- }
- }
- else if ( aGASurface->IsUPeriodic() || aGASurface->IsVPeriodic() ) {
- // re-compute point near boundary if shifted on a period
- ap2 = AdjustByNeighbour( ap1, anewpoint, aGASurface );
-
- if ( ( ap2.X() < umin ) || ( ap2.X() > umax ) ||
- ( ap2.Y() < vmin ) || ( ap2.Y() > vmax ) ) {
- found = FindPoint(ap1, ap2, umin, umax, vmin, vmax, anewpoint);
- }
- else {
- anewpoint = ap2;
- aNewP.SetValue( (surfit == 0), anewpoint.X(), anewpoint.Y() );
- }
- }
- }
- else {
-
- Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
- const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
- Standard_Real nU1, nV1;
-
- if(surfit == 0)
- aNeighbourPoint.ParametersOnS1(nU1, nV1);
- else
- aNeighbourPoint.ParametersOnS2(nU1, nV1);
- gp_Pnt2d ap1(nU1, nV1);
- gp_Pnt2d ap2(nU1, nV1);
- Standard_Integer aneighbourpointindex2 = aneighbourpointindex1;
-
- while((aneighbourpointindex2 <= aListOfIndex.Last()) && (aneighbourpointindex2 >= aListOfIndex.First())) {
- aneighbourpointindex2 = (j == 0) ? (aneighbourpointindex2 + 1) : (aneighbourpointindex2 - 1);
- const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(aneighbourpointindex2);
- Standard_Real nU2, nV2;
-
- if(surfit == 0)
- aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
- else
- aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
- ap2.SetX(nU2);
- ap2.SetY(nV2);
-
- if(ap1.SquareDistance(ap2) > (gp::Resolution() * gp::Resolution())) {
- break;
- }
- }
- found = FindPoint(ap2, ap1, umin, umax, vmin, vmax, anewpoint);
- }
-
- if(found) {
- // check point
- Standard_Real aCriteria = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
- GeomAPI_ProjectPointOnSurf& aProjector =
- (surfit == 0) ? aContext->ProjPS(theFace2) : aContext->ProjPS(theFace1);
- Handle(GeomAdaptor_HSurface) aSurface = (surfit == 0) ? theSurface1 : theSurface2;
-
- Handle(GeomAdaptor_HSurface) aSurfaceOther = (surfit == 0) ? theSurface2 : theSurface1;
-
- gp_Pnt aP3d = aSurface->Value(anewpoint.X(), anewpoint.Y());
- aProjector.Perform(aP3d);
-
- if(aProjector.IsDone()) {
- if(aProjector.LowerDistance() < aCriteria) {
- Standard_Real foundU = U, foundV = V;
- aProjector.LowerDistanceParameters(foundU, foundV);
-
- //Correction of projected coordinates. Begin
- //Note, it may be shifted on a period
- Standard_Integer aneindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
- const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneindex1);
- Standard_Real nUn, nVn;
-
- if(surfit == 0)
- aNeighbourPoint.ParametersOnS2(nUn, nVn);
- else
- aNeighbourPoint.ParametersOnS1(nUn, nVn);
- gp_Pnt2d aNeighbour2d(nUn, nVn);
- gp_Pnt2d anAdjustedPoint = AdjustByNeighbour( aNeighbour2d, gp_Pnt2d(foundU, foundV), aSurfaceOther );
- foundU = anAdjustedPoint.X();
- foundV = anAdjustedPoint.Y();
-
- if ( ( anAdjustedPoint.X() < umin ) && ( anAdjustedPoint.X() > umax ) &&
- ( anAdjustedPoint.Y() < vmin ) && ( anAdjustedPoint.Y() > vmax ) ) {
- // attempt to roughly re-compute point
- foundU = ( foundU < umin ) ? umin : foundU;
- foundU = ( foundU > umax ) ? umax : foundU;
- foundV = ( foundV < vmin ) ? vmin : foundV;
- foundV = ( foundV > vmax ) ? vmax : foundV;
-
- GeomAPI_ProjectPointOnSurf& aProjector2 =
- (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
-
- aP3d = aSurfaceOther->Value(foundU, foundV);
- aProjector2.Perform(aP3d);
-
- if(aProjector2.IsDone()) {
- if(aProjector2.LowerDistance() < aCriteria) {
- Standard_Real foundU2 = anewpoint.X(), foundV2 = anewpoint.Y();
- aProjector2.LowerDistanceParameters(foundU2, foundV2);
- anewpoint.SetX(foundU2);
- anewpoint.SetY(foundV2);
- }
- }
- }
- //Correction of projected coordinates. End
-
- if(surfit == 0)
- aNewP.SetValue(aP3d, anewpoint.X(), anewpoint.Y(), foundU, foundV);
- else
- aNewP.SetValue(aP3d, foundU, foundV, anewpoint.X(), anewpoint.Y());
- }
- }
- }
- }
+ if(!isperiodic) {
+ bIsPointOnBoundary=
+ IsPointOnBoundary(aParameter, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
+ if(bIsPointOnBoundary) {
+ bIsUBoundary = (parit == 0);
+ bIsFirstBoundary = bIsOnFirstBoundary;
+ nbboundaries++;
+ }
+ }
+ else {
+ Standard_Real aPeriod = (parit == 0) ? aGASurface->UPeriod() : aGASurface->VPeriod();
+ Standard_Real anoffset = 0.;
+ Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
+
+ bIsPointOnBoundary=
+ IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
+ if(bIsPointOnBoundary) {
+ bIsUBoundary = (parit == 0);
+ bIsFirstBoundary = bIsOnFirstBoundary;
+ nbboundaries++;
+ }
+ else {
+ //check neighbourhood of boundary
+ Standard_Real anEpsilon = aResolution * 100.;
+ Standard_Real aPart = ( aupperboundary - alowerboundary ) * 0.1;
+ anEpsilon = ( anEpsilon > aPart ) ? aPart : anEpsilon;
+
+ bIsNearBoundary = IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary,
+ anEpsilon, bIsOnFirstBoundary);
+
+ }
+ }
+ }
+
+ // check if a point belong to a tangent zone. Begin
+ for ( Standard_Integer zIt = 1; zIt <= aNbZone; zIt++ ) {
+ gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
+ Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
+
+ Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
+ const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
+ Standard_Real nU1, nV1;
+
+ if(surfit == 0)
+ aNeighbourPoint.ParametersOnS1(nU1, nV1);
+ else
+ aNeighbourPoint.ParametersOnS2(nU1, nV1);
+ gp_Pnt2d ap1(nU1, nV1);
+ gp_Pnt2d ap2 = AdjustByNeighbour( ap1, gp_Pnt2d( U, V ), aGASurface );
+
+
+ if ( IsInsideTanZone( ap2, aPZone, aZoneRadius, aGASurface ) ) {
+ aZoneIndex = zIt;
+ bIsNearBoundary = Standard_True;
+ if ( theReachedTol3d < aZoneRadius ) {
+ theReachedTol3d = aZoneRadius;
+ }
+ }
+ }
+ // check if a point belong to a tangent zone. End
+ Standard_Boolean bComputeLineEnd = Standard_False;
+
+ if(nbboundaries == 2) {
+ //xf
+ bComputeLineEnd = Standard_True;
+ //xt
+ }
+ else if(nbboundaries == 1) {
+ Standard_Boolean isperiodic = (bIsUBoundary) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
+
+ if(isperiodic) {
+ Standard_Real alowerboundary = (bIsUBoundary) ? umin : vmin;
+ Standard_Real aupperboundary = (bIsUBoundary) ? umax : vmax;
+ Standard_Real aPeriod = (bIsUBoundary) ? aGASurface->UPeriod() : aGASurface->VPeriod();
+ Standard_Real aParameter = (bIsUBoundary) ? U : V;
+ Standard_Real anoffset = 0.;
+ Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
+
+ Standard_Real adist = (bIsFirstBoundary) ? fabs(anAdjustPar - alowerboundary) : fabs(anAdjustPar - aupperboundary);
+ Standard_Real anotherPar = (bIsFirstBoundary) ? (aupperboundary - adist) : (alowerboundary + adist);
+ anotherPar += anoffset;
+ Standard_Integer aneighbourpointindex = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
+ const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex);
+ Standard_Real nU1, nV1;
+
+ if(surfit == 0)
+ aNeighbourPoint.ParametersOnS1(nU1, nV1);
+ else
+ aNeighbourPoint.ParametersOnS2(nU1, nV1);
+
+ Standard_Real adist1 = (bIsUBoundary) ? fabs(nU1 - U) : fabs(nV1 - V);
+ Standard_Real adist2 = (bIsUBoundary) ? fabs(nU1 - anotherPar) : fabs(nV1 - anotherPar);
+ bComputeLineEnd = Standard_True;
+ Standard_Boolean bCheckAngle1 = Standard_False;
+ Standard_Boolean bCheckAngle2 = Standard_False;
+ gp_Vec2d aNewVec;
+ Standard_Real anewU = (bIsUBoundary) ? anotherPar : U;
+ Standard_Real anewV = (bIsUBoundary) ? V : anotherPar;
+
+ if(((adist1 - adist2) > Precision::PConfusion()) &&
+ (adist2 < (aPeriod / 4.))) {
+ bCheckAngle1 = Standard_True;
+ aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(anewU, anewV));
+
+ if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
+ aNewP.SetValue((surfit == 0), anewU, anewV);
+ bCheckAngle1 = Standard_False;
+ }
+ }
+ else if(adist1 < (aPeriod / 4.)) {
+ bCheckAngle2 = Standard_True;
+ aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(U, V));
+
+ if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
+ bCheckAngle2 = Standard_False;
+ }
+ }
+
+ if(bCheckAngle1 || bCheckAngle2) {
+ // assume there are at least two points in line (see "if" above)
+ Standard_Integer anindexother = aneighbourpointindex;
+
+ while((anindexother <= aListOfIndex.Last()) && (anindexother >= aListOfIndex.First())) {
+ anindexother = (j == 0) ? (anindexother + 1) : (anindexother - 1);
+ const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(anindexother);
+ Standard_Real nU2, nV2;
+
+ if(surfit == 0)
+ aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
+ else
+ aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
+ gp_Vec2d aVecOld(gp_Pnt2d(nU2, nV2), gp_Pnt2d(nU1, nV1));
+
+ if(aVecOld.SquareMagnitude() <= (gp::Resolution() * gp::Resolution())) {
+ continue;
+ }
+ else {
+ Standard_Real anAngle = aNewVec.Angle(aVecOld);
+
+ if((fabs(anAngle) < (M_PI * 0.25)) && (aNewVec.Dot(aVecOld) > 0.)) {
+
+ if(bCheckAngle1) {
+ Standard_Real U1, U2, V1, V2;
+ IntSurf_PntOn2S atmppoint = aNewP;
+ atmppoint.SetValue((surfit == 0), anewU, anewV);
+ atmppoint.Parameters(U1, V1, U2, V2);
+ gp_Pnt P1 = theSurface1->Value(U1, V1);
+ gp_Pnt P2 = theSurface2->Value(U2, V2);
+ gp_Pnt P0 = aPoint.Value();
+
+ if(P0.IsEqual(P1, aTol) &&
+ P0.IsEqual(P2, aTol) &&
+ P1.IsEqual(P2, aTol)) {
+ bComputeLineEnd = Standard_False;
+ aNewP.SetValue((surfit == 0), anewU, anewV);
+ }
+ }
+
+ if(bCheckAngle2) {
+ bComputeLineEnd = Standard_False;
+ }
+ }
+ break;
+ }
+ } // end while(anindexother...)
+ }
+ }
+ }
+ else if ( bIsNearBoundary ) {
+ bComputeLineEnd = Standard_True;
+ }
+
+ if(bComputeLineEnd) {
+
+ gp_Pnt2d anewpoint;
+ Standard_Boolean found = Standard_False;
+
+ if ( bIsNearBoundary ) {
+ // re-compute point near natural boundary or near tangent zone
+ Standard_Real u1, v1, u2, v2;
+ aNewP.Parameters( u1, v1, u2, v2 );
+ if(surfit == 0)
+ anewpoint = gp_Pnt2d( u1, v1 );
+ else
+ anewpoint = gp_Pnt2d( u2, v2 );
+
+ Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
+ const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
+ Standard_Real nU1, nV1;
+
+ if(surfit == 0)
+ aNeighbourPoint.ParametersOnS1(nU1, nV1);
+ else
+ aNeighbourPoint.ParametersOnS2(nU1, nV1);
+ gp_Pnt2d ap1(nU1, nV1);
+ gp_Pnt2d ap2;
+
+
+ if ( aZoneIndex ) {
+ // exclude point from a tangent zone
+ anewpoint = AdjustByNeighbour( ap1, anewpoint, aGASurface );
+ gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(aZoneIndex) : aTanZoneS2->Value(aZoneIndex);
+ Standard_Real aZoneRadius = aTanZoneRadius->Value(aZoneIndex);
+
+ if ( FindPoint(ap1, anewpoint, umin, umax, vmin, vmax,
+ aPZone, aZoneRadius, aGASurface, ap2) ) {
+ anewpoint = ap2;
+ found = Standard_True;
+ }
+ }
+ else if ( aGASurface->IsUPeriodic() || aGASurface->IsVPeriodic() ) {
+ // re-compute point near boundary if shifted on a period
+ ap2 = AdjustByNeighbour( ap1, anewpoint, aGASurface );
+
+ if ( ( ap2.X() < umin ) || ( ap2.X() > umax ) ||
+ ( ap2.Y() < vmin ) || ( ap2.Y() > vmax ) ) {
+ found = FindPoint(ap1, ap2, umin, umax, vmin, vmax, anewpoint);
+ }
+ else {
+ anewpoint = ap2;
+ aNewP.SetValue( (surfit == 0), anewpoint.X(), anewpoint.Y() );
+ }
+ }
+ }
+ else {
+
+ Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
+ const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
+ Standard_Real nU1, nV1;
+
+ if(surfit == 0)
+ aNeighbourPoint.ParametersOnS1(nU1, nV1);
+ else
+ aNeighbourPoint.ParametersOnS2(nU1, nV1);
+ gp_Pnt2d ap1(nU1, nV1);
+ gp_Pnt2d ap2(nU1, nV1);
+ Standard_Integer aneighbourpointindex2 = aneighbourpointindex1;
+
+ while((aneighbourpointindex2 <= aListOfIndex.Last()) && (aneighbourpointindex2 >= aListOfIndex.First())) {
+ aneighbourpointindex2 = (j == 0) ? (aneighbourpointindex2 + 1) : (aneighbourpointindex2 - 1);
+ const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(aneighbourpointindex2);
+ Standard_Real nU2, nV2;
+
+ if(surfit == 0)
+ aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
+ else
+ aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
+ ap2.SetX(nU2);
+ ap2.SetY(nV2);
+
+ if(ap1.SquareDistance(ap2) > (gp::Resolution() * gp::Resolution())) {
+ break;
+ }
+ }
+ found = FindPoint(ap2, ap1, umin, umax, vmin, vmax, anewpoint);
+ }
+
+ if(found) {
+ // check point
+ Standard_Real aCriteria = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
+ GeomAPI_ProjectPointOnSurf& aProjector =
+ (surfit == 0) ? aContext->ProjPS(theFace2) : aContext->ProjPS(theFace1);
+ Handle(GeomAdaptor_HSurface) aSurface = (surfit == 0) ? theSurface1 : theSurface2;
+
+ Handle(GeomAdaptor_HSurface) aSurfaceOther = (surfit == 0) ? theSurface2 : theSurface1;
+
+ gp_Pnt aP3d = aSurface->Value(anewpoint.X(), anewpoint.Y());
+ aProjector.Perform(aP3d);
+
+ if(aProjector.IsDone()) {
+ if(aProjector.LowerDistance() < aCriteria) {
+ Standard_Real foundU = U, foundV = V;
+ aProjector.LowerDistanceParameters(foundU, foundV);
+
+ //Correction of projected coordinates. Begin
+ //Note, it may be shifted on a period
+ Standard_Integer aneindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
+ const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneindex1);
+ Standard_Real nUn, nVn;
+
+ if(surfit == 0)
+ aNeighbourPoint.ParametersOnS2(nUn, nVn);
+ else
+ aNeighbourPoint.ParametersOnS1(nUn, nVn);
+ gp_Pnt2d aNeighbour2d(nUn, nVn);
+ gp_Pnt2d anAdjustedPoint = AdjustByNeighbour( aNeighbour2d, gp_Pnt2d(foundU, foundV), aSurfaceOther );
+ foundU = anAdjustedPoint.X();
+ foundV = anAdjustedPoint.Y();
+
+ if ( ( anAdjustedPoint.X() < umin ) && ( anAdjustedPoint.X() > umax ) &&
+ ( anAdjustedPoint.Y() < vmin ) && ( anAdjustedPoint.Y() > vmax ) ) {
+ // attempt to roughly re-compute point
+ foundU = ( foundU < umin ) ? umin : foundU;
+ foundU = ( foundU > umax ) ? umax : foundU;
+ foundV = ( foundV < vmin ) ? vmin : foundV;
+ foundV = ( foundV > vmax ) ? vmax : foundV;
+
+ GeomAPI_ProjectPointOnSurf& aProjector2 =
+ (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
+
+ aP3d = aSurfaceOther->Value(foundU, foundV);
+ aProjector2.Perform(aP3d);
+
+ if(aProjector2.IsDone()) {
+ if(aProjector2.LowerDistance() < aCriteria) {
+ Standard_Real foundU2 = anewpoint.X(), foundV2 = anewpoint.Y();
+ aProjector2.LowerDistanceParameters(foundU2, foundV2);
+ anewpoint.SetX(foundU2);
+ anewpoint.SetY(foundV2);
+ }
+ }
+ }
+ //Correction of projected coordinates. End
+
+ if(surfit == 0)
+ aNewP.SetValue(aP3d, anewpoint.X(), anewpoint.Y(), foundU, foundV);
+ else
+ aNewP.SetValue(aP3d, foundU, foundV, anewpoint.X(), anewpoint.Y());
+ }
+ }
+ }
+ }