0024624: Lost word in license statement in source files
[occt.git] / src / AdvApp2Var / AdvApp2Var_Iso.cxx
CommitLineData
b311480e 1// Created on: 1996-07-02
2// Created by: Joelle CHAUVET
3// Copyright (c) 1996-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 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
31AdvApp2Var_Iso::AdvApp2Var_Iso() :
32myType(GeomAbs_IsoU),
33myConstPar(0.5),
34myU0(0.),
35myU1(1.),
36myV0(0.),
37myV1(1.),
38myPosition(0),
39myExtremOrder(2),
40myDerivOrder(2),
41myNbCoeff(0),
42myApprIsDone(Standard_False),
43myHasResult(Standard_False)
44{
45}
46
47//=======================================================================
48//function : AdvApp2Var_Iso
49//purpose :
50//=======================================================================
51
52AdvApp2Var_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) :
61myType(type),
62myConstPar(cte),
63myU0(Ufirst),
64myU1(Ulast),
65myV0(Vfirst),
66myV1(Vlast),
67myPosition(pos),
68myNbCoeff(0),
69myApprIsDone(Standard_False),
70myHasResult(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
87Standard_Boolean AdvApp2Var_Iso::IsApproximated() const
88{
89 return myApprIsDone;
90}
91
92//=======================================================================
93//function : HasResult
94//purpose :
95//=======================================================================
96
97Standard_Boolean AdvApp2Var_Iso::HasResult() const
98{
99 return myHasResult;
100}
101
102//=======================================================================
103//function : MakeApprox
104//purpose :
105//=======================================================================
106
107void 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{
0d969553 116// fixed values
7fd59977 117 Standard_Integer NBCRMX=1, NBCRBE;
0d969553 118// data stored in the Context
7fd59977 119 Standard_Integer NDIMEN, NBSESP, NDIMSE;
120 NDIMEN = Conditions.TotalDimension();
121 NBSESP = Conditions.TotalNumberSSP();
0d969553 122// Attention : works only in 3D
7fd59977 123 NDIMSE = 3;
0d969553 124// the domain of the grid
7fd59977 125 Standard_Real UVFONC[4];
126 UVFONC[0] = U0;
127 UVFONC[1] = U1;
128 UVFONC[2] = V0;
129 UVFONC[3] = V1;
130
0d969553 131// data related to the processed iso
7fd59977 132 Standard_Integer IORDRE = myExtremOrder, IDERIV = myDerivOrder;
133 Standard_Real TCONST = myConstPar;
134
0d969553 135// data related to the type of the iso
1d47d8d0 136 Standard_Integer ISOFAV = 0,NBROOT = 0,NDGJAC = 0,NCFLIM = 1;
7fd59977 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
0d969553 175// data relative to the position of iso (front or cut line)
7fd59977 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
0d969553 208// the tables of approximations
7fd59977 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
b6abaec0 242 // (Standard_Real *) &HERRMOY->ChangeArray2()(HERRMOY ->LowerRow(),HERRMOY ->LowerCol());
7fd59977 243 Standard_Real *EMYAPP = new Standard_Real[NBSESP];
244//
0d969553 245// the approximations
7fd59977 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++) {
0d969553 251// approximation of the derivative of order iapp
7fd59977 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);
0d969553 283// error and coefficient management.
7fd59977 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;
0d969553 291// return constraints of order 0 to IORDRE of extremities
7fd59977 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 }
0d969553 318// return errors
7fd59977 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 }
0d969553 323// passage to the approximation of higher order
7fd59977 324 CRBAPP += SZCRB;
325 SOMAPP += SZTAB;
326 DIFAPP += SZTAB;
327 }
328
0d969553 329// management of results
7fd59977 330 if (IERCOD == 0) {
0d969553 331// all approximations are correct
7fd59977 332 myApprIsDone = Standard_True;
333 myHasResult = Standard_True;
334 }
335 else if (IERCOD == -1) {
0d969553 336// at least one approximation is not correct
7fd59977 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
362void 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
379void 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
395void AdvApp2Var_Iso::SetConstante(const Standard_Real newcte)
396{
397 myConstPar = newcte;
398}
399
400//=======================================================================
401//function : SetPosition
402//purpose :
403//=======================================================================
404
405void AdvApp2Var_Iso::SetPosition(const Standard_Integer newpos)
406{
407 myPosition = newpos;
408}
409
410//=======================================================================
411//function : ResetApprox
412//purpose :
413//=======================================================================
414
415void AdvApp2Var_Iso::ResetApprox()
416{
417 myApprIsDone = Standard_False;
418 myHasResult = Standard_False;
419}
420
421//=======================================================================
422//function : OverwriteApprox
423//purpose :
424//=======================================================================
425
426void AdvApp2Var_Iso::OverwriteApprox()
427{
428 if (myHasResult) myApprIsDone = Standard_True;
429}
430
431//=======================================================================
432//function : Type
433//purpose :
434//=======================================================================
435
436GeomAbs_IsoType AdvApp2Var_Iso::Type() const
437{
438 return myType;
439}
440
441//=======================================================================
442//function : Constante
443//purpose :
444//=======================================================================
445
446Standard_Real AdvApp2Var_Iso::Constante() const
447{
448 return myConstPar;
449}
450
451//=======================================================================
452//function : T0
453//purpose :
454//=======================================================================
455
456Standard_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
471Standard_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
486Standard_Real AdvApp2Var_Iso::U0() const
487{
488 return myU0;
489}
490
491//=======================================================================
492//function : U1
493//purpose :
494//=======================================================================
495
496Standard_Real AdvApp2Var_Iso::U1() const
497{
498 return myU1;
499}
500
501//=======================================================================
502//function : V0
503//purpose :
504//=======================================================================
505
506Standard_Real AdvApp2Var_Iso::V0() const
507{
508 return myV0;
509}
510
511//=======================================================================
512//function : V1
513//purpose :
514//=======================================================================
515
516Standard_Real AdvApp2Var_Iso::V1() const
517{
518 return myV1;
519}
520
521//=======================================================================
522//function : UOrder
523//purpose :
524//=======================================================================
525
526Standard_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
538Standard_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
549Standard_Integer AdvApp2Var_Iso::Position() const
550{
551 return myPosition;
552}
553
554//=======================================================================
555//function : NbCoeff
556//purpose :
557//=======================================================================
558
559
560Standard_Integer AdvApp2Var_Iso::NbCoeff() const
561{
562 return myNbCoeff;
563}
564
565//=======================================================================
566//function : Polynom
567//purpose :
568//=======================================================================
569
570const Handle(TColStd_HArray1OfReal)& AdvApp2Var_Iso::Polynom() const
571{
572 return myEquation;
573}
574
575Handle(TColStd_HArray1OfReal) AdvApp2Var_Iso::SomTab() const
576{
577 return mySomTab;
578}
579
580Handle(TColStd_HArray1OfReal) AdvApp2Var_Iso::DifTab() const
581{
582 return myDifTab;
583}
584
585Handle(TColStd_HArray2OfReal) AdvApp2Var_Iso::MaxErrors() const
586{
587 return myMaxErrors;
588}
589
590Handle(TColStd_HArray2OfReal) AdvApp2Var_Iso::MoyErrors() const
591{
592 return myMoyErrors;
593}
594
595
596
597
598
599
600
601
602
603