1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <IntTools_WLineTool.hxx>
16 #include <BRep_Tool.hxx>
17 #include <Extrema_ExtCC.hxx>
18 #include <Geom2dAPI_InterCurveCurve.hxx>
19 #include <Geom2d_Circle.hxx>
20 #include <Geom2d_Line.hxx>
21 #include <Geom2d_TrimmedCurve.hxx>
22 #include <GeomAPI_ProjectPointOnSurf.hxx>
23 #include <GeomAdaptor_Curve.hxx>
24 #include <GeomAdaptor_Surface.hxx>
25 #include <GeomInt.hxx>
26 #include <GeomInt_LineConstructor.hxx>
27 #include <Geom_Circle.hxx>
28 #include <Geom_Surface.hxx>
29 #include <gp_Circ.hxx>
30 #include <IntTools_Context.hxx>
31 #include <TColStd_Array1OfListOfInteger.hxx>
32 #include <TColStd_SequenceOfReal.hxx>
33 #include <TColgp_SequenceOfPnt2d.hxx>
35 /////////////////////// NotUseSurfacesForApprox /////////////////////////
37 // The block is dedicated to determine whether WLine [ifprm, ilprm]
38 // crosses the degenerated zone on each given surface or not.
39 // If Yes -> We will not use info about surfaces during approximation
40 // because inside degenerated zone of the surface the approx. algo.
41 // uses wrong values of normal, etc., and resulting curve will have
42 // oscillations that we would not like to have.
44 //=======================================================================
45 //function : IsDegeneratedZone
46 //purpose : static subfunction in IsDegeneratedZone
47 //=======================================================================
49 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
50 const Handle(Geom_Surface)& aS,
51 const Standard_Integer iDir)
53 Standard_Boolean bFlag=Standard_True;
54 Standard_Real US1, US2, VS1, VS2, dY, dX, d1, d2, dD;
55 Standard_Real aXm, aYm, aXb, aYb, aXe, aYe;
56 aS->Bounds(US1, US2, VS1, VS2);
63 aS->D0(aXm, aYm, aPm);
80 aS->D0(aXb, aYb, aPb);
81 aS->D0(aXe, aYe, aPe);
85 if (d1 < dD && d2 < dD) {
102 aS->D0(aXb, aYb, aPb);
103 aS->D0(aXe, aYe, aPe);
105 d1=aPm.Distance(aPb);
106 d2=aPm.Distance(aPe);
107 if (d1 < dD && d2 < dD) {
115 //=======================================================================
116 //function : IsPointInDegeneratedZone
117 //purpose : static subfunction in NotUseSurfacesForApprox
118 //=======================================================================
120 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
121 const TopoDS_Face& aF1,
122 const TopoDS_Face& aF2)
125 Standard_Boolean bFlag=Standard_True;
126 Standard_Real US11, US12, VS11, VS12, US21, US22, VS21, VS22;
127 Standard_Real U1, V1, U2, V2, aDelta, aD;
130 Handle(Geom_Surface)aS1 = BRep_Tool::Surface(aF1);
131 aS1->Bounds(US11, US12, VS11, VS12);
132 GeomAdaptor_Surface aGAS1(aS1);
134 Handle(Geom_Surface)aS2 = BRep_Tool::Surface(aF2);
135 aS1->Bounds(US21, US22, VS21, VS22);
136 GeomAdaptor_Surface aGAS2(aS2);
138 //const gp_Pnt& aP=aP2S.Value();
139 aP2S.Parameters(U1, V1, U2, V2);
143 aD=aGAS1.UResolution(aDelta);
144 aP2d.SetCoord(U1, V1);
145 if (fabs(U1-US11) < aD) {
146 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
151 if (fabs(U1-US12) < aD) {
152 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
157 aD=aGAS1.VResolution(aDelta);
158 if (fabs(V1-VS11) < aDelta) {
159 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
164 if (fabs(V1-VS12) < aDelta) {
165 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
171 aD=aGAS2.UResolution(aDelta);
172 aP2d.SetCoord(U2, V2);
173 if (fabs(U2-US21) < aDelta) {
174 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
179 if (fabs(U2-US22) < aDelta) {
180 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
185 aD=aGAS2.VResolution(aDelta);
186 if (fabs(V2-VS21) < aDelta) {
187 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
192 if (fabs(V2-VS22) < aDelta) {
193 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
201 //=======================================================================
202 //function : NotUseSurfacesForApprox
204 //=======================================================================
205 Standard_Boolean IntTools_WLineTool::NotUseSurfacesForApprox(const TopoDS_Face& aF1,
206 const TopoDS_Face& aF2,
207 const Handle(IntPatch_WLine)& WL,
208 const Standard_Integer ifprm,
209 const Standard_Integer ilprm)
211 Standard_Boolean bPInDZ;
213 Handle(IntSurf_LineOn2S) aLineOn2S=WL->Curve();
215 const IntSurf_PntOn2S& aP2Sfprm=aLineOn2S->Value(ifprm);
216 bPInDZ=IsPointInDegeneratedZone(aP2Sfprm, aF1, aF2);
221 const IntSurf_PntOn2S& aP2Slprm=aLineOn2S->Value(ilprm);
222 bPInDZ=IsPointInDegeneratedZone(aP2Slprm, aF1, aF2);
227 /////////////////////// end of NotUseSurfacesForApprox //////////////////
229 /////////////////////// DecompositionOfWLine ////////////////////////////
231 //=======================================================================
232 //function : IsPointOnBoundary
233 //purpose : static subfunction in DecompositionOfWLine
234 //=======================================================================
236 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
237 const Standard_Real theFirstBoundary,
238 const Standard_Real theSecondBoundary,
239 const Standard_Real theResolution,
240 Standard_Boolean& IsOnFirstBoundary)
242 Standard_Boolean bRet;
247 for(i = 0; i < 2; ++i) {
248 IsOnFirstBoundary = (i == 0);
249 if (IsOnFirstBoundary) {
250 adist = fabs(theParameter - theFirstBoundary);
253 adist = fabs(theParameter - theSecondBoundary);
255 if(adist < theResolution) {
262 //=======================================================================
263 //function : AdjustByNeighbour
264 //purpose : static subfunction in DecompositionOfWLine
265 //=======================================================================
267 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
268 const gp_Pnt2d& theOriginalPoint,
269 Handle(GeomAdaptor_Surface) theGASurface)
271 gp_Pnt2d ap1 = theaNeighbourPoint;
272 gp_Pnt2d ap2 = theOriginalPoint;
274 if ( theGASurface->IsUPeriodic() ) {
275 Standard_Real aPeriod = theGASurface->UPeriod();
276 gp_Pnt2d aPTest = ap2;
277 Standard_Real aSqDistMin = 1.e+100;
279 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
280 aPTest.SetX( theOriginalPoint.X() + aPeriod * pIt );
281 Standard_Real dd = ap1.SquareDistance( aPTest );
283 if ( dd < aSqDistMin ) {
289 if ( theGASurface->IsVPeriodic() ) {
290 Standard_Real aPeriod = theGASurface->VPeriod();
291 gp_Pnt2d aPTest = ap2;
292 Standard_Real aSqDistMin = 1.e+100;
294 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
295 aPTest.SetY( theOriginalPoint.Y() + aPeriod * pIt );
296 Standard_Real dd = ap1.SquareDistance( aPTest );
298 if ( dd < aSqDistMin ) {
307 //=======================================================================
308 //function : RefineVector
309 //purpose : static subfunction in FindPoint
310 //=======================================================================
312 void RefineVector(gp_Vec2d& aV2D)
314 Standard_Integer k,m;
315 Standard_Real aC[2], aEps, aR1, aR2, aNum;
321 aV2D.Coord(aC[0], aC[1]);
323 for (k=0; k<2; ++k) {
326 if (aNum>aR1 && aNum<aR2) {
337 aV2D.SetCoord(aC[0], aC[1]);
340 //=======================================================================
341 //function : FindPoint
342 //purpose : static subfunction in DecompositionOfWLine
343 //=======================================================================
345 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
346 const gp_Pnt2d& theLastPoint,
347 const Standard_Real theUmin,
348 const Standard_Real theUmax,
349 const Standard_Real theVmin,
350 const Standard_Real theVmax,
351 gp_Pnt2d& theNewPoint)
353 gp_Vec2d aVec(theFirstPoint, theLastPoint);
354 Standard_Integer i = 0, j = 0;
356 for(i = 0; i < 4; i++) {
358 gp_Vec2d anOtherVecNormal;
359 gp_Pnt2d aprojpoint = theLastPoint;
364 anOtherVecNormal.SetX(1.);
365 anOtherVecNormal.SetY(0.);
368 aprojpoint.SetX(theUmin);
370 aprojpoint.SetX(theUmax);
375 anOtherVecNormal.SetX(0.);
376 anOtherVecNormal.SetY(1.);
379 aprojpoint.SetY(theVmin);
381 aprojpoint.SetY(theVmax);
383 gp_Vec2d anormvec = aVec;
384 anormvec.Normalize();
385 RefineVector(anormvec);
386 Standard_Real adot1 = anormvec.Dot(anOtherVecNormal);
388 if(fabs(adot1) < Precision::Angular())
390 Standard_Real adist = 0.;
391 Standard_Boolean bIsOut = Standard_False;
394 adist = (i < 2) ? fabs(theLastPoint.X() - theUmin) : fabs(theLastPoint.X() - theUmax);
395 bIsOut = (i < 2) ? (theLastPoint.X() < theUmin) : (theLastPoint.X() > theUmax);
398 adist = (i < 2) ? fabs(theLastPoint.Y() - theVmin) : fabs(theLastPoint.Y() - theVmax);
399 bIsOut = (i < 2) ? (theLastPoint.Y() < theVmin) : (theLastPoint.Y() > theVmax);
401 Standard_Real anoffset = adist * anOtherVec.Dot(anormvec) / adot1;
403 for(j = 0; j < 2; j++) {
404 anoffset = (j == 0) ? anoffset : -anoffset;
405 gp_Pnt2d acurpoint(aprojpoint.XY() + (anOtherVec.XY()*anoffset));
406 gp_Vec2d acurvec(theLastPoint, acurpoint);
410 Standard_Real aDotX, anAngleX;
412 aDotX = aVec.Dot(acurvec);
413 anAngleX = aVec.Angle(acurvec);
415 if(aDotX > 0. && fabs(anAngleX) < Precision::PConfusion()) {
417 if((acurpoint.Y() >= theVmin) &&
418 (acurpoint.Y() <= theVmax)) {
419 theNewPoint = acurpoint;
420 return Standard_True;
424 if((acurpoint.X() >= theUmin) &&
425 (acurpoint.X() <= theUmax)) {
426 theNewPoint = acurpoint;
427 return Standard_True;
433 return Standard_False;
436 //=======================================================================
437 //function : DecompositionOfWLine
439 //=======================================================================
440 Standard_Boolean IntTools_WLineTool::
441 DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
442 const Handle(GeomAdaptor_Surface)& theSurface1,
443 const Handle(GeomAdaptor_Surface)& theSurface2,
444 const TopoDS_Face& theFace1,
445 const TopoDS_Face& theFace2,
446 const GeomInt_LineConstructor& theLConstructor,
447 const Standard_Boolean theAvoidLConstructor,
448 const Standard_Real theTol,
449 IntPatch_SequenceOfLine& theNewLines,
450 const Handle(IntTools_Context)& aContext)
452 Standard_Boolean bRet, bAvoidLineConstructor;
453 Standard_Integer aNbPnts, aNbParts;
456 aNbPnts=theWLine->NbPnts();
457 bAvoidLineConstructor=theAvoidLConstructor;
462 if (!bAvoidLineConstructor) {
463 aNbParts=theLConstructor.NbParts();
469 Standard_Boolean bIsPrevPointOnBoundary, bIsPointOnBoundary, bIsCurrentPointOnBoundary;
470 Standard_Integer nblines, pit, i, j;
472 TColStd_Array1OfListOfInteger anArrayOfLines(1, aNbPnts);
473 TColStd_Array1OfInteger anArrayOfLineType(1, aNbPnts);
474 TColStd_ListOfInteger aListOfPointIndex;
478 aTol=Precision::Confusion();
480 bIsPrevPointOnBoundary=Standard_False;
481 bIsPointOnBoundary=Standard_False;
486 for(pit = 1; pit <= aNbPnts; ++pit) {
487 Standard_Boolean bIsOnFirstBoundary, isperiodic;
488 Standard_Real aResolution, aPeriod, alowerboundary, aupperboundary, U, V;
489 Standard_Real aParameter, anoffset, anAdjustPar;
490 Standard_Real umin, umax, vmin, vmax;
492 bIsCurrentPointOnBoundary = Standard_False;
493 const IntSurf_PntOn2S& aPoint = theWLine->Point(pit);
496 for(i = 0; i < 2; ++i) {
497 Handle(GeomAdaptor_Surface) aGASurface = (!i) ? theSurface1 : theSurface2;
498 aGASurface->Surface()->Bounds(umin, umax, vmin, vmax);
500 aPoint.ParametersOnS1(U, V);
503 aPoint.ParametersOnS2(U, V);
506 for(j = 0; j < 2; j++) {
507 isperiodic = (!j) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
513 aResolution=aGASurface->UResolution(aTol);
514 aPeriod=aGASurface->UPeriod();
520 aResolution=aGASurface->VResolution(aTol);
521 aPeriod=aGASurface->VPeriod();
527 GeomInt::AdjustPeriodic(aParameter,
534 bIsOnFirstBoundary = Standard_True;// ?
536 IsPointOnBoundary(anAdjustPar,
542 if(bIsPointOnBoundary) {
543 bIsCurrentPointOnBoundary = Standard_True;
546 }//for(j = 0; j < 2; j++) {
548 if(bIsCurrentPointOnBoundary){
551 }//for(i = 0; i < 2; ++i) {
553 if((bIsCurrentPointOnBoundary != bIsPrevPointOnBoundary)) {
554 if(!aListOfPointIndex.IsEmpty()) {
556 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
557 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
558 aListOfPointIndex.Clear();
560 bIsPrevPointOnBoundary = bIsCurrentPointOnBoundary;
562 aListOfPointIndex.Append(pit);
563 } //for(pit = 1; pit <= aNbPnts; ++pit) {
565 if(!aListOfPointIndex.IsEmpty()) {
567 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
568 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
569 aListOfPointIndex.Clear();
573 return bRet; //Standard_False;
577 // 2. Correct wlines.begin
578 TColStd_Array1OfListOfInteger anArrayOfLineEnds(1, nblines);
579 Handle(IntSurf_LineOn2S) aSeqOfPntOn2S = new IntSurf_LineOn2S();
581 for(i = 1; i <= nblines; i++) {
582 if(anArrayOfLineType.Value(i) != 0) {
585 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
586 TColStd_ListOfInteger aListOfFLIndex;
588 for(j = 0; j < 2; j++) {
589 Standard_Integer aneighbourindex = (j == 0) ? (i - 1) : (i + 1);
591 if((aneighbourindex < 1) || (aneighbourindex > nblines))
594 if(anArrayOfLineType.Value(aneighbourindex) == 0)
596 const TColStd_ListOfInteger& aNeighbour = anArrayOfLines.Value(aneighbourindex);
597 Standard_Integer anIndex = (j == 0) ? aNeighbour.Last() : aNeighbour.First();
598 const IntSurf_PntOn2S& aPoint = theWLine->Point(anIndex);
600 IntSurf_PntOn2S aNewP = aPoint;
601 if(aListOfIndex.Extent() < 2) {
602 aSeqOfPntOn2S->Add(aNewP);
603 aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
607 Standard_Integer iFirst = aListOfIndex.First();
608 Standard_Integer iLast = aListOfIndex.Last();
610 for(Standard_Integer surfit = 0; surfit < 2; surfit++) {
612 Handle(GeomAdaptor_Surface) aGASurface = (surfit == 0) ? theSurface1 : theSurface2;
613 Standard_Real umin=0., umax=0., vmin=0., vmax=0.;
614 aGASurface->Surface()->Bounds(umin, umax, vmin, vmax);
615 Standard_Real U=0., V=0.;
618 aNewP.ParametersOnS1(U, V);
620 aNewP.ParametersOnS2(U, V);
621 Standard_Integer nbboundaries = 0;
623 Standard_Boolean bIsNearBoundary = Standard_False;
624 //Standard_Integer aZoneIndex = 0;
625 Standard_Integer bIsUBoundary = Standard_False; // use if nbboundaries == 1
626 Standard_Integer bIsFirstBoundary = Standard_False; // use if nbboundaries == 1
629 for(Standard_Integer parit = 0; parit < 2; parit++) {
630 Standard_Boolean isperiodic = (parit == 0) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
632 Standard_Real aResolution = (parit == 0) ? aGASurface->UResolution(aTol) : aGASurface->VResolution(aTol);
633 Standard_Real alowerboundary = (parit == 0) ? umin : vmin;
634 Standard_Real aupperboundary = (parit == 0) ? umax : vmax;
636 Standard_Real aParameter = (parit == 0) ? U : V;
637 Standard_Boolean bIsOnFirstBoundary = Standard_True;
641 IsPointOnBoundary(aParameter, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
642 if(bIsPointOnBoundary) {
643 bIsUBoundary = (parit == 0);
644 bIsFirstBoundary = bIsOnFirstBoundary;
649 Standard_Real aPeriod = (parit == 0) ? aGASurface->UPeriod() : aGASurface->VPeriod();
650 Standard_Real anoffset, anAdjustPar;
651 GeomInt::AdjustPeriodic(aParameter, alowerboundary, aupperboundary,
652 aPeriod, anAdjustPar, anoffset);
655 IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
656 if(bIsPointOnBoundary) {
657 bIsUBoundary = (parit == 0);
658 bIsFirstBoundary = bIsOnFirstBoundary;
662 //check neighbourhood of boundary
663 Standard_Real anEpsilon = aResolution * 100.;
664 Standard_Real aPart = ( aupperboundary - alowerboundary ) * 0.1;
665 anEpsilon = ( anEpsilon > aPart ) ? aPart : anEpsilon;
667 bIsNearBoundary = IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary,
668 anEpsilon, bIsOnFirstBoundary);
674 Standard_Boolean bComputeLineEnd = Standard_False;
676 if(nbboundaries == 2) {
678 bComputeLineEnd = Standard_True;
681 else if(nbboundaries == 1) {
682 Standard_Boolean isperiodic = (bIsUBoundary) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
685 Standard_Real alowerboundary = (bIsUBoundary) ? umin : vmin;
686 Standard_Real aupperboundary = (bIsUBoundary) ? umax : vmax;
687 Standard_Real aPeriod = (bIsUBoundary) ? aGASurface->UPeriod() : aGASurface->VPeriod();
688 Standard_Real aParameter = (bIsUBoundary) ? U : V;
689 Standard_Real anoffset, anAdjustPar;
690 GeomInt::AdjustPeriodic(aParameter, alowerboundary, aupperboundary,
691 aPeriod, anAdjustPar, anoffset);
693 Standard_Real adist = (bIsFirstBoundary) ? fabs(anAdjustPar - alowerboundary) : fabs(anAdjustPar - aupperboundary);
694 Standard_Real anotherPar = (bIsFirstBoundary) ? (aupperboundary - adist) : (alowerboundary + adist);
695 anotherPar += anoffset;
696 Standard_Integer aneighbourpointindex = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
697 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex);
698 Standard_Real nU1, nV1;
701 aNeighbourPoint.ParametersOnS1(nU1, nV1);
703 aNeighbourPoint.ParametersOnS2(nU1, nV1);
705 Standard_Real adist1 = (bIsUBoundary) ? fabs(nU1 - U) : fabs(nV1 - V);
706 Standard_Real adist2 = (bIsUBoundary) ? fabs(nU1 - anotherPar) : fabs(nV1 - anotherPar);
707 bComputeLineEnd = Standard_True;
708 Standard_Boolean bCheckAngle1 = Standard_False;
709 Standard_Boolean bCheckAngle2 = Standard_False;
711 Standard_Real anewU = (bIsUBoundary) ? anotherPar : U;
712 Standard_Real anewV = (bIsUBoundary) ? V : anotherPar;
714 if(((adist1 - adist2) > Precision::PConfusion()) &&
715 (adist2 < (aPeriod / 4.))) {
716 bCheckAngle1 = Standard_True;
717 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(anewU, anewV));
719 if(aNewVec.SquareMagnitude() < gp::Resolution()) {
720 aNewP.SetValue((surfit == 0), anewU, anewV);
721 bCheckAngle1 = Standard_False;
724 else if(adist1 < (aPeriod / 4.)) {
725 bCheckAngle2 = Standard_True;
726 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(U, V));
728 if(aNewVec.SquareMagnitude() < gp::Resolution()) {
729 bCheckAngle2 = Standard_False;
733 if(bCheckAngle1 || bCheckAngle2) {
734 // assume there are at least two points in line (see "if" above)
735 Standard_Integer anindexother = aneighbourpointindex;
737 while((anindexother <= iLast) && (anindexother >= iFirst)) {
738 anindexother = (j == 0) ? (anindexother + 1) : (anindexother - 1);
739 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(anindexother);
740 Standard_Real nU2, nV2;
743 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
745 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
746 gp_Vec2d aVecOld(gp_Pnt2d(nU2, nV2), gp_Pnt2d(nU1, nV1));
748 if(aVecOld.SquareMagnitude() <= gp::Resolution()) {
752 Standard_Real anAngle = aNewVec.Angle(aVecOld);
754 if((fabs(anAngle) < (M_PI * 0.25)) && (aNewVec.Dot(aVecOld) > 0.)) {
757 Standard_Real U1, U2, V1, V2;
758 IntSurf_PntOn2S atmppoint = aNewP;
759 atmppoint.SetValue((surfit == 0), anewU, anewV);
760 atmppoint.Parameters(U1, V1, U2, V2);
761 gp_Pnt P1 = theSurface1->Value(U1, V1);
762 gp_Pnt P2 = theSurface2->Value(U2, V2);
763 gp_Pnt P0 = aPoint.Value();
765 if(P0.IsEqual(P1, aTol) &&
766 P0.IsEqual(P2, aTol) &&
767 P1.IsEqual(P2, aTol)) {
768 bComputeLineEnd = Standard_False;
769 aNewP.SetValue((surfit == 0), anewU, anewV);
774 bComputeLineEnd = Standard_False;
779 } // end while(anindexother...)
783 else if ( bIsNearBoundary ) {
784 bComputeLineEnd = Standard_True;
787 if(bComputeLineEnd) {
790 Standard_Boolean found = Standard_False;
792 if ( bIsNearBoundary ) {
793 // re-compute point near natural boundary or near tangent zone
794 Standard_Real u1, v1, u2, v2;
795 aNewP.Parameters( u1, v1, u2, v2 );
797 anewpoint = gp_Pnt2d( u1, v1 );
799 anewpoint = gp_Pnt2d( u2, v2 );
801 Standard_Integer aneighbourpointindex1 = (j == 0) ? iFirst : iLast;
802 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
803 Standard_Real nU1, nV1;
806 aNeighbourPoint.ParametersOnS1(nU1, nV1);
808 aNeighbourPoint.ParametersOnS2(nU1, nV1);
809 gp_Pnt2d ap1(nU1, nV1);
812 if ( aGASurface->IsUPeriodic() || aGASurface->IsVPeriodic() ) {
813 // re-compute point near boundary if shifted on a period
814 ap2 = AdjustByNeighbour( ap1, anewpoint, aGASurface );
816 if ( ( ap2.X() < umin ) || ( ap2.X() > umax ) ||
817 ( ap2.Y() < vmin ) || ( ap2.Y() > vmax ) ) {
818 found = FindPoint(ap1, ap2, umin, umax, vmin, vmax, anewpoint);
822 aNewP.SetValue( (surfit == 0), anewpoint.X(), anewpoint.Y() );
828 Standard_Integer aneighbourpointindex1 = (j == 0) ? iFirst : iLast;
829 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
830 Standard_Real nU1, nV1;
833 aNeighbourPoint.ParametersOnS1(nU1, nV1);
835 aNeighbourPoint.ParametersOnS2(nU1, nV1);
836 gp_Pnt2d ap1(nU1, nV1);
837 gp_Pnt2d ap2(nU1, nV1);
838 Standard_Integer aneighbourpointindex2 = aneighbourpointindex1;
840 while((aneighbourpointindex2 <= iLast) && (aneighbourpointindex2 >= iFirst)) {
841 aneighbourpointindex2 = (j == 0) ? (aneighbourpointindex2 + 1) : (aneighbourpointindex2 - 1);
842 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(aneighbourpointindex2);
843 Standard_Real nU2, nV2;
846 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
848 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
852 if(ap1.SquareDistance(ap2) > gp::Resolution()) {
856 found = FindPoint(ap2, ap1, umin, umax, vmin, vmax, anewpoint);
861 Standard_Real aCriteria = theTol;
862 GeomAPI_ProjectPointOnSurf& aProjector =
863 (surfit == 0) ? aContext->ProjPS(theFace2) : aContext->ProjPS(theFace1);
864 Handle(GeomAdaptor_Surface) aSurface = (surfit == 0) ? theSurface1 : theSurface2;
866 Handle(GeomAdaptor_Surface) aSurfaceOther = (surfit == 0) ? theSurface2 : theSurface1;
868 gp_Pnt aP3d = aSurface->Value(anewpoint.X(), anewpoint.Y());
869 aProjector.Perform(aP3d);
871 if(aProjector.IsDone()) {
872 if(aProjector.LowerDistance() < aCriteria) {
873 Standard_Real foundU = U, foundV = V;
874 aProjector.LowerDistanceParameters(foundU, foundV);
876 //Correction of projected coordinates. Begin
877 //Note, it may be shifted on a period
878 Standard_Integer aneindex1 = (j == 0) ? iFirst : iLast;
879 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneindex1);
880 Standard_Real nUn, nVn;
883 aNeighbourPoint.ParametersOnS2(nUn, nVn);
885 aNeighbourPoint.ParametersOnS1(nUn, nVn);
886 gp_Pnt2d aNeighbour2d(nUn, nVn);
887 gp_Pnt2d anAdjustedPoint = AdjustByNeighbour( aNeighbour2d, gp_Pnt2d(foundU, foundV), aSurfaceOther );
888 foundU = anAdjustedPoint.X();
889 foundV = anAdjustedPoint.Y();
891 if ( ( anAdjustedPoint.X() < umin ) && ( anAdjustedPoint.X() > umax ) &&
892 ( anAdjustedPoint.Y() < vmin ) && ( anAdjustedPoint.Y() > vmax ) ) {
893 // attempt to roughly re-compute point
894 foundU = ( foundU < umin ) ? umin : foundU;
895 foundU = ( foundU > umax ) ? umax : foundU;
896 foundV = ( foundV < vmin ) ? vmin : foundV;
897 foundV = ( foundV > vmax ) ? vmax : foundV;
899 GeomAPI_ProjectPointOnSurf& aProjector2 =
900 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
902 aP3d = aSurfaceOther->Value(foundU, foundV);
903 aProjector2.Perform(aP3d);
905 if(aProjector2.IsDone()) {
906 if(aProjector2.LowerDistance() < aCriteria) {
907 Standard_Real foundU2 = anewpoint.X(), foundV2 = anewpoint.Y();
908 aProjector2.LowerDistanceParameters(foundU2, foundV2);
909 anewpoint.SetX(foundU2);
910 anewpoint.SetY(foundV2);
914 //Correction of projected coordinates. End
917 aNewP.SetValue(aP3d, anewpoint.X(), anewpoint.Y(), foundU, foundV);
919 aNewP.SetValue(aP3d, foundU, foundV, anewpoint.X(), anewpoint.Y());
925 aSeqOfPntOn2S->Add(aNewP);
926 aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
928 anArrayOfLineEnds.SetValue(i, aListOfFLIndex);
930 // Correct wlines.end
932 // Split wlines.begin
933 Standard_Integer nbiter;
936 if (!bAvoidLineConstructor) {
937 nbiter=theLConstructor.NbParts();
940 for(j = 1; j <= nbiter; ++j) {
941 Standard_Real fprm, lprm;
942 Standard_Integer ifprm, ilprm;
944 if(bAvoidLineConstructor) {
946 ilprm = theWLine->NbPnts();
949 theLConstructor.Part(j, fprm, lprm);
950 ifprm = (Standard_Integer)fprm;
951 ilprm = (Standard_Integer)lprm;
954 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
956 for(i = 1; i <= nblines; i++) {
957 if(anArrayOfLineType.Value(i) != 0) {
960 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
961 const TColStd_ListOfInteger& aListOfFLIndex = anArrayOfLineEnds.Value(i);
962 Standard_Boolean bhasfirstpoint = (aListOfFLIndex.Extent() == 2);
963 Standard_Boolean bhaslastpoint = (aListOfFLIndex.Extent() == 2);
965 if(!bhasfirstpoint && !aListOfFLIndex.IsEmpty()) {
966 bhasfirstpoint = (i != 1);
969 if(!bhaslastpoint && !aListOfFLIndex.IsEmpty()) {
970 bhaslastpoint = (i != nblines);
973 Standard_Integer iFirst = aListOfIndex.First();
974 Standard_Integer iLast = aListOfIndex.Last();
975 Standard_Boolean bIsFirstInside = ((ifprm >= iFirst) && (ifprm <= iLast));
976 Standard_Boolean bIsLastInside = ((ilprm >= iFirst) && (ilprm <= iLast));
978 if(!bIsFirstInside && !bIsLastInside) {
979 if((ifprm < iFirst) && (ilprm > iLast)) {
980 // append whole line, and boundaries if necessary
982 pit = aListOfFLIndex.First();
983 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
986 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
988 for(; anIt.More(); anIt.Next()) {
990 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
995 pit = aListOfFLIndex.Last();
996 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
1000 // check end of split line (end is almost always)
1001 Standard_Integer aneighbour = i + 1;
1002 Standard_Boolean bIsEndOfLine = Standard_True;
1004 if(aneighbour <= nblines) {
1005 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
1007 if((anArrayOfLineType.Value(aneighbour) != 0) &&
1008 (aListOfNeighbourIndex.IsEmpty())) {
1009 bIsEndOfLine = Standard_False;
1014 if(aLineOn2S->NbPoints() > 1) {
1015 Handle(IntPatch_WLine) aNewWLine =
1016 new IntPatch_WLine(aLineOn2S, Standard_False);
1017 aNewWLine->SetCreatingWayInfo(theWLine->GetCreatingWay());
1018 theNewLines.Append(aNewWLine);
1020 aLineOn2S = new IntSurf_LineOn2S();
1025 // end if(!bIsFirstInside && !bIsLastInside)
1027 if(bIsFirstInside && bIsLastInside) {
1028 // append inside points between ifprm and ilprm
1029 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
1031 for(; anIt.More(); anIt.Next()) {
1033 if((pit < ifprm) || (pit > ilprm))
1035 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
1041 if(bIsFirstInside) {
1042 // append points from ifprm to last point + boundary point
1043 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
1045 for(; anIt.More(); anIt.Next()) {
1049 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
1054 pit = aListOfFLIndex.Last();
1055 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
1058 // check end of split line (end is almost always)
1059 Standard_Integer aneighbour = i + 1;
1060 Standard_Boolean bIsEndOfLine = Standard_True;
1062 if(aneighbour <= nblines) {
1063 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
1065 if((anArrayOfLineType.Value(aneighbour) != 0) &&
1066 (aListOfNeighbourIndex.IsEmpty())) {
1067 bIsEndOfLine = Standard_False;
1072 if(aLineOn2S->NbPoints() > 1) {
1073 Handle(IntPatch_WLine) aNewWLine =
1074 new IntPatch_WLine(aLineOn2S, Standard_False);
1075 aNewWLine->SetCreatingWayInfo(theWLine->GetCreatingWay());
1076 theNewLines.Append(aNewWLine);
1078 aLineOn2S = new IntSurf_LineOn2S();
1081 // end if(bIsFirstInside)
1084 // append points from first boundary point to ilprm
1085 if(bhasfirstpoint) {
1086 pit = aListOfFLIndex.First();
1087 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
1090 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
1092 for(; anIt.More(); anIt.Next()) {
1096 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
1100 //end if(bIsLastInside)
1104 if(aLineOn2S->NbPoints() > 1) {
1105 Handle(IntPatch_WLine) aNewWLine =
1106 new IntPatch_WLine(aLineOn2S, Standard_False);
1107 aNewWLine->SetCreatingWayInfo(theWLine->GetCreatingWay());
1108 theNewLines.Append(aNewWLine);
1113 return Standard_True;
1116 ///////////////////// end of DecompositionOfWLine ///////////////////////