0024624: Lost word in license statement in source files
[occt.git] / src / AdvApp2Var / AdvApp2Var_Context.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 under
9 // the terms of the GNU Lesser General Public License 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_Context.ixx>
18 #include <Standard_ConstructionError.hxx>
19 #include <AdvApp2Var_ApproxF2var.hxx>
20
21 // Calculaton of parameters
22 static Standard_Boolean lesparam(const Standard_Integer iordre,
23                                  const Standard_Integer ncflim, 
24                                  const Standard_Integer icodeo, 
25                                  Standard_Integer& nbpnts, 
26                                  Standard_Integer& ndgjac)
27 {
28   // jacobi degree
29   ndgjac = ncflim; // it always keeps a reserve coefficient
30   if (icodeo< 0) return Standard_False;
31   if (icodeo > 0) {
32     ndgjac += (9 - (iordre+1)); //iordre rescales the frequences upwards
33     ndgjac += (icodeo-1)*10;
34   }
35   // ---> Min Number of required pointss.
36   if (ndgjac < 8) { nbpnts = 8;  } 
37   else if (ndgjac < 10) { nbpnts = 10; }
38   //  else if (ndgjac < 15) { nbpnt = 15; } Bug Uneven number
39   else if (ndgjac < 20) { nbpnts = 20;}
40   //  else if (ndgjac < 25) { nbpnt = 25; } Bug Uneven number
41   else if (ndgjac < 30) { nbpnts = 30;}
42   else if (ndgjac < 40) { nbpnts = 40;}
43   else if (ndgjac < 50) { nbpnts = 50;}
44   //  else if (*ndgjac < 61) { nbpnt = 61;} Bug Uneven number
45   else {
46     nbpnts = 50;
47 #if DEB
48     cout << "F(U, V) : Not enough points of discretization" << endl; 
49 #endif
50   }
51
52   // If constraints are on borders, this adds 2 points
53   if (iordre>-1) {  nbpnts += 2;}
54
55   return Standard_True;
56 }
57 //============================================================================
58 //function : AdvApp2Var_Context
59 //purpose  :
60 //============================================================================
61
62  AdvApp2Var_Context::
63 AdvApp2Var_Context()
64 {
65 }
66
67 //============================================================================
68 //function : AdvApp2Var_Context
69 //purpose  :
70 //============================================================================
71
72  AdvApp2Var_Context::
73 AdvApp2Var_Context(const Standard_Integer ifav,
74                    const Standard_Integer iu,
75                    const Standard_Integer iv, 
76                    const Standard_Integer nlimu,
77                    const Standard_Integer nlimv, 
78                    const Standard_Integer iprecis,
79                    const Standard_Integer nb1Dss,
80                    const Standard_Integer nb2Dss,
81                    const Standard_Integer nb3Dss,
82                    const Handle(TColStd_HArray1OfReal)& tol1D,
83                    const Handle(TColStd_HArray1OfReal)& tol2D,
84                    const Handle(TColStd_HArray1OfReal)& tol3D,
85                    const Handle(TColStd_HArray2OfReal)& tof1D,
86                    const Handle(TColStd_HArray2OfReal)& tof2D,
87                    const Handle(TColStd_HArray2OfReal)& tof3D) :
88 myFav(ifav),
89 myOrdU(iu),
90 myOrdV(iv),
91 myLimU(nlimu),
92 myLimV(nlimv),
93 myNb1DSS(nb1Dss),
94 myNb2DSS(nb2Dss),
95 myNb3DSS(nb3Dss)
96 {
97 Standard_Integer ErrorCode=0,NbPntU=0,JDegU=0,NbPntV=0,JDegV=0;
98 Standard_Integer ncfl;
99
100 // myNbURoot,myJDegU
101 ncfl = nlimu;
102 if (ncfl<2*iu+2) ncfl = 2*iu+2;
103 if (!lesparam(iu,ncfl,iprecis,NbPntU,JDegU) )
104   { Standard_ConstructionError::Raise("AdvApp2Var_Context");}
105 myNbURoot = NbPntU;
106 myJDegU = JDegU;
107 if (iu>-1) NbPntU = myNbURoot - 2;
108
109 // myJMaxU
110 Standard_Integer i,j,size = JDegU-2*iu-1;
111 Handle (TColStd_HArray1OfReal) JMaxU =
112   new TColStd_HArray1OfReal(1,size);
113 Standard_Real *JU_array =
114   (Standard_Real *) &JMaxU->ChangeArray1()(JMaxU->Lower());
115 AdvApp2Var_ApproxF2var::mma2jmx_(&JDegU,(integer *)&iu,JU_array);
116 myJMaxU = JMaxU;
117
118 // myNbVRoot,myJDegV
119 ncfl = nlimv;
120 if (ncfl<2*iv+2) ncfl = 2*iv+2;
121 //Ma1nbp(&iv,&ncfl,&iprec,&NbPntV,&JDegV,&ErrorCode);
122 if (!lesparam(iv, ncfl, iprecis, NbPntV, JDegV) )
123   { Standard_ConstructionError::Raise("AdvApp2Var_Context");}
124 myNbVRoot = NbPntV;
125 myJDegV = JDegV;
126 if (iv>-1) NbPntV = myNbVRoot - 2;
127
128 // myJMaxV
129 size = JDegV-2*iv-1;
130 Handle (TColStd_HArray1OfReal) JMaxV =
131   new TColStd_HArray1OfReal(1,size);
132 Standard_Real *JV_array =
133   (Standard_Real *) &JMaxV->ChangeArray1()(JMaxV->Lower());
134 AdvApp2Var_ApproxF2var::mma2jmx_(&JDegV,(integer *)&iv,JV_array);
135 myJMaxV = JMaxV;
136
137 // myURoots, myVRoots
138 Handle (TColStd_HArray1OfReal) URoots =
139   new TColStd_HArray1OfReal(1,myNbURoot);
140 Standard_Real *U_array =
141   (Standard_Real *) &URoots->ChangeArray1()(URoots->Lower());
142 Handle (TColStd_HArray1OfReal) VRoots =
143   new TColStd_HArray1OfReal(1,myNbVRoot);
144 Standard_Real *V_array =
145   (Standard_Real *) &VRoots->ChangeArray1()(VRoots->Lower());
146 AdvApp2Var_ApproxF2var::mma2roo_(&NbPntU,&NbPntV,U_array,V_array);
147 myURoots = URoots;
148 myVRoots = VRoots;
149
150 // myUGauss
151 size = (NbPntU/2+1)*(myJDegU-2*iu-1);
152 Handle (TColStd_HArray1OfReal) UGauss =
153   new TColStd_HArray1OfReal(1,size);
154 Standard_Real *UG_array =
155   (Standard_Real *) &UGauss->ChangeArray1()(UGauss->Lower());
156 AdvApp2Var_ApproxF2var::mmapptt_(&JDegU,&NbPntU,&iu,UG_array,&ErrorCode);
157 if (ErrorCode != 0 ) {
158   Standard_ConstructionError::Raise("AdvApp2Var_Context : Error in FORTRAN");
159 }
160 myUGauss = UGauss;
161
162 // myVGauss
163 size = (NbPntV/2+1)*(myJDegV-2*iv-1);
164 Handle (TColStd_HArray1OfReal) VGauss =
165   new TColStd_HArray1OfReal(1,size);
166 Standard_Real *VG_array =
167   (Standard_Real *) &VGauss->ChangeArray1()(VGauss->Lower());
168 AdvApp2Var_ApproxF2var::mmapptt_(&JDegV,&NbPntV,&iv,VG_array,&ErrorCode);
169 if (ErrorCode != 0 ) {
170   Standard_ConstructionError::Raise("AdvApp2Var_Context : Error in FORTRAN");
171 }
172 myVGauss = VGauss;
173
174 //myInternalTol, myFrontierTol, myCuttingTol
175 Standard_Integer nbss = nb1Dss + nb2Dss + nb3Dss;
176 Handle (TColStd_HArray1OfReal) ITol =
177   new TColStd_HArray1OfReal(1,nbss);
178 for (i=1;i<=nb1Dss;i++) {
179   ITol->SetValue(i,tol1D->Value(i));
180 }
181 for (i=1;i<=nb2Dss;i++) {
182   ITol->SetValue(i+nb1Dss,tol2D->Value(i));
183 }
184 for (i=1;i<=nb3Dss;i++) {
185   ITol->SetValue(i+nb1Dss+nb2Dss,tol3D->Value(i));
186 }
187 if (iu>-1||iv>-1) {
188   for (i=1;i<=nbss;i++) { ITol->SetValue(i,ITol->Value(i)/2); }
189 }
190 Handle (TColStd_HArray2OfReal) FTol =
191   new TColStd_HArray2OfReal(1,nbss,1,4);
192 Handle (TColStd_HArray2OfReal) CTol =
193   new TColStd_HArray2OfReal(1,nbss,1,4);
194 for (i=1;i<=nb1Dss;i++) {
195 for (j=1;j<=4;j++) {
196   FTol->SetValue(i,j,tof1D->Value(i,j));
197   CTol->SetValue(i,j,0);
198 }
199 }
200 for (i=1;i<=nb2Dss;i++) {
201 for (j=1;j<=4;j++) {
202   FTol->SetValue(nb1Dss+i,j,tof2D->Value(i,j));
203   CTol->SetValue(nb1Dss+i,j,0);
204 }
205 }
206 for (i=1;i<=nb3Dss;i++) {
207 for (j=1;j<=4;j++) {
208   FTol->SetValue(nb1Dss+nb2Dss+i,j,tof3D->Value(i,j));
209   CTol->SetValue(nb1Dss+nb2Dss+i,j,0);
210 }
211 }
212 if (iu>-1||iv>-1) {
213   Standard_Real tolmin, poids, hmax[4];
214   hmax[0] = 0;
215   hmax[1] = 1;
216   hmax[2] = 1.5;
217   hmax[3] = 1.75;
218   poids = hmax[iu+1]*hmax[iv+1] + hmax[iu+1] + hmax[iv+1];
219   for (i=1;i<=nbss;i++) {
220     for (j=1;j<=4;j++) {
221       tolmin = (ITol->Value(i))/poids;
222       if (tolmin<FTol->Value(i,j)) FTol->SetValue(i,j,tolmin);
223       CTol->SetValue(i,j,tolmin);
224     }
225   }
226 }
227 myInternalTol = ITol;
228 myFrontierTol = FTol;
229 myCuttingTol = CTol;
230 }
231
232 //============================================================================
233 //function : TotalDimension
234 //purpose  : 
235 //============================================================================
236
237 Standard_Integer AdvApp2Var_Context::TotalDimension() const 
238 {
239   return myNb1DSS + 2*myNb2DSS + 3*myNb3DSS; 
240 }
241
242 //============================================================================
243 //function : TotalNumberSSP
244 //purpose  :
245 //============================================================================
246
247 Standard_Integer AdvApp2Var_Context::TotalNumberSSP() const 
248 {
249   return myNb1DSS + myNb2DSS + myNb3DSS; 
250 }
251
252 //============================================================================
253 //function : FavorIso
254 //purpose  : return 1 for IsoU, 2 for IsoV, 2 by default
255 //============================================================================
256
257 Standard_Integer AdvApp2Var_Context::FavorIso() const 
258 {
259   return myFav; 
260 }
261
262 //============================================================================
263 //function : UOrder
264 //purpose  : return the order of continuity requested in U
265 //============================================================================
266
267 Standard_Integer AdvApp2Var_Context::UOrder() const 
268 {
269   return myOrdU; 
270 }
271
272 //============================================================================
273 //function : VOrder
274 //purpose  : return the order of continuity requested in V
275 //============================================================================
276
277 Standard_Integer AdvApp2Var_Context::VOrder() const 
278 {
279   return myOrdV; 
280 }
281
282 //============================================================================
283 //function : ULimit
284 //purpose  : return the max number of coeff. in U of the polynomial approx.
285 //============================================================================
286
287 Standard_Integer AdvApp2Var_Context::ULimit() const 
288 {
289   return myLimU; 
290 }
291
292 //============================================================================
293 //function : VLimit
294 //purpose  : return the max number of coeff. in V of the polynomial approx.
295 //============================================================================
296
297 Standard_Integer AdvApp2Var_Context::VLimit() const 
298 {
299   return myLimV;
300 }
301
302 //============================================================================
303 //function : UJacDeg
304 //purpose  : return the max degree of the Jacobi functions for U parameter
305 //============================================================================
306
307 Standard_Integer AdvApp2Var_Context::UJacDeg() const 
308 {
309   return myJDegU; 
310 }
311
312 //============================================================================
313 //function : VJacDeg
314 //purpose  : return the max degree of the Jacobi functions for V parameter
315 //============================================================================
316
317 Standard_Integer AdvApp2Var_Context::VJacDeg() const 
318 {
319   return myJDegV; 
320 }
321
322 //============================================================================
323 //function : UJacMax
324 //purpose  : return the max value of the Jacobi functions for U parameter
325 //============================================================================
326
327 Handle(TColStd_HArray1OfReal) AdvApp2Var_Context::UJacMax() const 
328 {
329   return myJMaxU;
330 }
331
332 //============================================================================
333 //function : VJacMax
334 //purpose  : return the max value of the Jacobi functions for V parameter
335 //============================================================================
336
337 Handle(TColStd_HArray1OfReal) AdvApp2Var_Context::VJacMax() const 
338 {
339   return myJMaxV;
340 }
341
342 //============================================================================
343 //function : URoots
344 //purpose  : return Legendre roots for U parameter
345 //============================================================================
346
347 Handle(TColStd_HArray1OfReal) AdvApp2Var_Context::URoots() const 
348 {
349   return myURoots;
350 }
351
352 //============================================================================
353 //function : VRoots
354 //purpose  : return Legendre roots for V parameter
355 //============================================================================
356
357 Handle(TColStd_HArray1OfReal) AdvApp2Var_Context::VRoots() const 
358 {
359   return myVRoots;
360 }
361
362 //============================================================================
363 //function : UGauss
364 //purpose  : return Gauss roots for U parameter
365 //============================================================================
366
367 Handle(TColStd_HArray1OfReal) AdvApp2Var_Context::UGauss() const 
368 {
369   return myUGauss;
370 }
371
372 //============================================================================
373 //function : VGauss
374 //purpose  : return Gauss roots for V parameter
375 //============================================================================
376
377 Handle(TColStd_HArray1OfReal) AdvApp2Var_Context::VGauss() const 
378 {
379   return myVGauss;
380 }
381
382 //============================================================================
383 //function : IToler
384 //purpose  : return tolerances for the approximation of patches
385 //============================================================================
386
387 Handle(TColStd_HArray1OfReal) AdvApp2Var_Context::IToler() const 
388 {
389   return myInternalTol;
390 }
391
392 //============================================================================
393 //function : FToler
394 //purpose  : return tolerances for the approximation of frontiers
395 //============================================================================
396
397 Handle(TColStd_HArray2OfReal) AdvApp2Var_Context::FToler() const 
398 {
399   return myFrontierTol;
400 }
401
402 //============================================================================
403 //function : CToler
404 //purpose  : return tolerances for the approximation of cutting lines
405 //============================================================================
406
407 Handle(TColStd_HArray2OfReal) AdvApp2Var_Context::CToler() const 
408 {
409   return myCuttingTol;
410 }
411