1 // File: IntTools_EdgeFace.cxx
2 // Created: Mon Feb 26 10:23:38 2001
3 // Author: Peter KURNEV
7 #include <IntTools_EdgeFace.ixx>
11 #include <IntTools_CArray1OfReal.hxx>
12 #include <IntTools.hxx>
13 #include <IntTools_CArray1OfInteger.hxx>
14 #include <IntTools_Range.hxx>
15 #include <IntTools_Tools.hxx>
16 #include <IntTools_Array1OfRange.hxx>
17 #include <IntTools_QuickSortRange.hxx>
18 #include <IntTools_CompareRange.hxx>
19 #include <IntTools_CommonPrt.hxx>
20 #include <IntTools_Root.hxx>
21 #include <IntTools_BeanFaceIntersector.hxx>
22 #include <IntTools_Context.hxx>
24 #include <BRep_Tool.hxx>
26 #include <GeomAdaptor_Surface.hxx>
27 #include <GeomAdaptor_Curve.hxx>
29 #include <Geom_Surface.hxx>
30 #include <Geom_Curve.hxx>
32 #include <GeomAPI_ProjectPointOnSurf.hxx>
34 #include <Precision.hxx>
36 #include <Bnd_Box.hxx>
37 #include <BndLib_AddSurface.hxx>
39 #include <gp_Cylinder.hxx>
42 #include <gp_Cone.hxx>
43 #include <gp_Torus.hxx>
44 #include <gp_Circ.hxx>
48 #include <Extrema_ExtCS.hxx>
49 #include <Extrema_POnCurv.hxx>
50 #include <Extrema_POnSurf.hxx>
52 // modified by NIZHNY-MKK Thu Jul 21 11:35:59 2005
53 #include <IntCurveSurface_HInter.hxx>
54 #include <GeomAdaptor_HCurve.hxx>
55 #include <GeomAdaptor_HSurface.hxx>
56 #include <IntCurveSurface_IntersectionPoint.hxx>
59 #pragma warning ( disable : 4101 )
63 Standard_Boolean IsCoplanar (const BRepAdaptor_Curve& ,
64 const BRepAdaptor_Surface& );
66 Standard_Boolean IsRadius (const BRepAdaptor_Curve& aCurve ,
67 const BRepAdaptor_Surface& aSurface);
69 Standard_Integer AdaptiveDiscret (const Standard_Integer iDiscret,
70 const BRepAdaptor_Curve& aCurve ,
71 const BRepAdaptor_Surface& aSurface);
73 //=======================================================================
74 //function : IntTools_EdgeFace::IntTools_EdgeFace
76 //=======================================================================
77 IntTools_EdgeFace::IntTools_EdgeFace()
85 myIsDone=Standard_False;
87 myParallel=Standard_False;
92 //=======================================================================
95 //=======================================================================
96 void IntTools_EdgeFace::SetEdge(const TopoDS_Edge& anEdge)
101 //=======================================================================
104 //=======================================================================
105 void IntTools_EdgeFace::SetFace(const TopoDS_Face& aFace)
110 //=======================================================================
113 //=======================================================================
114 void IntTools_EdgeFace::SetTolE(const Standard_Real aTol)
118 //=======================================================================
121 //=======================================================================
122 void IntTools_EdgeFace::SetTolF(const Standard_Real aTol)
127 //=======================================================================
128 //function : SetDiscretize
130 //=======================================================================
131 void IntTools_EdgeFace::SetDiscretize(const Standard_Integer aDiscret)
135 //=======================================================================
136 //function : SetDeflection
138 //=======================================================================
139 void IntTools_EdgeFace::SetDeflection(const Standard_Real aDefl)
143 //=======================================================================
144 //function : SetEpsilonT
146 //=======================================================================
147 void IntTools_EdgeFace::SetEpsilonT(const Standard_Real anEpsT)
151 //=======================================================================
152 //function : SetEpsilonNull
154 //=======================================================================
155 void IntTools_EdgeFace::SetEpsilonNull(const Standard_Real anEpsNull)
160 //=======================================================================
161 //function : SetRange
163 //=======================================================================
164 void IntTools_EdgeFace::SetRange(const Standard_Real aFirst,
165 const Standard_Real aLast)
167 myRange.SetFirst (aFirst);
168 myRange.SetLast (aLast);
171 //=======================================================================
172 //function : SetRange
174 //=======================================================================
175 void IntTools_EdgeFace::SetRange(const IntTools_Range& aRange)
177 myRange.SetFirst (aRange.First());
178 myRange.SetLast (aRange.Last());
180 //=======================================================================
183 //=======================================================================
184 Standard_Boolean IntTools_EdgeFace::IsDone()const
188 //=======================================================================
189 //function : ErrorStatus
191 //=======================================================================
192 Standard_Integer IntTools_EdgeFace::ErrorStatus()const
194 return myErrorStatus;
196 //=======================================================================
197 //function : CommonParts
199 //=======================================================================
200 const IntTools_SequenceOfCommonPrts& IntTools_EdgeFace::CommonParts() const
202 return mySeqOfCommonPrts;
204 //=======================================================================
207 //=======================================================================
208 const IntTools_Range& IntTools_EdgeFace::Range() const
213 //=======================================================================
214 //function : CheckData
216 //=======================================================================
217 void IntTools_EdgeFace::CheckData()
219 if (BRep_Tool::Degenerated(myEdge)) {
222 if (!BRep_Tool::IsGeometric(myEdge)) {
228 //=======================================================================
231 //=======================================================================
232 void IntTools_EdgeFace::Prepare()
234 Standard_Integer pri;
235 IntTools_CArray1OfReal aPars;
238 // 1.Prepare Curve's data and Surface's data
239 myC.Initialize(myEdge);
240 GeomAbs_CurveType aCurveType;
241 aCurveType=myC.GetType();
243 // 2.Prepare myCriteria
244 if (aCurveType==GeomAbs_BSplineCurve||
245 aCurveType==GeomAbs_BezierCurve) {
246 myCriteria=1.5*myTolE+myTolF;
249 myCriteria=myTolE+myTolF;
251 // 2.a myTmin, myTmax
252 myTmin=myRange.First();
253 myTmax=myRange.Last();
255 myS.Initialize (myFace,Standard_True);
256 myFClass2d.Init(myFace, 1.e-6);
258 // 2.c Prepare adaptive myDiscret
259 myDiscret=AdaptiveDiscret(myDiscret, myC, myS);
263 pri = IntTools::PrepareArgs(myC, myTmax, myTmin, myDiscret, myDeflection, aPars);
270 Standard_Integer i, iProj, aNb, aNbProj, ind0, ind1;
271 Standard_Real t0, t1, tRoot;
274 // Table of Projection's function values
276 IntTools_CArray1OfInteger anArrProjectability;
277 anArrProjectability.Resize(aNb);
279 for (iProj=0, i=0; i<aNb; i++) {
281 aNbProj=IsProjectable (t0);
283 anArrProjectability(i)=0;
285 anArrProjectability(i)=1;
297 // Projectable Ranges
298 IntTools_Range aRange;
300 ind0=anArrProjectability(0);
306 for(i=1; i<aNb; i++) {
307 ind1=anArrProjectability(i);
314 myProjectableRanges.Append(aRange);
317 FindProjectableRoot(t0, t1, ind0, ind1, tRoot);
318 aRange.SetFirst(tRoot);
320 myProjectableRanges.Append(aRange);
324 FindProjectableRoot(t0, t1, ind0, ind1, tRoot);
325 aRange.SetLast(tRoot);
326 myProjectableRanges.Append(aRange);
333 FindProjectableRoot(t0, t1, ind0, ind1, tRoot);
336 aRange.SetLast(tRoot);
337 myProjectableRanges.Append(aRange);
340 aRange.SetFirst(tRoot);
342 } // if (ind0 != ind1)
344 } // for(i=1; i<aNb; i++) {
347 //=======================================================================
348 //function : FindProjectableRoot
350 //=======================================================================
351 void IntTools_EdgeFace::FindProjectableRoot (const Standard_Real tt1,
352 const Standard_Real tt2,
353 const Standard_Integer ff1,
354 const Standard_Integer ff2,
355 Standard_Real& tRoot)
357 Standard_Real tm, t1, t2, aEpsT;
358 Standard_Integer anIsProj1, anIsProj2, anIsProjm;
361 // Root is inside [tt1, tt2]
368 if (fabs(t1-t2) < aEpsT) {
369 tRoot=(anIsProj1) ? t1 : t2;
373 anIsProjm=IsProjectable(tm);
375 if (anIsProjm != anIsProj1) {
385 //=======================================================================
386 //function : IsProjectable
388 //=======================================================================
389 Standard_Boolean IntTools_EdgeFace::IsProjectable(const Standard_Real t) const
391 Standard_Boolean bFlag;
392 Standard_Real Umin, Usup, Vmin, Vsup;
394 const Handle(Geom_Surface)& GS=BRep_Tool::Surface(myFace);
395 Umin=myS.FirstUParameter();
396 Usup=myS.LastUParameter();
397 Vmin=myS.FirstVParameter();
398 Vsup=myS.LastVParameter ();
402 GeomAPI_ProjectPointOnSurf aProjector;
404 Standard_Real ULD, VLD;
406 if(myContext == NULL) {
407 aProjector.Init(P, GS, Umin, Usup, Vmin, Vsup, myEpsT);
408 bFlag=aProjector.IsDone();
411 aProjector.LowerDistanceParameters(ULD, VLD);
415 GeomAPI_ProjectPointOnSurf& aLocProj = myContext->ProjPS(myFace);
417 bFlag = aLocProj.IsDone();
420 aLocProj.LowerDistanceParameters(ULD, VLD);
426 bFlag=Standard_False;
430 gp_Pnt2d aP2d(ULD, VLD);
432 if(myContext == NULL) {
433 aState=myFClass2d.Perform(aP2d);
436 aState = myContext->FClass2d(myFace).Perform(aP2d);
440 if (aState==TopAbs_IN || aState==TopAbs_ON) {
447 //=======================================================================
448 //function : DistanceFunction
450 //=======================================================================
451 Standard_Real IntTools_EdgeFace::DistanceFunction(const Standard_Real t)
453 Standard_Real Umin, Usup, Vmin, Vsup, aD;
458 Standard_Boolean bIsEqDistance;
460 bIsEqDistance= IntTools_EdgeFace::IsEqDistance(P, myS, 1.e-7, aD);
466 const Handle(Geom_Surface)& GS=BRep_Tool::Surface(myFace);
468 Umin=myS.FirstUParameter();
469 Usup=myS.LastUParameter();
470 Vmin=myS.FirstVParameter();
471 Vsup=myS.LastVParameter ();
474 Standard_Boolean bFlag = Standard_False;
476 if(myContext == NULL) {
477 GeomAPI_ProjectPointOnSurf aProjector;
478 aProjector.Init(P, GS, Umin, Usup, Vmin, Vsup, myEpsT);
479 bFlag=aProjector.IsDone();
482 aD=aProjector.LowerDistance();
486 GeomAPI_ProjectPointOnSurf& aLocProj = myContext->ProjPS(myFace);
488 bFlag = aLocProj.IsDone();
491 aD = aLocProj.LowerDistance();
502 // aD=aProjector.LowerDistance();
508 //=======================================================================
509 //function : IsEqDistance
511 //=======================================================================
512 Standard_Boolean IntTools_EdgeFace::IsEqDistance(const gp_Pnt& aP,
513 const BRepAdaptor_Surface& aBAS,
514 const Standard_Real aTol,
517 Standard_Boolean bRetFlag=Standard_True;
519 GeomAbs_SurfaceType aSurfType=aBAS.GetType();
521 if (aSurfType==GeomAbs_Cylinder) {
522 gp_Cylinder aCyl=aBAS.Cylinder();
523 const gp_Ax1& anAx1 =aCyl.Axis();
524 gp_Lin aLinAxis(anAx1);
525 Standard_Real aDC, aRadius=aCyl.Radius();
526 aDC=aLinAxis.Distance(aP);
533 if (aSurfType==GeomAbs_Cone) {
534 gp_Cone aCone=aBAS.Cone();
535 const gp_Ax1& anAx1 =aCone.Axis();
536 gp_Lin aLinAxis(anAx1);
537 Standard_Real aDC, aRadius, aDS, aSemiAngle;
538 aDC=aLinAxis.Distance(aP);
540 gp_Pnt anApex=aCone.Apex();
541 aSemiAngle=aCone.SemiAngle();
542 aDS=aP.Distance(anApex);
544 aRadius=aDS*tan(aSemiAngle);
550 if (aSurfType==GeomAbs_Torus) {
551 Standard_Real aMajorRadius, aMinorRadius, aDC;
553 gp_Torus aTorus=aBAS.Torus();
554 gp_Pnt aPLoc=aTorus.Location();
555 aMajorRadius=aTorus.MajorRadius();
557 aDC=fabs(aPLoc.Distance(aP)-aMajorRadius);
559 aMinorRadius=aTorus.MinorRadius();
567 //=======================================================================
568 //function : PrepareArgsFuncArrays
570 // myFuncArray and myArgsArray for the interval [ta, tb]
571 //=======================================================================
572 void IntTools_EdgeFace::PrepareArgsFuncArrays(const Standard_Real ta,
573 const Standard_Real tb)
575 IntTools_CArray1OfReal anArgs, aFunc;
576 Standard_Integer i, aNb, pri;
577 Standard_Real t, f, f1;
579 // Prepare values of arguments for the interval [ta, tb]
580 pri=IntTools::PrepareArgs (myC, tb, ta, myDiscret, myDeflection, anArgs);
594 // Prepare values of functions for the interval [ta, tb]
596 for (i=0; i<aNb; i++) {
598 f1=DistanceFunction(t);
601 if (myErrorStatus==11)
604 if (f1 < myEpsNull) {
610 // Add points where the derivative = 0
611 AddDerivativePoints(anArgs, aFunc);
616 //=======================================================================
617 //function : AddDerivativePoints
619 //=======================================================================
620 void IntTools_EdgeFace::AddDerivativePoints(const IntTools_CArray1OfReal& t,
621 const IntTools_CArray1OfReal& f)
623 Standard_Integer i, j, n, k, nn=100;
624 Standard_Real fr, tr, tr1, dEpsNull=10.*myEpsNull;
625 IntTools_CArray1OfReal fd;
626 TColStd_SequenceOfReal aTSeq, aFSeq;
631 // Table of derivatives
632 Standard_Real dfx, tx, tx1, fx, fx1, dt=1.e-6;
637 fx1=DistanceFunction(tx1);
639 if (fx1 < myEpsNull) {
645 if (fabs(fd(0)) < dEpsNull){
651 for (i=1; i<k; i++) {
652 Standard_Real ti, ti1;
655 fd(i)=.5*(f(i+1)-f(i-1))/(t(i)-t(i-1));
656 if (fabs(fd(i)) < dEpsNull){
664 fx1=DistanceFunction(tx1);
666 if (fx1 < myEpsNull) {
672 if (fabs(fd(n-1)) < dEpsNull){
676 // Finding the range where the derivatives have different signs
677 // for neighbouring points
678 for (i=1; i<n; i++) {
679 Standard_Real fd1, fd2, t1, t2;
686 if (fabs(fd1) < myEpsNull) {
688 fr=DistanceFunction(tr);//fd1;
690 else if (fabs(fd2) < myEpsNull) {
692 fr=DistanceFunction(tr);
695 tr=FindSimpleRoot(2, t1, t2, fd1);
696 fr=DistanceFunction(tr);
702 } // end of for (i=1; i<n; i++)
704 // remove identical t, f
707 for (i=1; i<=aTSeq.Length(); i++) {
709 for (j=0; j<n; j++) {
711 if (fabs (tr1-tr) < myEpsT) {
720 // sorting args and funcs in increasing order
723 IntTools_Array1OfRange anArray1OfRange(1, k);
724 for (i=1; i<=n; i++) {
725 anArray1OfRange(i).SetFirst(t(i-1));
726 anArray1OfRange(i).SetLast (f(i-1));
728 for (i=1; i<=nn; i++) {
729 anArray1OfRange(n+i).SetFirst(aTSeq(i));
730 anArray1OfRange(n+i).SetLast (aFSeq(i));
733 IntTools_QuickSortRange aQuickSortRange;
734 IntTools_CompareRange aComparator;
735 aQuickSortRange.Sort (anArray1OfRange, aComparator);
737 // filling the output arrays
738 myArgsArray.Resize(k);
739 myFuncArray.Resize(k);
740 for (i=1; i<=k; i++) {
741 myArgsArray(i-1)=anArray1OfRange(i).First();
742 myFuncArray(i-1)=anArray1OfRange(i).Last ();
747 myArgsArray.Resize(n);
748 myFuncArray.Resize(n);
749 for (i=0; i<n; i++) {
756 //=======================================================================
757 //function : DerivativeFunction
759 //=======================================================================
760 Standard_Real IntTools_EdgeFace::DerivativeFunction(const Standard_Real t2)
762 Standard_Real t1, t3, aD1, aD2, aD3;
763 Standard_Real dt=1.e-9;
765 aD1=DistanceFunction(t1);
767 aD3=DistanceFunction(t3);
773 //=======================================================================
774 //function : FindSimpleRoot
775 //purpose : [private]
776 //=======================================================================
777 Standard_Real IntTools_EdgeFace::FindSimpleRoot (const Standard_Integer IP,
778 const Standard_Real tA,
779 const Standard_Real tB,
780 const Standard_Real fA)
782 Standard_Real r, a, b, y, x0, s;
790 y=DistanceFunction(x0);
792 y=DerivativeFunction(x0);
794 if (fabs(b-a) < myEpsT || y==0.) {
811 //=======================================================================
812 //function : FindGoldRoot
813 //purpose : [private]
814 //=======================================================================
815 Standard_Real IntTools_EdgeFace::FindGoldRoot (const Standard_Real tA,
816 const Standard_Real tB,
817 const Standard_Real coeff)
819 Standard_Real gs=0.61803399;
820 Standard_Real a, b, xp, xl, yp, yl;
826 yp=coeff*DistanceFunction(xp);
827 yl=coeff*DistanceFunction(xl);
832 if (fabs(b-a) < myEpsT) {
840 yp=coeff*DistanceFunction(xp);
848 yl=coeff*DistanceFunction(xl);
853 //=======================================================================
854 //function : MakeType
856 //=======================================================================
857 Standard_Integer IntTools_EdgeFace::MakeType(IntTools_CommonPrt& aCommonPrt)
859 Standard_Real af1, al1;
860 Standard_Real dt, df1, df2, tm;
861 Standard_Boolean bAllNullFlag;
863 bAllNullFlag=aCommonPrt.AllNullFlag();
865 aCommonPrt.SetType(TopAbs_EDGE);
869 aCommonPrt.Range1(af1, al1);
875 df1=aPF.Distance(aPL);
876 Standard_Boolean isWholeRange = Standard_False;
878 if((Abs(af1 - myRange.First()) < myC.Resolution(myCriteria)) &&
879 (Abs(al1 - myRange.Last()) < myC.Resolution(myCriteria)))
880 isWholeRange = Standard_True;
883 if ((df1 > myCriteria * 2.) && isWholeRange) {
884 aCommonPrt.SetType(TopAbs_EDGE);
888 tm = (af1 + al1) * 0.5;
890 if(aPF.Distance(myC.Value(tm)) > myCriteria * 2.) {
891 aCommonPrt.SetType(TopAbs_EDGE);
896 if(!CheckTouch(aCommonPrt, tm)) {
897 tm = (af1 + al1) * 0.5;
899 aCommonPrt.SetType(TopAbs_VERTEX);
900 aCommonPrt.SetVertexParameter1(tm);
901 aCommonPrt.SetRange1 (af1, al1);
912 df1=aPF.Distance(aPL);
913 if (df1<myCriteria) {
916 aCommonPrt.SetType(TopAbs_VERTEX);
917 aCommonPrt.SetVertexParameter1(tm);
918 aCommonPrt.SetRange1 (af1, al1);
923 IsIntersection (af1, al1);
926 aCommonPrt.SetType(TopAbs_VERTEX);
927 aCommonPrt.SetVertexParameter1(myPar1);
928 aCommonPrt.SetRange1 (af1, al1);
933 df1=DistanceFunction(af1);
934 df2=DistanceFunction(al1);
935 tm=(df1 < df2) ? af1 : al1;
936 aCommonPrt.SetType(TopAbs_VERTEX);
937 aCommonPrt.SetVertexParameter1(tm);
938 aCommonPrt.SetRange1 (af1, al1);
942 aCommonPrt.SetType(TopAbs_EDGE);
949 //=======================================================================
950 //function : IsIntersection
952 //=======================================================================
953 void IntTools_EdgeFace::IsIntersection (const Standard_Real ta,
954 const Standard_Real tb)
956 IntTools_CArray1OfReal anArgs, aFunc;
957 Standard_Integer i, aNb, pri, aCnt=0;
959 Standard_Integer aCntIncreasing=1, aCntDecreasing=1;
960 Standard_Real t, f, f1;
962 // Prepare values of arguments for the interval [ta, tb]
963 pri=IntTools::PrepareArgs (myC, tb, ta, myDiscret, myDeflection, anArgs);
967 for (i=0; i<aNb; i++) {
970 f1=DistanceFunction(t);
973 if (fabs(f1) < myEpsNull) {
980 if (aFunc(i)>aFunc(i-1)) {
983 if (aFunc(i)<aFunc(i-1)) {
991 myParallel=Standard_True;
995 FindDerivativeRoot(anArgs, aFunc);
999 if (!(myC.GetType()==GeomAbs_Line
1001 myS.GetType()==GeomAbs_Cylinder)) {
1002 if (aCntDecreasing==aNb) {
1003 myPar1=anArgs(aNb-1);
1004 myParallel=Standard_False;
1006 if (aCntIncreasing==aNb) {
1008 myParallel=Standard_False;
1016 //=======================================================================
1017 //function : FindDerivativeRoot
1019 //=======================================================================
1020 void IntTools_EdgeFace::FindDerivativeRoot(const IntTools_CArray1OfReal& t,
1021 const IntTools_CArray1OfReal& f)
1023 Standard_Integer i, n, k;
1024 Standard_Real fr, tr;
1025 IntTools_CArray1OfReal fd;
1026 TColStd_SequenceOfReal aTSeq, aFSeq;
1029 myParallel=Standard_True;
1034 // Table of derivatives
1035 fd(0)=(f(1)-f(0))/(t(1)-t(0));
1036 if (fabs(fd(0)) < myEpsNull) {
1041 for (i=1; i<k; i++) {
1042 fd(i)=.5*(f(i+1)-f(i-1))/(t(i)-t(i-1));
1043 if (fabs(fd(i)) < myEpsNull) {
1048 fd(n-1)=(f(n-1)-f(n-2))/(t(n-1)-t(n-2));
1049 if (fabs(fd(n-1)) < myEpsNull) {
1053 // Finding the range where the derivatives have different signs
1054 // for neighbouring points
1055 for (i=1; i<n; i++) {
1056 Standard_Real fd1, fd2, t1, t2, fabsfd1, fabsfd2;
1057 Standard_Boolean bF1, bF2;
1064 bF1=fabsfd1 < myEpsNull;
1067 bF2=fabsfd2 < myEpsNull;
1070 tr=FindSimpleRoot(2, t1, t2, fd1);
1071 fr=DistanceFunction(tr);
1073 myParallel=Standard_False;
1081 myParallel=Standard_False;
1089 myParallel=Standard_False;
1095 //=======================================================================
1096 //function : RemoveIdenticalRoots
1098 //=======================================================================
1099 void IntTools_EdgeFace::RemoveIdenticalRoots()
1101 Standard_Integer aNbRoots, j, k;
1103 aNbRoots=mySequenceOfRoots.Length();
1104 for (j=1; j<=aNbRoots; j++) {
1105 const IntTools_Root& aRj=mySequenceOfRoots(j);
1106 for (k=j+1; k<=aNbRoots; k++) {
1107 const IntTools_Root& aRk=mySequenceOfRoots(k);
1109 Standard_Real aTj, aTk, aDistance;
1118 aDistance=aPj.Distance(aPk);
1119 if (aDistance < myCriteria) {
1120 mySequenceOfRoots.Remove(k);
1121 aNbRoots=mySequenceOfRoots.Length();
1127 //=======================================================================
1128 //function : CheckTouch
1130 //=======================================================================
1131 Standard_Boolean IntTools_EdgeFace::CheckTouch(const IntTools_CommonPrt& aCP,
1134 Standard_Real aTF, aTL, Tol, U1f, U1l, V1f, V1l, af, al,aDist2, aMinDist2;
1135 Standard_Boolean theflag=Standard_False;
1136 Standard_Integer aNbExt, i, iLower ;
1138 aCP.Range1(aTF, aTL);
1142 aCR=myC.Resolution(myCriteria);
1143 if((Abs(aTF - myRange.First()) < aCR) &&
1144 (Abs(aTL - myRange.Last()) < aCR)) {
1145 return theflag; // EDGE
1149 Tol = Precision::PConfusion();
1151 const Handle(Geom_Curve)& Curve =BRep_Tool::Curve (myC.Edge(), af, al);
1152 const Handle(Geom_Surface)& Surface=BRep_Tool::Surface(myS.Face());
1153 // Surface->Bounds(U1f,U1l,V1f,V1l);
1154 U1f = myS.FirstUParameter();
1155 U1l = myS.LastUParameter();
1156 V1f = myS.FirstVParameter();
1157 V1l = myS.LastVParameter();
1159 GeomAdaptor_Curve TheCurve (Curve,aTF, aTL);
1160 GeomAdaptor_Surface TheSurface (Surface, U1f, U1l, V1f, V1l);
1162 Extrema_ExtCS anExtrema (TheCurve, TheSurface, Tol, Tol);
1166 if(anExtrema.IsDone()) {
1169 if(!anExtrema.IsParallel()) {
1170 aNbExt=anExtrema.NbExt();
1174 for (i=1; i<=aNbExt; i++) {
1175 aDist2=anExtrema.SquareDistance(i);
1176 if (aDist2 < aMinDist2) {
1181 aDist2=anExtrema.SquareDistance(iLower);
1182 Extrema_POnCurv aPOnC;
1183 Extrema_POnSurf aPOnS;
1184 anExtrema.Points(iLower, aPOnC, aPOnS);
1185 aTx=aPOnC.Parameter();
1188 // modified by NIZHNY-MKK Thu Jul 21 11:35:32 2005.BEGIN
1189 IntCurveSurface_HInter anExactIntersector;
1191 Handle(GeomAdaptor_HCurve) aCurve = new GeomAdaptor_HCurve(TheCurve);
1192 Handle(GeomAdaptor_HSurface) aSurface = new GeomAdaptor_HSurface(TheSurface);
1194 anExactIntersector.Perform(aCurve, aSurface);
1196 if(anExactIntersector.IsDone()) {
1197 Standard_Integer i = 0;
1199 for(i = 1; i <= anExactIntersector.NbPoints(); i++) {
1200 const IntCurveSurface_IntersectionPoint& aPoint = anExactIntersector.Point(i);
1202 if((aPoint.W() >= aTF) && (aPoint.W() <= aTL)) {
1208 // modified by NIZHNY-MKK Thu Jul 21 11:35:40 2005.END
1216 Standard_Real aBoundaryDist;
1218 aBoundaryDist = DistanceFunction(aTF) + myCriteria;
1219 if(aBoundaryDist * aBoundaryDist < aDist2) {
1220 aDist2 = aBoundaryDist * aBoundaryDist;
1224 aBoundaryDist = DistanceFunction(aTL) + myCriteria;
1225 if(aBoundaryDist * aBoundaryDist < aDist2) {
1226 aDist2 = aBoundaryDist * aBoundaryDist;
1230 Standard_Real aParameter = (aTF + aTL) * 0.5;
1231 aBoundaryDist = DistanceFunction(aParameter) + myCriteria;
1232 if(aBoundaryDist * aBoundaryDist < aDist2) {
1233 aDist2 = aBoundaryDist * aBoundaryDist;
1237 if(aDist2 > myCriteria * myCriteria) {
1241 if (fabs (aTx-aTF) < myEpsT) {
1245 if (fabs (aTx-aTL) < myEpsT) {
1249 if (aTx>aTF && aTx<aTL) {
1256 //=======================================================================
1257 //function : SetContext
1259 //=======================================================================
1260 void IntTools_EdgeFace::SetContext(const IntTools_PContext& theContext)
1262 myContext = theContext;
1265 //=======================================================================
1266 //function : Perform
1268 //=======================================================================
1269 void IntTools_EdgeFace::Perform()
1271 Standard_Integer i, aNb;
1272 IntTools_CommonPrt aCommonPrt;
1273 //IntTools_Root aRoot; // Wng in Gcc 3.0
1276 aCommonPrt.SetEdge1(myEdge);
1284 myIsDone = Standard_False;
1285 myC.Initialize(myEdge);
1286 GeomAbs_CurveType aCurveType;
1287 aCurveType=myC.GetType();
1289 // Prepare myCriteria
1290 if (aCurveType==GeomAbs_BSplineCurve||
1291 aCurveType==GeomAbs_BezierCurve) {
1293 Standard_Real diff1 = (myTolE/myTolF);
1294 Standard_Real diff2 = (myTolF/myTolE);
1295 if( diff1 > 100 || diff2 > 100 ) {
1296 myCriteria = Max(myTolE,myTolF);
1299 myCriteria=1.5*myTolE+myTolF;
1302 myCriteria=myTolE+myTolF;
1305 myTmin=myRange.First();
1306 myTmax=myRange.Last();
1308 myS.Initialize (myFace,Standard_True);
1310 if(myContext == NULL) {
1311 myFClass2d.Init(myFace, 1.e-6);
1314 IntTools_BeanFaceIntersector anIntersector(myC, myS, myTolE, myTolF);
1315 anIntersector.SetBeanParameters(myRange.First(), myRange.Last());
1317 anIntersector.SetContext(myContext);
1319 anIntersector.Perform();
1321 if(!anIntersector.IsDone()) {
1325 for(Standard_Integer r = 1; r <= anIntersector.Result().Length(); r++) {
1326 const IntTools_Range& aRange = anIntersector.Result().Value(r);
1328 if(IsProjectable(IntTools_Tools::IntermediatePoint(aRange.First(), aRange.Last()))) {
1329 aCommonPrt.SetRange1(aRange.First(), aRange.Last());
1330 mySeqOfCommonPrts.Append(aCommonPrt);
1334 aNb = mySeqOfCommonPrts.Length();
1336 for (i=1; i<=aNb; i++) {
1337 IntTools_CommonPrt& aCP=mySeqOfCommonPrts.ChangeValue(i);
1339 Standard_Real aTx1, aTx2;
1342 aCP.Range1(aTx1, aTx2);
1345 aCP.SetBoundingPoints(aPx1, aPx2);
1350 // Line\Cylinder's Common Parts treatement
1351 GeomAbs_CurveType aCType;
1352 GeomAbs_SurfaceType aSType;
1353 TopAbs_ShapeEnum aType;
1354 Standard_Boolean bIsTouch;
1357 aCType=myC.GetType();
1358 aSType=myS.GetType();
1360 if (aCType==GeomAbs_Line && aSType==GeomAbs_Cylinder) {
1361 for (i=1; i<=aNb; i++) {
1362 IntTools_CommonPrt& aCP=mySeqOfCommonPrts(i);
1364 if (aType==TopAbs_EDGE) {
1365 bIsTouch=CheckTouch (aCP, aTx);
1367 aCP.SetType(TopAbs_VERTEX);
1368 aCP.SetVertexParameter1(aTx);
1369 aCP.SetRange1 (aTx, aTx);
1372 if (aType==TopAbs_VERTEX) {
1373 bIsTouch=CheckTouchVertex (aCP, aTx);
1375 aCP.SetVertexParameter1(aTx);
1376 aCP.SetRange1 (aTx, aTx);
1382 // Circle\Plane's Common Parts treatement
1384 if (aCType==GeomAbs_Circle && aSType==GeomAbs_Plane) {
1385 Standard_Boolean bIsCoplanar, bIsRadius;
1386 bIsCoplanar=IsCoplanar(myC, myS);
1387 bIsRadius=IsRadius(myC, myS);
1388 if (!bIsCoplanar && !bIsRadius) {
1389 for (i=1; i<=aNb; i++) {
1390 IntTools_CommonPrt& aCP=mySeqOfCommonPrts(i);
1392 if (aType==TopAbs_EDGE) {
1393 bIsTouch=CheckTouch (aCP, aTx);
1395 aCP.SetType(TopAbs_VERTEX);
1396 aCP.SetVertexParameter1(aTx);
1397 aCP.SetRange1 (aTx, aTx);
1404 myIsDone=Standard_True;
1409 // 1 - the method Perform() is not invoked
1410 // 2,3,4,5 -the method CheckData() fails
1411 // 6 - PrepareArgs() problems
1412 // 7 - No Projectable ranges
1413 // 8,9 - PrepareArgs() problems occured inside projectable Ranges
1414 // 11 - can't fill array aFunc(i) in PrepareArgsFuncArrays
1417 //=======================================================================
1418 //function : CheckTouch
1420 //=======================================================================
1421 Standard_Boolean IntTools_EdgeFace::CheckTouchVertex (const IntTools_CommonPrt& aCP,
1424 Standard_Real aTF, aTL, Tol, U1f,U1l,V1f,V1l, af, al,aDist2, aMinDist2, aTm, aDist2New;
1425 Standard_Boolean theflag=Standard_False;
1426 Standard_Integer aNbExt, i, iLower ;
1428 aCP.Range1(aTF, aTL);
1431 aDist2=DistanceFunction(aTm);
1434 Tol = Precision::PConfusion();
1436 const Handle(Geom_Curve)& Curve =BRep_Tool::Curve (myC.Edge(), af, al);
1437 const Handle(Geom_Surface)& Surface=BRep_Tool::Surface(myS.Face());
1439 Surface->Bounds(U1f,U1l,V1f,V1l);
1441 GeomAdaptor_Curve TheCurve (Curve,aTF, aTL);
1442 GeomAdaptor_Surface TheSurface (Surface, U1f, U1l, V1f, V1l);
1444 Extrema_ExtCS anExtrema (TheCurve, TheSurface, Tol, Tol);
1446 if(!anExtrema.IsDone()) {
1449 if (anExtrema.IsParallel()) {
1453 aNbExt=anExtrema.NbExt() ;
1460 for (i=1; i<=aNbExt; ++i) {
1461 aDist2=anExtrema.SquareDistance(i);
1462 if (aDist2 < aMinDist2) {
1468 aDist2New=anExtrema.SquareDistance(iLower);
1470 if (aDist2New > aDist2) {
1475 if (aDist2New > myCriteria * myCriteria) {
1479 Extrema_POnCurv aPOnC;
1480 Extrema_POnSurf aPOnS;
1481 anExtrema.Points(iLower, aPOnC, aPOnS);
1484 aTx=aPOnC.Parameter();
1486 if (fabs (aTx-aTF) < myEpsT) {
1490 if (fabs (aTx-aTL) < myEpsT) {
1494 if (aTx>aTF && aTx<aTL) {
1502 //=======================================================================
1503 //function : IsCoplanar
1505 //=======================================================================
1506 Standard_Boolean IsCoplanar (const BRepAdaptor_Curve& aCurve ,
1507 const BRepAdaptor_Surface& aSurface)
1509 Standard_Boolean bFlag=Standard_False;
1511 GeomAbs_CurveType aCType;
1512 GeomAbs_SurfaceType aSType;
1514 aCType=aCurve.GetType();
1515 aSType=aSurface.GetType();
1517 if (aCType==GeomAbs_Circle && aSType==GeomAbs_Plane) {
1518 gp_Circ aCirc=aCurve.Circle();
1519 const gp_Ax1& anAx1=aCirc.Axis();
1520 const gp_Dir& aDirAx1=anAx1.Direction();
1522 gp_Pln aPln=aSurface.Plane();
1523 const gp_Ax1& anAx=aPln.Axis();
1524 const gp_Dir& aDirPln=anAx.Direction();
1526 bFlag=IntTools_Tools::IsDirsCoinside(aDirAx1, aDirPln);
1530 //=======================================================================
1531 //function : IsRadius
1533 //=======================================================================
1534 Standard_Boolean IsRadius (const BRepAdaptor_Curve& aCurve ,
1535 const BRepAdaptor_Surface& aSurface)
1537 Standard_Boolean bFlag=Standard_False;
1539 GeomAbs_CurveType aCType;
1540 GeomAbs_SurfaceType aSType;
1542 aCType=aCurve.GetType();
1543 aSType=aSurface.GetType();
1545 if (aCType==GeomAbs_Circle && aSType==GeomAbs_Plane) {
1546 gp_Circ aCirc=aCurve.Circle();
1547 const gp_Pnt aCenter=aCirc.Location();
1548 Standard_Real aR=aCirc.Radius();
1549 gp_Pln aPln=aSurface.Plane();
1550 Standard_Real aD=aPln.Distance(aCenter);
1551 if (fabs (aD-aR) < 1.e-7) {
1558 //=======================================================================
1559 //function : AdaptiveDiscret
1561 //=======================================================================
1562 Standard_Integer AdaptiveDiscret (const Standard_Integer iDiscret,
1563 const BRepAdaptor_Curve& aCurve ,
1564 const BRepAdaptor_Surface& aSurface)
1566 Standard_Integer iDiscretNew;
1568 iDiscretNew=iDiscret;
1570 GeomAbs_CurveType aCType;
1571 GeomAbs_SurfaceType aSType;
1573 aCType=aCurve.GetType();
1574 aSType=aSurface.GetType();
1576 if (aSType==GeomAbs_Cylinder) {
1577 Standard_Real aELength, aRadius, dL, dLR;
1579 aELength=IntTools::Length(aCurve.Edge());
1580 dL=aELength/iDiscret;
1582 gp_Cylinder aCylinder=aSurface.Cylinder();
1583 aRadius=aCylinder.Radius();
1586 iDiscretNew=(Standard_Integer)(aELength/dLR);
1588 if (iDiscretNew<iDiscret) {
1589 iDiscretNew=iDiscret;
1598 #pragma warning ( default : 4101 )