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