b311480e |
1 | // Created on: 1996-07-02 |
2 | // Created by: Joelle CHAUVET |
3 | // Copyright (c) 1996-1999 Matra Datavision |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
5 | // |
6 | // The content of this file is subject to the Open CASCADE Technology Public |
7 | // License Version 6.5 (the "License"). You may not use the content of this file |
8 | // except in compliance with the License. Please obtain a copy of the License |
9 | // at http://www.opencascade.org and read it completely before using this file. |
10 | // |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
13 | // |
14 | // The Original Code and all software distributed under the License is |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
16 | // Initial Developer hereby disclaims all such warranties, including without |
17 | // limitation, any warranties of merchantability, fitness for a particular |
18 | // purpose or non-infringement. Please see the License for the specific terms |
19 | // and conditions governing the rights and limitations under the License. |
20 | |
7fd59977 |
21 | |
22 | |
23 | #include <AdvApp2Var_Iso.ixx> |
24 | #include <TColStd_HArray1OfInteger.hxx> |
25 | #include <TColStd_HArray2OfReal.hxx> |
26 | #include <TColStd_HArray1OfReal.hxx> |
27 | #include <gp_Pnt.hxx> |
28 | #include <AdvApp2Var_ApproxF2var.hxx> |
29 | |
30 | |
31 | |
32 | //======================================================================= |
33 | //function : AdvApp2Var_Iso |
34 | //purpose : |
35 | //======================================================================= |
36 | |
37 | AdvApp2Var_Iso::AdvApp2Var_Iso() : |
38 | myType(GeomAbs_IsoU), |
39 | myConstPar(0.5), |
40 | myU0(0.), |
41 | myU1(1.), |
42 | myV0(0.), |
43 | myV1(1.), |
44 | myPosition(0), |
45 | myExtremOrder(2), |
46 | myDerivOrder(2), |
47 | myNbCoeff(0), |
48 | myApprIsDone(Standard_False), |
49 | myHasResult(Standard_False) |
50 | { |
51 | } |
52 | |
53 | //======================================================================= |
54 | //function : AdvApp2Var_Iso |
55 | //purpose : |
56 | //======================================================================= |
57 | |
58 | AdvApp2Var_Iso::AdvApp2Var_Iso(const GeomAbs_IsoType type, |
59 | const Standard_Real cte, |
60 | const Standard_Real Ufirst, |
61 | const Standard_Real Ulast, |
62 | const Standard_Real Vfirst, |
63 | const Standard_Real Vlast, |
64 | const Standard_Integer pos, |
65 | const Standard_Integer iu, |
66 | const Standard_Integer iv) : |
67 | myType(type), |
68 | myConstPar(cte), |
69 | myU0(Ufirst), |
70 | myU1(Ulast), |
71 | myV0(Vfirst), |
72 | myV1(Vlast), |
73 | myPosition(pos), |
74 | myNbCoeff(0), |
75 | myApprIsDone(Standard_False), |
76 | myHasResult(Standard_False) |
77 | { |
78 | if (myType==GeomAbs_IsoU) { |
79 | myExtremOrder = iv; |
80 | myDerivOrder = iu; |
81 | } |
82 | else { |
83 | myExtremOrder = iu; |
84 | myDerivOrder = iv; |
85 | } |
86 | } |
87 | |
88 | //======================================================================= |
89 | //function : IsApproximated |
90 | //purpose : |
91 | //======================================================================= |
92 | |
93 | Standard_Boolean AdvApp2Var_Iso::IsApproximated() const |
94 | { |
95 | return myApprIsDone; |
96 | } |
97 | |
98 | //======================================================================= |
99 | //function : HasResult |
100 | //purpose : |
101 | //======================================================================= |
102 | |
103 | Standard_Boolean AdvApp2Var_Iso::HasResult() const |
104 | { |
105 | return myHasResult; |
106 | } |
107 | |
108 | //======================================================================= |
109 | //function : MakeApprox |
110 | //purpose : |
111 | //======================================================================= |
112 | |
113 | void AdvApp2Var_Iso::MakeApprox(const AdvApp2Var_Context& Conditions, |
114 | const Standard_Real U0, |
115 | const Standard_Real U1, |
116 | const Standard_Real V0, |
117 | const Standard_Real V1, |
118 | const AdvApp2Var_EvaluatorFunc2Var& Func, |
119 | AdvApp2Var_Node& NodeBegin, |
120 | AdvApp2Var_Node& NodeEnd) |
121 | { |
0d969553 |
122 | // fixed values |
7fd59977 |
123 | Standard_Integer NBCRMX=1, NBCRBE; |
0d969553 |
124 | // data stored in the Context |
7fd59977 |
125 | Standard_Integer NDIMEN, NBSESP, NDIMSE; |
126 | NDIMEN = Conditions.TotalDimension(); |
127 | NBSESP = Conditions.TotalNumberSSP(); |
0d969553 |
128 | // Attention : works only in 3D |
7fd59977 |
129 | NDIMSE = 3; |
0d969553 |
130 | // the domain of the grid |
7fd59977 |
131 | Standard_Real UVFONC[4]; |
132 | UVFONC[0] = U0; |
133 | UVFONC[1] = U1; |
134 | UVFONC[2] = V0; |
135 | UVFONC[3] = V1; |
136 | |
0d969553 |
137 | // data related to the processed iso |
7fd59977 |
138 | Standard_Integer IORDRE = myExtremOrder, IDERIV = myDerivOrder; |
139 | Standard_Real TCONST = myConstPar; |
140 | |
0d969553 |
141 | // data related to the type of the iso |
7fd59977 |
142 | Standard_Integer ISOFAV,NBROOT,NDGJAC,NCFLIM; |
143 | Standard_Real TABDEC[2]; |
144 | Handle (TColStd_HArray1OfReal) HUROOT = Conditions.URoots(); |
145 | Handle (TColStd_HArray1OfReal) HVROOT = Conditions.VRoots(); |
146 | Standard_Real * ROOTLG=NULL; |
147 | switch(myType) { |
148 | case GeomAbs_IsoV : |
149 | ISOFAV = 2; |
150 | TABDEC[0] = myU0; |
151 | TABDEC[1] = myU1; |
152 | UVFONC[0] = myU0; |
153 | UVFONC[1] = myU1; |
154 | NBROOT = (Conditions.URoots())->Length(); |
155 | if (myExtremOrder>-1) NBROOT -= 2; |
156 | ROOTLG = (Standard_Real *) &HUROOT ->ChangeArray1()(HUROOT ->Lower()); |
157 | NDGJAC = Conditions.UJacDeg(); |
158 | NCFLIM = Conditions.ULimit(); |
159 | break; |
160 | case GeomAbs_IsoU : |
161 | ISOFAV = 1; |
162 | TABDEC[0] = myV0; |
163 | TABDEC[1] = myV1; |
164 | UVFONC[2] = myV0; |
165 | UVFONC[3] = myV1; |
166 | NBROOT = (Conditions.VRoots())->Length(); |
167 | if (myExtremOrder>-1) NBROOT -= 2; |
168 | ROOTLG = (Standard_Real *) &HVROOT ->ChangeArray1()(HVROOT ->Lower()); |
169 | NDGJAC = Conditions.VJacDeg(); |
170 | NCFLIM = Conditions.VLimit(); |
171 | break; |
172 | //#ifndef DEB |
173 | //pkv f |
174 | case GeomAbs_NoneIso: |
175 | //pkv t |
176 | default: |
177 | break; |
178 | //#endif |
179 | } |
180 | |
0d969553 |
181 | // data relative to the position of iso (front or cut line) |
7fd59977 |
182 | Handle (TColStd_HArray1OfReal) HEPSAPR = new TColStd_HArray1OfReal(1,NBSESP); |
183 | Standard_Integer iesp; |
184 | switch(myPosition) { |
185 | case 0 : |
186 | for (iesp=1;iesp<=NBSESP;iesp++) { |
187 | HEPSAPR->SetValue(iesp,(Conditions.CToler())->Value(iesp,1)); |
188 | } |
189 | break; |
190 | case 1 : |
191 | for (iesp=1;iesp<=NBSESP;iesp++) { |
192 | HEPSAPR->SetValue(iesp,(Conditions.FToler())->Value(iesp,1)); |
193 | } |
194 | break; |
195 | case 2 : |
196 | for (iesp=1;iesp<=NBSESP;iesp++) { |
197 | HEPSAPR->SetValue(iesp,(Conditions.FToler())->Value(iesp,2)); |
198 | } |
199 | break; |
200 | case 3 : |
201 | for (iesp=1;iesp<=NBSESP;iesp++) { |
202 | HEPSAPR->SetValue(iesp,(Conditions.FToler())->Value(iesp,3)); |
203 | } |
204 | break; |
205 | case 4 : |
206 | for (iesp=1;iesp<=NBSESP;iesp++) { |
207 | HEPSAPR->SetValue(iesp,(Conditions.FToler())->Value(iesp,4)); |
208 | } |
209 | break; |
210 | } |
211 | Standard_Real *EPSAPR |
212 | = (Standard_Real *) &HEPSAPR ->ChangeArray1()(HEPSAPR ->Lower()); |
213 | |
0d969553 |
214 | // the tables of approximations |
7fd59977 |
215 | Standard_Integer SZCRB = NDIMEN*NCFLIM; |
216 | Handle (TColStd_HArray1OfReal) HCOURBE = |
217 | new TColStd_HArray1OfReal(1,SZCRB*(IDERIV+1)); |
218 | Standard_Real *COURBE = |
219 | (Standard_Real *) &HCOURBE ->ChangeArray1()(HCOURBE ->Lower()); |
220 | Standard_Real *CRBAPP = COURBE; |
221 | Standard_Integer SZTAB = (1+NBROOT/2)*NDIMEN; |
222 | Handle (TColStd_HArray1OfReal) HSOMTAB = |
223 | new TColStd_HArray1OfReal(1,SZTAB*(IDERIV+1)); |
224 | Standard_Real *SOMTAB = |
225 | (Standard_Real *) &HSOMTAB ->ChangeArray1()(HSOMTAB ->Lower()); |
226 | Standard_Real *SOMAPP = SOMTAB; |
227 | Handle (TColStd_HArray1OfReal) HDIFTAB = |
228 | new TColStd_HArray1OfReal(1,SZTAB*(IDERIV+1)); |
229 | Standard_Real *DIFTAB = |
230 | (Standard_Real *) &HDIFTAB ->ChangeArray1()(HDIFTAB ->Lower()); |
231 | Standard_Real *DIFAPP = DIFTAB; |
232 | Handle (TColStd_HArray1OfReal) HCONTR1 = |
233 | new TColStd_HArray1OfReal(1,(IORDRE+2)*NDIMEN); |
234 | Standard_Real *CONTR1 = |
235 | (Standard_Real *) &HCONTR1->ChangeArray1()(HCONTR1->Lower()); |
236 | Handle (TColStd_HArray1OfReal) HCONTR2 = |
237 | new TColStd_HArray1OfReal(1,(IORDRE+2)*NDIMEN); |
238 | Standard_Real *CONTR2 = |
239 | (Standard_Real *) &HCONTR2->ChangeArray1()(HCONTR2->Lower()); |
240 | Handle (TColStd_HArray2OfReal) HERRMAX = |
241 | new TColStd_HArray2OfReal(1,NBSESP,1,IDERIV+1); |
242 | Standard_Real *EMXAPP = new Standard_Real[NBSESP]; |
243 | Handle (TColStd_HArray2OfReal) HERRMOY = |
244 | new TColStd_HArray2OfReal(1,NBSESP,1,IDERIV+1); |
245 | //#ifdef DEB |
246 | //Standard_Real *ERRMOY = |
247 | //#endif |
248 | (Standard_Real *) &HERRMOY->ChangeArray2() |
249 | (HERRMOY ->LowerRow(),HERRMOY ->LowerCol()); |
250 | Standard_Real *EMYAPP = new Standard_Real[NBSESP]; |
251 | // |
0d969553 |
252 | // the approximations |
7fd59977 |
253 | // |
254 | Standard_Integer IERCOD=0, NCOEFF=0; |
255 | Standard_Integer iapp,ncfapp,ierapp; |
256 | // Standard_Integer id,ic,ideb; |
257 | for (iapp=0;iapp<=IDERIV;iapp++) { |
0d969553 |
258 | // approximation of the derivative of order iapp |
7fd59977 |
259 | ncfapp = 0; |
260 | ierapp = 0; |
261 | // GCC 3.0 would not accept this line without the void |
262 | // pointer cast. Perhaps the real problem is a definition |
263 | // somewhere that has a void * in it. |
264 | AdvApp2Var_ApproxF2var::mma2fnc_(&NDIMEN, |
265 | &NBSESP, |
266 | &NDIMSE, |
267 | UVFONC, |
268 | /*(void *)*/Func, |
269 | &TCONST, |
270 | &ISOFAV, |
271 | &NBROOT, |
272 | ROOTLG, |
273 | &IORDRE, |
274 | &iapp, |
275 | &NDGJAC, |
276 | &NBCRMX, |
277 | &NCFLIM, |
278 | EPSAPR, |
279 | &ncfapp, |
280 | CRBAPP, |
281 | &NBCRBE, |
282 | SOMAPP, |
283 | DIFAPP, |
284 | CONTR1, |
285 | CONTR2, |
286 | TABDEC, |
287 | EMXAPP, |
288 | EMYAPP, |
289 | &ierapp); |
0d969553 |
290 | // error and coefficient management. |
7fd59977 |
291 | if (ierapp>0) { |
292 | myApprIsDone = Standard_False; |
293 | myHasResult = Standard_False; |
294 | goto FINISH; |
295 | } |
296 | if (NCOEFF<=ncfapp) NCOEFF=ncfapp; |
297 | if (ierapp==-1) IERCOD = -1; |
0d969553 |
298 | // return constraints of order 0 to IORDRE of extremities |
7fd59977 |
299 | Standard_Integer ider, jpos=HCONTR1->Lower(); |
300 | for (ider=0; ider<=IORDRE;ider++) { |
301 | gp_Pnt pt(HCONTR1->Value(jpos), |
302 | HCONTR1->Value(jpos+1), |
303 | HCONTR1->Value(jpos+2)); |
304 | if (ISOFAV==2) { |
305 | NodeBegin.SetPoint(ider,iapp, pt); |
306 | } |
307 | else { |
308 | NodeBegin.SetPoint(iapp,ider, pt); |
309 | } |
310 | jpos+=3; |
311 | } |
312 | jpos=HCONTR2->Lower(); |
313 | for (ider=0; ider<=IORDRE;ider++) { |
314 | gp_Pnt pt(HCONTR2->Value(jpos), |
315 | HCONTR2->Value(jpos+1), |
316 | HCONTR2->Value(jpos+2)); |
317 | if (ISOFAV==2) { |
318 | NodeEnd.SetPoint(ider,iapp, pt); |
319 | } |
320 | else { |
321 | NodeEnd.SetPoint(iapp,ider, pt); |
322 | } |
323 | jpos+=3; |
324 | } |
0d969553 |
325 | // return errors |
7fd59977 |
326 | for (iesp=1; iesp<=NBSESP;iesp++) { |
327 | HERRMAX->SetValue(iesp,iapp+1,EMXAPP[iesp-1]); |
328 | HERRMOY->SetValue(iesp,iapp+1,EMYAPP[iesp-1]); |
329 | } |
0d969553 |
330 | // passage to the approximation of higher order |
7fd59977 |
331 | CRBAPP += SZCRB; |
332 | SOMAPP += SZTAB; |
333 | DIFAPP += SZTAB; |
334 | } |
335 | |
0d969553 |
336 | // management of results |
7fd59977 |
337 | if (IERCOD == 0) { |
0d969553 |
338 | // all approximations are correct |
7fd59977 |
339 | myApprIsDone = Standard_True; |
340 | myHasResult = Standard_True; |
341 | } |
342 | else if (IERCOD == -1) { |
0d969553 |
343 | // at least one approximation is not correct |
7fd59977 |
344 | myApprIsDone = Standard_False; |
345 | myHasResult = Standard_True; |
346 | } |
347 | else { |
348 | myApprIsDone = Standard_False; |
349 | myHasResult = Standard_False; |
350 | } |
351 | if ( myHasResult ) { |
352 | myEquation = HCOURBE; |
353 | myNbCoeff = NCOEFF; |
354 | myMaxErrors = HERRMAX; |
355 | myMoyErrors = HERRMOY; |
356 | mySomTab = HSOMTAB; |
357 | myDifTab = HDIFTAB; |
358 | } |
359 | FINISH: |
360 | delete []EMXAPP; |
361 | delete []EMYAPP; |
362 | } |
363 | |
364 | //======================================================================= |
365 | //function : ChangeDomain |
366 | //purpose : |
367 | //======================================================================= |
368 | |
369 | void AdvApp2Var_Iso::ChangeDomain(const Standard_Real a, const Standard_Real b) |
370 | { |
371 | if (myType==GeomAbs_IsoU) { |
372 | myV0 = a; |
373 | myV1 = b; |
374 | } |
375 | else { |
376 | myU0 = a; |
377 | myU1 = b; |
378 | } |
379 | } |
380 | |
381 | //======================================================================= |
382 | //function : ChangeDomain |
383 | //purpose : |
384 | //======================================================================= |
385 | |
386 | void AdvApp2Var_Iso::ChangeDomain(const Standard_Real a, |
387 | const Standard_Real b, |
388 | const Standard_Real c, |
389 | const Standard_Real d) |
390 | { |
391 | myU0 = a; |
392 | myU1 = b; |
393 | myV0 = c; |
394 | myV1 = d; |
395 | } |
396 | |
397 | //======================================================================= |
398 | //function : SetConstante |
399 | //purpose : |
400 | //======================================================================= |
401 | |
402 | void AdvApp2Var_Iso::SetConstante(const Standard_Real newcte) |
403 | { |
404 | myConstPar = newcte; |
405 | } |
406 | |
407 | //======================================================================= |
408 | //function : SetPosition |
409 | //purpose : |
410 | //======================================================================= |
411 | |
412 | void AdvApp2Var_Iso::SetPosition(const Standard_Integer newpos) |
413 | { |
414 | myPosition = newpos; |
415 | } |
416 | |
417 | //======================================================================= |
418 | //function : ResetApprox |
419 | //purpose : |
420 | //======================================================================= |
421 | |
422 | void AdvApp2Var_Iso::ResetApprox() |
423 | { |
424 | myApprIsDone = Standard_False; |
425 | myHasResult = Standard_False; |
426 | } |
427 | |
428 | //======================================================================= |
429 | //function : OverwriteApprox |
430 | //purpose : |
431 | //======================================================================= |
432 | |
433 | void AdvApp2Var_Iso::OverwriteApprox() |
434 | { |
435 | if (myHasResult) myApprIsDone = Standard_True; |
436 | } |
437 | |
438 | //======================================================================= |
439 | //function : Type |
440 | //purpose : |
441 | //======================================================================= |
442 | |
443 | GeomAbs_IsoType AdvApp2Var_Iso::Type() const |
444 | { |
445 | return myType; |
446 | } |
447 | |
448 | //======================================================================= |
449 | //function : Constante |
450 | //purpose : |
451 | //======================================================================= |
452 | |
453 | Standard_Real AdvApp2Var_Iso::Constante() const |
454 | { |
455 | return myConstPar; |
456 | } |
457 | |
458 | //======================================================================= |
459 | //function : T0 |
460 | //purpose : |
461 | //======================================================================= |
462 | |
463 | Standard_Real AdvApp2Var_Iso::T0() const |
464 | { |
465 | if (myType==GeomAbs_IsoU) { |
466 | return myV0; |
467 | } |
468 | else { |
469 | return myU0; |
470 | } |
471 | } |
472 | |
473 | //======================================================================= |
474 | //function : T1 |
475 | //purpose : |
476 | //======================================================================= |
477 | |
478 | Standard_Real AdvApp2Var_Iso::T1() const |
479 | { |
480 | if (myType==GeomAbs_IsoU) { |
481 | return myV1; |
482 | } |
483 | else { |
484 | return myU1; |
485 | } |
486 | } |
487 | |
488 | //======================================================================= |
489 | //function : U0 |
490 | //purpose : |
491 | //======================================================================= |
492 | |
493 | Standard_Real AdvApp2Var_Iso::U0() const |
494 | { |
495 | return myU0; |
496 | } |
497 | |
498 | //======================================================================= |
499 | //function : U1 |
500 | //purpose : |
501 | //======================================================================= |
502 | |
503 | Standard_Real AdvApp2Var_Iso::U1() const |
504 | { |
505 | return myU1; |
506 | } |
507 | |
508 | //======================================================================= |
509 | //function : V0 |
510 | //purpose : |
511 | //======================================================================= |
512 | |
513 | Standard_Real AdvApp2Var_Iso::V0() const |
514 | { |
515 | return myV0; |
516 | } |
517 | |
518 | //======================================================================= |
519 | //function : V1 |
520 | //purpose : |
521 | //======================================================================= |
522 | |
523 | Standard_Real AdvApp2Var_Iso::V1() const |
524 | { |
525 | return myV1; |
526 | } |
527 | |
528 | //======================================================================= |
529 | //function : UOrder |
530 | //purpose : |
531 | //======================================================================= |
532 | |
533 | Standard_Integer AdvApp2Var_Iso::UOrder() const |
534 | { |
535 | if (Type()==GeomAbs_IsoU) return myDerivOrder; |
536 | else return myExtremOrder; |
537 | } |
538 | |
539 | |
540 | //======================================================================= |
541 | //function : VOrder |
542 | //purpose : |
543 | //======================================================================= |
544 | |
545 | Standard_Integer AdvApp2Var_Iso::VOrder() const |
546 | { |
547 | if (Type()==GeomAbs_IsoV) return myDerivOrder; |
548 | else return myExtremOrder; |
549 | } |
550 | |
551 | //======================================================================= |
552 | //function : Position |
553 | //purpose : |
554 | //======================================================================= |
555 | |
556 | Standard_Integer AdvApp2Var_Iso::Position() const |
557 | { |
558 | return myPosition; |
559 | } |
560 | |
561 | //======================================================================= |
562 | //function : NbCoeff |
563 | //purpose : |
564 | //======================================================================= |
565 | |
566 | |
567 | Standard_Integer AdvApp2Var_Iso::NbCoeff() const |
568 | { |
569 | return myNbCoeff; |
570 | } |
571 | |
572 | //======================================================================= |
573 | //function : Polynom |
574 | //purpose : |
575 | //======================================================================= |
576 | |
577 | const Handle(TColStd_HArray1OfReal)& AdvApp2Var_Iso::Polynom() const |
578 | { |
579 | return myEquation; |
580 | } |
581 | |
582 | Handle(TColStd_HArray1OfReal) AdvApp2Var_Iso::SomTab() const |
583 | { |
584 | return mySomTab; |
585 | } |
586 | |
587 | Handle(TColStd_HArray1OfReal) AdvApp2Var_Iso::DifTab() const |
588 | { |
589 | return myDifTab; |
590 | } |
591 | |
592 | Handle(TColStd_HArray2OfReal) AdvApp2Var_Iso::MaxErrors() const |
593 | { |
594 | return myMaxErrors; |
595 | } |
596 | |
597 | Handle(TColStd_HArray2OfReal) AdvApp2Var_Iso::MoyErrors() const |
598 | { |
599 | return myMoyErrors; |
600 | } |
601 | |
602 | |
603 | |
604 | |
605 | |
606 | |
607 | |
608 | |
609 | |
610 | |