0029915: Porting to VC 2017 : Regressions in Modeling Algorithms on VC 2017
[occt.git] / src / IntImp / IntImp_ZerParFunc.gxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
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.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #ifndef OCCT_DEBUG
16 #define No_Standard_RangeError
17 #define No_Standard_OutOfRange
18 #endif
19
20
21 #include <IntImp_ComputeTangence.hxx>
22 #include <Standard_ConstructionError.hxx>
23 #include <Precision.hxx>
24
25 #define SURF1 (*((ThePSurface *)(surf1)))
26 #define SURF2 (*((ThePSurface *)(surf2)))
27
28
29 IntImp_ZerParFunc::IntImp_ZerParFunc(const ThePSurface& S1 ,
30                                      const ThePSurface& S2) {
31     surf1 = (Standard_Address)(&S1);
32     surf2 = (Standard_Address)(&S2);
33
34     ua0 = ThePSurfaceTool::FirstUParameter(SURF1); //-- ThePSurfaceTool::UIntervalFirst(surf1);
35     va0 = ThePSurfaceTool::FirstVParameter(SURF1); //-- ThePSurfaceTool::VIntervalFirst(surf1);
36     ua1 = ThePSurfaceTool::LastUParameter(SURF1);  //-- ThePSurfaceTool::UIntervalLast(surf1);
37     va1 = ThePSurfaceTool::LastVParameter(SURF1);  //-- ThePSurfaceTool::VIntervalLast(surf1);
38
39     ub0 = ThePSurfaceTool::FirstUParameter(SURF2); //-- ThePSurfaceTool::UIntervalFirst(SURF2);
40     vb0 = ThePSurfaceTool::FirstVParameter(SURF2); //-- ThePSurfaceTool::VIntervalFirst(surf2);
41     ub1 = ThePSurfaceTool::LastUParameter(SURF2);  //-- ThePSurfaceTool::UIntervalLast(surf2);
42     vb1 = ThePSurfaceTool::LastVParameter(SURF2);  //-- ThePSurfaceTool::VIntervalLast(surf2);
43
44     ures1 = ThePSurfaceTool::UResolution(SURF1,Precision::Confusion());
45     vres1 = ThePSurfaceTool::VResolution(SURF1,Precision::Confusion());
46
47     ures2 = ThePSurfaceTool::UResolution(SURF2,Precision::Confusion());
48     vres2 = ThePSurfaceTool::VResolution(SURF2,Precision::Confusion());
49
50     compute = Standard_False;  
51     tangent = Standard_False;
52 }
53
54 Standard_Integer IntImp_ZerParFunc::NbVariables() const { return 3;}
55
56 Standard_Integer IntImp_ZerParFunc::NbEquations() const { return 3;}
57
58 Standard_Boolean IntImp_ZerParFunc::Value(const math_Vector& X,
59                                           math_Vector& F) {
60
61   switch (chxIso) {
62   case IntImp_UIsoparametricOnCaro1:
63     {
64       pntsol1= ThePSurfaceTool::Value(SURF1,paramConst,X(1));
65       pntsol2= ThePSurfaceTool::Value(SURF2,X(2),X(3));
66     }
67     break;
68   case IntImp_VIsoparametricOnCaro1:
69     {
70       pntsol1= ThePSurfaceTool::Value(SURF1,X(1),paramConst);
71       pntsol2= ThePSurfaceTool::Value(SURF2,X(2),X(3));
72     }
73     break;
74   case IntImp_UIsoparametricOnCaro2:
75     {
76       pntsol1= ThePSurfaceTool::Value(SURF1,X(1),X(2));
77       pntsol2= ThePSurfaceTool::Value(SURF2,paramConst,X(3));
78     }
79     break;
80   case IntImp_VIsoparametricOnCaro2:
81     {
82       pntsol1= ThePSurfaceTool::Value(SURF1,X(1),X(2));
83       pntsol2= ThePSurfaceTool::Value(SURF2,X(3),paramConst);
84     }
85     break;
86   }
87
88   f[0] = F(1) = pntsol1.X() - pntsol2.X();
89   f[1] = F(2) = pntsol1.Y() - pntsol2.Y();
90   f[2] = F(3) = pntsol1.Z() - pntsol2.Z();
91   return Standard_True;
92 }
93
94 Standard_Boolean IntImp_ZerParFunc::Derivatives (const math_Vector& X,
95                                                  math_Matrix& D) {
96   
97   switch (chxIso) {
98   case IntImp_UIsoparametricOnCaro1:
99     {
100       ThePSurfaceTool::D1(SURF1,paramConst,X(1),pntsol1,dpuv[0],dpuv[1]);
101       ThePSurfaceTool::D1(SURF2,X(2),X(3),pntsol2,dpuv[2],dpuv[3]);
102       D(1,1) = dpuv[1].X();
103       D(1,2) =-dpuv[2].X();
104       D(1,3) =-dpuv[3].X();
105       D(2,1) = dpuv[1].Y();
106       D(2,2) =-dpuv[2].Y();
107       D(2,3) =-dpuv[3].Y();
108       D(3,1) = dpuv[1].Z();
109       D(3,2) =-dpuv[2].Z();
110       D(3,3) =-dpuv[3].Z();
111     }
112     break;
113   case IntImp_VIsoparametricOnCaro1:
114     {
115       ThePSurfaceTool::D1(SURF1,X(1),paramConst,pntsol1,dpuv[0],dpuv[1]);
116       ThePSurfaceTool::D1(SURF2,X(2),X(3),pntsol2,dpuv[2],dpuv[3]);
117       D(1,1) = dpuv[0].X();
118       D(1,2) =-dpuv[2].X();
119       D(1,3) =-dpuv[3].X();
120       D(2,1) = dpuv[0].Y();
121       D(2,2) =-dpuv[2].Y();
122       D(2,3) =-dpuv[3].Y();
123       D(3,1) = dpuv[0].Z();
124       D(3,2) =-dpuv[2].Z();
125       D(3,3) =-dpuv[3].Z();
126     }
127     break;
128   case IntImp_UIsoparametricOnCaro2:
129     {
130       ThePSurfaceTool::D1(SURF1,X(1),X(2),pntsol1,dpuv[0],dpuv[1]);
131       ThePSurfaceTool::D1(SURF2,paramConst,X(3),pntsol2,dpuv[2],dpuv[3]);
132       D(1,1) = dpuv[0].X();
133       D(1,2) = dpuv[1].X();
134       D(1,3) =-dpuv[3].X();
135       D(2,1) = dpuv[0].Y();
136       D(2,2) = dpuv[1].Y();
137       D(2,3) =-dpuv[3].Y();
138       D(3,1) = dpuv[0].Z();
139       D(3,2) = dpuv[1].Z();
140       D(3,3) =-dpuv[3].Z();
141     }
142     break;
143   case IntImp_VIsoparametricOnCaro2:
144     {
145       ThePSurfaceTool::D1(SURF1,X(1),X(2),pntsol1,dpuv[0],dpuv[1]);
146       ThePSurfaceTool::D1(SURF2,X(3),paramConst,pntsol2,dpuv[2],dpuv[3]);
147       D(1,1) = dpuv[0].X();
148       D(1,2) = dpuv[1].X();
149       D(1,3) =-dpuv[2].X();
150       D(2,1) = dpuv[0].Y();
151       D(2,2) = dpuv[1].Y();
152       D(2,3) =-dpuv[2].Y();
153       D(3,1) = dpuv[0].Z();
154       D(3,2) = dpuv[1].Z();
155       D(3,3) =-dpuv[2].Z();
156     }
157     break;
158   }
159   return Standard_True;
160 }
161
162 Standard_Boolean IntImp_ZerParFunc::Values( const math_Vector& X,
163                                            math_Vector& F,
164                                            math_Matrix& D) {
165
166   switch (chxIso) {
167   case IntImp_UIsoparametricOnCaro1:
168     {
169       ThePSurfaceTool::D1(SURF1,paramConst,X(1),pntsol1,dpuv[0],dpuv[1]);
170       ThePSurfaceTool::D1(SURF2,X(2),X(3),pntsol2,dpuv[2],dpuv[3]);
171       D(1,1) = dpuv[1].X();
172       D(1,2) =-dpuv[2].X();
173       D(1,3) =-dpuv[3].X();
174       D(2,1) = dpuv[1].Y();
175       D(2,2) =-dpuv[2].Y();
176       D(2,3) =-dpuv[3].Y();
177       D(3,1) = dpuv[1].Z();
178       D(3,2) =-dpuv[2].Z();
179       D(3,3) =-dpuv[3].Z();
180     }
181     break;
182   case IntImp_VIsoparametricOnCaro1:
183     {
184       ThePSurfaceTool::D1(SURF1,X(1),paramConst,pntsol1,dpuv[0],dpuv[1]);
185       ThePSurfaceTool::D1(SURF2,X(2),X(3),pntsol2,dpuv[2],dpuv[3]);
186       D(1,1) = dpuv[0].X();
187       D(1,2) =-dpuv[2].X();
188       D(1,3) =-dpuv[3].X();
189       D(2,1) = dpuv[0].Y();
190       D(2,2) =-dpuv[2].Y();
191       D(2,3) =-dpuv[3].Y();
192       D(3,1) = dpuv[0].Z();
193       D(3,2) =-dpuv[2].Z();
194       D(3,3) =-dpuv[3].Z();
195     }
196     break;
197   case IntImp_UIsoparametricOnCaro2:
198     {
199       ThePSurfaceTool::D1(SURF1,X(1),X(2),pntsol1,dpuv[0],dpuv[1]);
200       ThePSurfaceTool::D1(SURF2,paramConst,X(3),pntsol2,dpuv[2],dpuv[3]);
201       D(1,1) = dpuv[0].X();
202       D(1,2) = dpuv[1].X();
203       D(1,3) =-dpuv[3].X();
204       D(2,1) = dpuv[0].Y();
205       D(2,2) = dpuv[1].Y();
206       D(2,3) =-dpuv[3].Y();
207       D(3,1) = dpuv[0].Z();
208       D(3,2) = dpuv[1].Z();
209       D(3,3) =-dpuv[3].Z();
210     }
211     break;
212   case IntImp_VIsoparametricOnCaro2:
213     {
214       ThePSurfaceTool::D1(SURF1,X(1),X(2),pntsol1,dpuv[0],dpuv[1]);
215       ThePSurfaceTool::D1(SURF2,X(3),paramConst,pntsol2,dpuv[2],dpuv[3]);
216       D(1,1) = dpuv[0].X();
217       D(1,2) = dpuv[1].X();
218       D(1,3) =-dpuv[2].X();
219       D(2,1) = dpuv[0].Y();
220       D(2,2) = dpuv[1].Y();
221       D(2,3) =-dpuv[2].Y();
222       D(3,1) = dpuv[0].Z();
223       D(3,2) = dpuv[1].Z();
224       D(3,3) =-dpuv[2].Z();
225     }
226     break;
227   }
228   f[0] = F(1) = pntsol1.X() - pntsol2.X();
229   f[1] = F(2) = pntsol1.Y() - pntsol2.Y();
230   f[2] = F(3) = pntsol1.Z() - pntsol2.Z();
231   return Standard_True;
232 }
233
234 void IntImp_ZerParFunc::ComputeParameters(
235                       const IntImp_ConstIsoparametric  ChoixIso,
236                       const TColStd_Array1OfReal& Param,  
237                       math_Vector&  UVap,
238                       math_Vector&  BornInf,
239                       math_Vector&  BornSup,
240                       math_Vector&  Tolerance ) {
241
242   chxIso = ChoixIso;
243   switch (chxIso) {
244   case IntImp_UIsoparametricOnCaro1:
245     {
246       paramConst = Param(1);
247       UVap(1) = Param(2);
248       UVap(2) = Param(3);
249       UVap(3) = Param(4);
250       
251       BornInf(1) = va0;
252       BornSup(1) = va1;
253       
254       BornInf(2) = ub0;
255       BornInf(3) = vb0;
256       BornSup(2) = ub1;
257       BornSup(3) = vb1;
258       
259       Tolerance(1)= vres1;
260       Tolerance(2)= ures2;
261       Tolerance(3)= vres2;
262     }
263     break;
264   case IntImp_VIsoparametricOnCaro1:
265     {
266       paramConst = Param(2);
267       UVap(1) = Param(1);
268       UVap(2) = Param(3);
269       UVap(3) = Param(4);
270       BornInf(1) = ua0;
271       BornSup(1) = ua1;
272       
273       BornInf(2) = ub0;
274       BornSup(2) = ub1;
275       BornInf(3) = vb0;
276       BornSup(3) = vb1;
277
278       Tolerance(1)= ures1;
279       Tolerance(2)= ures2;
280       Tolerance(3)= vres2;
281     }
282     break;
283   case IntImp_UIsoparametricOnCaro2:
284     {
285       paramConst = Param(3); 
286       UVap(1) = Param(1);
287       UVap(2) = Param(2);
288       UVap(3) = Param(4);
289       
290       BornInf(1) = ua0;
291       BornSup(1) = ua1;
292       BornInf(2) = va0;
293       BornSup(2) = va1;
294       
295       BornInf(3) = vb0;
296       BornSup(3) = vb1;
297
298       Tolerance(1)= ures1;
299       Tolerance(2)= vres1;
300       Tolerance(3)= vres2;
301     }
302     break;
303   case IntImp_VIsoparametricOnCaro2:
304     {
305       paramConst = Param(4); 
306       UVap(1) = Param(1);
307       UVap(2) = Param(2);
308       UVap(3) = Param(3);
309       
310       BornInf(1) = ua0;
311       BornSup(1) = ua1;
312       BornInf(2) = va0;
313       BornSup(2) = va1;
314
315       BornInf(3) = ub0;
316       BornSup(3) = ub1;
317
318       Tolerance(1)= ures1;
319       Tolerance(2)= vres1;
320       Tolerance(3)= ures2;
321     }
322     break;
323   }
324
325   Standard_Real Incr1 = (BornSup(1)-BornInf(1))*0.01;
326   Standard_Real Incr2 = (BornSup(2)-BornInf(2))*0.01;
327   Standard_Real Incr3 = (BornSup(3)-BornInf(3))*0.01;
328   BornInf(1) -= Incr1;
329   BornSup(1) += Incr1;
330   BornInf(2) -= Incr2;
331   BornSup(2) += Incr2;
332   BornInf(3) -= Incr3;
333   BornSup(3) += Incr3;
334
335
336
337 Standard_Boolean IntImp_ZerParFunc::IsTangent(
338               const math_Vector& UVap,
339               TColStd_Array1OfReal& Param,
340               IntImp_ConstIsoparametric& BestChoix) 
341 {
342   switch (chxIso) {
343   case IntImp_UIsoparametricOnCaro1:
344     {
345       Param(1) = paramConst;
346       Param(2) = UVap(1) ;
347       Param(3) = UVap(2) ;
348       Param(4) = UVap(3) ;
349     }
350     break;
351   case IntImp_VIsoparametricOnCaro1:
352     {
353       Param(2) = paramConst;
354       Param(1) = UVap(1) ;
355       Param(3) = UVap(2) ;
356       Param(4) = UVap(3) ;
357     }
358     break;
359   case IntImp_UIsoparametricOnCaro2:
360     {
361       Param(3) = paramConst;
362       Param(1) = UVap(1) ;
363       Param(2) = UVap(2) ;
364       Param(4) = UVap(3) ;
365     }
366     break;
367   case IntImp_VIsoparametricOnCaro2:
368     {
369       Param(4) = paramConst;
370       Param(1) = UVap(1) ;
371       Param(2) = UVap(2) ;
372       Param(3) = UVap(3) ;
373     }
374     break;
375   }
376
377   IntImp_ConstIsoparametric TabIso[4];
378   Standard_Real EpsUV[4];
379   EpsUV[0] = ures1;
380   EpsUV[1] = vres1;
381   
382   EpsUV[2] = ures2;
383   EpsUV[3] = vres2;
384
385
386   tangent = IntImp_ComputeTangence(dpuv,EpsUV,tgduv,TabIso);
387   if (!tangent) 
388     chxIso = TabIso[0];
389   BestChoix = chxIso;
390   return tangent;
391 }
392      
393
394 #undef SURF1
395 #undef SURF2
396
397
398
399
400
401
402