Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/opencascade/IntCurve_ExactIntersectionPoint.gxx is written in an unsupported language. File is not indexed.

0001 // Created on: 1999-12-15
0002 // Created by: Atelier CAS2000
0003 // Copyright (c) 1999-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #include <math_Vector.hxx>
0018 #include <math_FunctionSetRoot.hxx>
0019 #include <math_NewtonFunctionSetRoot.hxx>
0020 #include <gp_Vec2d.hxx>
0021 
0022 
0023 
0024 //======================================================================
0025 //===   
0026 //======================================================================
0027 IntCurve_ExactIntersectionPoint::IntCurve_ExactIntersectionPoint(const TheCurve& C1,const TheCurve& C2,const Standard_Real Tol)
0028     : done(Standard_False),
0029       nbroots(0),
0030       myTol(Tol*Tol),
0031       FctDist(C1,C2),
0032       ToleranceVector(1,2),
0033       BInfVector(1,2),
0034       BSupVector(1,2),
0035       StartingPoint(1,2),
0036       Root(1,2),
0037       anErrorOccurred(Standard_False)
0038 {
0039   ToleranceVector.Value(1) = TheCurveTool::EpsX(C1);
0040   ToleranceVector.Value(2) = TheCurveTool::EpsX(C2);
0041 }
0042   //----------------------------------------------------------------------
0043 void IntCurve_ExactIntersectionPoint::Perform( const IntCurve_ThePolygon2d& Poly1
0044                                               ,const IntCurve_ThePolygon2d& Poly2
0045                                               ,Standard_Integer&            NumSegOn1
0046                                               ,Standard_Integer&            NumSegOn2
0047                                               ,Standard_Real&               ParamOnSeg1
0048                                               ,Standard_Real&               ParamOnSeg2) 
0049 {
0050   //----------------------------------------------------------------------
0051   //-- On prend comme bornes de recherches  : 
0052   //--
0053   //--   Segment      :      i-1        i           i+1        i+2      
0054   //--
0055   //--                  |---------|-----X-------|---------|----------|
0056   //--                Inf                                Sup
0057   //--                  
0058   if(NumSegOn1 >= Poly1.NbSegments() && ParamOnSeg1==0.0) { 
0059     NumSegOn1--; ParamOnSeg1 = 1.0;
0060   }
0061   if(NumSegOn2 >= Poly2.NbSegments() && ParamOnSeg2==0.0) { 
0062     NumSegOn2--; ParamOnSeg2 = 1.0;
0063   }
0064   if(NumSegOn1 <=0) { 
0065     NumSegOn1=1; ParamOnSeg1 = 0.0;
0066   }
0067   if(NumSegOn2 <=0) { 
0068     NumSegOn2=1; ParamOnSeg2 = 0.0;
0069   }
0070 
0071   StartingPoint.Value(1) = Poly1.ApproxParamOnCurve(NumSegOn1,ParamOnSeg1);
0072   if(NumSegOn1<=2) BInfVector.Value(1)= Poly1.InfParameter(); 
0073   else  BInfVector.Value(1)= Poly1.ApproxParamOnCurve(NumSegOn1-1,(Standard_Real)0.0); 
0074   if(NumSegOn1 >= (Poly1.NbSegments() -2)) BSupVector.Value(1)= Poly1.SupParameter();
0075   else BSupVector.Value(1)= Poly1.ApproxParamOnCurve(NumSegOn1+2,(Standard_Real)0.0);
0076 
0077   StartingPoint.Value(2) = Poly2.ApproxParamOnCurve(NumSegOn2,ParamOnSeg2);
0078   if(NumSegOn2<=2) BInfVector.Value(2)= Poly2.InfParameter();
0079   else BInfVector.Value(2)= Poly2.ApproxParamOnCurve(NumSegOn2-1,(Standard_Real)0.0);
0080   if(NumSegOn2 >= (Poly2.NbSegments() -2)) BSupVector.Value(2)= Poly2.SupParameter();
0081   else BSupVector.Value(2)= Poly2.ApproxParamOnCurve(NumSegOn2+2,(Standard_Real)0.0);
0082 
0083 
0084   IntCurve_ExactIntersectionPoint::MathPerform();
0085   if(nbroots == 0) { 
0086     //      Standard_Real DeflectionOn1 = Poly1.DeflectionOverEstimation();
0087     Poly1.DeflectionOverEstimation();
0088     //      Standard_Real DeflectionOn2 = Poly2.DeflectionOverEstimation();
0089     Poly2.DeflectionOverEstimation();
0090     // if(DeflectionOn2 > Poly1.BeginOfSeg(NumSegOn1).Distance(Poly1.EndOfSeg(NumSegOn1))) {
0091     {
0092       //-- On risque de donner des bornes sur la courbe 1 trop etroites. 
0093       Standard_Integer diff=1;
0094       Standard_Real AnBinfVector = BInfVector.Value(1);
0095       Standard_Real AnBsupVector = BSupVector.Value(1);
0096       //---------------- On elargit les bornes par la gauche --------------------
0097       do { 
0098         diff++;
0099         if((NumSegOn1-diff)<=1) { 
0100           BInfVector.Value(1)= Poly1.InfParameter(); 
0101           diff=0;
0102         }
0103         else BInfVector.Value(1)= Poly1.ApproxParamOnCurve(NumSegOn1-diff,(Standard_Real)0.0); 
0104         IntCurve_ExactIntersectionPoint::MathPerform();
0105         //-- le 18 nov 97 
0106         if(diff>3) diff+=NumSegOn1/2;     
0107       }
0108       while( nbroots==0 && diff!=0);
0109       //---------------- On elargit les bornes par la droite --------------------       
0110       if(nbroots==0) { 
0111         BInfVector.Value(1) = AnBinfVector;
0112         diff=1;
0113         do { 
0114           diff++;
0115           if((NumSegOn1+diff) >= (Poly1.NbSegments() -1)) { 
0116             BSupVector.Value(1)= Poly1.SupParameter();
0117             diff=0;
0118           }
0119           else BSupVector.Value(1)= Poly1.ApproxParamOnCurve(NumSegOn1+1+diff,(Standard_Real)0.0);
0120           IntCurve_ExactIntersectionPoint::MathPerform();
0121           //-- le 18 nov 97 
0122           if(diff>3) diff+=1+(Poly1.NbSegments()-NumSegOn1)/2;
0123         }
0124         while( nbroots==0 && diff!=0);
0125       }
0126       BSupVector.Value(1) = AnBsupVector;
0127     }
0128 
0129     if(nbroots==0) { 
0130       //-- On risque de donner des bornes sur la courbe 1 trop etroites. 
0131       Standard_Integer diff=1;
0132       Standard_Real AnBinfVector = BInfVector.Value(2);
0133       Standard_Real AnBsupVector = BSupVector.Value(2);
0134       //---------------- On elargit les bornes par la gauche --------------------
0135       do { 
0136         diff++;
0137         if((NumSegOn2-diff)<=1) { 
0138           BInfVector.Value(2)= Poly2.InfParameter(); 
0139           diff=0;
0140         }
0141         else BInfVector.Value(2)= Poly2.ApproxParamOnCurve(NumSegOn2-diff,(Standard_Real)0.0); 
0142         IntCurve_ExactIntersectionPoint::MathPerform();
0143         //-- le 18 nov 97 
0144         if(diff>3) diff+=NumSegOn2/2;
0145       }
0146       while( nbroots==0 && diff!=0);
0147       //---------------- On elargit les bornes par la droite --------------------       
0148       if(nbroots==0) 
0149       { 
0150         BInfVector.Value(2) = AnBinfVector;
0151         diff=1;
0152         do { 
0153           diff++;
0154           if((NumSegOn2+diff) >= (Poly2.NbSegments() -1)) { 
0155             BSupVector.Value(2)= Poly2.SupParameter();
0156             diff=0;
0157           }
0158           else BSupVector.Value(2)= Poly2.ApproxParamOnCurve(NumSegOn2+1+diff,(Standard_Real)0.0);
0159           IntCurve_ExactIntersectionPoint::MathPerform();
0160           //-- le 18 nov 97 
0161           if(diff>3) diff+=1+(Poly2.NbSegments()-NumSegOn2)/2;
0162         }
0163         while( nbroots==0 && diff!=0);
0164       }
0165       BSupVector.Value(2) = AnBsupVector;
0166     }
0167   }
0168 }
0169   //----------------------------------------------------------------------
0170 void IntCurve_ExactIntersectionPoint::Perform( const Standard_Real Uo
0171                ,const Standard_Real Vo
0172                ,const Standard_Real UInf
0173                ,const Standard_Real VInf
0174                ,const Standard_Real USup
0175                ,const Standard_Real VSup) { 
0176     
0177     done = Standard_True;
0178     
0179     BInfVector.Value(1) = UInf;
0180     BInfVector.Value(2) = VInf;
0181     BSupVector.Value(1) = USup;
0182     BSupVector.Value(2) = VSup;
0183     StartingPoint.Value(1) = Uo;
0184     StartingPoint.Value(2) = Vo;
0185     
0186     IntCurve_ExactIntersectionPoint::MathPerform();
0187     
0188   }
0189   //----------------------------------------------------------------------
0190 Standard_Integer IntCurve_ExactIntersectionPoint::NbRoots() const { return(nbroots); } 
0191   //----------------------------------------------------------------------
0192 
0193 void IntCurve_ExactIntersectionPoint::Roots(Standard_Real& U,Standard_Real& V) {
0194     U=Root.Value(1);
0195     V=Root.Value(2); 
0196   }
0197   //----------------------------------------------------------------------
0198 
0199 void IntCurve_ExactIntersectionPoint::MathPerform(void)
0200 {
0201   math_FunctionSetRoot Fct(FctDist, ToleranceVector, 60);
0202   Fct.Perform(FctDist, StartingPoint, BInfVector, BSupVector);
0203 
0204   if(Fct.IsDone()) { 
0205     Fct.Root(Root); nbroots = 1; 
0206     math_Vector XY(1,2);
0207     FctDist.Value(Root,XY);
0208     Standard_Real dist2 = ((XY(1)*XY(1)+XY(2)*XY(2)));
0209 
0210     if(dist2 > myTol) 
0211     {
0212       nbroots = 0;
0213     }
0214   }
0215   else { 
0216     anErrorOccurred = Standard_True;
0217     nbroots = 0; 
0218   }
0219 }
0220     
0221 //======================================================================
0222 
0223 Standard_Boolean IntCurve_ExactIntersectionPoint::AnErrorOccurred() const
0224 {
0225   return anErrorOccurred;
0226 }