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