1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
16 #define No_Standard_RangeError
17 #define No_Standard_OutOfRange
21 #include <IntImp_ComputeTangence.hxx>
22 #include <math_FunctionSetRoot.hxx>
23 #include <math_Vector.hxx>
24 #include <IntImp_ConstIsoparametric.hxx>
25 #include <Standard_ConstructionError.hxx>
26 #include <Precision.hxx>
28 IntImp_Int2S::IntImp_Int2S(const ThePSurface& surf1,
29 const ThePSurface& surf2,
30 const Standard_Real TolTangency ) :
33 myZerParFunc(surf1,surf2),
34 tol(TolTangency*TolTangency)
36 ua0 = ThePSurfaceTool::FirstUParameter(surf1); //-- ThePSurfaceTool::UIntervalFirst(surf1);
37 va0 = ThePSurfaceTool::FirstVParameter(surf1); //-- ThePSurfaceTool::VIntervalFirst(surf1);
38 ua1 = ThePSurfaceTool::LastUParameter(surf1); //-- ThePSurfaceTool::UIntervalLast(surf1);
39 va1 = ThePSurfaceTool::LastVParameter(surf1); //-- ThePSurfaceTool::VIntervalLast(surf1);
41 ub0 = ThePSurfaceTool::FirstUParameter(surf2); //-- ThePSurfaceTool::UIntervalFirst(surf2);
42 vb0 = ThePSurfaceTool::FirstVParameter(surf2); //-- ThePSurfaceTool::VIntervalFirst(surf2);
43 ub1 = ThePSurfaceTool::LastUParameter(surf2); //-- ThePSurfaceTool::UIntervalLast(surf2);
44 vb1 = ThePSurfaceTool::LastVParameter(surf2); //-- ThePSurfaceTool::VIntervalLast(surf2);
46 ures1 = ThePSurfaceTool::UResolution(surf1,Precision::Confusion());
47 vres1 = ThePSurfaceTool::VResolution(surf1,Precision::Confusion());
49 ures2 = ThePSurfaceTool::UResolution(surf2,Precision::Confusion());
50 vres2 = ThePSurfaceTool::VResolution(surf2,Precision::Confusion());
54 IntImp_Int2S::IntImp_Int2S(const TColStd_Array1OfReal& Param,
55 const ThePSurface& surf1,
56 const ThePSurface& surf2,
57 const Standard_Real TolTangency ) :
60 myZerParFunc(surf1,surf2),
61 tol(TolTangency*TolTangency)
63 math_FunctionSetRoot Rsnld(myZerParFunc,15); //-- Modif lbr 18 MAI ?????????????
64 ua0 = ThePSurfaceTool::FirstUParameter(surf1); //-- ThePSurfaceTool::UIntervalFirst(surf1);
65 va0 = ThePSurfaceTool::FirstVParameter(surf1); //-- ThePSurfaceTool::VIntervalFirst(surf1);
66 ua1 = ThePSurfaceTool::LastUParameter(surf1); //-- ThePSurfaceTool::UIntervalLast(surf1);
67 va1 = ThePSurfaceTool::LastVParameter(surf1); //-- ThePSurfaceTool::VIntervalLast(surf1);
69 ub0 = ThePSurfaceTool::FirstUParameter(surf2); //-- ThePSurfaceTool::UIntervalFirst(surf2);
70 vb0 = ThePSurfaceTool::FirstVParameter(surf2); //-- ThePSurfaceTool::VIntervalFirst(surf2);
71 ub1 = ThePSurfaceTool::LastUParameter(surf2); //-- ThePSurfaceTool::UIntervalLast(surf2);
72 vb1 = ThePSurfaceTool::LastVParameter(surf2); //-- ThePSurfaceTool::VIntervalLast(surf2);
74 ures1 = ThePSurfaceTool::UResolution(surf1,Precision::Confusion());
75 vres1 = ThePSurfaceTool::VResolution(surf1,Precision::Confusion());
77 ures2 = ThePSurfaceTool::UResolution(surf2,Precision::Confusion());
78 vres2 = ThePSurfaceTool::VResolution(surf2,Precision::Confusion());
82 IntImp_ConstIsoparametric IntImp_Int2S:: Perform(const TColStd_Array1OfReal& Param,
83 math_FunctionSetRoot& Rsnld,
84 const IntImp_ConstIsoparametric ChoixIso)
86 Standard_Real BornInfBuf[3], BornSupBuf[3], ToleranceBuf[3], UVapBuf[3];
87 Standard_Real UvresBuf[4];
88 math_Vector BornInf (BornInfBuf, 1, 3), BornSup (BornSupBuf, 1, 3),
89 Tolerance (ToleranceBuf, 1, 3), UVap (UVapBuf, 1, 3);
90 TColStd_Array1OfReal Uvres (UvresBuf[0], 1, 4);
92 IntImp_ConstIsoparametric BestChoix;
94 myZerParFunc.ComputeParameters(ChoixIso,Param,UVap,BornInf,BornSup,Tolerance);
95 Rsnld.SetTolerance(Tolerance);
96 Rsnld.Perform(myZerParFunc,UVap,BornInf,BornSup);
99 if (Abs(myZerParFunc.Root()) <= tol) { //distance des 2 points
102 empty = Standard_False;
103 tangent = myZerParFunc.IsTangent(UVap,Uvres,BestChoix);
104 pint.SetValue(myZerParFunc.Point(),Uvres(1),Uvres(2),Uvres(3),Uvres(4));
106 d3d = myZerParFunc.Direction();
107 d2d1 = myZerParFunc.DirectionOnS1();
108 d2d2 = myZerParFunc.DirectionOnS2();
112 empty = Standard_True;
116 empty = Standard_True;
121 IntImp_ConstIsoparametric IntImp_Int2S:: Perform(const TColStd_Array1OfReal& Param,
122 math_FunctionSetRoot& Rsnld)
126 Standard_Real Epsuv[4];
127 Standard_Real DuvBuf[4];
128 TColStd_Array1OfReal Duv (DuvBuf[0], 1, 4);
129 Standard_Real UVd[4],UVf[4];
130 IntImp_ConstIsoparametric ChoixIso[4];
131 IntImp_ConstIsoparametric BestChoix = ChoixRef(0);
132 const ThePSurface& Caro1 = myZerParFunc.AuxillarSurface1();
133 const ThePSurface& Caro2 = myZerParFunc.AuxillarSurface2();
135 ThePSurfaceTool::D1(Caro1, Param(1),Param(2),P1,DPUV[0],DPUV[1]);
136 ThePSurfaceTool::D1(Caro2, Param(3),Param(4),P2,DPUV[2],DPUV[3]);
138 Epsuv[0] = ThePSurfaceTool::UResolution(Caro1,Precision::Confusion());
139 Epsuv[1] = ThePSurfaceTool::VResolution(Caro1,Precision::Confusion());
141 Epsuv[2] = ThePSurfaceTool::UResolution(Caro2,Precision::Confusion());
142 Epsuv[3] = ThePSurfaceTool::VResolution(Caro2,Precision::Confusion());
144 for (Standard_Integer j=0;j<=3;j++)
147 empty = Standard_True;
149 Standard_Boolean Tangent = IntImp_ComputeTangence(DPUV,Epsuv,UVd,ChoixIso);
153 Standard_Integer i=0;
154 IntImp_ConstIsoparametric CurrentChoix = BestChoix; //-- Modif 17 Mai 93
156 while (empty && i<= 3)
158 CurrentChoix = Perform(Param,Rsnld,ChoixIso[i]);
160 BestChoix = CurrentChoix;
164 if (!empty) { // verifier que l on ne deborde pas les frontieres
165 pint.Parameters(Duv(1),Duv(2),Duv(3),Duv(4));
167 UVd[0] = ua0; //-- ThePSurfaceTool::UIntervalFirst(Caro1);
168 UVd[1] = va0; //-- ThePSurfaceTool::VIntervalFirst(Caro1);
169 UVf[0] = ua1; //-- ThePSurfaceTool::UIntervalLast(Caro1);
170 UVf[1] = va1; //-- ThePSurfaceTool::VIntervalLast(Caro1);
172 UVd[2] = ub0; //-- ThePSurfaceTool::UIntervalFirst(Caro2);
173 UVd[3] = vb0; //-- ubThePSurfaceTool::VIntervalFirst(Caro2);
174 UVf[2] = ub1; //-- ThePSurfaceTool::UIntervalLast(Caro2);
175 UVf[3] = vb1; //-- ThePSurfaceTool::VIntervalLast(Caro2);
177 Standard_Integer Nc,Iiso;
178 if (Duv(1) <= UVd[0]-Epsuv[0]) {
183 else if (Duv(1) >= UVf[0]+ Epsuv[0]) {
188 else if (Duv(2) <= UVd[1] -Epsuv[1]) {
193 else if (Duv(2) >= UVf[1]+Epsuv[1]) {
198 else if (Duv(3) <= UVd[2]-Epsuv[2]) {
203 else if (Duv(3) >= UVf[2]+Epsuv[2]) {
208 else if (Duv(4) <= UVd[3]-Epsuv[3]) {
213 else if (Duv(4) >= UVf[3]+Epsuv[3]) {
218 else return BestChoix; // on a gagne
219 empty = Standard_True;
220 BestChoix = ChoixRef(Iiso); //en attendant
221 BestChoix = Perform(Duv,Rsnld,BestChoix);
222 if (!empty) { // verification si l on ne deborde pas sur le carreau
225 if (Duv(Nc) <= UVd[Nc-1]-Epsuv[Nc-1])
227 else if (Duv(Nc) >=UVf[Nc-1]+Epsuv[Nc-1])
229 else if (Duv(Nc+1) <= UVd[Nc])
234 else if (Duv(Nc+1) >=UVf[Nc])
242 empty = Standard_True;
247 BestChoix = ChoixRef(Nc); //en attendant
248 BestChoix = Perform(Duv,Rsnld,BestChoix);