summaryrefslogtreecommitdiff
path: root/src/AdvApp2Var/AdvApp2Var_Iso.cxx
blob: fe1cb9c1068443e38e5a2b44dea9dedd90c87dde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
// File:	AdvApp2Var_Iso.cxx
// Created:	Tue Jul  2 12:12:24 1996
// Author:	Joelle CHAUVET
//		<jct@sgi38>


#include <AdvApp2Var_Iso.ixx>
#include <TColStd_HArray1OfInteger.hxx>
#include <TColStd_HArray2OfReal.hxx>
#include <TColStd_HArray1OfReal.hxx>
#include <gp_Pnt.hxx>
#include <AdvApp2Var_ApproxF2var.hxx>



//=======================================================================
//function : AdvApp2Var_Iso
//purpose  : 
//=======================================================================

AdvApp2Var_Iso::AdvApp2Var_Iso()  :
myType(GeomAbs_IsoU),
myConstPar(0.5),
myU0(0.),
myU1(1.),
myV0(0.),
myV1(1.),
myPosition(0),
myExtremOrder(2),
myDerivOrder(2),
myNbCoeff(0),
myApprIsDone(Standard_False),
myHasResult(Standard_False)
{
}

//=======================================================================
//function : AdvApp2Var_Iso
//purpose  : 
//=======================================================================

AdvApp2Var_Iso::AdvApp2Var_Iso(const GeomAbs_IsoType type,
			       const Standard_Real cte,
			       const Standard_Real Ufirst,
			       const Standard_Real Ulast,
			       const Standard_Real Vfirst,
			       const Standard_Real Vlast,
			       const Standard_Integer pos,
			       const Standard_Integer iu,
			       const Standard_Integer iv) :
myType(type),
myConstPar(cte),
myU0(Ufirst),
myU1(Ulast),
myV0(Vfirst),
myV1(Vlast),
myPosition(pos),
myNbCoeff(0),
myApprIsDone(Standard_False),
myHasResult(Standard_False)
{
  if (myType==GeomAbs_IsoU) {
    myExtremOrder = iv;
    myDerivOrder = iu;
  }
  else {
    myExtremOrder = iu;
    myDerivOrder = iv;
  }
}

//=======================================================================
//function : IsApproximated
//purpose  : 
//=======================================================================

Standard_Boolean AdvApp2Var_Iso::IsApproximated() const
{
  return myApprIsDone;
}

//=======================================================================
//function : HasResult
//purpose  : 
//=======================================================================

Standard_Boolean AdvApp2Var_Iso::HasResult() const
{
  return myHasResult;
}

//=======================================================================
//function : MakeApprox
//purpose  : 
//=======================================================================

void AdvApp2Var_Iso::MakeApprox(const AdvApp2Var_Context& Conditions,
                                const Standard_Real U0, 
                                const Standard_Real U1, 
                                const Standard_Real V0, 
                                const Standard_Real V1, 
			     	const AdvApp2Var_EvaluatorFunc2Var& Func,
			     	AdvApp2Var_Node& NodeBegin,
				AdvApp2Var_Node& NodeEnd)
{
// les valeurs fixes
  Standard_Integer NBCRMX=1, NBCRBE;
// les donnees stockees dans le Context
  Standard_Integer NDIMEN, NBSESP, NDIMSE;
  NDIMEN = Conditions.TotalDimension();
  NBSESP = Conditions.TotalNumberSSP();
// Attention : ne marche que pour le 3D
  NDIMSE = 3;
// le domaine de la grille
  Standard_Real UVFONC[4];
  UVFONC[0] = U0;
  UVFONC[1] = U1;
  UVFONC[2] = V0;
  UVFONC[3] = V1;

// les donnees relatives a l'iso a approcher
  Standard_Integer IORDRE = myExtremOrder, IDERIV = myDerivOrder;
  Standard_Real TCONST = myConstPar;

// les donnees relatives au type de l'iso
  Standard_Integer ISOFAV,NBROOT = 0,NDGJAC,NCFLIM = 0;
  Standard_Real TABDEC[2];
  Handle (TColStd_HArray1OfReal) HUROOT  = Conditions.URoots();
  Handle (TColStd_HArray1OfReal) HVROOT  = Conditions.VRoots();
  Standard_Real * ROOTLG=NULL;
  switch(myType) {
   case GeomAbs_IsoV : 
    ISOFAV = 2;
    TABDEC[0] = myU0;
    TABDEC[1] = myU1;
    UVFONC[0] = myU0;
    UVFONC[1] = myU1;
    NBROOT = (Conditions.URoots())->Length();
    if (myExtremOrder>-1) NBROOT -= 2;
    ROOTLG =  (Standard_Real *) &HUROOT ->ChangeArray1()(HUROOT ->Lower());
    NDGJAC = Conditions.UJacDeg();
    NCFLIM = Conditions.ULimit();
    break;
   case GeomAbs_IsoU : 
    ISOFAV = 1;
    TABDEC[0] = myV0;
    TABDEC[1] = myV1;
    UVFONC[2] = myV0;
    UVFONC[3] = myV1;
    NBROOT = (Conditions.VRoots())->Length();
    if (myExtremOrder>-1) NBROOT -= 2;
    ROOTLG =  (Standard_Real *) &HVROOT ->ChangeArray1()(HVROOT ->Lower());
    NDGJAC = Conditions.VJacDeg();
    NCFLIM = Conditions.VLimit();
    break;
    //#ifndef DEB
    //pkv f
  case GeomAbs_NoneIso:
    //pkv t
  default:
    break;
    //#endif
  }

// les donnees relatives a la position de l'iso (frontiere ou ligne de decoupe)
  Handle (TColStd_HArray1OfReal) HEPSAPR = new TColStd_HArray1OfReal(1,NBSESP);
  Standard_Integer iesp;
  switch(myPosition) {
   case 0 :
    for (iesp=1;iesp<=NBSESP;iesp++) {
      HEPSAPR->SetValue(iesp,(Conditions.CToler())->Value(iesp,1));
    }
    break;
   case 1 : 
    for (iesp=1;iesp<=NBSESP;iesp++) {
      HEPSAPR->SetValue(iesp,(Conditions.FToler())->Value(iesp,1));
    }
    break;
   case 2 : 
    for (iesp=1;iesp<=NBSESP;iesp++) {
      HEPSAPR->SetValue(iesp,(Conditions.FToler())->Value(iesp,2));
    }
    break;
   case 3 : 
    for (iesp=1;iesp<=NBSESP;iesp++) {
      HEPSAPR->SetValue(iesp,(Conditions.FToler())->Value(iesp,3));
    }
    break;
   case 4 : 
    for (iesp=1;iesp<=NBSESP;iesp++) {
      HEPSAPR->SetValue(iesp,(Conditions.FToler())->Value(iesp,4));
    }
    break;
  }
  Standard_Real *EPSAPR  
    =  (Standard_Real *) &HEPSAPR ->ChangeArray1()(HEPSAPR ->Lower());

// les tableaux des approximations
  Standard_Integer SZCRB = NDIMEN*NCFLIM;
  Handle (TColStd_HArray1OfReal) HCOURBE  =
    new TColStd_HArray1OfReal(1,SZCRB*(IDERIV+1));
  Standard_Real *COURBE  =  
    (Standard_Real *) &HCOURBE ->ChangeArray1()(HCOURBE ->Lower());
  Standard_Real *CRBAPP = COURBE;
  Standard_Integer SZTAB = (1+NBROOT/2)*NDIMEN;
  Handle (TColStd_HArray1OfReal) HSOMTAB  =
    new TColStd_HArray1OfReal(1,SZTAB*(IDERIV+1));
  Standard_Real *SOMTAB  =  
    (Standard_Real *) &HSOMTAB ->ChangeArray1()(HSOMTAB ->Lower());
  Standard_Real *SOMAPP = SOMTAB;
  Handle (TColStd_HArray1OfReal) HDIFTAB  =
    new TColStd_HArray1OfReal(1,SZTAB*(IDERIV+1));
  Standard_Real *DIFTAB  =  
    (Standard_Real *) &HDIFTAB ->ChangeArray1()(HDIFTAB ->Lower());
  Standard_Real *DIFAPP = DIFTAB;
  Handle (TColStd_HArray1OfReal) HCONTR1 = 
    new TColStd_HArray1OfReal(1,(IORDRE+2)*NDIMEN);
  Standard_Real *CONTR1 = 
    (Standard_Real *) &HCONTR1->ChangeArray1()(HCONTR1->Lower()); 
  Handle (TColStd_HArray1OfReal) HCONTR2 = 
    new TColStd_HArray1OfReal(1,(IORDRE+2)*NDIMEN);
  Standard_Real *CONTR2 = 
    (Standard_Real *) &HCONTR2->ChangeArray1()(HCONTR2->Lower()); 
  Handle (TColStd_HArray2OfReal) HERRMAX  =  
    new TColStd_HArray2OfReal(1,NBSESP,1,IDERIV+1);
  Standard_Real *EMXAPP = new Standard_Real[NBSESP];
  Handle (TColStd_HArray2OfReal) HERRMOY  =  
    new TColStd_HArray2OfReal(1,NBSESP,1,IDERIV+1);
  //#ifdef DEB
  //Standard_Real *ERRMOY =
  //#endif
    (Standard_Real *) &HERRMOY->ChangeArray2()
                                (HERRMOY ->LowerRow(),HERRMOY ->LowerCol());
  Standard_Real *EMYAPP = new Standard_Real[NBSESP];
//
// les approximations
//
  Standard_Integer IERCOD=0, NCOEFF=0;
  Standard_Integer iapp,ncfapp,ierapp;
//  Standard_Integer id,ic,ideb;
  for (iapp=0;iapp<=IDERIV;iapp++) {
//   approximation de la derivee d'ordre iapp
    ncfapp = 0;
    ierapp = 0;
    // GCC 3.0 would not accept this line without the void
    // pointer cast.  Perhaps the real problem is a definition
    // somewhere that has a void * in it.
    AdvApp2Var_ApproxF2var::mma2fnc_(&NDIMEN,
				     &NBSESP,
				     &NDIMSE,
				     UVFONC,
				     /*(void *)*/Func,
				     &TCONST,
				     &ISOFAV,
				     &NBROOT,
				     ROOTLG,
				     &IORDRE,
				     &iapp,
				     &NDGJAC,
				     &NBCRMX,
				     &NCFLIM,
				     EPSAPR,
				     &ncfapp,
				     CRBAPP,
				     &NBCRBE,
				     SOMAPP,
				     DIFAPP,
				     CONTR1,
				     CONTR2,
				     TABDEC,
				     EMXAPP,
				     EMYAPP,
				     &ierapp);
//   gestion des erreurs et du nombre de coeff.
    if (ierapp>0) {
      myApprIsDone = Standard_False;
      myHasResult  = Standard_False;
      goto FINISH;
    }
    if (NCOEFF<=ncfapp) NCOEFF=ncfapp;
    if (ierapp==-1) IERCOD = -1;
//   recuperation des contraintes d'ordre 0 a IORDRE aux extremites
    Standard_Integer ider, jpos=HCONTR1->Lower();
    for (ider=0; ider<=IORDRE;ider++) {
      gp_Pnt pt(HCONTR1->Value(jpos),
		HCONTR1->Value(jpos+1),
		HCONTR1->Value(jpos+2));
      if (ISOFAV==2) {
	NodeBegin.SetPoint(ider,iapp, pt);
      }
      else {
	NodeBegin.SetPoint(iapp,ider, pt);
      }
      jpos+=3;
    }
    jpos=HCONTR2->Lower();
    for (ider=0; ider<=IORDRE;ider++) {
      gp_Pnt pt(HCONTR2->Value(jpos),
		HCONTR2->Value(jpos+1),
		HCONTR2->Value(jpos+2));
      if (ISOFAV==2) {
	NodeEnd.SetPoint(ider,iapp, pt);
      }
      else {
	NodeEnd.SetPoint(iapp,ider, pt);
      }
      jpos+=3;
    }
//   recuperation des erreurs
    for (iesp=1; iesp<=NBSESP;iesp++) {
      HERRMAX->SetValue(iesp,iapp+1,EMXAPP[iesp-1]);
      HERRMOY->SetValue(iesp,iapp+1,EMYAPP[iesp-1]);
    }
// passage a l'approximation d'ordre superieur
    CRBAPP += SZCRB;
    SOMAPP += SZTAB;
    DIFAPP += SZTAB;
  }

// gestion des resultats
  if (IERCOD == 0) {
//   toutes les approx. sont bonnes
    myApprIsDone = Standard_True;
    myHasResult  = Standard_True;
  }
  else if (IERCOD == -1) {
//   une approx. au moins n'est pas bonne
    myApprIsDone = Standard_False;
    myHasResult  = Standard_True;
  } 
  else { 
    myApprIsDone = Standard_False;
    myHasResult  = Standard_False;
  } 
  if ( myHasResult ) {
    myEquation = HCOURBE;
    myNbCoeff  = NCOEFF;
    myMaxErrors = HERRMAX;
    myMoyErrors = HERRMOY;
    mySomTab = HSOMTAB;
    myDifTab = HDIFTAB;
  }
  FINISH:
  delete []EMXAPP;
  delete []EMYAPP;
}

//=======================================================================
//function : ChangeDomain
//purpose  : 
//=======================================================================

void AdvApp2Var_Iso::ChangeDomain(const Standard_Real a, const Standard_Real b)
{
  if (myType==GeomAbs_IsoU) {
    myV0 = a;
    myV1 = b;
  }
  else {
    myU0 = a;
    myU1 = b;
  }
}

//=======================================================================
//function : ChangeDomain
//purpose  : 
//=======================================================================

void AdvApp2Var_Iso::ChangeDomain(const Standard_Real a,
				  const Standard_Real b,
				  const Standard_Real c,
				  const Standard_Real d)
{
  myU0 = a;
  myU1 = b;
  myV0 = c;
  myV1 = d;
}

//=======================================================================
//function : SetConstante
//purpose  : 
//=======================================================================

void AdvApp2Var_Iso::SetConstante(const Standard_Real newcte)
{
  myConstPar = newcte;
}

//=======================================================================
//function : SetPosition
//purpose  : 
//=======================================================================

void AdvApp2Var_Iso::SetPosition(const Standard_Integer newpos)
{
  myPosition = newpos;
}

//=======================================================================
//function : ResetApprox
//purpose  : 
//=======================================================================

void AdvApp2Var_Iso::ResetApprox()
{
  myApprIsDone = Standard_False;
  myHasResult = Standard_False;
}

//=======================================================================
//function : OverwriteApprox
//purpose  : 
//=======================================================================

void AdvApp2Var_Iso::OverwriteApprox()
{
  if (myHasResult) myApprIsDone = Standard_True;
}

//=======================================================================
//function : Type
//purpose  : 
//=======================================================================

GeomAbs_IsoType AdvApp2Var_Iso::Type() const 
{
  return myType;
}

//=======================================================================
//function : Constante
//purpose  : 
//=======================================================================

Standard_Real AdvApp2Var_Iso::Constante() const 
{
  return myConstPar;
}

//=======================================================================
//function : T0
//purpose  : 
//=======================================================================

Standard_Real AdvApp2Var_Iso::T0() const 
{
  if (myType==GeomAbs_IsoU) {
    return myV0;
  }
  else {
    return myU0;
  }
}

//=======================================================================
//function : T1
//purpose  : 
//=======================================================================

Standard_Real AdvApp2Var_Iso::T1() const 
{
  if (myType==GeomAbs_IsoU) {
    return myV1;
  }
  else {
    return myU1;
  }
}

//=======================================================================
//function : U0
//purpose  : 
//=======================================================================

Standard_Real AdvApp2Var_Iso::U0() const 
{
  return myU0;
}

//=======================================================================
//function : U1
//purpose  : 
//=======================================================================

Standard_Real AdvApp2Var_Iso::U1() const 
{
  return myU1;
}

//=======================================================================
//function : V0
//purpose  : 
//=======================================================================

Standard_Real AdvApp2Var_Iso::V0() const 
{
  return myV0;
}

//=======================================================================
//function : V1
//purpose  : 
//=======================================================================

Standard_Real AdvApp2Var_Iso::V1() const 
{
  return myV1;
}

//=======================================================================
//function : UOrder
//purpose  : 
//=======================================================================

Standard_Integer AdvApp2Var_Iso::UOrder() const 
{
  if (Type()==GeomAbs_IsoU) return myDerivOrder;
  else return myExtremOrder;
}


//=======================================================================
//function : VOrder
//purpose  : 
//=======================================================================

Standard_Integer AdvApp2Var_Iso::VOrder() const 
{
  if (Type()==GeomAbs_IsoV) return myDerivOrder;
  else return myExtremOrder;
}

//=======================================================================
//function : Position
//purpose  : 
//=======================================================================

Standard_Integer AdvApp2Var_Iso::Position() const 
{
  return myPosition;
}

//=======================================================================
//function : NbCoeff
//purpose  : 
//=======================================================================


Standard_Integer AdvApp2Var_Iso::NbCoeff() const 
{
  return myNbCoeff;
}

//=======================================================================
//function : Polynom
//purpose  : 
//=======================================================================

const Handle(TColStd_HArray1OfReal)& AdvApp2Var_Iso::Polynom() const 
{
  return myEquation;
}

Handle(TColStd_HArray1OfReal) AdvApp2Var_Iso::SomTab() const 
{
  return mySomTab;
}

Handle(TColStd_HArray1OfReal) AdvApp2Var_Iso::DifTab() const 
{
  return myDifTab;
}

Handle(TColStd_HArray2OfReal) AdvApp2Var_Iso::MaxErrors() const 
{
  return myMaxErrors;
}

Handle(TColStd_HArray2OfReal) AdvApp2Var_Iso::MoyErrors() const 
{
  return myMoyErrors;
}