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;
90 //=======================================================================
91 //function : SetContext
93 //=======================================================================
94 void IntTools_EdgeFace::SetContext(const Handle(IntTools_Context)& theContext)
96 myContext = theContext;
99 //=======================================================================
102 //=======================================================================
103 const Handle(IntTools_Context)& IntTools_EdgeFace::Context()const
107 //=======================================================================
110 //=======================================================================
111 void IntTools_EdgeFace::SetEdge(const TopoDS_Edge& anEdge)
116 //=======================================================================
119 //=======================================================================
120 void IntTools_EdgeFace::SetFace(const TopoDS_Face& aFace)
125 //=======================================================================
128 //=======================================================================
129 void IntTools_EdgeFace::SetTolE(const Standard_Real aTol)
133 //=======================================================================
136 //=======================================================================
137 void IntTools_EdgeFace::SetTolF(const Standard_Real aTol)
142 //=======================================================================
143 //function : SetDiscretize
145 //=======================================================================
146 void IntTools_EdgeFace::SetDiscretize(const Standard_Integer aDiscret)
150 //=======================================================================
151 //function : SetDeflection
153 //=======================================================================
154 void IntTools_EdgeFace::SetDeflection(const Standard_Real aDefl)
158 //=======================================================================
159 //function : SetEpsilonT
161 //=======================================================================
162 void IntTools_EdgeFace::SetEpsilonT(const Standard_Real anEpsT)
166 //=======================================================================
167 //function : SetEpsilonNull
169 //=======================================================================
170 void IntTools_EdgeFace::SetEpsilonNull(const Standard_Real anEpsNull)
175 //=======================================================================
176 //function : SetRange
178 //=======================================================================
179 void IntTools_EdgeFace::SetRange(const Standard_Real aFirst,
180 const Standard_Real aLast)
182 myRange.SetFirst (aFirst);
183 myRange.SetLast (aLast);
186 //=======================================================================
187 //function : SetRange
189 //=======================================================================
190 void IntTools_EdgeFace::SetRange(const IntTools_Range& aRange)
192 myRange.SetFirst (aRange.First());
193 myRange.SetLast (aRange.Last());
195 //=======================================================================
198 //=======================================================================
199 Standard_Boolean IntTools_EdgeFace::IsDone()const
203 //=======================================================================
204 //function : ErrorStatus
206 //=======================================================================
207 Standard_Integer IntTools_EdgeFace::ErrorStatus()const
209 return myErrorStatus;
211 //=======================================================================
212 //function : CommonParts
214 //=======================================================================
215 const IntTools_SequenceOfCommonPrts& IntTools_EdgeFace::CommonParts() const
217 return mySeqOfCommonPrts;
219 //=======================================================================
222 //=======================================================================
223 const IntTools_Range& IntTools_EdgeFace::Range() const
228 //=======================================================================
229 //function : CheckData
231 //=======================================================================
232 void IntTools_EdgeFace::CheckData()
234 if (BRep_Tool::Degenerated(myEdge)) {
237 if (!BRep_Tool::IsGeometric(myEdge)) {
241 //=======================================================================
244 //=======================================================================
245 void IntTools_EdgeFace::Prepare()
247 Standard_Integer pri;
248 IntTools_CArray1OfReal aPars;
251 // 1.Prepare Curve's data and Surface's data
252 myC.Initialize(myEdge);
253 GeomAbs_CurveType aCurveType;
254 aCurveType=myC.GetType();
256 // 2.Prepare myCriteria
257 if (aCurveType==GeomAbs_BSplineCurve||
258 aCurveType==GeomAbs_BezierCurve) {
259 myCriteria=1.5*myTolE+myTolF;
262 myCriteria=myTolE+myTolF;
264 // 2.a myTmin, myTmax
265 myTmin=myRange.First();
266 myTmax=myRange.Last();
268 myS.Initialize (myFace,Standard_True);
269 myFClass2d.Init(myFace, 1.e-6);
271 // 2.c Prepare adaptive myDiscret
272 myDiscret=AdaptiveDiscret(myDiscret, myC, myS);
276 pri = IntTools::PrepareArgs(myC, myTmax, myTmin, myDiscret, myDeflection, aPars);
283 Standard_Integer i, iProj, aNb, aNbProj, ind0, ind1;
284 Standard_Real t0, t1, tRoot;
287 // Table of Projection's function values
289 IntTools_CArray1OfInteger anArrProjectability;
290 anArrProjectability.Resize(aNb);
292 for (iProj=0, i=0; i<aNb; i++) {
294 aNbProj=IsProjectable (t0);
296 anArrProjectability(i)=0;
298 anArrProjectability(i)=1;
310 // Projectable Ranges
311 IntTools_Range aRange;
313 ind0=anArrProjectability(0);
319 for(i=1; i<aNb; i++) {
320 ind1=anArrProjectability(i);
327 myProjectableRanges.Append(aRange);
330 FindProjectableRoot(t0, t1, ind0, ind1, tRoot);
331 aRange.SetFirst(tRoot);
333 myProjectableRanges.Append(aRange);
337 FindProjectableRoot(t0, t1, ind0, ind1, tRoot);
338 aRange.SetLast(tRoot);
339 myProjectableRanges.Append(aRange);
346 FindProjectableRoot(t0, t1, ind0, ind1, tRoot);
349 aRange.SetLast(tRoot);
350 myProjectableRanges.Append(aRange);
353 aRange.SetFirst(tRoot);
355 } // if (ind0 != ind1)
357 } // for(i=1; i<aNb; i++) {
360 //=======================================================================
361 //function : FindProjectableRoot
363 //=======================================================================
364 void IntTools_EdgeFace::FindProjectableRoot (const Standard_Real tt1,
365 const Standard_Real tt2,
366 const Standard_Integer ff1,
367 const Standard_Integer ff2,
368 Standard_Real& tRoot)
370 Standard_Real tm, t1, t2, aEpsT;
371 Standard_Integer anIsProj1, anIsProj2, anIsProjm;
374 // Root is inside [tt1, tt2]
381 if (fabs(t1-t2) < aEpsT) {
382 tRoot=(anIsProj1) ? t1 : t2;
386 anIsProjm=IsProjectable(tm);
388 if (anIsProjm != anIsProj1) {
398 //=======================================================================
399 //function : IsProjectable
401 //=======================================================================
402 Standard_Boolean IntTools_EdgeFace::IsProjectable(const Standard_Real t) const
404 Standard_Boolean bFlag;
405 Standard_Real Umin, Usup, Vmin, Vsup;
407 Umin=myS.FirstUParameter();
408 Usup=myS.LastUParameter();
409 Vmin=myS.FirstVParameter();
410 Vsup=myS.LastVParameter ();
414 GeomAPI_ProjectPointOnSurf aProjector;
416 Standard_Real ULD, VLD;
418 GeomAPI_ProjectPointOnSurf& aLocProj = myContext->ProjPS(myFace);
420 bFlag = aLocProj.IsDone();
423 aLocProj.LowerDistanceParameters(ULD, VLD);
428 bFlag=Standard_False;
432 gp_Pnt2d aP2d(ULD, VLD);
434 aState = myContext->FClass2d(myFace).Perform(aP2d);
437 if (aState==TopAbs_IN || aState==TopAbs_ON) {
444 //=======================================================================
445 //function : DistanceFunction
447 //=======================================================================
448 Standard_Real IntTools_EdgeFace::DistanceFunction(const Standard_Real t)
450 Standard_Real Umin, Usup, Vmin, Vsup, aD;
455 Standard_Boolean bIsEqDistance;
457 bIsEqDistance= IntTools_EdgeFace::IsEqDistance(P, myS, 1.e-7, aD);
463 Umin=myS.FirstUParameter();
464 Usup=myS.LastUParameter();
465 Vmin=myS.FirstVParameter();
466 Vsup=myS.LastVParameter ();
469 Standard_Boolean bFlag = Standard_False;
471 GeomAPI_ProjectPointOnSurf& aLocProj = myContext->ProjPS(myFace);
473 bFlag = aLocProj.IsDone();
476 aD = aLocProj.LowerDistance();
486 // aD=aProjector.LowerDistance();
492 //=======================================================================
493 //function : IsEqDistance
495 //=======================================================================
496 Standard_Boolean IntTools_EdgeFace::IsEqDistance(const gp_Pnt& aP,
497 const BRepAdaptor_Surface& aBAS,
498 const Standard_Real aTol,
501 Standard_Boolean bRetFlag=Standard_True;
503 GeomAbs_SurfaceType aSurfType=aBAS.GetType();
505 if (aSurfType==GeomAbs_Cylinder) {
506 gp_Cylinder aCyl=aBAS.Cylinder();
507 const gp_Ax1& anAx1 =aCyl.Axis();
508 gp_Lin aLinAxis(anAx1);
509 Standard_Real aDC, aRadius=aCyl.Radius();
510 aDC=aLinAxis.Distance(aP);
517 if (aSurfType==GeomAbs_Cone) {
518 gp_Cone aCone=aBAS.Cone();
519 const gp_Ax1& anAx1 =aCone.Axis();
520 gp_Lin aLinAxis(anAx1);
521 Standard_Real aDC, aRadius, aDS, aSemiAngle;
522 aDC=aLinAxis.Distance(aP);
524 gp_Pnt anApex=aCone.Apex();
525 aSemiAngle=aCone.SemiAngle();
526 aDS=aP.Distance(anApex);
528 aRadius=aDS*tan(aSemiAngle);
534 if (aSurfType==GeomAbs_Torus) {
535 Standard_Real aMajorRadius, aMinorRadius, aDC;
537 gp_Torus aTorus=aBAS.Torus();
538 gp_Pnt aPLoc=aTorus.Location();
539 aMajorRadius=aTorus.MajorRadius();
541 aDC=fabs(aPLoc.Distance(aP)-aMajorRadius);
543 aMinorRadius=aTorus.MinorRadius();
551 //=======================================================================
552 //function : PrepareArgsFuncArrays
554 // myFuncArray and myArgsArray for the interval [ta, tb]
555 //=======================================================================
556 void IntTools_EdgeFace::PrepareArgsFuncArrays(const Standard_Real ta,
557 const Standard_Real tb)
559 IntTools_CArray1OfReal anArgs, aFunc;
560 Standard_Integer i, aNb, pri;
561 Standard_Real t, f, f1;
563 // Prepare values of arguments for the interval [ta, tb]
564 pri=IntTools::PrepareArgs (myC, tb, ta, myDiscret, myDeflection, anArgs);
578 // Prepare values of functions for the interval [ta, tb]
580 for (i=0; i<aNb; i++) {
582 f1=DistanceFunction(t);
585 if (myErrorStatus==11)
588 if (f1 < myEpsNull) {
594 // Add points where the derivative = 0
595 AddDerivativePoints(anArgs, aFunc);
600 //=======================================================================
601 //function : AddDerivativePoints
603 //=======================================================================
604 void IntTools_EdgeFace::AddDerivativePoints(const IntTools_CArray1OfReal& t,
605 const IntTools_CArray1OfReal& f)
607 Standard_Integer i, j, n, k, nn=100;
608 Standard_Real fr, tr, tr1, dEpsNull=10.*myEpsNull;
609 IntTools_CArray1OfReal fd;
610 TColStd_SequenceOfReal aTSeq, aFSeq;
615 // Table of derivatives
616 Standard_Real dfx, tx, tx1, fx, fx1, dt=1.e-6;
621 fx1=DistanceFunction(tx1);
623 if (fx1 < myEpsNull) {
629 if (fabs(fd(0)) < dEpsNull){
635 for (i=1; i<k; i++) {
636 Standard_Real ti, ti1;
639 fd(i)=.5*(f(i+1)-f(i-1))/(t(i)-t(i-1));
640 if (fabs(fd(i)) < dEpsNull){
648 fx1=DistanceFunction(tx1);
650 if (fx1 < myEpsNull) {
656 if (fabs(fd(n-1)) < dEpsNull){
660 // Finding the range where the derivatives have different signs
661 // for neighbouring points
662 for (i=1; i<n; i++) {
663 Standard_Real fd1, fd2, t1, t2;
670 if (fabs(fd1) < myEpsNull) {
672 fr=DistanceFunction(tr);//fd1;
674 else if (fabs(fd2) < myEpsNull) {
676 fr=DistanceFunction(tr);
679 tr=FindSimpleRoot(2, t1, t2, fd1);
680 fr=DistanceFunction(tr);
686 } // end of for (i=1; i<n; i++)
688 // remove identical t, f
691 for (i=1; i<=aTSeq.Length(); i++) {
693 for (j=0; j<n; j++) {
695 if (fabs (tr1-tr) < myEpsT) {
704 // sorting args and funcs in increasing order
707 IntTools_Array1OfRange anArray1OfRange(1, k);
708 for (i=1; i<=n; i++) {
709 anArray1OfRange(i).SetFirst(t(i-1));
710 anArray1OfRange(i).SetLast (f(i-1));
712 for (i=1; i<=nn; i++) {
713 anArray1OfRange(n+i).SetFirst(aTSeq(i));
714 anArray1OfRange(n+i).SetLast (aFSeq(i));
717 IntTools_QuickSortRange aQuickSortRange;
718 IntTools_CompareRange aComparator;
719 aQuickSortRange.Sort (anArray1OfRange, aComparator);
721 // filling the output arrays
722 myArgsArray.Resize(k);
723 myFuncArray.Resize(k);
724 for (i=1; i<=k; i++) {
725 myArgsArray(i-1)=anArray1OfRange(i).First();
726 myFuncArray(i-1)=anArray1OfRange(i).Last ();
731 myArgsArray.Resize(n);
732 myFuncArray.Resize(n);
733 for (i=0; i<n; i++) {
740 //=======================================================================
741 //function : DerivativeFunction
743 //=======================================================================
744 Standard_Real IntTools_EdgeFace::DerivativeFunction(const Standard_Real t2)
746 Standard_Real t1, t3, aD1, aD2, aD3;
747 Standard_Real dt=1.e-9;
749 aD1=DistanceFunction(t1);
751 aD3=DistanceFunction(t3);
757 //=======================================================================
758 //function : FindSimpleRoot
759 //purpose : [private]
760 //=======================================================================
761 Standard_Real IntTools_EdgeFace::FindSimpleRoot (const Standard_Integer IP,
762 const Standard_Real tA,
763 const Standard_Real tB,
764 const Standard_Real fA)
766 Standard_Real r, a, b, y, x0, s;
774 y=DistanceFunction(x0);
776 y=DerivativeFunction(x0);
778 if (fabs(b-a) < myEpsT || y==0.) {
795 //=======================================================================
796 //function : FindGoldRoot
797 //purpose : [private]
798 //=======================================================================
799 Standard_Real IntTools_EdgeFace::FindGoldRoot (const Standard_Real tA,
800 const Standard_Real tB,
801 const Standard_Real coeff)
803 Standard_Real gs=0.61803399;
804 Standard_Real a, b, xp, xl, yp, yl;
810 yp=coeff*DistanceFunction(xp);
811 yl=coeff*DistanceFunction(xl);
816 if (fabs(b-a) < myEpsT) {
824 yp=coeff*DistanceFunction(xp);
832 yl=coeff*DistanceFunction(xl);
837 //=======================================================================
838 //function : MakeType
840 //=======================================================================
841 Standard_Integer IntTools_EdgeFace::MakeType(IntTools_CommonPrt& aCommonPrt)
843 Standard_Real af1, al1;
844 Standard_Real dt, df1, df2, tm;
845 Standard_Boolean bAllNullFlag;
847 bAllNullFlag=aCommonPrt.AllNullFlag();
849 aCommonPrt.SetType(TopAbs_EDGE);
853 aCommonPrt.Range1(af1, al1);
859 df1=aPF.Distance(aPL);
860 Standard_Boolean isWholeRange = Standard_False;
862 if((Abs(af1 - myRange.First()) < myC.Resolution(myCriteria)) &&
863 (Abs(al1 - myRange.Last()) < myC.Resolution(myCriteria)))
864 isWholeRange = Standard_True;
867 if ((df1 > myCriteria * 2.) && isWholeRange) {
868 aCommonPrt.SetType(TopAbs_EDGE);
872 tm = (af1 + al1) * 0.5;
874 if(aPF.Distance(myC.Value(tm)) > myCriteria * 2.) {
875 aCommonPrt.SetType(TopAbs_EDGE);
880 if(!CheckTouch(aCommonPrt, tm)) {
881 tm = (af1 + al1) * 0.5;
883 aCommonPrt.SetType(TopAbs_VERTEX);
884 aCommonPrt.SetVertexParameter1(tm);
885 aCommonPrt.SetRange1 (af1, al1);
896 df1=aPF.Distance(aPL);
897 if (df1<myCriteria) {
900 aCommonPrt.SetType(TopAbs_VERTEX);
901 aCommonPrt.SetVertexParameter1(tm);
902 aCommonPrt.SetRange1 (af1, al1);
907 IsIntersection (af1, al1);
910 aCommonPrt.SetType(TopAbs_VERTEX);
911 aCommonPrt.SetVertexParameter1(myPar1);
912 aCommonPrt.SetRange1 (af1, al1);
917 df1=DistanceFunction(af1);
918 df2=DistanceFunction(al1);
919 tm=(df1 < df2) ? af1 : al1;
920 aCommonPrt.SetType(TopAbs_VERTEX);
921 aCommonPrt.SetVertexParameter1(tm);
922 aCommonPrt.SetRange1 (af1, al1);
926 aCommonPrt.SetType(TopAbs_EDGE);
933 //=======================================================================
934 //function : IsIntersection
936 //=======================================================================
937 void IntTools_EdgeFace::IsIntersection (const Standard_Real ta,
938 const Standard_Real tb)
940 IntTools_CArray1OfReal anArgs, aFunc;
941 Standard_Integer i, aNb, pri, aCnt=0;
943 Standard_Integer aCntIncreasing=1, aCntDecreasing=1;
944 Standard_Real t, f, f1;
946 // Prepare values of arguments for the interval [ta, tb]
947 pri=IntTools::PrepareArgs (myC, tb, ta, myDiscret, myDeflection, anArgs);
951 for (i=0; i<aNb; i++) {
954 f1=DistanceFunction(t);
957 if (fabs(f1) < myEpsNull) {
964 if (aFunc(i)>aFunc(i-1)) {
967 if (aFunc(i)<aFunc(i-1)) {
975 myParallel=Standard_True;
979 FindDerivativeRoot(anArgs, aFunc);
983 if (!(myC.GetType()==GeomAbs_Line
985 myS.GetType()==GeomAbs_Cylinder)) {
986 if (aCntDecreasing==aNb) {
987 myPar1=anArgs(aNb-1);
988 myParallel=Standard_False;
990 if (aCntIncreasing==aNb) {
992 myParallel=Standard_False;
1000 //=======================================================================
1001 //function : FindDerivativeRoot
1003 //=======================================================================
1004 void IntTools_EdgeFace::FindDerivativeRoot(const IntTools_CArray1OfReal& t,
1005 const IntTools_CArray1OfReal& f)
1007 Standard_Integer i, n, k;
1008 Standard_Real fr, tr;
1009 IntTools_CArray1OfReal fd;
1010 TColStd_SequenceOfReal aTSeq, aFSeq;
1013 myParallel=Standard_True;
1018 // Table of derivatives
1019 fd(0)=(f(1)-f(0))/(t(1)-t(0));
1020 if (fabs(fd(0)) < myEpsNull) {
1025 for (i=1; i<k; i++) {
1026 fd(i)=.5*(f(i+1)-f(i-1))/(t(i)-t(i-1));
1027 if (fabs(fd(i)) < myEpsNull) {
1032 fd(n-1)=(f(n-1)-f(n-2))/(t(n-1)-t(n-2));
1033 if (fabs(fd(n-1)) < myEpsNull) {
1037 // Finding the range where the derivatives have different signs
1038 // for neighbouring points
1039 for (i=1; i<n; i++) {
1040 Standard_Real fd1, fd2, t1, t2, fabsfd1, fabsfd2;
1041 Standard_Boolean bF1, bF2;
1048 bF1=fabsfd1 < myEpsNull;
1051 bF2=fabsfd2 < myEpsNull;
1054 tr=FindSimpleRoot(2, t1, t2, fd1);
1055 fr=DistanceFunction(tr);
1057 myParallel=Standard_False;
1065 myParallel=Standard_False;
1073 myParallel=Standard_False;
1079 //=======================================================================
1080 //function : RemoveIdenticalRoots
1082 //=======================================================================
1083 void IntTools_EdgeFace::RemoveIdenticalRoots()
1085 Standard_Integer aNbRoots, j, k;
1087 aNbRoots=mySequenceOfRoots.Length();
1088 for (j=1; j<=aNbRoots; j++) {
1089 const IntTools_Root& aRj=mySequenceOfRoots(j);
1090 for (k=j+1; k<=aNbRoots; k++) {
1091 const IntTools_Root& aRk=mySequenceOfRoots(k);
1093 Standard_Real aTj, aTk, aDistance;
1102 aDistance=aPj.Distance(aPk);
1103 if (aDistance < myCriteria) {
1104 mySequenceOfRoots.Remove(k);
1105 aNbRoots=mySequenceOfRoots.Length();
1111 //=======================================================================
1112 //function : CheckTouch
1114 //=======================================================================
1115 Standard_Boolean IntTools_EdgeFace::CheckTouch(const IntTools_CommonPrt& aCP,
1118 Standard_Real aTF, aTL, Tol, U1f, U1l, V1f, V1l, af, al,aDist2, aMinDist2;
1119 Standard_Boolean theflag=Standard_False;
1120 Standard_Integer aNbExt, i, iLower ;
1122 aCP.Range1(aTF, aTL);
1126 aCR=myC.Resolution(myCriteria);
1127 if((Abs(aTF - myRange.First()) < aCR) &&
1128 (Abs(aTL - myRange.Last()) < aCR)) {
1129 return theflag; // EDGE
1133 Tol = Precision::PConfusion();
1135 const Handle(Geom_Curve)& Curve =BRep_Tool::Curve (myC.Edge(), af, al);
1136 const Handle(Geom_Surface)& Surface=BRep_Tool::Surface(myS.Face());
1137 // Surface->Bounds(U1f,U1l,V1f,V1l);
1138 U1f = myS.FirstUParameter();
1139 U1l = myS.LastUParameter();
1140 V1f = myS.FirstVParameter();
1141 V1l = myS.LastVParameter();
1143 GeomAdaptor_Curve TheCurve (Curve,aTF, aTL);
1144 GeomAdaptor_Surface TheSurface (Surface, U1f, U1l, V1f, V1l);
1146 Extrema_ExtCS anExtrema (TheCurve, TheSurface, Tol, Tol);
1150 if(anExtrema.IsDone()) {
1153 if(!anExtrema.IsParallel()) {
1154 aNbExt=anExtrema.NbExt();
1158 for (i=1; i<=aNbExt; i++) {
1159 aDist2=anExtrema.SquareDistance(i);
1160 if (aDist2 < aMinDist2) {
1165 aDist2=anExtrema.SquareDistance(iLower);
1166 Extrema_POnCurv aPOnC;
1167 Extrema_POnSurf aPOnS;
1168 anExtrema.Points(iLower, aPOnC, aPOnS);
1169 aTx=aPOnC.Parameter();
1172 // modified by NIZHNY-MKK Thu Jul 21 11:35:32 2005.BEGIN
1173 IntCurveSurface_HInter anExactIntersector;
1175 Handle(GeomAdaptor_HCurve) aCurve = new GeomAdaptor_HCurve(TheCurve);
1176 Handle(GeomAdaptor_HSurface) aSurface = new GeomAdaptor_HSurface(TheSurface);
1178 anExactIntersector.Perform(aCurve, aSurface);
1180 if(anExactIntersector.IsDone()) {
1181 Standard_Integer i = 0;
1183 for(i = 1; i <= anExactIntersector.NbPoints(); i++) {
1184 const IntCurveSurface_IntersectionPoint& aPoint = anExactIntersector.Point(i);
1186 if((aPoint.W() >= aTF) && (aPoint.W() <= aTL)) {
1192 // modified by NIZHNY-MKK Thu Jul 21 11:35:40 2005.END
1200 Standard_Real aBoundaryDist;
1202 aBoundaryDist = DistanceFunction(aTF) + myCriteria;
1203 if(aBoundaryDist * aBoundaryDist < aDist2) {
1204 aDist2 = aBoundaryDist * aBoundaryDist;
1208 aBoundaryDist = DistanceFunction(aTL) + myCriteria;
1209 if(aBoundaryDist * aBoundaryDist < aDist2) {
1210 aDist2 = aBoundaryDist * aBoundaryDist;
1214 Standard_Real aParameter = (aTF + aTL) * 0.5;
1215 aBoundaryDist = DistanceFunction(aParameter) + myCriteria;
1216 if(aBoundaryDist * aBoundaryDist < aDist2) {
1217 aDist2 = aBoundaryDist * aBoundaryDist;
1221 if(aDist2 > myCriteria * myCriteria) {
1225 if (fabs (aTx-aTF) < myEpsT) {
1229 if (fabs (aTx-aTL) < myEpsT) {
1233 if (aTx>aTF && aTx<aTL) {
1241 //=======================================================================
1242 //function : Perform
1244 //=======================================================================
1245 void IntTools_EdgeFace::Perform()
1247 Standard_Integer i, aNb;
1248 IntTools_CommonPrt aCommonPrt;
1250 aCommonPrt.SetEdge1(myEdge);
1254 if (myErrorStatus) {
1258 if (myContext.IsNull()) {
1259 myContext=new IntTools_Context;
1262 myIsDone = Standard_False;
1263 myC.Initialize(myEdge);
1264 GeomAbs_CurveType aCurveType;
1265 aCurveType=myC.GetType();
1267 // Prepare myCriteria
1268 if (aCurveType==GeomAbs_BSplineCurve||
1269 aCurveType==GeomAbs_BezierCurve) {
1271 Standard_Real diff1 = (myTolE/myTolF);
1272 Standard_Real diff2 = (myTolF/myTolE);
1273 if( diff1 > 100 || diff2 > 100 ) {
1274 myCriteria = Max(myTolE,myTolF);
1277 myCriteria=1.5*myTolE+myTolF;
1280 myCriteria=myTolE+myTolF;
1283 myTmin=myRange.First();
1284 myTmax=myRange.Last();
1286 myS.Initialize (myFace,Standard_True);
1288 if(myContext.IsNull()) {
1289 myFClass2d.Init(myFace, 1.e-6);
1292 IntTools_BeanFaceIntersector anIntersector(myC, myS, myTolE, myTolF);
1293 anIntersector.SetBeanParameters(myRange.First(), myRange.Last());
1295 anIntersector.SetContext(myContext);
1297 anIntersector.Perform();
1299 if(!anIntersector.IsDone()) {
1303 for(Standard_Integer r = 1; r <= anIntersector.Result().Length(); r++) {
1304 const IntTools_Range& aRange = anIntersector.Result().Value(r);
1306 if(IsProjectable(IntTools_Tools::IntermediatePoint(aRange.First(), aRange.Last()))) {
1307 aCommonPrt.SetRange1(aRange.First(), aRange.Last());
1308 mySeqOfCommonPrts.Append(aCommonPrt);
1312 aNb = mySeqOfCommonPrts.Length();
1314 for (i=1; i<=aNb; i++) {
1315 IntTools_CommonPrt& aCP=mySeqOfCommonPrts.ChangeValue(i);
1317 Standard_Real aTx1, aTx2;
1320 aCP.Range1(aTx1, aTx2);
1323 aCP.SetBoundingPoints(aPx1, aPx2);
1328 // Line\Cylinder's Common Parts treatement
1329 GeomAbs_CurveType aCType;
1330 GeomAbs_SurfaceType aSType;
1331 TopAbs_ShapeEnum aType;
1332 Standard_Boolean bIsTouch;
1335 aCType=myC.GetType();
1336 aSType=myS.GetType();
1338 if (aCType==GeomAbs_Line && aSType==GeomAbs_Cylinder) {
1339 for (i=1; i<=aNb; i++) {
1340 IntTools_CommonPrt& aCP=mySeqOfCommonPrts(i);
1342 if (aType==TopAbs_EDGE) {
1343 bIsTouch=CheckTouch (aCP, aTx);
1345 aCP.SetType(TopAbs_VERTEX);
1346 aCP.SetVertexParameter1(aTx);
1347 aCP.SetRange1 (aTx, aTx);
1350 if (aType==TopAbs_VERTEX) {
1351 bIsTouch=CheckTouchVertex (aCP, aTx);
1353 aCP.SetVertexParameter1(aTx);
1354 aCP.SetRange1 (aTx, aTx);
1360 // Circle\Plane's Common Parts treatement
1362 if (aCType==GeomAbs_Circle && aSType==GeomAbs_Plane) {
1363 Standard_Boolean bIsCoplanar, bIsRadius;
1364 bIsCoplanar=IsCoplanar(myC, myS);
1365 bIsRadius=IsRadius(myC, myS);
1366 if (!bIsCoplanar && !bIsRadius) {
1367 for (i=1; i<=aNb; i++) {
1368 IntTools_CommonPrt& aCP=mySeqOfCommonPrts(i);
1370 if (aType==TopAbs_EDGE) {
1371 bIsTouch=CheckTouch (aCP, aTx);
1373 aCP.SetType(TopAbs_VERTEX);
1374 aCP.SetVertexParameter1(aTx);
1375 aCP.SetRange1 (aTx, aTx);
1382 myIsDone=Standard_True;
1387 // 1 - the method Perform() is not invoked
1388 // 2,3,4,5 -the method CheckData() fails
1389 // 6 - PrepareArgs() problems
1390 // 7 - No Projectable ranges
1391 // 8,9 - PrepareArgs() problems occured inside projectable Ranges
1392 // 11 - can't fill array aFunc(i) in PrepareArgsFuncArrays
1395 //=======================================================================
1396 //function : CheckTouch
1398 //=======================================================================
1399 Standard_Boolean IntTools_EdgeFace::CheckTouchVertex (const IntTools_CommonPrt& aCP,
1402 Standard_Real aTF, aTL, Tol, U1f,U1l,V1f,V1l, af, al,aDist2, aMinDist2, aTm, aDist2New;
1403 Standard_Boolean theflag=Standard_False;
1404 Standard_Integer aNbExt, i, iLower ;
1406 aCP.Range1(aTF, aTL);
1409 aDist2=DistanceFunction(aTm);
1412 Tol = Precision::PConfusion();
1414 const Handle(Geom_Curve)& Curve =BRep_Tool::Curve (myC.Edge(), af, al);
1415 const Handle(Geom_Surface)& Surface=BRep_Tool::Surface(myS.Face());
1417 Surface->Bounds(U1f,U1l,V1f,V1l);
1419 GeomAdaptor_Curve TheCurve (Curve,aTF, aTL);
1420 GeomAdaptor_Surface TheSurface (Surface, U1f, U1l, V1f, V1l);
1422 Extrema_ExtCS anExtrema (TheCurve, TheSurface, Tol, Tol);
1424 if(!anExtrema.IsDone()) {
1427 if (anExtrema.IsParallel()) {
1431 aNbExt=anExtrema.NbExt() ;
1438 for (i=1; i<=aNbExt; ++i) {
1439 aDist2=anExtrema.SquareDistance(i);
1440 if (aDist2 < aMinDist2) {
1446 aDist2New=anExtrema.SquareDistance(iLower);
1448 if (aDist2New > aDist2) {
1453 if (aDist2New > myCriteria * myCriteria) {
1457 Extrema_POnCurv aPOnC;
1458 Extrema_POnSurf aPOnS;
1459 anExtrema.Points(iLower, aPOnC, aPOnS);
1462 aTx=aPOnC.Parameter();
1464 if (fabs (aTx-aTF) < myEpsT) {
1468 if (fabs (aTx-aTL) < myEpsT) {
1472 if (aTx>aTF && aTx<aTL) {
1480 //=======================================================================
1481 //function : IsCoplanar
1483 //=======================================================================
1484 Standard_Boolean IsCoplanar (const BRepAdaptor_Curve& aCurve ,
1485 const BRepAdaptor_Surface& aSurface)
1487 Standard_Boolean bFlag=Standard_False;
1489 GeomAbs_CurveType aCType;
1490 GeomAbs_SurfaceType aSType;
1492 aCType=aCurve.GetType();
1493 aSType=aSurface.GetType();
1495 if (aCType==GeomAbs_Circle && aSType==GeomAbs_Plane) {
1496 gp_Circ aCirc=aCurve.Circle();
1497 const gp_Ax1& anAx1=aCirc.Axis();
1498 const gp_Dir& aDirAx1=anAx1.Direction();
1500 gp_Pln aPln=aSurface.Plane();
1501 const gp_Ax1& anAx=aPln.Axis();
1502 const gp_Dir& aDirPln=anAx.Direction();
1504 bFlag=IntTools_Tools::IsDirsCoinside(aDirAx1, aDirPln);
1508 //=======================================================================
1509 //function : IsRadius
1511 //=======================================================================
1512 Standard_Boolean IsRadius (const BRepAdaptor_Curve& aCurve ,
1513 const BRepAdaptor_Surface& aSurface)
1515 Standard_Boolean bFlag=Standard_False;
1517 GeomAbs_CurveType aCType;
1518 GeomAbs_SurfaceType aSType;
1520 aCType=aCurve.GetType();
1521 aSType=aSurface.GetType();
1523 if (aCType==GeomAbs_Circle && aSType==GeomAbs_Plane) {
1524 gp_Circ aCirc=aCurve.Circle();
1525 const gp_Pnt aCenter=aCirc.Location();
1526 Standard_Real aR=aCirc.Radius();
1527 gp_Pln aPln=aSurface.Plane();
1528 Standard_Real aD=aPln.Distance(aCenter);
1529 if (fabs (aD-aR) < 1.e-7) {
1536 //=======================================================================
1537 //function : AdaptiveDiscret
1539 //=======================================================================
1540 Standard_Integer AdaptiveDiscret (const Standard_Integer iDiscret,
1541 const BRepAdaptor_Curve& aCurve ,
1542 const BRepAdaptor_Surface& aSurface)
1544 Standard_Integer iDiscretNew;
1546 iDiscretNew=iDiscret;
1548 GeomAbs_CurveType aCType;
1549 GeomAbs_SurfaceType aSType;
1551 aCType=aCurve.GetType();
1552 aSType=aSurface.GetType();
1554 if (aSType==GeomAbs_Cylinder) {
1555 Standard_Real aELength, aRadius, dL, dLR;
1557 aELength=IntTools::Length(aCurve.Edge());
1558 dL=aELength/iDiscret;
1560 gp_Cylinder aCylinder=aSurface.Cylinder();
1561 aRadius=aCylinder.Radius();
1564 iDiscretNew=(Standard_Integer)(aELength/dLR);
1566 if (iDiscretNew<iDiscret) {
1567 iDiscretNew=iDiscret;
1576 #pragma warning ( default : 4101 )