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,
77 const Standard_Real aCriteria);
79 Standard_Integer AdaptiveDiscret (const Standard_Integer iDiscret,
80 const BRepAdaptor_Curve& aCurve ,
81 const BRepAdaptor_Surface& aSurface);
83 //=======================================================================
84 //function : IntTools_EdgeFace::IntTools_EdgeFace
86 //=======================================================================
87 IntTools_EdgeFace::IntTools_EdgeFace()
95 myIsDone=Standard_False;
97 myParallel=Standard_False;
100 //=======================================================================
101 //function : SetContext
103 //=======================================================================
104 void IntTools_EdgeFace::SetContext(const Handle(IntTools_Context)& theContext)
106 myContext = theContext;
109 //=======================================================================
112 //=======================================================================
113 const Handle(IntTools_Context)& IntTools_EdgeFace::Context()const
117 //=======================================================================
120 //=======================================================================
121 void IntTools_EdgeFace::SetEdge(const TopoDS_Edge& anEdge)
125 //=======================================================================
128 //=======================================================================
129 void IntTools_EdgeFace::SetFace(const TopoDS_Face& aFace)
133 //=======================================================================
136 //=======================================================================
137 void IntTools_EdgeFace::SetTolE(const Standard_Real aTol)
141 //=======================================================================
144 //=======================================================================
145 void IntTools_EdgeFace::SetTolF(const Standard_Real aTol)
149 //=======================================================================
152 //=======================================================================
153 const TopoDS_Edge& IntTools_EdgeFace::Edge()const
157 //=======================================================================
160 //=======================================================================
161 const TopoDS_Face& IntTools_EdgeFace::Face()const
165 //=======================================================================
168 //=======================================================================
169 Standard_Real IntTools_EdgeFace::TolE()const
173 //=======================================================================
176 //=======================================================================
177 Standard_Real IntTools_EdgeFace::TolF()const
181 //=======================================================================
182 //function : SetDiscretize
184 //=======================================================================
185 void IntTools_EdgeFace::SetDiscretize(const Standard_Integer aDiscret)
189 //=======================================================================
190 //function : SetDeflection
192 //=======================================================================
193 void IntTools_EdgeFace::SetDeflection(const Standard_Real aDefl)
197 //=======================================================================
198 //function : SetEpsilonT
200 //=======================================================================
201 void IntTools_EdgeFace::SetEpsilonT(const Standard_Real anEpsT)
205 //=======================================================================
206 //function : SetEpsilonNull
208 //=======================================================================
209 void IntTools_EdgeFace::SetEpsilonNull(const Standard_Real anEpsNull)
214 //=======================================================================
215 //function : SetRange
217 //=======================================================================
218 void IntTools_EdgeFace::SetRange(const Standard_Real aFirst,
219 const Standard_Real aLast)
221 myRange.SetFirst (aFirst);
222 myRange.SetLast (aLast);
225 //=======================================================================
226 //function : SetRange
228 //=======================================================================
229 void IntTools_EdgeFace::SetRange(const IntTools_Range& aRange)
231 myRange.SetFirst (aRange.First());
232 myRange.SetLast (aRange.Last());
234 //=======================================================================
237 //=======================================================================
238 Standard_Boolean IntTools_EdgeFace::IsDone()const
242 //=======================================================================
243 //function : ErrorStatus
245 //=======================================================================
246 Standard_Integer IntTools_EdgeFace::ErrorStatus()const
248 return myErrorStatus;
250 //=======================================================================
251 //function : CommonParts
253 //=======================================================================
254 const IntTools_SequenceOfCommonPrts& IntTools_EdgeFace::CommonParts() const
256 return mySeqOfCommonPrts;
258 //=======================================================================
261 //=======================================================================
262 const IntTools_Range& IntTools_EdgeFace::Range() const
267 //=======================================================================
268 //function : CheckData
270 //=======================================================================
271 void IntTools_EdgeFace::CheckData()
273 if (BRep_Tool::Degenerated(myEdge)) {
276 if (!BRep_Tool::IsGeometric(myEdge)) {
280 //=======================================================================
283 //=======================================================================
284 void IntTools_EdgeFace::Prepare()
286 Standard_Integer pri;
287 IntTools_CArray1OfReal aPars;
290 // 1.Prepare Curve's data and Surface's data
291 myC.Initialize(myEdge);
292 GeomAbs_CurveType aCurveType;
293 aCurveType=myC.GetType();
295 // 2.Prepare myCriteria
296 if (aCurveType==GeomAbs_BSplineCurve||
297 aCurveType==GeomAbs_BezierCurve) {
298 myCriteria=1.5*myTolE+myTolF;
301 myCriteria=myTolE+myTolF;
303 // 2.a myTmin, myTmax
304 myTmin=myRange.First();
305 myTmax=myRange.Last();
307 myS.Initialize (myFace,Standard_True);
308 myFClass2d.Init(myFace, 1.e-6);
310 // 2.c Prepare adaptive myDiscret
311 myDiscret=AdaptiveDiscret(myDiscret, myC, myS);
315 pri = IntTools::PrepareArgs(myC, myTmax, myTmin,
316 myDiscret, myDeflection, aPars);
323 Standard_Integer i, iProj, aNb, aNbProj, ind0, ind1;
324 Standard_Real t0, t1, tRoot;
327 // Table of Projection's function values
329 IntTools_CArray1OfInteger anArrProjectability;
330 anArrProjectability.Resize(aNb);
332 for (iProj=0, i=0; i<aNb; i++) {
334 aNbProj=IsProjectable (t0);
336 anArrProjectability(i)=0;
338 anArrProjectability(i)=1;
350 // Projectable Ranges
351 IntTools_Range aRange;
353 ind0=anArrProjectability(0);
359 for(i=1; i<aNb; i++) {
360 ind1=anArrProjectability(i);
367 myProjectableRanges.Append(aRange);
370 FindProjectableRoot(t0, t1, ind0, ind1, tRoot);
371 aRange.SetFirst(tRoot);
373 myProjectableRanges.Append(aRange);
377 FindProjectableRoot(t0, t1, ind0, ind1, tRoot);
378 aRange.SetLast(tRoot);
379 myProjectableRanges.Append(aRange);
386 FindProjectableRoot(t0, t1, ind0, ind1, tRoot);
389 aRange.SetLast(tRoot);
390 myProjectableRanges.Append(aRange);
393 aRange.SetFirst(tRoot);
395 } // if (ind0 != ind1)
397 } // for(i=1; i<aNb; i++) {
400 //=======================================================================
401 //function : FindProjectableRoot
403 //=======================================================================
404 void IntTools_EdgeFace::FindProjectableRoot (const Standard_Real tt1,
405 const Standard_Real tt2,
406 const Standard_Integer ff1,
407 const Standard_Integer /*ff2*/,
408 Standard_Real& tRoot)
410 Standard_Real tm, t1, t2, aEpsT;
411 Standard_Integer anIsProj1, anIsProjm;
412 aEpsT = 0.5 * myEpsT;
414 // Root is inside [tt1, tt2]
421 if (fabs(t1 - t2) < aEpsT)
423 tRoot = (anIsProj1) ? t1 : t2;
426 tm = 0.5 * (t1 + t2);
427 anIsProjm = IsProjectable(tm);
429 if (anIsProjm != anIsProj1)
436 anIsProj1 = anIsProjm;
440 //=======================================================================
441 //function : IsProjectable
443 //=======================================================================
444 Standard_Boolean IntTools_EdgeFace::IsProjectable
445 (const Standard_Real aT) const
447 Standard_Boolean bFlag;
451 bFlag=myContext->IsValidPointForFace(aPC, myFace, myCriteria);
455 //=======================================================================
456 //function : DistanceFunction
458 //=======================================================================
459 Standard_Real IntTools_EdgeFace::DistanceFunction
460 (const Standard_Real t)
468 Standard_Boolean bIsEqDistance;
470 bIsEqDistance= IntTools_EdgeFace::IsEqDistance(P, myS, 1.e-7, aD);
477 Standard_Boolean bFlag = Standard_False;
479 GeomAPI_ProjectPointOnSurf& aLocProj = myContext->ProjPS(myFace);
481 bFlag = aLocProj.IsDone();
484 aD = aLocProj.LowerDistance();
494 // aD=aProjector.LowerDistance();
500 //=======================================================================
501 //function : IsEqDistance
503 //=======================================================================
504 Standard_Boolean IntTools_EdgeFace::IsEqDistance
506 const BRepAdaptor_Surface& aBAS,
507 const Standard_Real aTol,
510 Standard_Boolean bRetFlag=Standard_True;
512 GeomAbs_SurfaceType aSurfType=aBAS.GetType();
514 if (aSurfType==GeomAbs_Cylinder) {
515 gp_Cylinder aCyl=aBAS.Cylinder();
516 const gp_Ax1& anAx1 =aCyl.Axis();
517 gp_Lin aLinAxis(anAx1);
518 Standard_Real aDC, aRadius=aCyl.Radius();
519 aDC=aLinAxis.Distance(aP);
526 if (aSurfType==GeomAbs_Cone) {
527 gp_Cone aCone=aBAS.Cone();
528 const gp_Ax1& anAx1 =aCone.Axis();
529 gp_Lin aLinAxis(anAx1);
530 Standard_Real aDC, aRadius, aDS, aSemiAngle;
531 aDC=aLinAxis.Distance(aP);
533 gp_Pnt anApex=aCone.Apex();
534 aSemiAngle=aCone.SemiAngle();
535 aDS=aP.Distance(anApex);
537 aRadius=aDS*tan(aSemiAngle);
543 if (aSurfType==GeomAbs_Torus) {
544 Standard_Real aMajorRadius, aMinorRadius, aDC;
546 gp_Torus aTorus=aBAS.Torus();
547 gp_Pnt aPLoc=aTorus.Location();
548 aMajorRadius=aTorus.MajorRadius();
550 aDC=fabs(aPLoc.Distance(aP)-aMajorRadius);
552 aMinorRadius=aTorus.MinorRadius();
560 //=======================================================================
561 //function : PrepareArgsFuncArrays
563 // myFuncArray and myArgsArray for the interval [ta, tb]
564 //=======================================================================
565 void IntTools_EdgeFace::PrepareArgsFuncArrays(const Standard_Real ta,
566 const Standard_Real tb)
568 IntTools_CArray1OfReal anArgs, aFunc;
569 Standard_Integer i, aNb, pri;
570 Standard_Real t, f, f1;
572 // Prepare values of arguments for the interval [ta, tb]
573 pri=IntTools::PrepareArgs (myC, tb, ta, myDiscret, myDeflection, anArgs);
587 // Prepare values of functions for the interval [ta, tb]
589 for (i=0; i<aNb; i++) {
591 f1=DistanceFunction(t);
594 if (myErrorStatus==11)
597 if (f1 < myEpsNull) {
603 // Add points where the derivative = 0
604 AddDerivativePoints(anArgs, aFunc);
607 //=======================================================================
608 //function : AddDerivativePoints
610 //=======================================================================
611 void IntTools_EdgeFace::AddDerivativePoints
612 (const IntTools_CArray1OfReal& t,
613 const IntTools_CArray1OfReal& f)
615 Standard_Integer i, j, n, k, nn=100;
616 Standard_Real fr, tr, tr1, dEpsNull=10.*myEpsNull;
617 IntTools_CArray1OfReal fd;
618 TColStd_SequenceOfReal aTSeq, aFSeq;
623 // Table of derivatives
624 Standard_Real dfx, tx, tx1, fx, fx1, dt=1.e-6;
629 fx1=DistanceFunction(tx1);
631 if (fx1 < myEpsNull) {
637 if (fabs(fd(0)) < dEpsNull){
643 for (i=1; i<k; i++) {
644 fd(i)=.5*(f(i+1)-f(i-1))/(t(i)-t(i-1));
645 if (fabs(fd(i)) < dEpsNull){
653 fx1=DistanceFunction(tx1);
655 if (fx1 < myEpsNull) {
661 if (fabs(fd(n-1)) < dEpsNull){
665 // Finding the range where the derivatives have different signs
666 // for neighbouring points
667 for (i=1; i<n; i++) {
668 Standard_Real fd1, fd2, t1, t2;
675 if (fabs(fd1) < myEpsNull) {
677 fr=DistanceFunction(tr);//fd1;
679 else if (fabs(fd2) < myEpsNull) {
681 fr=DistanceFunction(tr);
684 tr=FindSimpleRoot(2, t1, t2, fd1);
685 fr=DistanceFunction(tr);
691 } // end of for (i=1; i<n; i++)
693 // remove identical t, f
696 for (i=1; i<=aTSeq.Length(); i++) {
698 for (j=0; j<n; j++) {
700 if (fabs (tr1-tr) < myEpsT) {
709 // sorting args and funcs in increasing order
712 IntTools_Array1OfRange anArray1OfRange(1, k);
713 for (i=1; i<=n; i++) {
714 anArray1OfRange(i).SetFirst(t(i-1));
715 anArray1OfRange(i).SetLast (f(i-1));
717 for (i=1; i<=nn; i++) {
718 anArray1OfRange(n+i).SetFirst(aTSeq(i));
719 anArray1OfRange(n+i).SetLast (aFSeq(i));
722 IntTools_QuickSortRange aQuickSortRange;
723 IntTools_CompareRange aComparator;
724 aQuickSortRange.Sort (anArray1OfRange, aComparator);
726 // filling the output arrays
727 myArgsArray.Resize(k);
728 myFuncArray.Resize(k);
729 for (i=1; i<=k; i++) {
730 myArgsArray(i-1)=anArray1OfRange(i).First();
731 myFuncArray(i-1)=anArray1OfRange(i).Last ();
736 myArgsArray.Resize(n);
737 myFuncArray.Resize(n);
738 for (i=0; i<n; i++) {
745 //=======================================================================
746 //function : DerivativeFunction
748 //=======================================================================
749 Standard_Real IntTools_EdgeFace::DerivativeFunction
750 (const Standard_Real t2)
752 Standard_Real t1, t3, aD1, aD2, aD3;
753 Standard_Real dt=1.e-9;
755 aD1=DistanceFunction(t1);
757 aD3=DistanceFunction(t3);
763 //=======================================================================
764 //function : FindSimpleRoot
765 //purpose : [private]
766 //=======================================================================
767 Standard_Real IntTools_EdgeFace::FindSimpleRoot
768 (const Standard_Integer IP,
769 const Standard_Real tA,
770 const Standard_Real tB,
771 const Standard_Real fA)
773 Standard_Real r, a, b, y, x0, s;
781 y=DistanceFunction(x0);
783 y=DerivativeFunction(x0);
785 if (fabs(b-a) < myEpsT || y==0.) {
802 //=======================================================================
803 //function : FindGoldRoot
804 //purpose : [private]
805 //=======================================================================
806 Standard_Real IntTools_EdgeFace::FindGoldRoot
807 (const Standard_Real tA,
808 const Standard_Real tB,
809 const Standard_Real coeff)
811 Standard_Real gs=0.61803399;
812 Standard_Real a, b, xp, xl, yp, yl;
818 yp=coeff*DistanceFunction(xp);
819 yl=coeff*DistanceFunction(xl);
824 if (fabs(b-a) < myEpsT) {
832 yp=coeff*DistanceFunction(xp);
840 yl=coeff*DistanceFunction(xl);
845 //=======================================================================
846 //function : MakeType
848 //=======================================================================
849 Standard_Integer IntTools_EdgeFace::MakeType
850 (IntTools_CommonPrt& aCommonPrt)
852 Standard_Real af1, al1;
853 Standard_Real df1, tm;
854 Standard_Boolean bAllNullFlag;
856 bAllNullFlag=aCommonPrt.AllNullFlag();
858 aCommonPrt.SetType(TopAbs_EDGE);
862 aCommonPrt.Range1(af1, al1);
868 df1=aPF.Distance(aPL);
869 Standard_Boolean isWholeRange = Standard_False;
871 if((Abs(af1 - myRange.First()) < myC.Resolution(myCriteria)) &&
872 (Abs(al1 - myRange.Last()) < myC.Resolution(myCriteria)))
873 isWholeRange = Standard_True;
876 if ((df1 > myCriteria * 2.) && isWholeRange) {
877 aCommonPrt.SetType(TopAbs_EDGE);
881 tm = (af1 + al1) * 0.5;
883 if(aPF.Distance(myC.Value(tm)) > myCriteria * 2.) {
884 aCommonPrt.SetType(TopAbs_EDGE);
889 if(!CheckTouch(aCommonPrt, tm)) {
890 tm = (af1 + al1) * 0.5;
892 aCommonPrt.SetType(TopAbs_VERTEX);
893 aCommonPrt.SetVertexParameter1(tm);
894 aCommonPrt.SetRange1 (af1, al1);
901 //=======================================================================
902 //function : IsIntersection
904 //=======================================================================
905 void IntTools_EdgeFace::IsIntersection (const Standard_Real ta,
906 const Standard_Real tb)
908 IntTools_CArray1OfReal anArgs, aFunc;
909 Standard_Integer i, aNb, aCnt=0;
911 Standard_Integer aCntIncreasing=1, aCntDecreasing=1;
912 Standard_Real t, f, f1;
914 // Prepare values of arguments for the interval [ta, tb]
915 IntTools::PrepareArgs (myC, tb, ta, myDiscret, myDeflection, anArgs);
919 for (i=0; i<aNb; i++) {
922 f1=DistanceFunction(t);
925 if (fabs(f1) < myEpsNull) {
932 if (aFunc(i)>aFunc(i-1)) {
935 if (aFunc(i)<aFunc(i-1)) {
943 myParallel=Standard_True;
947 FindDerivativeRoot(anArgs, aFunc);
951 if (!(myC.GetType()==GeomAbs_Line
953 myS.GetType()==GeomAbs_Cylinder)) {
954 if (aCntDecreasing==aNb) {
955 myPar1=anArgs(aNb-1);
956 myParallel=Standard_False;
958 if (aCntIncreasing==aNb) {
960 myParallel=Standard_False;
968 //=======================================================================
969 //function : FindDerivativeRoot
971 //=======================================================================
972 void IntTools_EdgeFace::FindDerivativeRoot
973 (const IntTools_CArray1OfReal& t,
974 const IntTools_CArray1OfReal& f)
976 Standard_Integer i, n, k;
978 IntTools_CArray1OfReal fd;
979 TColStd_SequenceOfReal aTSeq, aFSeq;
982 myParallel=Standard_True;
987 // Table of derivatives
988 fd(0)=(f(1)-f(0))/(t(1)-t(0));
989 if (fabs(fd(0)) < myEpsNull) {
994 for (i=1; i<k; i++) {
995 fd(i)=.5*(f(i+1)-f(i-1))/(t(i)-t(i-1));
996 if (fabs(fd(i)) < myEpsNull) {
1001 fd(n-1)=(f(n-1)-f(n-2))/(t(n-1)-t(n-2));
1002 if (fabs(fd(n-1)) < myEpsNull) {
1006 // Finding the range where the derivatives have different signs
1007 // for neighbouring points
1008 for (i=1; i<n; i++) {
1009 Standard_Real fd1, fd2, t1, t2, fabsfd1, fabsfd2;
1010 Standard_Boolean bF1, bF2;
1017 bF1=fabsfd1 < myEpsNull;
1020 bF2=fabsfd2 < myEpsNull;
1023 tr=FindSimpleRoot(2, t1, t2, fd1);
1024 DistanceFunction(tr);
1026 myParallel=Standard_False;
1033 myParallel=Standard_False;
1040 myParallel=Standard_False;
1046 //=======================================================================
1047 //function : RemoveIdenticalRoots
1049 //=======================================================================
1050 void IntTools_EdgeFace::RemoveIdenticalRoots()
1052 Standard_Integer aNbRoots, j, k;
1054 aNbRoots=mySequenceOfRoots.Length();
1055 for (j=1; j<=aNbRoots; j++) {
1056 const IntTools_Root& aRj=mySequenceOfRoots(j);
1057 for (k=j+1; k<=aNbRoots; k++) {
1058 const IntTools_Root& aRk=mySequenceOfRoots(k);
1060 Standard_Real aTj, aTk, aDistance;
1069 aDistance=aPj.Distance(aPk);
1070 if (aDistance < myCriteria) {
1071 mySequenceOfRoots.Remove(k);
1072 aNbRoots=mySequenceOfRoots.Length();
1078 //=======================================================================
1079 //function : CheckTouch
1081 //=======================================================================
1082 Standard_Boolean IntTools_EdgeFace::CheckTouch
1083 (const IntTools_CommonPrt& aCP,
1086 Standard_Real aTF, aTL, Tol, U1f, U1l, V1f, V1l, af, al,aDist2, aMinDist2;
1087 Standard_Boolean theflag=Standard_False;
1088 Standard_Integer aNbExt, i, iLower ;
1090 aCP.Range1(aTF, aTL);
1094 aCR=myC.Resolution(myCriteria);
1095 if((Abs(aTF - myRange.First()) < aCR) &&
1096 (Abs(aTL - myRange.Last()) < aCR)) {
1097 return theflag; // EDGE
1101 Tol = Precision::PConfusion();
1103 const Handle(Geom_Curve)& Curve =BRep_Tool::Curve (myC.Edge(), af, al);
1104 const Handle(Geom_Surface)& Surface=BRep_Tool::Surface(myS.Face());
1105 // Surface->Bounds(U1f,U1l,V1f,V1l);
1106 U1f = myS.FirstUParameter();
1107 U1l = myS.LastUParameter();
1108 V1f = myS.FirstVParameter();
1109 V1l = myS.LastVParameter();
1111 GeomAdaptor_Curve TheCurve (Curve,aTF, aTL);
1112 GeomAdaptor_Surface TheSurface (Surface, U1f, U1l, V1f, V1l);
1114 Extrema_ExtCS anExtrema (TheCurve, TheSurface, Tol, Tol);
1118 if(anExtrema.IsDone()) {
1121 if(!anExtrema.IsParallel()) {
1122 aNbExt=anExtrema.NbExt();
1126 for (i=1; i<=aNbExt; i++) {
1127 aDist2=anExtrema.SquareDistance(i);
1128 if (aDist2 < aMinDist2) {
1133 aDist2=anExtrema.SquareDistance(iLower);
1134 Extrema_POnCurv aPOnC;
1135 Extrema_POnSurf aPOnS;
1136 anExtrema.Points(iLower, aPOnC, aPOnS);
1137 aTx=aPOnC.Parameter();
1140 // modified by NIZHNY-MKK Thu Jul 21 11:35:32 2005.BEGIN
1141 IntCurveSurface_HInter anExactIntersector;
1143 Handle(GeomAdaptor_HCurve) aCurve = new GeomAdaptor_HCurve(TheCurve);
1144 Handle(GeomAdaptor_HSurface) aSurface = new GeomAdaptor_HSurface(TheSurface);
1146 anExactIntersector.Perform(aCurve, aSurface);
1148 if(anExactIntersector.IsDone()) {
1149 Standard_Integer i = 0;
1151 for(i = 1; i <= anExactIntersector.NbPoints(); i++) {
1152 const IntCurveSurface_IntersectionPoint& aPoint = anExactIntersector.Point(i);
1154 if((aPoint.W() >= aTF) && (aPoint.W() <= aTL)) {
1160 // modified by NIZHNY-MKK Thu Jul 21 11:35:40 2005.END
1168 Standard_Real aBoundaryDist;
1170 aBoundaryDist = DistanceFunction(aTF) + myCriteria;
1171 if(aBoundaryDist * aBoundaryDist < aDist2) {
1172 aDist2 = aBoundaryDist * aBoundaryDist;
1176 aBoundaryDist = DistanceFunction(aTL) + myCriteria;
1177 if(aBoundaryDist * aBoundaryDist < aDist2) {
1178 aDist2 = aBoundaryDist * aBoundaryDist;
1182 Standard_Real aParameter = (aTF + aTL) * 0.5;
1183 aBoundaryDist = DistanceFunction(aParameter) + myCriteria;
1184 if(aBoundaryDist * aBoundaryDist < aDist2) {
1185 aDist2 = aBoundaryDist * aBoundaryDist;
1189 if(aDist2 > myCriteria * myCriteria) {
1193 if (fabs (aTx-aTF) < myEpsT) {
1197 if (fabs (aTx-aTL) < myEpsT) {
1201 if (aTx>aTF && aTx<aTL) {
1207 //=======================================================================
1208 //function : Perform
1210 //=======================================================================
1211 void IntTools_EdgeFace::Perform()
1213 Standard_Integer i, aNb;
1214 IntTools_CommonPrt aCommonPrt;
1216 aCommonPrt.SetEdge1(myEdge);
1220 if (myErrorStatus) {
1224 if (myContext.IsNull()) {
1225 myContext=new IntTools_Context;
1228 myIsDone = Standard_False;
1229 myC.Initialize(myEdge);
1230 GeomAbs_CurveType aCurveType;
1231 aCurveType=myC.GetType();
1233 // Prepare myCriteria
1234 if (aCurveType==GeomAbs_BSplineCurve||
1235 aCurveType==GeomAbs_BezierCurve) {
1237 Standard_Real diff1 = (myTolE/myTolF);
1238 Standard_Real diff2 = (myTolF/myTolE);
1239 if( diff1 > 100 || diff2 > 100 ) {
1240 myCriteria = Max(myTolE,myTolF);
1243 myCriteria=1.5*myTolE+myTolF;
1246 myCriteria=myTolE+myTolF;
1249 myTmin=myRange.First();
1250 myTmax=myRange.Last();
1252 myS.Initialize (myFace,Standard_True);
1254 if(myContext.IsNull()) {
1255 myFClass2d.Init(myFace, 1.e-6);
1258 IntTools_BeanFaceIntersector anIntersector(myC, myS, myTolE, myTolF);
1259 anIntersector.SetBeanParameters(myRange.First(), myRange.Last());
1261 anIntersector.SetContext(myContext);
1263 anIntersector.Perform();
1265 if(!anIntersector.IsDone()) {
1269 for(Standard_Integer r = 1; r <= anIntersector.Result().Length(); r++) {
1270 const IntTools_Range& aRange = anIntersector.Result().Value(r);
1272 if(IsProjectable(IntTools_Tools::IntermediatePoint(aRange.First(), aRange.Last()))) {
1273 aCommonPrt.SetRange1(aRange.First(), aRange.Last());
1274 mySeqOfCommonPrts.Append(aCommonPrt);
1278 aNb = mySeqOfCommonPrts.Length();
1280 for (i=1; i<=aNb; i++) {
1281 IntTools_CommonPrt& aCP=mySeqOfCommonPrts.ChangeValue(i);
1283 Standard_Real aTx1, aTx2;
1286 aCP.Range1(aTx1, aTx2);
1289 aCP.SetBoundingPoints(aPx1, aPx2);
1294 // Line\Cylinder's Common Parts treatement
1295 GeomAbs_CurveType aCType;
1296 GeomAbs_SurfaceType aSType;
1297 TopAbs_ShapeEnum aType;
1298 Standard_Boolean bIsTouch;
1301 aCType=myC.GetType();
1302 aSType=myS.GetType();
1304 if (aCType==GeomAbs_Line && aSType==GeomAbs_Cylinder) {
1305 for (i=1; i<=aNb; i++) {
1306 IntTools_CommonPrt& aCP=mySeqOfCommonPrts(i);
1308 if (aType==TopAbs_EDGE) {
1309 bIsTouch=CheckTouch (aCP, aTx);
1311 aCP.SetType(TopAbs_VERTEX);
1312 aCP.SetVertexParameter1(aTx);
1313 //aCP.SetRange1 (aTx, aTx);
1316 else if (aType==TopAbs_VERTEX) {
1317 bIsTouch=CheckTouchVertex (aCP, aTx);
1319 aCP.SetVertexParameter1(aTx);
1320 //aCP.SetRange1 (aTx, aTx);
1326 // Circle\Plane's Common Parts treatement
1328 if (aCType==GeomAbs_Circle && aSType==GeomAbs_Plane) {
1329 Standard_Boolean bIsCoplanar, bIsRadius;
1330 bIsCoplanar=IsCoplanar(myC, myS);
1331 bIsRadius=IsRadius(myC, myS, myCriteria);
1332 if (!bIsCoplanar && !bIsRadius) {
1333 for (i=1; i<=aNb; i++) {
1334 IntTools_CommonPrt& aCP=mySeqOfCommonPrts(i);
1336 if (aType==TopAbs_EDGE) {
1337 bIsTouch=CheckTouch (aCP, aTx);
1339 aCP.SetType(TopAbs_VERTEX);
1340 aCP.SetVertexParameter1(aTx);
1341 //aCP.SetRange1 (aTx, aTx);
1344 else if (aType==TopAbs_VERTEX) {
1345 bIsTouch=CheckTouchVertex (aCP, aTx);
1347 aCP.SetVertexParameter1(aTx);
1348 //aCP.SetRange1 (aTx, aTx);
1355 myIsDone=Standard_True;
1360 // 1 - the method Perform() is not invoked
1361 // 2,3,4,5 -the method CheckData() fails
1362 // 6 - PrepareArgs() problems
1363 // 7 - No Projectable ranges
1364 // 8,9 - PrepareArgs() problems occured inside projectable Ranges
1365 // 11 - can't fill array aFunc(i) in PrepareArgsFuncArrays
1368 //=======================================================================
1369 //function : CheckTouch
1371 //=======================================================================
1372 Standard_Boolean IntTools_EdgeFace::CheckTouchVertex
1373 (const IntTools_CommonPrt& aCP,
1376 Standard_Real aTF, aTL, Tol, U1f,U1l,V1f,V1l;
1377 Standard_Real aEpsT, af, al,aDist2, aMinDist2, aTm, aDist2New;
1378 Standard_Boolean theflag=Standard_False;
1379 Standard_Integer aNbExt, i, iLower ;
1380 GeomAbs_CurveType aType;
1382 aCP.Range1(aTF, aTL);
1383 aType=myC.GetType();
1386 if (aType==GeomAbs_Line) {
1391 aDist2=DistanceFunction(aTm);
1394 Tol = Precision::PConfusion();
1396 const Handle(Geom_Curve)& Curve =BRep_Tool::Curve (myC.Edge(), af, al);
1397 const Handle(Geom_Surface)& Surface=BRep_Tool::Surface(myS.Face());
1399 Surface->Bounds(U1f,U1l,V1f,V1l);
1401 GeomAdaptor_Curve TheCurve (Curve,aTF, aTL);
1402 GeomAdaptor_Surface TheSurface (Surface, U1f, U1l, V1f, V1l);
1404 Extrema_ExtCS anExtrema (TheCurve, TheSurface, Tol, Tol);
1406 if(!anExtrema.IsDone()) {
1409 if (anExtrema.IsParallel()) {
1413 aNbExt=anExtrema.NbExt() ;
1420 for (i=1; i<=aNbExt; ++i) {
1421 aDist2=anExtrema.SquareDistance(i);
1422 if (aDist2 < aMinDist2) {
1428 aDist2New=anExtrema.SquareDistance(iLower);
1430 if (aDist2New > aDist2) {
1435 if (aDist2New > myCriteria * myCriteria) {
1439 Extrema_POnCurv aPOnC;
1440 Extrema_POnSurf aPOnS;
1441 anExtrema.Points(iLower, aPOnC, aPOnS);
1444 aTx=aPOnC.Parameter();
1446 if (fabs (aTx-aTF) < aEpsT) {
1450 if (fabs (aTx-aTL) < aEpsT) {
1454 if (aTx>aTF && aTx<aTL) {
1462 //=======================================================================
1463 //function : IsCoplanar
1465 //=======================================================================
1466 Standard_Boolean IsCoplanar (const BRepAdaptor_Curve& aCurve ,
1467 const BRepAdaptor_Surface& aSurface)
1469 Standard_Boolean bFlag=Standard_False;
1471 GeomAbs_CurveType aCType;
1472 GeomAbs_SurfaceType aSType;
1474 aCType=aCurve.GetType();
1475 aSType=aSurface.GetType();
1477 if (aCType==GeomAbs_Circle && aSType==GeomAbs_Plane) {
1478 gp_Circ aCirc=aCurve.Circle();
1479 const gp_Ax1& anAx1=aCirc.Axis();
1480 const gp_Dir& aDirAx1=anAx1.Direction();
1482 gp_Pln aPln=aSurface.Plane();
1483 const gp_Ax1& anAx=aPln.Axis();
1484 const gp_Dir& aDirPln=anAx.Direction();
1486 bFlag=IntTools_Tools::IsDirsCoinside(aDirAx1, aDirPln);
1490 //=======================================================================
1491 //function : IsRadius
1493 //=======================================================================
1494 Standard_Boolean IsRadius (const BRepAdaptor_Curve& aCurve,
1495 const BRepAdaptor_Surface& aSurface,
1496 const Standard_Real aCriteria)
1498 Standard_Boolean bFlag=Standard_False;
1500 GeomAbs_CurveType aCType;
1501 GeomAbs_SurfaceType aSType;
1503 aCType=aCurve.GetType();
1504 aSType=aSurface.GetType();
1506 if (aCType==GeomAbs_Circle && aSType==GeomAbs_Plane) {
1507 gp_Circ aCirc=aCurve.Circle();
1508 const gp_Pnt aCenter=aCirc.Location();
1509 Standard_Real aR=aCirc.Radius();
1510 gp_Pln aPln=aSurface.Plane();
1511 Standard_Real aD=aPln.Distance(aCenter);
1512 if (fabs (aD-aR) < aCriteria) {
1519 //=======================================================================
1520 //function : AdaptiveDiscret
1522 //=======================================================================
1523 Standard_Integer AdaptiveDiscret (const Standard_Integer iDiscret,
1524 const BRepAdaptor_Curve& aCurve ,
1525 const BRepAdaptor_Surface& aSurface)
1527 Standard_Integer iDiscretNew;
1529 iDiscretNew=iDiscret;
1531 GeomAbs_SurfaceType aSType;
1533 aSType=aSurface.GetType();
1535 if (aSType==GeomAbs_Cylinder) {
1536 Standard_Real aELength, aRadius, dLR;
1538 aELength=IntTools::Length(aCurve.Edge());
1540 gp_Cylinder aCylinder=aSurface.Cylinder();
1541 aRadius=aCylinder.Radius();
1544 iDiscretNew=(Standard_Integer)(aELength/dLR);
1546 if (iDiscretNew<iDiscret) {
1547 iDiscretNew=iDiscret;
1556 #pragma warning ( default : 4101 )