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