1 // Created on: 2001-02-26
2 // Created by: Peter KURNEV
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <IntTools_EdgeFace.ixx>
20 #include <IntTools_CArray1OfReal.hxx>
21 #include <IntTools.hxx>
22 #include <IntTools_CArray1OfInteger.hxx>
23 #include <IntTools_Range.hxx>
24 #include <IntTools_Tools.hxx>
25 #include <IntTools_Array1OfRange.hxx>
26 #include <IntTools_QuickSortRange.hxx>
27 #include <IntTools_CompareRange.hxx>
28 #include <IntTools_CommonPrt.hxx>
29 #include <IntTools_Root.hxx>
30 #include <IntTools_BeanFaceIntersector.hxx>
31 #include <IntTools_Context.hxx>
33 #include <BRep_Tool.hxx>
35 #include <GeomAdaptor_Surface.hxx>
36 #include <GeomAdaptor_Curve.hxx>
38 #include <Geom_Surface.hxx>
39 #include <Geom_Curve.hxx>
41 #include <GeomAPI_ProjectPointOnSurf.hxx>
43 #include <Precision.hxx>
45 #include <Bnd_Box.hxx>
46 #include <BndLib_AddSurface.hxx>
48 #include <gp_Cylinder.hxx>
51 #include <gp_Cone.hxx>
52 #include <gp_Torus.hxx>
53 #include <gp_Circ.hxx>
57 #include <Extrema_ExtCS.hxx>
58 #include <Extrema_POnCurv.hxx>
59 #include <Extrema_POnSurf.hxx>
62 #include <IntCurveSurface_HInter.hxx>
63 #include <GeomAdaptor_HCurve.hxx>
64 #include <GeomAdaptor_HSurface.hxx>
65 #include <IntCurveSurface_IntersectionPoint.hxx>
68 #pragma warning ( disable : 4101 )
72 Standard_Boolean IsCoplanar (const BRepAdaptor_Curve& ,
73 const BRepAdaptor_Surface& );
75 Standard_Boolean IsRadius (const BRepAdaptor_Curve& aCurve ,
76 const BRepAdaptor_Surface& aSurface);
78 Standard_Integer AdaptiveDiscret (const Standard_Integer iDiscret,
79 const BRepAdaptor_Curve& aCurve ,
80 const BRepAdaptor_Surface& aSurface);
82 //=======================================================================
83 //function : IntTools_EdgeFace::IntTools_EdgeFace
85 //=======================================================================
86 IntTools_EdgeFace::IntTools_EdgeFace()
94 myIsDone=Standard_False;
96 myParallel=Standard_False;
99 //=======================================================================
100 //function : SetContext
102 //=======================================================================
103 void IntTools_EdgeFace::SetContext(const Handle(IntTools_Context)& theContext)
105 myContext = theContext;
108 //=======================================================================
111 //=======================================================================
112 const Handle(IntTools_Context)& IntTools_EdgeFace::Context()const
116 //=======================================================================
119 //=======================================================================
120 void IntTools_EdgeFace::SetEdge(const TopoDS_Edge& anEdge)
124 //=======================================================================
127 //=======================================================================
128 void IntTools_EdgeFace::SetFace(const TopoDS_Face& aFace)
132 //=======================================================================
135 //=======================================================================
136 void IntTools_EdgeFace::SetTolE(const Standard_Real aTol)
140 //=======================================================================
143 //=======================================================================
144 void IntTools_EdgeFace::SetTolF(const Standard_Real aTol)
148 //=======================================================================
151 //=======================================================================
152 const TopoDS_Edge& IntTools_EdgeFace::Edge()const
156 //=======================================================================
159 //=======================================================================
160 const TopoDS_Face& IntTools_EdgeFace::Face()const
164 //=======================================================================
167 //=======================================================================
168 Standard_Real IntTools_EdgeFace::TolE()const
172 //=======================================================================
175 //=======================================================================
176 Standard_Real IntTools_EdgeFace::TolF()const
180 //=======================================================================
181 //function : SetDiscretize
183 //=======================================================================
184 void IntTools_EdgeFace::SetDiscretize(const Standard_Integer aDiscret)
188 //=======================================================================
189 //function : SetDeflection
191 //=======================================================================
192 void IntTools_EdgeFace::SetDeflection(const Standard_Real aDefl)
196 //=======================================================================
197 //function : SetEpsilonT
199 //=======================================================================
200 void IntTools_EdgeFace::SetEpsilonT(const Standard_Real anEpsT)
204 //=======================================================================
205 //function : SetEpsilonNull
207 //=======================================================================
208 void IntTools_EdgeFace::SetEpsilonNull(const Standard_Real anEpsNull)
213 //=======================================================================
214 //function : SetRange
216 //=======================================================================
217 void IntTools_EdgeFace::SetRange(const Standard_Real aFirst,
218 const Standard_Real aLast)
220 myRange.SetFirst (aFirst);
221 myRange.SetLast (aLast);
224 //=======================================================================
225 //function : SetRange
227 //=======================================================================
228 void IntTools_EdgeFace::SetRange(const IntTools_Range& aRange)
230 myRange.SetFirst (aRange.First());
231 myRange.SetLast (aRange.Last());
233 //=======================================================================
236 //=======================================================================
237 Standard_Boolean IntTools_EdgeFace::IsDone()const
241 //=======================================================================
242 //function : ErrorStatus
244 //=======================================================================
245 Standard_Integer IntTools_EdgeFace::ErrorStatus()const
247 return myErrorStatus;
249 //=======================================================================
250 //function : CommonParts
252 //=======================================================================
253 const IntTools_SequenceOfCommonPrts& IntTools_EdgeFace::CommonParts() const
255 return mySeqOfCommonPrts;
257 //=======================================================================
260 //=======================================================================
261 const IntTools_Range& IntTools_EdgeFace::Range() const
266 //=======================================================================
267 //function : CheckData
269 //=======================================================================
270 void IntTools_EdgeFace::CheckData()
272 if (BRep_Tool::Degenerated(myEdge)) {
275 if (!BRep_Tool::IsGeometric(myEdge)) {
279 //=======================================================================
282 //=======================================================================
283 void IntTools_EdgeFace::Prepare()
285 Standard_Integer pri;
286 IntTools_CArray1OfReal aPars;
289 // 1.Prepare Curve's data and Surface's data
290 myC.Initialize(myEdge);
291 GeomAbs_CurveType aCurveType;
292 aCurveType=myC.GetType();
294 // 2.Prepare myCriteria
295 if (aCurveType==GeomAbs_BSplineCurve||
296 aCurveType==GeomAbs_BezierCurve) {
297 myCriteria=1.5*myTolE+myTolF;
300 myCriteria=myTolE+myTolF;
302 // 2.a myTmin, myTmax
303 myTmin=myRange.First();
304 myTmax=myRange.Last();
306 myS.Initialize (myFace,Standard_True);
307 myFClass2d.Init(myFace, 1.e-6);
309 // 2.c Prepare adaptive myDiscret
310 myDiscret=AdaptiveDiscret(myDiscret, myC, myS);
314 pri = IntTools::PrepareArgs(myC, myTmax, myTmin,
315 myDiscret, myDeflection, aPars);
322 Standard_Integer i, iProj, aNb, aNbProj, ind0, ind1;
323 Standard_Real t0, t1, tRoot;
326 // Table of Projection's function values
328 IntTools_CArray1OfInteger anArrProjectability;
329 anArrProjectability.Resize(aNb);
331 for (iProj=0, i=0; i<aNb; i++) {
333 aNbProj=IsProjectable (t0);
335 anArrProjectability(i)=0;
337 anArrProjectability(i)=1;
349 // Projectable Ranges
350 IntTools_Range aRange;
352 ind0=anArrProjectability(0);
358 for(i=1; i<aNb; i++) {
359 ind1=anArrProjectability(i);
366 myProjectableRanges.Append(aRange);
369 FindProjectableRoot(t0, t1, ind0, ind1, tRoot);
370 aRange.SetFirst(tRoot);
372 myProjectableRanges.Append(aRange);
376 FindProjectableRoot(t0, t1, ind0, ind1, tRoot);
377 aRange.SetLast(tRoot);
378 myProjectableRanges.Append(aRange);
385 FindProjectableRoot(t0, t1, ind0, ind1, tRoot);
388 aRange.SetLast(tRoot);
389 myProjectableRanges.Append(aRange);
392 aRange.SetFirst(tRoot);
394 } // if (ind0 != ind1)
396 } // for(i=1; i<aNb; i++) {
399 //=======================================================================
400 //function : FindProjectableRoot
402 //=======================================================================
403 void IntTools_EdgeFace::FindProjectableRoot (const Standard_Real tt1,
404 const Standard_Real tt2,
405 const Standard_Integer ff1,
406 const Standard_Integer /*ff2*/,
407 Standard_Real& tRoot)
409 Standard_Real tm, t1, t2, aEpsT;
410 Standard_Integer anIsProj1, anIsProjm;
411 aEpsT = 0.5 * myEpsT;
413 // Root is inside [tt1, tt2]
420 if (fabs(t1 - t2) < aEpsT)
422 tRoot = (anIsProj1) ? t1 : t2;
425 tm = 0.5 * (t1 + t2);
426 anIsProjm = IsProjectable(tm);
428 if (anIsProjm != anIsProj1)
435 anIsProj1 = anIsProjm;
439 //=======================================================================
440 //function : IsProjectable
442 //=======================================================================
443 Standard_Boolean IntTools_EdgeFace::IsProjectable
444 (const Standard_Real aT) const
446 Standard_Boolean bFlag;
450 bFlag=myContext->IsValidPointForFace(aPC, myFace, myCriteria);
454 //=======================================================================
455 //function : DistanceFunction
457 //=======================================================================
458 Standard_Real IntTools_EdgeFace::DistanceFunction
459 (const Standard_Real t)
467 Standard_Boolean bIsEqDistance;
469 bIsEqDistance= IntTools_EdgeFace::IsEqDistance(P, myS, 1.e-7, aD);
476 Standard_Boolean bFlag = Standard_False;
478 GeomAPI_ProjectPointOnSurf& aLocProj = myContext->ProjPS(myFace);
480 bFlag = aLocProj.IsDone();
483 aD = aLocProj.LowerDistance();
493 // aD=aProjector.LowerDistance();
499 //=======================================================================
500 //function : IsEqDistance
502 //=======================================================================
503 Standard_Boolean IntTools_EdgeFace::IsEqDistance
505 const BRepAdaptor_Surface& aBAS,
506 const Standard_Real aTol,
509 Standard_Boolean bRetFlag=Standard_True;
511 GeomAbs_SurfaceType aSurfType=aBAS.GetType();
513 if (aSurfType==GeomAbs_Cylinder) {
514 gp_Cylinder aCyl=aBAS.Cylinder();
515 const gp_Ax1& anAx1 =aCyl.Axis();
516 gp_Lin aLinAxis(anAx1);
517 Standard_Real aDC, aRadius=aCyl.Radius();
518 aDC=aLinAxis.Distance(aP);
525 if (aSurfType==GeomAbs_Cone) {
526 gp_Cone aCone=aBAS.Cone();
527 const gp_Ax1& anAx1 =aCone.Axis();
528 gp_Lin aLinAxis(anAx1);
529 Standard_Real aDC, aRadius, aDS, aSemiAngle;
530 aDC=aLinAxis.Distance(aP);
532 gp_Pnt anApex=aCone.Apex();
533 aSemiAngle=aCone.SemiAngle();
534 aDS=aP.Distance(anApex);
536 aRadius=aDS*tan(aSemiAngle);
542 if (aSurfType==GeomAbs_Torus) {
543 Standard_Real aMajorRadius, aMinorRadius, aDC;
545 gp_Torus aTorus=aBAS.Torus();
546 gp_Pnt aPLoc=aTorus.Location();
547 aMajorRadius=aTorus.MajorRadius();
549 aDC=fabs(aPLoc.Distance(aP)-aMajorRadius);
551 aMinorRadius=aTorus.MinorRadius();
559 //=======================================================================
560 //function : PrepareArgsFuncArrays
562 // myFuncArray and myArgsArray for the interval [ta, tb]
563 //=======================================================================
564 void IntTools_EdgeFace::PrepareArgsFuncArrays(const Standard_Real ta,
565 const Standard_Real tb)
567 IntTools_CArray1OfReal anArgs, aFunc;
568 Standard_Integer i, aNb, pri;
569 Standard_Real t, f, f1;
571 // Prepare values of arguments for the interval [ta, tb]
572 pri=IntTools::PrepareArgs (myC, tb, ta, myDiscret, myDeflection, anArgs);
586 // Prepare values of functions for the interval [ta, tb]
588 for (i=0; i<aNb; i++) {
590 f1=DistanceFunction(t);
593 if (myErrorStatus==11)
596 if (f1 < myEpsNull) {
602 // Add points where the derivative = 0
603 AddDerivativePoints(anArgs, aFunc);
606 //=======================================================================
607 //function : AddDerivativePoints
609 //=======================================================================
610 void IntTools_EdgeFace::AddDerivativePoints
611 (const IntTools_CArray1OfReal& t,
612 const IntTools_CArray1OfReal& f)
614 Standard_Integer i, j, n, k, nn=100;
615 Standard_Real fr, tr, tr1, dEpsNull=10.*myEpsNull;
616 IntTools_CArray1OfReal fd;
617 TColStd_SequenceOfReal aTSeq, aFSeq;
622 // Table of derivatives
623 Standard_Real dfx, tx, tx1, fx, fx1, dt=1.e-6;
628 fx1=DistanceFunction(tx1);
630 if (fx1 < myEpsNull) {
636 if (fabs(fd(0)) < dEpsNull){
642 for (i=1; i<k; i++) {
643 fd(i)=.5*(f(i+1)-f(i-1))/(t(i)-t(i-1));
644 if (fabs(fd(i)) < dEpsNull){
652 fx1=DistanceFunction(tx1);
654 if (fx1 < myEpsNull) {
660 if (fabs(fd(n-1)) < dEpsNull){
664 // Finding the range where the derivatives have different signs
665 // for neighbouring points
666 for (i=1; i<n; i++) {
667 Standard_Real fd1, fd2, t1, t2;
674 if (fabs(fd1) < myEpsNull) {
676 fr=DistanceFunction(tr);//fd1;
678 else if (fabs(fd2) < myEpsNull) {
680 fr=DistanceFunction(tr);
683 tr=FindSimpleRoot(2, t1, t2, fd1);
684 fr=DistanceFunction(tr);
690 } // end of for (i=1; i<n; i++)
692 // remove identical t, f
695 for (i=1; i<=aTSeq.Length(); i++) {
697 for (j=0; j<n; j++) {
699 if (fabs (tr1-tr) < myEpsT) {
708 // sorting args and funcs in increasing order
711 IntTools_Array1OfRange anArray1OfRange(1, k);
712 for (i=1; i<=n; i++) {
713 anArray1OfRange(i).SetFirst(t(i-1));
714 anArray1OfRange(i).SetLast (f(i-1));
716 for (i=1; i<=nn; i++) {
717 anArray1OfRange(n+i).SetFirst(aTSeq(i));
718 anArray1OfRange(n+i).SetLast (aFSeq(i));
721 IntTools_QuickSortRange aQuickSortRange;
722 IntTools_CompareRange aComparator;
723 aQuickSortRange.Sort (anArray1OfRange, aComparator);
725 // filling the output arrays
726 myArgsArray.Resize(k);
727 myFuncArray.Resize(k);
728 for (i=1; i<=k; i++) {
729 myArgsArray(i-1)=anArray1OfRange(i).First();
730 myFuncArray(i-1)=anArray1OfRange(i).Last ();
735 myArgsArray.Resize(n);
736 myFuncArray.Resize(n);
737 for (i=0; i<n; i++) {
744 //=======================================================================
745 //function : DerivativeFunction
747 //=======================================================================
748 Standard_Real IntTools_EdgeFace::DerivativeFunction
749 (const Standard_Real t2)
751 Standard_Real t1, t3, aD1, aD2, aD3;
752 Standard_Real dt=1.e-9;
754 aD1=DistanceFunction(t1);
756 aD3=DistanceFunction(t3);
762 //=======================================================================
763 //function : FindSimpleRoot
764 //purpose : [private]
765 //=======================================================================
766 Standard_Real IntTools_EdgeFace::FindSimpleRoot
767 (const Standard_Integer IP,
768 const Standard_Real tA,
769 const Standard_Real tB,
770 const Standard_Real fA)
772 Standard_Real r, a, b, y, x0, s;
780 y=DistanceFunction(x0);
782 y=DerivativeFunction(x0);
784 if (fabs(b-a) < myEpsT || y==0.) {
801 //=======================================================================
802 //function : FindGoldRoot
803 //purpose : [private]
804 //=======================================================================
805 Standard_Real IntTools_EdgeFace::FindGoldRoot
806 (const Standard_Real tA,
807 const Standard_Real tB,
808 const Standard_Real coeff)
810 Standard_Real gs=0.61803399;
811 Standard_Real a, b, xp, xl, yp, yl;
817 yp=coeff*DistanceFunction(xp);
818 yl=coeff*DistanceFunction(xl);
823 if (fabs(b-a) < myEpsT) {
831 yp=coeff*DistanceFunction(xp);
839 yl=coeff*DistanceFunction(xl);
844 //=======================================================================
845 //function : MakeType
847 //=======================================================================
848 Standard_Integer IntTools_EdgeFace::MakeType
849 (IntTools_CommonPrt& aCommonPrt)
851 Standard_Real af1, al1;
852 Standard_Real df1, tm;
853 Standard_Boolean bAllNullFlag;
855 bAllNullFlag=aCommonPrt.AllNullFlag();
857 aCommonPrt.SetType(TopAbs_EDGE);
861 aCommonPrt.Range1(af1, al1);
867 df1=aPF.Distance(aPL);
868 Standard_Boolean isWholeRange = Standard_False;
870 if((Abs(af1 - myRange.First()) < myC.Resolution(myCriteria)) &&
871 (Abs(al1 - myRange.Last()) < myC.Resolution(myCriteria)))
872 isWholeRange = Standard_True;
875 if ((df1 > myCriteria * 2.) && isWholeRange) {
876 aCommonPrt.SetType(TopAbs_EDGE);
880 tm = (af1 + al1) * 0.5;
882 if(aPF.Distance(myC.Value(tm)) > myCriteria * 2.) {
883 aCommonPrt.SetType(TopAbs_EDGE);
888 if(!CheckTouch(aCommonPrt, tm)) {
889 tm = (af1 + al1) * 0.5;
891 aCommonPrt.SetType(TopAbs_VERTEX);
892 aCommonPrt.SetVertexParameter1(tm);
893 aCommonPrt.SetRange1 (af1, al1);
900 //=======================================================================
901 //function : IsIntersection
903 //=======================================================================
904 void IntTools_EdgeFace::IsIntersection (const Standard_Real ta,
905 const Standard_Real tb)
907 IntTools_CArray1OfReal anArgs, aFunc;
908 Standard_Integer i, aNb, aCnt=0;
910 Standard_Integer aCntIncreasing=1, aCntDecreasing=1;
911 Standard_Real t, f, f1;
913 // Prepare values of arguments for the interval [ta, tb]
914 IntTools::PrepareArgs (myC, tb, ta, myDiscret, myDeflection, anArgs);
918 for (i=0; i<aNb; i++) {
921 f1=DistanceFunction(t);
924 if (fabs(f1) < myEpsNull) {
931 if (aFunc(i)>aFunc(i-1)) {
934 if (aFunc(i)<aFunc(i-1)) {
942 myParallel=Standard_True;
946 FindDerivativeRoot(anArgs, aFunc);
950 if (!(myC.GetType()==GeomAbs_Line
952 myS.GetType()==GeomAbs_Cylinder)) {
953 if (aCntDecreasing==aNb) {
954 myPar1=anArgs(aNb-1);
955 myParallel=Standard_False;
957 if (aCntIncreasing==aNb) {
959 myParallel=Standard_False;
967 //=======================================================================
968 //function : FindDerivativeRoot
970 //=======================================================================
971 void IntTools_EdgeFace::FindDerivativeRoot
972 (const IntTools_CArray1OfReal& t,
973 const IntTools_CArray1OfReal& f)
975 Standard_Integer i, n, k;
977 IntTools_CArray1OfReal fd;
978 TColStd_SequenceOfReal aTSeq, aFSeq;
981 myParallel=Standard_True;
986 // Table of derivatives
987 fd(0)=(f(1)-f(0))/(t(1)-t(0));
988 if (fabs(fd(0)) < myEpsNull) {
993 for (i=1; i<k; i++) {
994 fd(i)=.5*(f(i+1)-f(i-1))/(t(i)-t(i-1));
995 if (fabs(fd(i)) < myEpsNull) {
1000 fd(n-1)=(f(n-1)-f(n-2))/(t(n-1)-t(n-2));
1001 if (fabs(fd(n-1)) < myEpsNull) {
1005 // Finding the range where the derivatives have different signs
1006 // for neighbouring points
1007 for (i=1; i<n; i++) {
1008 Standard_Real fd1, fd2, t1, t2, fabsfd1, fabsfd2;
1009 Standard_Boolean bF1, bF2;
1016 bF1=fabsfd1 < myEpsNull;
1019 bF2=fabsfd2 < myEpsNull;
1022 tr=FindSimpleRoot(2, t1, t2, fd1);
1023 DistanceFunction(tr);
1025 myParallel=Standard_False;
1032 myParallel=Standard_False;
1039 myParallel=Standard_False;
1045 //=======================================================================
1046 //function : RemoveIdenticalRoots
1048 //=======================================================================
1049 void IntTools_EdgeFace::RemoveIdenticalRoots()
1051 Standard_Integer aNbRoots, j, k;
1053 aNbRoots=mySequenceOfRoots.Length();
1054 for (j=1; j<=aNbRoots; j++) {
1055 const IntTools_Root& aRj=mySequenceOfRoots(j);
1056 for (k=j+1; k<=aNbRoots; k++) {
1057 const IntTools_Root& aRk=mySequenceOfRoots(k);
1059 Standard_Real aTj, aTk, aDistance;
1068 aDistance=aPj.Distance(aPk);
1069 if (aDistance < myCriteria) {
1070 mySequenceOfRoots.Remove(k);
1071 aNbRoots=mySequenceOfRoots.Length();
1077 //=======================================================================
1078 //function : CheckTouch
1080 //=======================================================================
1081 Standard_Boolean IntTools_EdgeFace::CheckTouch
1082 (const IntTools_CommonPrt& aCP,
1085 Standard_Real aTF, aTL, Tol, U1f, U1l, V1f, V1l, af, al,aDist2, aMinDist2;
1086 Standard_Boolean theflag=Standard_False;
1087 Standard_Integer aNbExt, i, iLower ;
1089 aCP.Range1(aTF, aTL);
1093 aCR=myC.Resolution(myCriteria);
1094 if((Abs(aTF - myRange.First()) < aCR) &&
1095 (Abs(aTL - myRange.Last()) < aCR)) {
1096 return theflag; // EDGE
1100 Tol = Precision::PConfusion();
1102 const Handle(Geom_Curve)& Curve =BRep_Tool::Curve (myC.Edge(), af, al);
1103 const Handle(Geom_Surface)& Surface=BRep_Tool::Surface(myS.Face());
1104 // Surface->Bounds(U1f,U1l,V1f,V1l);
1105 U1f = myS.FirstUParameter();
1106 U1l = myS.LastUParameter();
1107 V1f = myS.FirstVParameter();
1108 V1l = myS.LastVParameter();
1110 GeomAdaptor_Curve TheCurve (Curve,aTF, aTL);
1111 GeomAdaptor_Surface TheSurface (Surface, U1f, U1l, V1f, V1l);
1113 Extrema_ExtCS anExtrema (TheCurve, TheSurface, Tol, Tol);
1117 if(anExtrema.IsDone()) {
1120 if(!anExtrema.IsParallel()) {
1121 aNbExt=anExtrema.NbExt();
1125 for (i=1; i<=aNbExt; i++) {
1126 aDist2=anExtrema.SquareDistance(i);
1127 if (aDist2 < aMinDist2) {
1132 aDist2=anExtrema.SquareDistance(iLower);
1133 Extrema_POnCurv aPOnC;
1134 Extrema_POnSurf aPOnS;
1135 anExtrema.Points(iLower, aPOnC, aPOnS);
1136 aTx=aPOnC.Parameter();
1139 // modified by NIZHNY-MKK Thu Jul 21 11:35:32 2005.BEGIN
1140 IntCurveSurface_HInter anExactIntersector;
1142 Handle(GeomAdaptor_HCurve) aCurve = new GeomAdaptor_HCurve(TheCurve);
1143 Handle(GeomAdaptor_HSurface) aSurface = new GeomAdaptor_HSurface(TheSurface);
1145 anExactIntersector.Perform(aCurve, aSurface);
1147 if(anExactIntersector.IsDone()) {
1148 Standard_Integer i = 0;
1150 for(i = 1; i <= anExactIntersector.NbPoints(); i++) {
1151 const IntCurveSurface_IntersectionPoint& aPoint = anExactIntersector.Point(i);
1153 if((aPoint.W() >= aTF) && (aPoint.W() <= aTL)) {
1159 // modified by NIZHNY-MKK Thu Jul 21 11:35:40 2005.END
1167 Standard_Real aBoundaryDist;
1169 aBoundaryDist = DistanceFunction(aTF) + myCriteria;
1170 if(aBoundaryDist * aBoundaryDist < aDist2) {
1171 aDist2 = aBoundaryDist * aBoundaryDist;
1175 aBoundaryDist = DistanceFunction(aTL) + myCriteria;
1176 if(aBoundaryDist * aBoundaryDist < aDist2) {
1177 aDist2 = aBoundaryDist * aBoundaryDist;
1181 Standard_Real aParameter = (aTF + aTL) * 0.5;
1182 aBoundaryDist = DistanceFunction(aParameter) + myCriteria;
1183 if(aBoundaryDist * aBoundaryDist < aDist2) {
1184 aDist2 = aBoundaryDist * aBoundaryDist;
1188 if(aDist2 > myCriteria * myCriteria) {
1192 if (fabs (aTx-aTF) < myEpsT) {
1196 if (fabs (aTx-aTL) < myEpsT) {
1200 if (aTx>aTF && aTx<aTL) {
1206 //=======================================================================
1207 //function : Perform
1209 //=======================================================================
1210 void IntTools_EdgeFace::Perform()
1212 Standard_Integer i, aNb;
1213 IntTools_CommonPrt aCommonPrt;
1215 aCommonPrt.SetEdge1(myEdge);
1219 if (myErrorStatus) {
1223 if (myContext.IsNull()) {
1224 myContext=new IntTools_Context;
1227 myIsDone = Standard_False;
1228 myC.Initialize(myEdge);
1229 GeomAbs_CurveType aCurveType;
1230 aCurveType=myC.GetType();
1232 // Prepare myCriteria
1233 if (aCurveType==GeomAbs_BSplineCurve||
1234 aCurveType==GeomAbs_BezierCurve) {
1236 Standard_Real diff1 = (myTolE/myTolF);
1237 Standard_Real diff2 = (myTolF/myTolE);
1238 if( diff1 > 100 || diff2 > 100 ) {
1239 myCriteria = Max(myTolE,myTolF);
1242 myCriteria=1.5*myTolE+myTolF;
1245 myCriteria=myTolE+myTolF;
1248 myTmin=myRange.First();
1249 myTmax=myRange.Last();
1251 myS.Initialize (myFace,Standard_True);
1253 if(myContext.IsNull()) {
1254 myFClass2d.Init(myFace, 1.e-6);
1257 IntTools_BeanFaceIntersector anIntersector(myC, myS, myTolE, myTolF);
1258 anIntersector.SetBeanParameters(myRange.First(), myRange.Last());
1260 anIntersector.SetContext(myContext);
1262 anIntersector.Perform();
1264 if(!anIntersector.IsDone()) {
1268 for(Standard_Integer r = 1; r <= anIntersector.Result().Length(); r++) {
1269 const IntTools_Range& aRange = anIntersector.Result().Value(r);
1271 if(IsProjectable(IntTools_Tools::IntermediatePoint(aRange.First(), aRange.Last()))) {
1272 aCommonPrt.SetRange1(aRange.First(), aRange.Last());
1273 mySeqOfCommonPrts.Append(aCommonPrt);
1277 aNb = mySeqOfCommonPrts.Length();
1279 for (i=1; i<=aNb; i++) {
1280 IntTools_CommonPrt& aCP=mySeqOfCommonPrts.ChangeValue(i);
1282 Standard_Real aTx1, aTx2;
1285 aCP.Range1(aTx1, aTx2);
1288 aCP.SetBoundingPoints(aPx1, aPx2);
1293 // Line\Cylinder's Common Parts treatement
1294 GeomAbs_CurveType aCType;
1295 GeomAbs_SurfaceType aSType;
1296 TopAbs_ShapeEnum aType;
1297 Standard_Boolean bIsTouch;
1300 aCType=myC.GetType();
1301 aSType=myS.GetType();
1303 if (aCType==GeomAbs_Line && aSType==GeomAbs_Cylinder) {
1304 for (i=1; i<=aNb; i++) {
1305 IntTools_CommonPrt& aCP=mySeqOfCommonPrts(i);
1307 if (aType==TopAbs_EDGE) {
1308 bIsTouch=CheckTouch (aCP, aTx);
1310 aCP.SetType(TopAbs_VERTEX);
1311 aCP.SetVertexParameter1(aTx);
1312 aCP.SetRange1 (aTx, aTx);
1315 if (aType==TopAbs_VERTEX) {
1316 bIsTouch=CheckTouchVertex (aCP, aTx);
1318 aCP.SetVertexParameter1(aTx);
1319 aCP.SetRange1 (aTx, aTx);
1325 // Circle\Plane's Common Parts treatement
1327 if (aCType==GeomAbs_Circle && aSType==GeomAbs_Plane) {
1328 Standard_Boolean bIsCoplanar, bIsRadius;
1329 bIsCoplanar=IsCoplanar(myC, myS);
1330 bIsRadius=IsRadius(myC, myS);
1331 if (!bIsCoplanar && !bIsRadius) {
1332 for (i=1; i<=aNb; i++) {
1333 IntTools_CommonPrt& aCP=mySeqOfCommonPrts(i);
1335 if (aType==TopAbs_EDGE) {
1336 bIsTouch=CheckTouch (aCP, aTx);
1338 aCP.SetType(TopAbs_VERTEX);
1339 aCP.SetVertexParameter1(aTx);
1340 aCP.SetRange1 (aTx, aTx);
1347 myIsDone=Standard_True;
1352 // 1 - the method Perform() is not invoked
1353 // 2,3,4,5 -the method CheckData() fails
1354 // 6 - PrepareArgs() problems
1355 // 7 - No Projectable ranges
1356 // 8,9 - PrepareArgs() problems occured inside projectable Ranges
1357 // 11 - can't fill array aFunc(i) in PrepareArgsFuncArrays
1360 //=======================================================================
1361 //function : CheckTouch
1363 //=======================================================================
1364 Standard_Boolean IntTools_EdgeFace::CheckTouchVertex
1365 (const IntTools_CommonPrt& aCP,
1368 Standard_Real aTF, aTL, Tol, U1f,U1l,V1f,V1l, af, al,aDist2, aMinDist2, aTm, aDist2New;
1369 Standard_Real aEpsT;
1370 Standard_Boolean theflag=Standard_False;
1371 Standard_Integer aNbExt, i, iLower ;
1373 aCP.Range1(aTF, aTL);
1376 aDist2=DistanceFunction(aTm);
1379 Tol = Precision::PConfusion();
1381 const Handle(Geom_Curve)& Curve =BRep_Tool::Curve (myC.Edge(), af, al);
1382 const Handle(Geom_Surface)& Surface=BRep_Tool::Surface(myS.Face());
1384 Surface->Bounds(U1f,U1l,V1f,V1l);
1386 GeomAdaptor_Curve TheCurve (Curve,aTF, aTL);
1387 GeomAdaptor_Surface TheSurface (Surface, U1f, U1l, V1f, V1l);
1389 Extrema_ExtCS anExtrema (TheCurve, TheSurface, Tol, Tol);
1391 if(!anExtrema.IsDone()) {
1394 if (anExtrema.IsParallel()) {
1398 aNbExt=anExtrema.NbExt() ;
1405 for (i=1; i<=aNbExt; ++i) {
1406 aDist2=anExtrema.SquareDistance(i);
1407 if (aDist2 < aMinDist2) {
1413 aDist2New=anExtrema.SquareDistance(iLower);
1415 if (aDist2New > aDist2) {
1420 if (aDist2New > myCriteria * myCriteria) {
1424 Extrema_POnCurv aPOnC;
1425 Extrema_POnSurf aPOnS;
1426 anExtrema.Points(iLower, aPOnC, aPOnS);
1429 aTx=aPOnC.Parameter();
1431 if (fabs (aTx-aTF) < aEpsT) {
1435 if (fabs (aTx-aTL) < aEpsT) {
1439 if (aTx>aTF && aTx<aTL) {
1447 //=======================================================================
1448 //function : IsCoplanar
1450 //=======================================================================
1451 Standard_Boolean IsCoplanar (const BRepAdaptor_Curve& aCurve ,
1452 const BRepAdaptor_Surface& aSurface)
1454 Standard_Boolean bFlag=Standard_False;
1456 GeomAbs_CurveType aCType;
1457 GeomAbs_SurfaceType aSType;
1459 aCType=aCurve.GetType();
1460 aSType=aSurface.GetType();
1462 if (aCType==GeomAbs_Circle && aSType==GeomAbs_Plane) {
1463 gp_Circ aCirc=aCurve.Circle();
1464 const gp_Ax1& anAx1=aCirc.Axis();
1465 const gp_Dir& aDirAx1=anAx1.Direction();
1467 gp_Pln aPln=aSurface.Plane();
1468 const gp_Ax1& anAx=aPln.Axis();
1469 const gp_Dir& aDirPln=anAx.Direction();
1471 bFlag=IntTools_Tools::IsDirsCoinside(aDirAx1, aDirPln);
1475 //=======================================================================
1476 //function : IsRadius
1478 //=======================================================================
1479 Standard_Boolean IsRadius (const BRepAdaptor_Curve& aCurve ,
1480 const BRepAdaptor_Surface& aSurface)
1482 Standard_Boolean bFlag=Standard_False;
1484 GeomAbs_CurveType aCType;
1485 GeomAbs_SurfaceType aSType;
1487 aCType=aCurve.GetType();
1488 aSType=aSurface.GetType();
1490 if (aCType==GeomAbs_Circle && aSType==GeomAbs_Plane) {
1491 gp_Circ aCirc=aCurve.Circle();
1492 const gp_Pnt aCenter=aCirc.Location();
1493 Standard_Real aR=aCirc.Radius();
1494 gp_Pln aPln=aSurface.Plane();
1495 Standard_Real aD=aPln.Distance(aCenter);
1496 if (fabs (aD-aR) < 1.e-7) {
1503 //=======================================================================
1504 //function : AdaptiveDiscret
1506 //=======================================================================
1507 Standard_Integer AdaptiveDiscret (const Standard_Integer iDiscret,
1508 const BRepAdaptor_Curve& aCurve ,
1509 const BRepAdaptor_Surface& aSurface)
1511 Standard_Integer iDiscretNew;
1513 iDiscretNew=iDiscret;
1515 GeomAbs_SurfaceType aSType;
1517 aSType=aSurface.GetType();
1519 if (aSType==GeomAbs_Cylinder) {
1520 Standard_Real aELength, aRadius, dLR;
1522 aELength=IntTools::Length(aCurve.Edge());
1524 gp_Cylinder aCylinder=aSurface.Cylinder();
1525 aRadius=aCylinder.Radius();
1528 iDiscretNew=(Standard_Integer)(aELength/dLR);
1530 if (iDiscretNew<iDiscret) {
1531 iDiscretNew=iDiscret;
1540 #pragma warning ( default : 4101 )