1 // Created on: 1995-01-27
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
19 #include <GeomInt_IntSS.ixx>
21 #include <GeomInt.hxx>
23 #include <Precision.hxx>
25 #include <gp_Pnt2d.hxx>
28 #include <TColStd_Array1OfReal.hxx>
29 #include <TColStd_Array1OfInteger.hxx>
30 #include <TColStd_Array1OfListOfInteger.hxx>
31 #include <TColStd_SequenceOfReal.hxx>
32 #include <TColStd_ListOfInteger.hxx>
33 #include <TColStd_ListIteratorOfListOfInteger.hxx>
35 #include <TColgp_Array1OfPnt.hxx>
36 #include <TColgp_Array1OfPnt2d.hxx>
38 #include <Adaptor3d_TopolTool.hxx>
39 #include <IntPatch_Line.hxx>
40 #include <IntPatch_WLine.hxx>
41 #include <IntPatch_GLine.hxx>
42 #include <IntPatch_RLine.hxx>
43 #include <IntPatch_ALineToWLine.hxx>
44 #include <IntPatch_IType.hxx>
45 #include <NCollection_IncAllocator.hxx>
46 #include <NCollection_List.hxx>
47 #include <NCollection_LocalArray.hxx>
48 #include <NCollection_StdAllocator.hxx>
51 #include <AppParCurves_MultiBSpCurve.hxx>
53 #include <GeomAbs_SurfaceType.hxx>
54 #include <GeomAbs_CurveType.hxx>
56 #include <GeomAdaptor.hxx>
57 #include <Geom_Curve.hxx>
58 #include <Geom_Line.hxx>
59 #include <Geom_Parabola.hxx>
60 #include <Geom_Hyperbola.hxx>
61 #include <Geom_TrimmedCurve.hxx>
62 #include <Geom_Circle.hxx>
63 #include <Geom_Ellipse.hxx>
64 #include <Geom_BSplineCurve.hxx>
66 #include <Geom2dAdaptor.hxx>
67 #include <Adaptor2d_HCurve2d.hxx>
68 #include <Geom2d_Curve.hxx>
69 #include <Geom2d_BSplineCurve.hxx>
70 #include <Geom2d_TrimmedCurve.hxx>
72 #include <GeomLib_CheckBSplineCurve.hxx>
73 #include <GeomLib_Check2dBSplineCurve.hxx>
74 #include <GeomProjLib.hxx>
75 #include <Approx_CurveOnSurface.hxx>
79 #include <GeomInt_WLApprox.hxx>
80 #include <Extrema_ExtPS.hxx>
82 #include <GeomAdaptor_HSurface.hxx>
83 #include <gp_Lin2d.hxx>
84 #include <Geom2d_Line.hxx>
85 #include <IntPatch_RLine.hxx>
86 #include <Geom2dAdaptor.hxx>
87 #include <Adaptor2d_HCurve2d.hxx>
88 #include <Approx_CurveOnSurface.hxx>
89 #include <GeomAdaptor.hxx>
90 #include <GeomProjLib.hxx>
91 #include <TColStd_Array1OfReal.hxx>
92 #include <TColgp_Array1OfPnt2d.hxx>
93 #include <TColStd_Array1OfInteger.hxx>
94 #include <Geom2d_BSplineCurve.hxx>
95 #include <Geom2dAdaptor_Curve.hxx>
96 #include <IntRes2d_IntersectionPoint.hxx>
97 #include <IntRes2d_IntersectionSegment.hxx>
98 #include <Geom2dInt_GInter.hxx>
101 void Parameters(const Handle(GeomAdaptor_HSurface)& HS1,
102 const Handle(GeomAdaptor_HSurface)& HS2,
110 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)& WL,
111 const Standard_Integer ideb,
112 const Standard_Integer ifin);
115 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
116 const Standard_Integer ideb,
117 const Standard_Integer ifin,
118 const Standard_Boolean onFirst);
121 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine);
125 Standard_Boolean DecompositionOfWLine (const Handle(IntPatch_WLine)& theWLine,
126 const Handle(GeomAdaptor_HSurface)& theSurface1,
127 const Handle(GeomAdaptor_HSurface)& theSurface2,
128 const Standard_Real aTolSum,
129 const GeomInt_LineConstructor& theLConstructor,
130 IntPatch_SequenceOfLine& theNewLines);
133 Standard_Real AdjustPeriodic(const Standard_Real theParameter,
134 const Standard_Real parmin,
135 const Standard_Real parmax,
136 const Standard_Real thePeriod,
137 Standard_Real& theOffset) ;
139 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
140 const Standard_Real theFirstBoundary,
141 const Standard_Real theSecondBoundary,
142 const Standard_Real theResolution,
143 Standard_Boolean& IsOnFirstBoundary);
146 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
147 const gp_Pnt2d& theLastPoint,
148 const Standard_Real theUmin,
149 const Standard_Real theUmax,
150 const Standard_Real theVmin,
151 const Standard_Real theVmax,
152 gp_Pnt2d& theNewPoint);
156 void AdjustUPeriodic (const Handle(Geom_Surface)& aS,
157 Handle(Geom2d_Curve)& aC2D);
159 void GetQuadric(const Handle(GeomAdaptor_HSurface)& HS1,
160 IntSurf_Quadric& quad1);
162 class ProjectPointOnSurf
165 ProjectPointOnSurf() : myIsDone (Standard_False),myIndex(0) {}
166 void Init(const Handle(Geom_Surface)& Surface,
167 const Standard_Real Umin,
168 const Standard_Real Usup,
169 const Standard_Real Vmin,
170 const Standard_Real Vsup);
172 void Perform(const gp_Pnt& P);
173 Standard_Boolean IsDone () const { return myIsDone; }
174 void LowerDistanceParameters(Standard_Real& U, Standard_Real& V ) const;
175 Standard_Real LowerDistance() const;
177 Standard_Boolean myIsDone;
178 Standard_Integer myIndex;
179 Extrema_ExtPS myExtPS;
180 GeomAdaptor_Surface myGeomAdaptor;
183 //=======================================================================
186 //=======================================================================
187 void ProjectPointOnSurf::Init (const Handle(Geom_Surface)& Surface,
188 const Standard_Real Umin,
189 const Standard_Real Usup,
190 const Standard_Real Vmin,
191 const Standard_Real Vsup )
193 const Standard_Real Tolerance = Precision::PConfusion();
195 myGeomAdaptor.Load(Surface, Umin,Usup,Vmin,Vsup);
196 myExtPS.Initialize(myGeomAdaptor, Umin, Usup, Vmin, Vsup, Tolerance, Tolerance);
197 myIsDone = Standard_False;
199 //=======================================================================
202 //=======================================================================
203 void ProjectPointOnSurf::Init ()
205 myIsDone = myExtPS.IsDone() && (myExtPS.NbExt() > 0);
207 // evaluate the lower distance and its index;
208 Standard_Real Dist2Min = myExtPS.SquareDistance(1);
210 for (Standard_Integer i = 2; i <= myExtPS.NbExt(); i++)
212 const Standard_Real Dist2 = myExtPS.SquareDistance(i);
213 if (Dist2 < Dist2Min) {
220 //=======================================================================
223 //=======================================================================
224 void ProjectPointOnSurf::Perform(const gp_Pnt& P)
229 //=======================================================================
230 //function : LowerDistanceParameters
232 //=======================================================================
233 void ProjectPointOnSurf::LowerDistanceParameters (Standard_Real& U,
234 Standard_Real& V ) const
236 StdFail_NotDone_Raise_if(!myIsDone, "GeomInt_IntSS::ProjectPointOnSurf::LowerDistanceParameters");
237 (myExtPS.Point(myIndex)).Parameter(U,V);
239 //=======================================================================
240 //function : LowerDistance
242 //=======================================================================
243 Standard_Real ProjectPointOnSurf::LowerDistance() const
245 StdFail_NotDone_Raise_if(!myIsDone, "GeomInt_IntSS::ProjectPointOnSurf::LowerDistance");
246 return sqrt(myExtPS.SquareDistance(myIndex));
250 //=======================================================================
251 //function : MakeCurve
253 //=======================================================================
254 void GeomInt_IntSS::MakeCurve(const Standard_Integer Index,
255 const Handle(Adaptor3d_TopolTool) & dom1,
256 const Handle(Adaptor3d_TopolTool) & dom2,
257 const Standard_Real Tol,
258 const Standard_Boolean Approx,
259 const Standard_Boolean ApproxS1,
260 const Standard_Boolean ApproxS2)
263 Standard_Boolean myApprox1, myApprox2, myApprox;
264 Standard_Real Tolpc, myTolApprox;
266 Handle(Geom2d_BSplineCurve) H1;
267 Handle(Geom_Surface) aS1, aS2;
273 myTolApprox=0.0000001;
275 aS1=myHS1->ChangeSurface().Surface();
276 aS2=myHS2->ChangeSurface().Surface();
278 Handle(IntPatch_Line) L = myIntersector.Line(Index);
281 if(typl==IntPatch_Walking) {
282 Handle(IntPatch_Line) anewL =
283 ComputePurgedWLine(Handle(IntPatch_WLine)::DownCast(L));
292 myLConstruct.Perform(L);
293 if (!myLConstruct.IsDone() || myLConstruct.NbParts() <= 0) {
298 Standard_Integer i, j, aNbParts;
299 Standard_Real fprm, lprm;
300 Handle(Geom_Curve) newc;
303 //########################################
304 // Line, Parabola, Hyperbola
305 //########################################
307 case IntPatch_Parabola:
308 case IntPatch_Hyperbola: {
309 if (typl == IntPatch_Lin) {
310 newc=new Geom_Line (Handle(IntPatch_GLine)::DownCast(L)->Line());
312 else if (typl == IntPatch_Parabola) {
313 newc=new Geom_Parabola(Handle(IntPatch_GLine)::DownCast(L)->Parabola());
315 else if (typl == IntPatch_Hyperbola) {
316 newc=new Geom_Hyperbola (Handle(IntPatch_GLine)::DownCast(L)->Hyperbola());
319 aNbParts=myLConstruct.NbParts();
320 for (i=1; i<=aNbParts; i++) {
321 myLConstruct.Part(i, fprm, lprm);
323 if (!Precision::IsNegativeInfinite(fprm) &&
324 !Precision::IsPositiveInfinite(lprm)) {
325 Handle(Geom_TrimmedCurve) aCT3D=new Geom_TrimmedCurve(newc, fprm, lprm);
329 Handle (Geom2d_Curve) C2d;
330 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
331 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
332 myTolReached2d=Tolpc;
334 slineS1.Append(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
341 Handle (Geom2d_Curve) C2d;
342 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
343 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
344 myTolReached2d=Tolpc;
347 slineS2.Append(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
352 } // if (!Precision::IsNegativeInfinite(fprm) && !Precision::IsPositiveInfinite(lprm))
355 GeomAbs_SurfaceType typS1 = myHS1->Surface().GetType();
356 GeomAbs_SurfaceType typS2 = myHS2->Surface().GetType();
357 if( typS1 == GeomAbs_SurfaceOfExtrusion ||
358 typS1 == GeomAbs_OffsetSurface ||
359 typS1 == GeomAbs_SurfaceOfRevolution ||
360 typS2 == GeomAbs_SurfaceOfExtrusion ||
361 typS2 == GeomAbs_OffsetSurface ||
362 typS2 == GeomAbs_SurfaceOfRevolution) {
368 Standard_Boolean bFNIt, bLPIt;
369 Standard_Real aTestPrm, dT=100.;
370 Standard_Real u1, v1, u2, v2, TolX;
372 bFNIt=Precision::IsNegativeInfinite(fprm);
373 bLPIt=Precision::IsPositiveInfinite(lprm);
377 if (bFNIt && !bLPIt) {
380 else if (!bFNIt && bLPIt) {
384 gp_Pnt ptref(newc->Value(aTestPrm));
386 TolX = Precision::Confusion();
387 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
388 ok = (dom1->Classify(gp_Pnt2d(u1, v1), TolX) != TopAbs_OUT);
390 ok = (dom2->Classify(gp_Pnt2d(u2,v2),TolX) != TopAbs_OUT);
398 }// end of for (i=1; i<=myLConstruct.NbParts(); i++)
399 }// case IntPatch_Lin: case IntPatch_Parabola: case IntPatch_Hyperbola:
402 //########################################
403 // Circle and Ellipse
404 //########################################
405 case IntPatch_Circle:
406 case IntPatch_Ellipse: {
408 if (typl == IntPatch_Circle) {
409 newc = new Geom_Circle
410 (Handle(IntPatch_GLine)::DownCast(L)->Circle());
413 newc = new Geom_Ellipse
414 (Handle(IntPatch_GLine)::DownCast(L)->Ellipse());
417 Standard_Real aPeriod, aRealEpsilon;
419 aRealEpsilon=RealEpsilon();
422 aNbParts=myLConstruct.NbParts();
424 for (i=1; i<=aNbParts; i++) {
425 myLConstruct.Part(i, fprm, lprm);
427 if (Abs(fprm) > aRealEpsilon || Abs(lprm-aPeriod) > aRealEpsilon) {
428 //==============================================
429 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
433 fprm=aTC3D->FirstParameter();
434 lprm=aTC3D->LastParameter ();
437 Handle (Geom2d_Curve) C2d;
438 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
439 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
440 myTolReached2d=Tolpc;
449 Handle (Geom2d_Curve) C2d;
450 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
451 if(Tolpc>myTolReached2d || myTolReached2d==0) {
452 myTolReached2d=Tolpc;
459 //==============================================
460 } //if (Abs(fprm) > RealEpsilon() || Abs(lprm-2.*M_PI) > RealEpsilon())
462 else {// on regarde si on garde
465 if (Abs(fprm) < RealEpsilon() && Abs(lprm-2.*M_PI) < RealEpsilon()) {
466 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
469 fprm=aTC3D->FirstParameter();
470 lprm=aTC3D->LastParameter ();
473 Handle (Geom2d_Curve) C2d;
474 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
475 if(Tolpc>myTolReached2d || myTolReached2d==0) {
476 myTolReached2d=Tolpc;
485 Handle (Geom2d_Curve) C2d;
486 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
487 if(Tolpc>myTolReached2d || myTolReached2d==0) {
488 myTolReached2d=Tolpc;
499 Standard_Real aTwoPIdiv17, u1, v1, u2, v2, TolX;
501 aTwoPIdiv17=2.*M_PI/17.;
503 for (j=0; j<=17; j++) {
504 gp_Pnt ptref (newc->Value (j*aTwoPIdiv17));
505 TolX = Precision::Confusion();
507 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
508 ok = (dom1->Classify(gp_Pnt2d(u1,v1),TolX) != TopAbs_OUT);
510 ok = (dom2->Classify(gp_Pnt2d(u2,v2),TolX) != TopAbs_OUT);
514 //==============================================
516 Handle (Geom2d_Curve) C2d;
517 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
518 if(Tolpc>myTolReached2d || myTolReached2d==0) {
519 myTolReached2d=Tolpc;
528 Handle (Geom2d_Curve) C2d;
529 BuildPCurves(fprm, lprm, Tolpc,myHS2->ChangeSurface().Surface(), newc, C2d);
530 if(Tolpc>myTolReached2d || myTolReached2d==0) {
531 myTolReached2d=Tolpc;
540 }// end of for (Standard_Integer j=0; j<=17; j++)
541 }// end of else { on regarde si on garde
542 }// for (i=1; i<=myLConstruct.NbParts(); i++)
543 }// IntPatch_Circle: IntPatch_Ellipse
546 //########################################
548 //########################################
549 case IntPatch_Analytic: {
550 IntSurf_Quadric quad1,quad2;
552 GetQuadric(myHS1, quad1);
553 GetQuadric(myHS2, quad2);
555 IntPatch_ALineToWLine convert (quad1, quad2);
558 Handle(Geom2d_BSplineCurve) aH1, aH2;
560 aNbParts=myLConstruct.NbParts();
561 for (i=1; i<=aNbParts; i++) {
562 myLConstruct.Part(i, fprm, lprm);
563 Handle(IntPatch_WLine) WL =
564 convert.MakeWLine(Handle(IntPatch_ALine)::DownCast(L), fprm, lprm);
567 aH1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
571 aH2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
573 sline.Append(MakeBSpline(WL,1,WL->NbPnts()));
579 else { // myApprox=TRUE
580 GeomInt_WLApprox theapp3d;
581 Standard_Real tol2d = myTolApprox;
583 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True);
585 aNbParts=myLConstruct.NbParts();
586 for (i=1; i<=aNbParts; i++) {
587 myLConstruct.Part(i, fprm, lprm);
588 Handle(IntPatch_WLine) WL =
589 convert.MakeWLine(Handle(IntPatch_ALine):: DownCast(L),fprm,lprm);
591 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,myApprox1,myApprox2, 1, WL->NbPnts());
592 if (!theapp3d.IsDone()) {
594 Handle(Geom2d_BSplineCurve) aH1, aH2;
597 aH1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
601 aH2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
603 sline.Append(MakeBSpline(WL,1,WL->NbPnts()));
609 if(myApprox1 || myApprox2) {
610 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0) {
611 myTolReached2d = theapp3d.TolReached2d();
615 if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0) {
616 myTolReached3d = theapp3d.TolReached3d();
619 Standard_Integer aNbMultiCurves, nbpoles;
620 aNbMultiCurves=theapp3d.NbMultiCurves();
621 for (j=1; j<=aNbMultiCurves; j++) {
622 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
624 nbpoles = mbspc.NbPoles();
625 TColgp_Array1OfPnt tpoles(1, nbpoles);
626 mbspc.Curve(1, tpoles);
627 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
629 mbspc.Multiplicities(),
632 GeomLib_CheckBSplineCurve Check(BS, myTolCheck, myTolAngCheck);
633 Check.FixTangent(Standard_True,Standard_True);
638 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
639 mbspc.Curve(2,tpoles2d);
640 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
642 mbspc.Multiplicities(),
645 GeomLib_Check2dBSplineCurve newCheck(BS2,myTolCheck,myTolAngCheck);
646 newCheck.FixTangent(Standard_True,Standard_True);
654 TColgp_Array1OfPnt2d tpoles2d(1, nbpoles);
655 Standard_Integer TwoOrThree;
656 TwoOrThree=myApprox1 ? 3 : 2;
657 mbspc.Curve(TwoOrThree, tpoles2d);
658 Handle(Geom2d_BSplineCurve) BS2 =new Geom2d_BSplineCurve(tpoles2d,
660 mbspc.Multiplicities(),
663 GeomLib_Check2dBSplineCurve newCheck(BS2,myTolCheck,myTolAngCheck);
664 newCheck.FixTangent(Standard_True,Standard_True);
672 }// for (j=1; j<=aNbMultiCurves; j++) {
673 }// else from if (!theapp3d.IsDone())
674 }// for (i=1; i<=aNbParts; i++) {
675 }// else { // myApprox=TRUE
676 }// case IntPatch_Analytic:
679 //########################################
681 //########################################
682 case IntPatch_Walking:{
683 Handle(IntPatch_WLine) WL =
684 Handle(IntPatch_WLine)::DownCast(L);
686 Standard_Integer ifprm, ilprm;
689 aNbParts=myLConstruct.NbParts();
690 for (i=1; i<=aNbParts; i++) {
691 myLConstruct.Part(i, fprm, lprm);
692 ifprm=(Standard_Integer)fprm;
693 ilprm=(Standard_Integer)lprm;
695 Handle(Geom2d_BSplineCurve) aH1, aH2;
698 aH1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
701 aH2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
704 Handle(Geom_Curve) aBSp=MakeBSpline(WL, ifprm, ilprm);
713 Standard_Boolean bIsDecomposited;
714 Standard_Integer nbiter, aNbSeqOfL;
715 GeomInt_WLApprox theapp3d;
716 IntPatch_SequenceOfLine aSeqOfL;
717 Standard_Real tol2d, aTolSS;
722 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False);
725 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True);
729 DecompositionOfWLine(WL, myHS1, myHS2, aTolSS, myLConstruct, aSeqOfL);
731 aNbParts=myLConstruct.NbParts();
732 aNbSeqOfL=aSeqOfL.Length();
734 nbiter = (bIsDecomposited) ? aNbSeqOfL : aNbParts;
736 for(i = 1; i <= nbiter; i++) {
737 if(bIsDecomposited) {
738 WL = Handle(IntPatch_WLine)::DownCast(aSeqOfL.Value(i));
740 ilprm = WL->NbPnts();
743 myLConstruct.Part(i, fprm, lprm);
744 ifprm = (Standard_Integer)fprm;
745 ilprm = (Standard_Integer)lprm;
748 //-- Si une des surfaces est un plan , on approxime en 2d
749 //-- sur cette surface et on remonte les points 2d en 3d.
750 GeomAbs_SurfaceType typs1, typs2;
751 typs1 = myHS1->Surface().GetType();
752 typs2 = myHS2->Surface().GetType();
754 if(typs1 == GeomAbs_Plane) {
755 theapp3d.Perform(myHS1, myHS2, WL, Standard_False,
756 Standard_True, myApprox2,
759 else if(typs2 == GeomAbs_Plane) {
760 theapp3d.Perform(myHS1,myHS2,WL,Standard_False,
761 myApprox1,Standard_True,
767 if ((typs1==GeomAbs_BezierSurface || typs1==GeomAbs_BSplineSurface) &&
768 (typs2==GeomAbs_BezierSurface || typs2==GeomAbs_BSplineSurface)) {
770 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True);
771 //Standard_Boolean bUseSurfaces;
772 //bUseSurfaces=NotUseSurfacesForApprox(myFace1, myFace2, WL, ifprm, ilprm);
773 //if (bUseSurfaces) {
774 //theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False);
779 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,
784 if (!theapp3d.IsDone()) {
786 Handle(Geom2d_BSplineCurve) aH1, aH2;
788 Handle(Geom_Curve) aBSp=MakeBSpline(WL, ifprm, ilprm);
790 aH1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
793 aH2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
799 }//if (!theapp3d.IsDone())
802 if(myApprox1 || myApprox2 || (typs1==GeomAbs_Plane || typs2==GeomAbs_Plane)) {
803 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0.) {
804 myTolReached2d = theapp3d.TolReached2d();
807 if(typs1==GeomAbs_Plane || typs2==GeomAbs_Plane) {
808 myTolReached3d = myTolReached2d;
810 else if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0.) {
811 myTolReached3d = theapp3d.TolReached3d();
814 Standard_Integer aNbMultiCurves, nbpoles;
816 aNbMultiCurves=theapp3d.NbMultiCurves();
817 for (j=1; j<=aNbMultiCurves; j++) {
818 if(typs1 == GeomAbs_Plane) {
819 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
820 nbpoles = mbspc.NbPoles();
822 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
823 TColgp_Array1OfPnt tpoles(1,nbpoles);
825 mbspc.Curve(1,tpoles2d);
826 const gp_Pln& Pln = myHS1->Surface().Plane();
829 for(ik = 1; ik<= nbpoles; ik++) {
831 ElSLib::Value(tpoles2d.Value(ik).X(),
832 tpoles2d.Value(ik).Y(),
836 Handle(Geom_BSplineCurve) BS =
837 new Geom_BSplineCurve(tpoles,
839 mbspc.Multiplicities(),
841 GeomLib_CheckBSplineCurve Check(BS,myTolCheck,myTolAngCheck);
842 Check.FixTangent(Standard_True, Standard_True);
847 Handle(Geom2d_BSplineCurve) BS1 =
848 new Geom2d_BSplineCurve(tpoles2d,
850 mbspc.Multiplicities(),
852 GeomLib_Check2dBSplineCurve Check1(BS1,myTolCheck,myTolAngCheck);
853 Check1.FixTangent(Standard_True,Standard_True);
855 AdjustUPeriodic (aS1, BS1);
864 mbspc.Curve(2, tpoles2d);
866 Handle(Geom2d_BSplineCurve) BS2 = new Geom2d_BSplineCurve(tpoles2d,
868 mbspc.Multiplicities(),
870 GeomLib_Check2dBSplineCurve newCheck(BS2,myTolCheck,myTolAngCheck);
871 newCheck.FixTangent(Standard_True,Standard_True);
873 AdjustUPeriodic (aS2, BS2);
880 }//if(typs1 == GeomAbs_Plane)
882 else if(typs2 == GeomAbs_Plane) {
883 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
884 nbpoles = mbspc.NbPoles();
886 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
887 TColgp_Array1OfPnt tpoles(1,nbpoles);
888 mbspc.Curve((myApprox1==Standard_True)? 2 : 1,tpoles2d);
889 const gp_Pln& Pln = myHS2->Surface().Plane();
892 for(ik = 1; ik<= nbpoles; ik++) {
894 ElSLib::Value(tpoles2d.Value(ik).X(),
895 tpoles2d.Value(ik).Y(),
900 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
902 mbspc.Multiplicities(),
904 GeomLib_CheckBSplineCurve Check(BS,myTolCheck,myTolAngCheck);
905 Check.FixTangent(Standard_True,Standard_True);
910 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
912 mbspc.Multiplicities(),
914 GeomLib_Check2dBSplineCurve Check1(BS1,myTolCheck,myTolAngCheck);
915 Check1.FixTangent(Standard_True,Standard_True);
918 AdjustUPeriodic (aS2, BS1);
927 mbspc.Curve(1,tpoles2d);
928 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
930 mbspc.Multiplicities(),
932 GeomLib_Check2dBSplineCurve Check2(BS2,myTolCheck,myTolAngCheck);
933 Check2.FixTangent(Standard_True,Standard_True);
936 AdjustUPeriodic (aS1, BS2);
943 } // else if(typs2 == GeomAbs_Plane)
945 else { // typs1!=GeomAbs_Plane && typs2!=GeomAbs_Plane
946 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
947 nbpoles = mbspc.NbPoles();
948 TColgp_Array1OfPnt tpoles(1,nbpoles);
949 mbspc.Curve(1,tpoles);
950 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
952 mbspc.Multiplicities(),
954 GeomLib_CheckBSplineCurve Check(BS,myTolCheck,myTolAngCheck);
955 Check.FixTangent(Standard_True,Standard_True);
958 Standard_Real aDist = Max(BS->StartPoint().XYZ().SquareModulus(),
959 BS->EndPoint().XYZ().SquareModulus());
960 Standard_Real eps = Epsilon(aDist);
961 if(BS->StartPoint().SquareDistance(BS->EndPoint()) < 2.*eps)
963 // Avoid creating B-splines containing two coincident poles only
964 if (mbspc.Degree() == 1 && nbpoles == 2)
967 if (!BS->IsClosed() && !BS->IsPeriodic())
970 gp_Pnt aPm((BS->Pole(1).XYZ() + BS->Pole(BS->NbPoles()).XYZ()) / 2.);
972 BS->SetPole(BS->NbPoles(), aPm);
978 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
979 mbspc.Curve(2,tpoles2d);
980 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
982 mbspc.Multiplicities(),
984 GeomLib_Check2dBSplineCurve newCheck(BS1,myTolCheck,myTolAngCheck);
985 newCheck.FixTangent(Standard_True,Standard_True);
987 AdjustUPeriodic (aS1, BS1);
995 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
996 mbspc.Curve((myApprox1==Standard_True)? 3 : 2,tpoles2d);
997 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
999 mbspc.Multiplicities(),
1001 GeomLib_Check2dBSplineCurve newCheck(BS2,myTolCheck,myTolAngCheck);
1002 newCheck.FixTangent(Standard_True,Standard_True);
1004 AdjustUPeriodic (aS2, BS2);
1006 slineS2.Append(BS2);
1011 }// else { // typs1!=GeomAbs_Plane && typs2!=GeomAbs_Plane
1012 }// for (j=1; j<=aNbMultiCurves; j++
1019 case IntPatch_Restriction:
1021 GeomAbs_SurfaceType typS1 = myHS1->Surface().GetType();
1022 GeomAbs_SurfaceType typS2 = myHS2->Surface().GetType();
1023 Standard_Boolean isAnalS1 = Standard_False;
1027 case GeomAbs_Cylinder:
1028 case GeomAbs_Sphere:
1030 case GeomAbs_Torus: isAnalS1 = Standard_True; break;
1034 Standard_Integer isAnalS2 = Standard_False;
1038 case GeomAbs_Cylinder:
1039 case GeomAbs_Sphere:
1041 case GeomAbs_Torus: isAnalS2 = Standard_True; break;
1045 Handle(IntPatch_RLine) RL =
1046 Handle(IntPatch_RLine)::DownCast(L);
1047 Handle(Geom_Curve) aC3d;
1048 Handle(Geom2d_Curve) aC2d1, aC2d2;
1049 Standard_Real aTolReached;
1050 TreatRLine(RL, myHS1, myHS2, aC3d,
1051 aC2d1, aC2d2, aTolReached);
1056 Bnd_Box2d aBox1, aBox2;
1058 const Standard_Real aU1f = myHS1->FirstUParameter(),
1059 aV1f = myHS1->FirstVParameter(),
1060 aU1l = myHS1->LastUParameter(),
1061 aV1l = myHS1->LastVParameter();
1062 const Standard_Real aU2f = myHS2->FirstUParameter(),
1063 aV2f = myHS2->FirstVParameter(),
1064 aU2l = myHS2->LastUParameter(),
1065 aV2l = myHS2->LastVParameter();
1067 aBox1.Add(gp_Pnt2d(aU1f, aV1f));
1068 aBox1.Add(gp_Pnt2d(aU1l, aV1l));
1069 aBox2.Add(gp_Pnt2d(aU2f, aV2f));
1070 aBox2.Add(gp_Pnt2d(aU2l, aV2l));
1072 GeomInt_VectorOfReal anArrayOfParameters;
1074 //We consider here that the intersection line is same-parameter-line
1075 anArrayOfParameters.Append(aC3d->FirstParameter());
1076 anArrayOfParameters.Append(aC3d->LastParameter());
1078 TrimILineOnSurfBoundaries(aC2d1, aC2d2, aBox1, aBox2, anArrayOfParameters);
1080 const Standard_Integer aNbIntersSolutionsm1 = anArrayOfParameters.Length() - 1;
1083 for(Standard_Integer anInd = 0; anInd < aNbIntersSolutionsm1; anInd++)
1085 const Standard_Real aParF = anArrayOfParameters(anInd),
1086 aParL = anArrayOfParameters(anInd+1);
1088 if((aParL - aParF) <= Precision::PConfusion())
1091 const Standard_Real aPar = 0.5*(aParF + aParL);
1094 Handle(Geom2d_Curve) aCurv2d1, aCurv2d2;
1097 aC2d1->D0(aPar, aPt);
1099 if(aBox1.IsOut(aPt))
1103 aCurv2d1 = new Geom2d_TrimmedCurve(aC2d1, aParF, aParL);
1108 aC2d2->D0(aPar, aPt);
1110 if(aBox2.IsOut(aPt))
1114 aCurv2d2 = new Geom2d_TrimmedCurve(aC2d2, aParF, aParL);
1117 Handle(Geom_Curve) aCurv3d = new Geom_TrimmedCurve(aC3d, aParF, aParL);
1119 sline.Append(aCurv3d);
1120 slineS1.Append(aCurv2d1);
1121 slineS2.Append(aCurv2d2);
1128 //=======================================================================
1129 //function : AdjustUPeriodic
1131 //=======================================================================
1132 void AdjustUPeriodic (const Handle(Geom_Surface)& aS, Handle(Geom2d_Curve)& aC2D)
1134 if (aC2D.IsNull() || !aS->IsUPeriodic())
1137 const Standard_Real aEps=Precision::PConfusion();//1.e-9
1138 const Standard_Real aEpsilon=Epsilon(10.);//1.77e-15
1140 Standard_Real umin,umax,vmin,vmax;
1141 aS->Bounds(umin,umax,vmin,vmax);
1142 const Standard_Real aPeriod = aS->UPeriod();
1144 const Standard_Real aT1=aC2D->FirstParameter();
1145 const Standard_Real aT2=aC2D->LastParameter();
1146 const Standard_Real aTx=aT1+0.467*(aT2-aT1);
1147 const gp_Pnt2d aPx=aC2D->Value(aTx);
1149 Standard_Real aUx=aPx.X();
1150 if (fabs(aUx)<aEpsilon)
1152 if (fabs(aUx-aPeriod)<aEpsilon)
1155 Standard_Real dU=0.;
1156 while(aUx <(umin-aEps)) {
1160 while(aUx>(umax+aEps)) {
1166 gp_Vec2d aV2D(dU, 0.);
1167 aC2D->Translate(aV2D);
1172 //=======================================================================
1173 //function : GetQuadric
1175 //=======================================================================
1176 void GetQuadric(const Handle(GeomAdaptor_HSurface)& HS1, IntSurf_Quadric& quad1)
1178 switch (HS1->Surface().GetType())
1180 case GeomAbs_Plane: quad1.SetValue(HS1->Surface().Plane()); break;
1181 case GeomAbs_Cylinder: quad1.SetValue(HS1->Surface().Cylinder()); break;
1182 case GeomAbs_Cone: quad1.SetValue(HS1->Surface().Cone()); break;
1183 case GeomAbs_Sphere: quad1.SetValue(HS1->Surface().Sphere()); break;
1184 case GeomAbs_Torus: quad1.SetValue(HS1->Surface().Torus()); break;
1185 default: Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
1189 //=======================================================================
1190 //function : Parameters
1192 //=======================================================================
1193 void Parameters(const Handle(GeomAdaptor_HSurface)& HS1,
1194 const Handle(GeomAdaptor_HSurface)& HS2,
1195 const gp_Pnt& Ptref,
1201 IntSurf_Quadric quad1,quad2;
1203 GetQuadric(HS1, quad1);
1204 GetQuadric(HS2, quad2);
1206 quad1.Parameters(Ptref,U1,V1);
1207 quad2.Parameters(Ptref,U2,V2);
1210 //=======================================================================
1211 //function : MakeBSpline
1213 //=======================================================================
1214 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)& WL,
1215 const Standard_Integer ideb,
1216 const Standard_Integer ifin)
1218 const Standard_Integer nbpnt = ifin-ideb+1;
1219 TColgp_Array1OfPnt poles(1,nbpnt);
1220 TColStd_Array1OfReal knots(1,nbpnt);
1221 TColStd_Array1OfInteger mults(1,nbpnt);
1222 Standard_Integer i = 1, ipidebm1 = ideb;
1223 for(; i<=nbpnt; ipidebm1++, i++)
1225 poles(i) = WL->Point(ipidebm1).Value();
1229 mults(1) = mults(nbpnt) = 2;
1230 return new Geom_BSplineCurve(poles,knots,mults,1);
1233 //=======================================================================
1234 //function : MakeBSpline2d
1236 //=======================================================================
1237 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
1238 const Standard_Integer ideb,
1239 const Standard_Integer ifin,
1240 const Standard_Boolean onFirst)
1242 const Standard_Integer nbpnt = ifin-ideb+1;
1243 TColgp_Array1OfPnt2d poles(1,nbpnt);
1244 TColStd_Array1OfReal knots(1,nbpnt);
1245 TColStd_Array1OfInteger mults(1,nbpnt);
1246 Standard_Integer i = 1, ipidebm1 = ideb;
1247 for(; i <= nbpnt; ipidebm1++, i++)
1251 theWLine->Point(ipidebm1).ParametersOnS1(U, V);
1253 theWLine->Point(ipidebm1).ParametersOnS2(U, V);
1254 poles(i).SetCoord(U, V);
1258 mults(1) = mults(nbpnt) = 2;
1259 return new Geom2d_BSplineCurve(poles,knots,mults,1);
1262 //=========================================================================
1263 // static function : ComputePurgedWLine
1264 // purpose : Removes equal points (leave one of equal points) from theWLine
1265 // and recompute vertex parameters.
1266 // Returns new WLine or null WLine if the number
1267 // of the points is less than 2.
1268 //=========================================================================
1269 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine)
1271 Handle(IntPatch_WLine) aResult;
1272 Handle(IntPatch_WLine) aLocalWLine;
1273 Handle(IntPatch_WLine) aTmpWLine = theWLine;
1275 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
1276 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
1277 Standard_Integer i, k, v, nb, nbvtx;
1278 nbvtx = theWLine->NbVertex();
1279 nb = theWLine->NbPnts();
1281 for(i = 1; i <= nb; i++) {
1282 aLineOn2S->Add(theWLine->Point(i));
1285 for(v = 1; v <= nbvtx; v++) {
1286 aLocalWLine->AddVertex(theWLine->Vertex(v));
1289 for(i = 1; i <= aLineOn2S->NbPoints(); i++) {
1290 Standard_Integer aStartIndex = i + 1;
1291 Standard_Integer anEndIndex = i + 5;
1292 nb = aLineOn2S->NbPoints();
1293 anEndIndex = (anEndIndex > nb) ? nb : anEndIndex;
1295 if((aStartIndex >= nb) || (anEndIndex <= 1)) {
1300 while(k <= anEndIndex) {
1303 IntSurf_PntOn2S p1 = aLineOn2S->Value(i);
1304 IntSurf_PntOn2S p2 = aLineOn2S->Value(k);
1306 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
1307 aTmpWLine = aLocalWLine;
1308 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
1310 for(v = 1; v <= aTmpWLine->NbVertex(); v++) {
1311 IntPatch_Point aVertex = aTmpWLine->Vertex(v);
1312 Standard_Integer avertexindex = (Standard_Integer)aVertex.ParameterOnLine();
1314 if(avertexindex >= k) {
1315 aVertex.SetParameter(aVertex.ParameterOnLine() - 1.);
1317 aLocalWLine->AddVertex(aVertex);
1319 aLineOn2S->RemovePoint(k);
1328 if(aLineOn2S->NbPoints() > 1) {
1329 aResult = aLocalWLine;
1333 //=======================================================================
1334 //function : DecompositionOfWLine
1336 //=======================================================================
1337 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
1338 const Handle(GeomAdaptor_HSurface)& theSurface1,
1339 const Handle(GeomAdaptor_HSurface)& theSurface2,
1340 const Standard_Real aTolSum,
1341 const GeomInt_LineConstructor& theLConstructor,
1342 IntPatch_SequenceOfLine& theNewLines)
1344 typedef NCollection_List<Standard_Integer> ListOfInteger;
1345 //have to use std::vector, not NCollection_Vector in order to use copy constructor of
1346 //ListOfInteger which will be created with specific allocator instance
1347 typedef std::vector<ListOfInteger, NCollection_StdAllocator<
1348 ListOfInteger> > ArrayOfListOfInteger;
1350 Standard_Boolean bIsPrevPointOnBoundary, bIsCurrentPointOnBoundary;
1351 Standard_Integer nblines, aNbPnts, aNbParts, pit, i, j, aNbListOfPointIndex;
1352 Standard_Real aTol, umin, umax, vmin, vmax;
1354 //an inc allocator, it will contain wasted space (upon list's Clear()) but it should
1355 //still be faster than the standard allocator, and wasted memory should not be
1356 //significant and will be limited by time span of this function;
1357 //this is a separate allocator from the anIncAlloc below what provides better data
1358 //locality in the latter (by avoiding wastes which will only be in anIdxAlloc)
1359 Handle(NCollection_IncAllocator) anIdxAlloc = new NCollection_IncAllocator();
1360 ListOfInteger aListOfPointIndex (anIdxAlloc);
1362 //GeomAPI_ProjectPointOnSurf aPrj1, aPrj2;
1363 ProjectPointOnSurf aPrj1, aPrj2;
1364 Handle(Geom_Surface) aSurf1, aSurf2;
1366 aNbParts=theLConstructor.NbParts();
1367 aNbPnts=theWLine->NbPnts();
1369 if((!aNbPnts) || (!aNbParts)){
1370 return Standard_False;
1373 Handle(NCollection_IncAllocator) anIncAlloc = new NCollection_IncAllocator();
1374 NCollection_StdAllocator<ListOfInteger> anAlloc (anIncAlloc);
1375 const ListOfInteger aDummy (anIncAlloc); //empty list to be copy constructed from
1376 ArrayOfListOfInteger anArrayOfLines (aNbPnts + 1, aDummy, anAlloc);
1378 NCollection_LocalArray<Standard_Integer> anArrayOfLineTypeArr (aNbPnts + 1);
1379 Standard_Integer* anArrayOfLineType = anArrayOfLineTypeArr;
1382 aTol = Precision::Confusion();
1384 aSurf1 = theSurface1->ChangeSurface().Surface();
1385 aSurf1->Bounds(umin, umax, vmin, vmax);
1386 aPrj1.Init(aSurf1, umin, umax, vmin, vmax);
1388 aSurf2 = theSurface2->ChangeSurface().Surface();
1389 aSurf2->Bounds(umin, umax, vmin, vmax);
1390 aPrj2.Init(aSurf2, umin, umax, vmin, vmax);
1393 bIsPrevPointOnBoundary=Standard_False;
1394 for(pit=1; pit<=aNbPnts; pit++) {
1395 const IntSurf_PntOn2S& aPoint = theWLine->Point(pit);
1396 bIsCurrentPointOnBoundary=Standard_False;
1398 // whether aPoint is on boundary or not
1400 for(i=0; i<2; i++) {// exploration Surface 1,2
1401 Handle(GeomAdaptor_HSurface) aGASurface = (!i) ? theSurface1 : theSurface2;
1402 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
1404 for(j=0; j<2; j++) {// exploration of coordinate U,V
1405 Standard_Boolean isperiodic;
1407 isperiodic = (!j) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
1412 Standard_Real aResolution, aPeriod, alowerboundary, aupperboundary, U, V;
1413 Standard_Real aParameter, anoffset, anAdjustPar;
1414 Standard_Boolean bIsOnFirstBoundary, bIsPointOnBoundary;
1416 aResolution = (!j) ? aGASurface->UResolution(aTol) : aGASurface->VResolution(aTol);
1417 aPeriod = (!j) ? aGASurface->UPeriod() : aGASurface->VPeriod();
1418 alowerboundary = (!j) ? umin : vmin;
1419 aupperboundary = (!j) ? umax : vmax;
1423 aPoint.ParametersOnS1(U, V);
1426 aPoint.ParametersOnS2(U, V);
1429 aParameter = (!j) ? U : V;
1431 anAdjustPar=AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
1433 bIsOnFirstBoundary=Standard_True;
1436 IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
1438 if(bIsPointOnBoundary) {
1439 bIsCurrentPointOnBoundary = Standard_True;
1442 }// for(j=0; j<2; j++)
1444 if(bIsCurrentPointOnBoundary){
1447 }// for(i=0; i<2; i++)
1449 if((bIsCurrentPointOnBoundary != bIsPrevPointOnBoundary)) {
1451 if(!aListOfPointIndex.IsEmpty()) {
1453 anArrayOfLines[nblines] = aListOfPointIndex;
1454 anArrayOfLineType[nblines] = bIsPrevPointOnBoundary;
1455 aListOfPointIndex.Clear();
1457 bIsPrevPointOnBoundary = bIsCurrentPointOnBoundary;
1459 aListOfPointIndex.Append(pit);
1460 } // for(pit=1; pit<=aNbPnts; pit++)
1462 aNbListOfPointIndex=aListOfPointIndex.Extent();
1463 if(aNbListOfPointIndex) {
1465 anArrayOfLines[nblines].Assign (aListOfPointIndex);
1466 anArrayOfLineType[nblines] = bIsPrevPointOnBoundary;
1467 aListOfPointIndex.Clear();
1471 return Standard_False;
1474 // Correct wlines.begin
1475 Standard_Integer aLineType;
1476 TColStd_Array1OfListOfInteger anArrayOfLineEnds(1, nblines);
1477 Handle(IntSurf_LineOn2S) aSeqOfPntOn2S = new IntSurf_LineOn2S (new NCollection_IncAllocator());
1479 for(i = 1; i <= nblines; i++) {
1480 aLineType=anArrayOfLineType[i];
1485 const ListOfInteger& aListOfIndex = anArrayOfLines[i];
1486 if(aListOfIndex.Extent() < 2) {
1490 TColStd_ListOfInteger aListOfFLIndex;
1491 Standard_Integer aneighbourindex, aLineTypeNeib;
1493 for(j = 0; j < 2; j++) {// neighbour line choice
1494 aneighbourindex = (!j) ? (i-1) : (i+1);
1495 if((aneighbourindex < 1) || (aneighbourindex > nblines)){
1499 aLineTypeNeib=anArrayOfLineType[aneighbourindex];
1504 const ListOfInteger& aNeighbour = anArrayOfLines[aneighbourindex];
1505 Standard_Integer anIndex = (!j) ? aNeighbour.Last() : aNeighbour.First();
1506 const IntSurf_PntOn2S& aPoint = theWLine->Point(anIndex);
1507 // check if need use derivative.begin .end [absence]
1509 IntSurf_PntOn2S aNewP = aPoint;
1510 Standard_Integer surfit, parit;
1512 for(surfit = 0; surfit < 2; ++surfit) {
1514 Handle(GeomAdaptor_HSurface) aGASurface = (!surfit) ? theSurface1 : theSurface2;
1516 umin = aGASurface->FirstUParameter();
1517 umax = aGASurface->LastUParameter();
1518 vmin = aGASurface->FirstVParameter();
1519 vmax = aGASurface->LastVParameter();
1520 Standard_Real U=0., V=0.;
1523 aNewP.ParametersOnS1(U, V);
1526 aNewP.ParametersOnS2(U, V);
1529 Standard_Integer nbboundaries = 0;
1530 Standard_Integer bIsUBoundary = Standard_False; // use if nbboundaries == 1
1531 Standard_Integer bIsFirstBoundary = Standard_False; // use if nbboundaries == 1
1533 for(parit = 0; parit < 2; parit++) {
1534 Standard_Boolean isperiodic = (!parit) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
1536 Standard_Real aResolution = (!parit) ? aGASurface->UResolution(aTol) : aGASurface->VResolution(aTol);
1537 Standard_Real alowerboundary = (!parit) ? umin : vmin;
1538 Standard_Real aupperboundary = (!parit) ? umax : vmax;
1540 Standard_Real aParameter = (!parit) ? U : V;
1541 Standard_Boolean bIsOnFirstBoundary = Standard_True;
1544 if(IsPointOnBoundary(aParameter, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary)) {
1545 bIsUBoundary = (!parit);
1546 bIsFirstBoundary = bIsOnFirstBoundary;
1551 Standard_Real aPeriod = (!parit) ? aGASurface->UPeriod() : aGASurface->VPeriod();
1552 Standard_Real anoffset = 0.;
1553 Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
1555 if(IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary)) {
1556 bIsUBoundary = (parit == 0);
1557 bIsFirstBoundary = bIsOnFirstBoundary;
1563 Standard_Boolean bComputeLineEnd = Standard_False;
1565 if(nbboundaries == 2) {
1566 bComputeLineEnd = Standard_True;
1568 else if(nbboundaries == 1) {
1569 Standard_Boolean isperiodic = (bIsUBoundary) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
1572 Standard_Real alowerboundary = (bIsUBoundary) ? umin : vmin;
1573 Standard_Real aupperboundary = (bIsUBoundary) ? umax : vmax;
1574 Standard_Real aPeriod = (bIsUBoundary) ? aGASurface->UPeriod() : aGASurface->VPeriod();
1575 Standard_Real aParameter = (bIsUBoundary) ? U : V;
1576 Standard_Real anoffset = 0.;
1577 Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
1579 Standard_Real adist = (bIsFirstBoundary) ? fabs(anAdjustPar - alowerboundary) : fabs(anAdjustPar - aupperboundary);
1580 Standard_Real anotherPar = (bIsFirstBoundary) ? (aupperboundary - adist) : (alowerboundary + adist);
1581 anotherPar += anoffset;
1582 Standard_Integer aneighbourpointindex = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
1583 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex);
1584 Standard_Real nU1, nV1;
1587 aNeighbourPoint.ParametersOnS1(nU1, nV1);
1589 aNeighbourPoint.ParametersOnS2(nU1, nV1);
1591 Standard_Real adist1 = (bIsUBoundary) ? fabs(nU1 - U) : fabs(nV1 - V);
1592 Standard_Real adist2 = (bIsUBoundary) ? fabs(nU1 - anotherPar) : fabs(nV1 - anotherPar);
1593 bComputeLineEnd = Standard_True;
1594 Standard_Boolean bCheckAngle1 = Standard_False;
1595 Standard_Boolean bCheckAngle2 = Standard_False;
1597 Standard_Real anewU = (bIsUBoundary) ? anotherPar : U;
1598 Standard_Real anewV = (bIsUBoundary) ? V : anotherPar;
1600 if(((adist1 - adist2) > Precision::PConfusion()) &&
1601 (adist2 < (aPeriod / 4.))) {
1602 bCheckAngle1 = Standard_True;
1603 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(anewU, anewV));
1605 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
1606 aNewP.SetValue((surfit == 0), anewU, anewV);
1607 bCheckAngle1 = Standard_False;
1610 else if(adist1 < (aPeriod / 4.)) {
1611 bCheckAngle2 = Standard_True;
1612 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(U, V));
1614 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
1615 bCheckAngle2 = Standard_False;
1619 if(bCheckAngle1 || bCheckAngle2) {
1620 // assume there are at least two points in line (see "if" above)
1621 Standard_Integer anindexother = aneighbourpointindex;
1623 while((anindexother <= aListOfIndex.Last()) && (anindexother >= aListOfIndex.First())) {
1624 anindexother = (j == 0) ? (anindexother + 1) : (anindexother - 1);
1625 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(anindexother);
1626 Standard_Real nU2, nV2;
1629 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
1631 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
1632 gp_Vec2d aVecOld(gp_Pnt2d(nU2, nV2), gp_Pnt2d(nU1, nV1));
1634 if(aVecOld.SquareMagnitude() <= (gp::Resolution() * gp::Resolution())) {
1638 Standard_Real anAngle = aNewVec.Angle(aVecOld);
1640 if((fabs(anAngle) < (M_PI * 0.25)) && (aNewVec.Dot(aVecOld) > 0.)) {
1643 Standard_Real U1, U2, V1, V2;
1644 IntSurf_PntOn2S atmppoint = aNewP;
1645 atmppoint.SetValue((surfit == 0), anewU, anewV);
1646 atmppoint.Parameters(U1, V1, U2, V2);
1647 gp_Pnt P1 = theSurface1->Value(U1, V1);
1648 gp_Pnt P2 = theSurface2->Value(U2, V2);
1649 gp_Pnt P0 = aPoint.Value();
1651 if(P0.IsEqual(P1, aTol) &&
1652 P0.IsEqual(P2, aTol) &&
1653 P1.IsEqual(P2, aTol)) {
1654 bComputeLineEnd = Standard_False;
1655 aNewP.SetValue((surfit == 0), anewU, anewV);
1660 bComputeLineEnd = Standard_False;
1665 } // end while(anindexother...)
1670 if(bComputeLineEnd) {
1671 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
1672 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
1673 Standard_Real nU1, nV1;
1676 aNeighbourPoint.ParametersOnS1(nU1, nV1);
1678 aNeighbourPoint.ParametersOnS2(nU1, nV1);
1679 gp_Pnt2d ap1(nU1, nV1);
1680 gp_Pnt2d ap2(nU1, nV1);
1681 Standard_Integer aneighbourpointindex2 = aneighbourpointindex1;
1683 while((aneighbourpointindex2 <= aListOfIndex.Last()) && (aneighbourpointindex2 >= aListOfIndex.First())) {
1684 aneighbourpointindex2 = (j == 0) ? (aneighbourpointindex2 + 1) : (aneighbourpointindex2 - 1);
1685 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(aneighbourpointindex2);
1686 Standard_Real nU2, nV2;
1689 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
1691 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
1695 if(ap1.SquareDistance(ap2) > (gp::Resolution() * gp::Resolution())) {
1700 Standard_Boolean found = FindPoint(ap2, ap1, umin, umax, vmin, vmax, anewpoint);
1704 Standard_Real aCriteria =aTolSum;// BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
1705 //GeomAPI_ProjectPointOnSurf& aProjector = (surfit == 0) ? aPrj2 : aPrj1;
1706 ProjectPointOnSurf& aProjector = (surfit == 0) ? aPrj2 : aPrj1;
1707 Handle(GeomAdaptor_HSurface) aSurface = (surfit == 0) ? theSurface1 : theSurface2;
1709 gp_Pnt aP3d = aSurface->Value(anewpoint.X(), anewpoint.Y());
1710 aProjector.Perform(aP3d);
1712 if(aProjector.IsDone()) {
1713 if(aProjector.LowerDistance() < aCriteria) {
1714 Standard_Real foundU = U, foundV = V;
1715 aProjector.LowerDistanceParameters(foundU, foundV);
1718 aNewP.SetValue(aP3d, anewpoint.X(), anewpoint.Y(), foundU, foundV);
1720 aNewP.SetValue(aP3d, foundU, foundV, anewpoint.X(), anewpoint.Y());
1726 aSeqOfPntOn2S->Add(aNewP);
1727 aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
1729 anArrayOfLineEnds.SetValue(i, aListOfFLIndex);
1731 // Correct wlines.end
1733 // Split wlines.begin
1734 for(j = 1; j <= theLConstructor.NbParts(); j++) {
1735 Standard_Real fprm = 0., lprm = 0.;
1736 theLConstructor.Part(j, fprm, lprm);
1737 Standard_Integer ifprm = (Standard_Integer)fprm;
1738 Standard_Integer ilprm = (Standard_Integer)lprm;
1740 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
1742 for(i = 1; i <= nblines; i++) {
1743 if(anArrayOfLineType[i] != 0) {
1746 const ListOfInteger& aListOfIndex = anArrayOfLines[i];
1748 if(aListOfIndex.Extent() < 2) {
1751 const TColStd_ListOfInteger& aListOfFLIndex = anArrayOfLineEnds.Value(i);
1752 Standard_Boolean bhasfirstpoint = (aListOfFLIndex.Extent() == 2);
1753 Standard_Boolean bhaslastpoint = (aListOfFLIndex.Extent() == 2);
1755 if(!bhasfirstpoint && !aListOfFLIndex.IsEmpty()) {
1756 bhasfirstpoint = (i != 1);
1759 if(!bhaslastpoint && !aListOfFLIndex.IsEmpty()) {
1760 bhaslastpoint = (i != nblines);
1762 Standard_Boolean bIsFirstInside = ((ifprm >= aListOfIndex.First()) && (ifprm <= aListOfIndex.Last()));
1763 Standard_Boolean bIsLastInside = ((ilprm >= aListOfIndex.First()) && (ilprm <= aListOfIndex.Last()));
1765 if(!bIsFirstInside && !bIsLastInside) {
1766 if((ifprm < aListOfIndex.First()) && (ilprm > aListOfIndex.Last())) {
1767 // append whole line, and boundaries if neccesary
1768 if(bhasfirstpoint) {
1769 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
1772 ListOfInteger::Iterator anIt(aListOfIndex);
1774 for(; anIt.More(); anIt.Next()) {
1775 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
1780 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
1784 // check end of split line (end is almost always)
1785 Standard_Integer aneighbour = i + 1;
1786 Standard_Boolean bIsEndOfLine = Standard_True;
1788 if(aneighbour <= nblines) {
1789 const ListOfInteger& aListOfNeighbourIndex = anArrayOfLines[aneighbour];
1791 if((anArrayOfLineType[aneighbour] != 0) &&
1792 (aListOfNeighbourIndex.IsEmpty())) {
1793 bIsEndOfLine = Standard_False;
1798 if(aLineOn2S->NbPoints() > 1) {
1799 Handle(IntPatch_WLine) aNewWLine =
1800 new IntPatch_WLine(aLineOn2S, Standard_False);
1801 theNewLines.Append(aNewWLine);
1803 aLineOn2S = new IntSurf_LineOn2S();
1808 // end if(!bIsFirstInside && !bIsLastInside)
1810 if(bIsFirstInside && bIsLastInside) {
1811 // append inside points between ifprm and ilprm
1812 ListOfInteger::Iterator anIt(aListOfIndex);
1814 for(; anIt.More(); anIt.Next()) {
1815 if((anIt.Value() < ifprm) || (anIt.Value() > ilprm))
1817 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
1823 if(bIsFirstInside) {
1824 // append points from ifprm to last point + boundary point
1825 ListOfInteger::Iterator anIt(aListOfIndex);
1827 for(; anIt.More(); anIt.Next()) {
1828 if(anIt.Value() < ifprm)
1830 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
1835 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
1838 // check end of split line (end is almost always)
1839 Standard_Integer aneighbour = i + 1;
1840 Standard_Boolean bIsEndOfLine = Standard_True;
1842 if(aneighbour <= nblines) {
1843 const ListOfInteger& aListOfNeighbourIndex = anArrayOfLines[aneighbour];
1845 if((anArrayOfLineType[aneighbour] != 0) &&
1846 (aListOfNeighbourIndex.IsEmpty())) {
1847 bIsEndOfLine = Standard_False;
1852 if(aLineOn2S->NbPoints() > 1) {
1853 Handle(IntPatch_WLine) aNewWLine =
1854 new IntPatch_WLine(aLineOn2S, Standard_False);
1855 theNewLines.Append(aNewWLine);
1857 aLineOn2S = new IntSurf_LineOn2S();
1860 // end if(bIsFirstInside)
1863 // append points from first boundary point to ilprm
1864 if(bhasfirstpoint) {
1865 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
1868 ListOfInteger::Iterator anIt(aListOfIndex);
1870 for(; anIt.More(); anIt.Next()) {
1871 if(anIt.Value() > ilprm)
1873 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
1877 //end if(bIsLastInside)
1881 if(aLineOn2S->NbPoints() > 1) {
1882 Handle(IntPatch_WLine) aNewWLine =
1883 new IntPatch_WLine(aLineOn2S, Standard_False);
1884 theNewLines.Append(aNewWLine);
1890 Standard_Real fprm, lprm;
1891 Standard_Integer ifprm, ilprm, aNbPoints, aIndex;
1893 aNbParts=theLConstructor.NbParts();
1895 for(j = 1; j <= aNbParts; j++) {
1896 theLConstructor.Part(j, fprm, lprm);
1897 ifprm=(Standard_Integer)fprm;
1898 ilprm=(Standard_Integer)lprm;
1900 if ((ilprm-ifprm)==1) {
1901 for(i = 1; i <= nblines; i++) {
1902 aLineType=anArrayOfLineType[i];
1907 const ListOfInteger& aListOfIndex = anArrayOfLines[i];
1908 aNbPoints=aListOfIndex.Extent();
1910 aIndex=aListOfIndex.First();
1911 if (aIndex==ifprm || aIndex==ilprm) {
1912 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
1913 const IntSurf_PntOn2S& aP1 = theWLine->Point(ifprm);
1914 const IntSurf_PntOn2S& aP2 = theWLine->Point(ilprm);
1915 aLineOn2S->Add(aP1);
1916 aLineOn2S->Add(aP2);
1917 Handle(IntPatch_WLine) aNewWLine =
1918 new IntPatch_WLine(aLineOn2S, Standard_False);
1919 theNewLines.Append(aNewWLine);
1926 return Standard_True;
1929 //=======================================================================
1930 //function : AdjustPeriodic
1932 //=======================================================================
1933 Standard_Real AdjustPeriodic(const Standard_Real theParameter,
1934 const Standard_Real parmin,
1935 const Standard_Real parmax,
1936 const Standard_Real thePeriod,
1937 Standard_Real& theOffset)
1939 Standard_Real aresult = theParameter;
1941 while(aresult < parmin) {
1942 aresult += thePeriod;
1943 theOffset += thePeriod;
1945 while(aresult > parmax) {
1946 aresult -= thePeriod;
1947 theOffset -= thePeriod;
1952 //=======================================================================
1953 //function : IsPointOnBoundary
1955 //=======================================================================
1956 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
1957 const Standard_Real theFirstBoundary,
1958 const Standard_Real theSecondBoundary,
1959 const Standard_Real theResolution,
1960 Standard_Boolean& IsOnFirstBoundary)
1962 IsOnFirstBoundary = Standard_True;
1963 if(fabs(theParameter - theFirstBoundary) < theResolution)
1964 return Standard_True;
1965 if(fabs(theParameter - theSecondBoundary) < theResolution)
1967 IsOnFirstBoundary = Standard_False;
1968 return Standard_True;
1970 return Standard_False;
1972 //=======================================================================
1973 //function : FindPoint
1975 //=======================================================================
1976 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
1977 const gp_Pnt2d& theLastPoint,
1978 const Standard_Real theUmin,
1979 const Standard_Real theUmax,
1980 const Standard_Real theVmin,
1981 const Standard_Real theVmax,
1982 gp_Pnt2d& theNewPoint)
1984 gp_Vec2d aVec(theFirstPoint, theLastPoint);
1985 Standard_Integer i = 0, j = 0;
1987 for(i = 0; i < 4; i++) {
1988 gp_Vec2d anOtherVec;
1989 gp_Vec2d anOtherVecNormal;
1990 gp_Pnt2d aprojpoint = theLastPoint;
1993 anOtherVec.SetX(0.);
1994 anOtherVec.SetY(1.);
1995 anOtherVecNormal.SetX(1.);
1996 anOtherVecNormal.SetY(0.);
1999 aprojpoint.SetX(theUmin);
2001 aprojpoint.SetX(theUmax);
2004 anOtherVec.SetX(1.);
2005 anOtherVec.SetY(0.);
2006 anOtherVecNormal.SetX(0.);
2007 anOtherVecNormal.SetY(1.);
2010 aprojpoint.SetY(theVmin);
2012 aprojpoint.SetY(theVmax);
2014 gp_Vec2d anormvec = aVec;
2015 anormvec.Normalize();
2016 Standard_Real adot1 = anormvec.Dot(anOtherVecNormal);
2018 if(fabs(adot1) < Precision::Angular())
2020 Standard_Real adist = 0.;
2023 adist = (i < 2) ? fabs(theLastPoint.X() - theUmin) : fabs(theLastPoint.X() - theUmax);
2026 adist = (i < 2) ? fabs(theLastPoint.Y() - theVmin) : fabs(theLastPoint.Y() - theVmax);
2028 Standard_Real anoffset = adist * anOtherVec.Dot(anormvec) / adot1;
2030 for(j = 0; j < 2; j++) {
2031 anoffset = (j == 0) ? anoffset : -anoffset;
2032 gp_Pnt2d acurpoint(aprojpoint.XY() + (anOtherVec.XY()*anoffset));
2033 gp_Vec2d acurvec(theLastPoint, acurpoint);
2036 Standard_Real aDotX, anAngleX, aPC;
2038 aDotX=aVec.Dot(acurvec);
2039 anAngleX=aVec.Angle(acurvec);
2040 aPC=Precision::PConfusion();
2042 if(aDotX > 0. && fabs(anAngleX) < aPC) {
2045 if((acurpoint.Y() >= theVmin) &&
2046 (acurpoint.Y() <= theVmax)) {
2047 theNewPoint = acurpoint;
2048 return Standard_True;
2052 if((acurpoint.X() >= theUmin) &&
2053 (acurpoint.X() <= theUmax)) {
2054 theNewPoint = acurpoint;
2055 return Standard_True;
2061 return Standard_False;
2064 //=======================================================================
2065 //function : ParametersOfNearestPointOnSurface
2067 //=======================================================================
2068 static Standard_Boolean ParametersOfNearestPointOnSurface(const Extrema_ExtPS theExtr,
2069 Standard_Real& theU,
2070 Standard_Real& theV)
2072 if(!theExtr.IsDone() || !theExtr.NbExt())
2073 return Standard_False;
2075 Standard_Integer anIndex = 1;
2076 Standard_Real aMinSQDist = theExtr.SquareDistance(anIndex);
2077 for(Standard_Integer i = 2; i <= theExtr.NbExt(); i++)
2079 Standard_Real aSQD = theExtr.SquareDistance(i);
2080 if (aSQD < aMinSQDist)
2087 theExtr.Point(anIndex).Parameter(theU, theV);
2089 return Standard_True;
2092 //=======================================================================
2093 //function : GetSegmentBoundary
2095 //=======================================================================
2096 static void GetSegmentBoundary( const IntRes2d_IntersectionSegment& theSegm,
2097 const Handle(Geom2d_Curve)& theCurve,
2098 GeomInt_VectorOfReal& theArrayOfParameters)
2100 Standard_Real aU1 = theCurve->FirstParameter(), aU2 = theCurve->LastParameter();
2102 if(theSegm.HasFirstPoint())
2104 const IntRes2d_IntersectionPoint& anIPF = theSegm.FirstPoint();
2105 aU1 = anIPF.ParamOnFirst();
2108 if(theSegm.HasLastPoint())
2110 const IntRes2d_IntersectionPoint& anIPL = theSegm.LastPoint();
2111 aU2 = anIPL.ParamOnFirst();
2114 theArrayOfParameters.Append(aU1);
2115 theArrayOfParameters.Append(aU2);
2118 //=======================================================================
2119 //function : IntersectCurveAndBoundary
2121 //=======================================================================
2122 static void IntersectCurveAndBoundary(const Handle(Geom2d_Curve)& theC2d,
2123 const Handle(Geom2d_Curve)* const theArrBounds,
2124 const Standard_Integer theNumberOfCurves,
2125 const Standard_Real theTol,
2126 GeomInt_VectorOfReal& theArrayOfParameters)
2131 Geom2dAdaptor_Curve anAC1(theC2d);
2132 for(Standard_Integer aCurID = 0; aCurID < theNumberOfCurves; aCurID++)
2134 if(theArrBounds[aCurID].IsNull())
2137 Geom2dAdaptor_Curve anAC2(theArrBounds[aCurID]);
2138 Geom2dInt_GInter anIntCC2d(anAC1, anAC2, theTol, theTol);
2140 if(!anIntCC2d.IsDone() || anIntCC2d.IsEmpty())
2143 for (Standard_Integer aPntID = 1; aPntID <= anIntCC2d.NbPoints(); aPntID++)
2145 const Standard_Real aParam = anIntCC2d.Point(aPntID).ParamOnFirst();
2146 theArrayOfParameters.Append(aParam);
2149 for (Standard_Integer aSegmID = 1; aSegmID <= anIntCC2d.NbSegments(); aSegmID++)
2151 GetSegmentBoundary(anIntCC2d.Segment(aSegmID), theC2d, theArrayOfParameters);
2156 //=======================================================================
2157 //function : TreatRLine
2158 //purpose : Approx of Restriction line
2159 //=======================================================================
2160 void GeomInt_IntSS::TreatRLine(const Handle(IntPatch_RLine)& theRL,
2161 const Handle(GeomAdaptor_HSurface)& theHS1,
2162 const Handle(GeomAdaptor_HSurface)& theHS2,
2163 Handle(Geom_Curve)& theC3d,
2164 Handle(Geom2d_Curve)& theC2d1,
2165 Handle(Geom2d_Curve)& theC2d2,
2166 Standard_Real& theTolReached)
2168 Handle(GeomAdaptor_HSurface) aGAHS;
2169 Handle(Adaptor2d_HCurve2d) anAHC2d;
2170 Standard_Real tf, tl;
2172 // It is assumed that 2d curve is 2d line (rectangular surface domain)
2173 if(theRL->IsArcOnS1())
2176 anAHC2d = theRL->ArcOnS1();
2177 theRL->ParamOnS1(tf, tl);
2178 theC2d1 = Geom2dAdaptor::MakeCurve(anAHC2d->Curve2d());
2180 else if (theRL->IsArcOnS2())
2183 anAHC2d = theRL->ArcOnS2();
2184 theRL->ParamOnS2(tf, tl);
2185 theC2d2 = Geom2dAdaptor::MakeCurve(anAHC2d->Curve2d());
2192 //To provide sameparameter it is necessary to get 3d curve as
2193 //approximation of curve on surface.
2194 Standard_Integer aMaxDeg = 8;
2195 Standard_Integer aMaxSeg = 1000;
2196 Approx_CurveOnSurface anApp(anAHC2d, aGAHS, tf, tl, Precision::Confusion(),
2197 GeomAbs_C1, aMaxDeg, aMaxSeg,
2198 Standard_True, Standard_False);
2199 if(!anApp.HasResult())
2202 theC3d = anApp.Curve3d();
2203 theTolReached = anApp.MaxError3d();
2204 Standard_Real aTol = Precision::Confusion();
2205 if(theRL->IsArcOnS1())
2207 Handle(Geom_Surface) aS = GeomAdaptor::MakeSurface(theHS2->Surface());
2208 BuildPCurves (tf, tl, aTol,
2209 aS, theC3d, theC2d2);
2211 if(theRL->IsArcOnS2())
2213 Handle(Geom_Surface) aS = GeomAdaptor::MakeSurface(theHS1->Surface());
2214 BuildPCurves (tf, tl, aTol,
2215 aS, theC3d, theC2d1);
2217 theTolReached = Max(theTolReached, aTol);
2220 //=======================================================================
2221 //function : BuildPCurves
2223 //=======================================================================
2224 void GeomInt_IntSS::BuildPCurves (Standard_Real f,
2227 const Handle (Geom_Surface)& S,
2228 const Handle (Geom_Curve)& C,
2229 Handle (Geom2d_Curve)& C2d)
2231 if (!C2d.IsNull()) {
2235 Standard_Real umin,umax,vmin,vmax;
2237 S->Bounds(umin, umax, vmin, vmax);
2238 // in class ProjLib_Function the range of parameters is shrank by 1.e-09
2239 if((l - f) > 2.e-09) {
2240 C2d = GeomProjLib::Curve2d(C,f,l,S,umin,umax,vmin,vmax,Tol);
2243 // proj. a circle that goes through the pole on a sphere to the sphere
2244 Tol += Precision::Confusion();
2245 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
2249 if((l - f) > Epsilon(Abs(f)))
2251 //The domain of C2d is [Epsilon(Abs(f)), 2.e-09]
2252 //On this small range C2d can be considered as segment
2255 Standard_Real aU=0., aV=0.;
2256 GeomAdaptor_Surface anAS;
2258 Extrema_ExtPS anExtr;
2259 const gp_Pnt aP3d1 = C->Value(f);
2260 const gp_Pnt aP3d2 = C->Value(l);
2262 anExtr.SetAlgo(Extrema_ExtAlgo_Grad);
2263 anExtr.Initialize(anAS, umin, umax, vmin, vmax,
2264 Precision::Confusion(), Precision::Confusion());
2265 anExtr.Perform(aP3d1);
2267 if(ParametersOfNearestPointOnSurface(anExtr, aU, aV))
2269 const gp_Pnt2d aP2d1(aU, aV);
2271 anExtr.Perform(aP3d2);
2273 if(ParametersOfNearestPointOnSurface(anExtr, aU, aV))
2275 const gp_Pnt2d aP2d2(aU, aV);
2277 if(aP2d1.Distance(aP2d2) > gp::Resolution())
2279 TColgp_Array1OfPnt2d poles(1,2);
2280 TColStd_Array1OfReal knots(1,2);
2281 TColStd_Array1OfInteger mults(1,2);
2286 mults(1) = mults(2) = 2;
2288 C2d = new Geom2d_BSplineCurve(poles,knots,mults,1);
2290 //Check same parameter in middle point .begin
2291 const gp_Pnt PMid(C->Value(0.5*(f+l)));
2292 const gp_Pnt2d pmidcurve2d(0.5*(aP2d1.XY() + aP2d2.XY()));
2293 const gp_Pnt aPC(anAS.Value(pmidcurve2d.X(), pmidcurve2d.Y()));
2294 const Standard_Real aDist = PMid.Distance(aPC);
2295 Tol = Max(aDist, Tol);
2296 //Check same parameter in middle point .end
2303 if (S->IsUPeriodic() && !C2d.IsNull()) {
2304 // Recadre dans le domaine UV de la face
2305 Standard_Real aTm, U0, aEps, period, du, U0x;
2306 Standard_Boolean bAdjust;
2308 aEps = Precision::PConfusion();
2309 period = S->UPeriod();
2312 gp_Pnt2d pm = C2d->Value(aTm);
2316 GeomInt::AdjustPeriodic(U0, umin, umax, period, U0x, du, aEps);
2318 gp_Vec2d T1(du, 0.);
2324 //=======================================================================
2325 //function : TrimILineOnSurfBoundaries
2326 //purpose : This function finds intersection points of given curves with
2327 // surface boundaries and fills theArrayOfParameters by parameters
2328 // along the given curves corresponding of these points.
2329 //=======================================================================
2330 void GeomInt_IntSS::TrimILineOnSurfBoundaries(const Handle(Geom2d_Curve)& theC2d1,
2331 const Handle(Geom2d_Curve)& theC2d2,
2332 const Bnd_Box2d& theBound1,
2333 const Bnd_Box2d& theBound2,
2334 GeomInt_VectorOfReal& theArrayOfParameters)
2336 //Rectangular boundaries of two surfaces: [0]:U=Ufirst, [1]:U=Ulast,
2337 // [2]:V=Vfirst, [3]:V=Vlast
2338 const Standard_Integer aNumberOfCurves = 4;
2339 Handle(Geom2d_Curve) aCurS1Bounds[aNumberOfCurves];
2340 Handle(Geom2d_Curve) aCurS2Bounds[aNumberOfCurves];
2342 Standard_Real aU1f=0.0, aV1f=0.0, aU1l=0.0, aV1l=0.0;
2343 Standard_Real aU2f=0.0, aV2f=0.0, aU2l=0.0, aV2l=0.0;
2345 theBound1.Get(aU1f, aV1f, aU1l, aV1l);
2346 theBound2.Get(aU2f, aV2f, aU2l, aV2l);
2348 Standard_Real aDelta = aV1l-aV1f;
2349 if(Abs(aDelta) > RealSmall())
2351 if(!Precision::IsInfinite(aU1f))
2353 aCurS1Bounds[0] = new Geom2d_Line(gp_Pnt2d(aU1f, aV1f), gp_Dir2d(0.0, 1.0));
2355 if(!Precision::IsInfinite(aDelta))
2356 aCurS1Bounds[0] = new Geom2d_TrimmedCurve(aCurS1Bounds[0], 0, aDelta);
2359 if(!Precision::IsInfinite(aU1l))
2361 aCurS1Bounds[1] = new Geom2d_Line(gp_Pnt2d(aU1l, aV1f), gp_Dir2d(0.0, 1.0));
2362 if(!Precision::IsInfinite(aDelta))
2363 aCurS1Bounds[1] = new Geom2d_TrimmedCurve(aCurS1Bounds[1], 0, aDelta);
2368 if(Abs(aDelta) > RealSmall())
2370 if(!Precision::IsInfinite(aV1f))
2372 aCurS1Bounds[2] = new Geom2d_Line(gp_Pnt2d(aU1f, aV1f), gp_Dir2d(1.0, 0.0));
2373 if(!Precision::IsInfinite(aDelta))
2374 aCurS1Bounds[2] = new Geom2d_TrimmedCurve(aCurS1Bounds[2], 0, aDelta);
2377 if(!Precision::IsInfinite(aV1l))
2379 aCurS1Bounds[3] = new Geom2d_Line(gp_Pnt2d(aU1l, aV1l), gp_Dir2d(1.0, 0.0));
2380 if(!Precision::IsInfinite(aDelta))
2381 aCurS1Bounds[3] = new Geom2d_TrimmedCurve(aCurS1Bounds[3], 0, aDelta);
2386 if(Abs(aDelta) > RealSmall())
2388 if(!Precision::IsInfinite(aU2f))
2390 aCurS2Bounds[0] = new Geom2d_Line(gp_Pnt2d(aU2f, aV2f), gp_Dir2d(0.0, 1.0));
2391 if(!Precision::IsInfinite(aDelta))
2392 aCurS2Bounds[0] = new Geom2d_TrimmedCurve(aCurS2Bounds[0], 0, aDelta);
2395 if(!Precision::IsInfinite(aU2l))
2397 aCurS2Bounds[1] = new Geom2d_Line(gp_Pnt2d(aU2l, aV2f), gp_Dir2d(0.0, 1.0));
2398 if(!Precision::IsInfinite(aDelta))
2399 aCurS2Bounds[1] = new Geom2d_TrimmedCurve(aCurS2Bounds[1], 0, aDelta);
2404 if(Abs(aDelta) > RealSmall())
2406 if(!Precision::IsInfinite(aV2f))
2408 aCurS2Bounds[2] = new Geom2d_Line(gp_Pnt2d(aU2f, aV2f), gp_Dir2d(1.0, 0.0));
2409 if(!Precision::IsInfinite(aDelta))
2410 aCurS2Bounds[2] = new Geom2d_TrimmedCurve(aCurS2Bounds[2], 0, aDelta);
2413 if(!Precision::IsInfinite(aV2l))
2415 aCurS2Bounds[3] = new Geom2d_Line(gp_Pnt2d(aU2l, aV2l), gp_Dir2d(1.0, 0.0));
2416 if(!Precision::IsInfinite(aDelta))
2417 aCurS2Bounds[3] = new Geom2d_TrimmedCurve(aCurS2Bounds[3], 0, aDelta);
2421 const Standard_Real anIntTol = 10.0*Precision::Confusion();
2423 IntersectCurveAndBoundary(theC2d1, aCurS1Bounds,
2424 aNumberOfCurves, anIntTol, theArrayOfParameters);
2426 IntersectCurveAndBoundary(theC2d2, aCurS2Bounds,
2427 aNumberOfCurves, anIntTol, theArrayOfParameters);
2429 std::sort(theArrayOfParameters.begin(), theArrayOfParameters.end());