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