0022550: Fixing data races
[occt.git] / src / GeomPlate / GeomPlate_MakeApprox.cxx
CommitLineData
7fd59977 1// File: GeomPlate_MakeApprox.cxx
2// Created: Wed Mar 5 11:01:17 1996
3// Author: Joelle CHAUVET
4// <jct@sgi38>
5// PMN : 7/07/1997 : cout en #if DEB ... #endif
6
7
8#include <GeomPlate_MakeApprox.ixx>
9#include <GeomPlate_Surface.hxx>
10#include <GeomPlate_PlateG0Criterion.hxx>
11#include <GeomPlate_PlateG1Criterion.hxx>
12
13#include <Geom_BSplineSurface.hxx>
14#include <Geom_Surface.hxx>
15
16#include <TColgp_SequenceOfXY.hxx>
17#include <TColgp_SequenceOfXYZ.hxx>
18#include <gp_Vec.hxx>
19#include <gp_Pnt.hxx>
20#include <gp_XY.hxx>
21#include <PLib.hxx>
22
23#include <TColStd_HArray1OfReal.hxx>
24#include <TColStd_HArray1OfInteger.hxx>
25#include <TColStd_HArray2OfReal.hxx>
26#include <Handle_TColStd_HArray1OfReal.hxx>
27#include <Handle_TColStd_HArray2OfReal.hxx>
28
29#include <AdvApp2Var_Criterion.hxx>
30#include <AdvApp2Var_ApproxAFunc2Var.hxx>
31#include <AdvApprox_PrefCutting.hxx>
32#include <AdvApprox_Cutting.hxx>
33#include <AdvApprox_DichoCutting.hxx>
34
35#include <Plate_Plate.hxx>
36
41194117
K
37class GeomPlate_MakeApprox_Eval : public AdvApp2Var_EvaluatorFunc2Var
38{
39
40public:
41
42 GeomPlate_MakeApprox_Eval (const Handle(Geom_Surface)& theSurf)
43 : mySurf (theSurf) {}
44
45 virtual void Evaluate (Standard_Integer* theDimension,
46 Standard_Real* theUStartEnd,
47 Standard_Real* theVStartEnd,
48 Standard_Integer* theFavorIso,
49 Standard_Real* theConstParam,
50 Standard_Integer* theNbParams,
51 Standard_Real* theParameters,
52 Standard_Integer* theUOrder,
53 Standard_Integer* theVOrder,
54 Standard_Real* theResult,
55 Standard_Integer* theErrorCode) const;
7fd59977 56
41194117 57private:
7fd59977 58
41194117
K
59 Handle(Geom_Surface) mySurf;
60
61};
62
63void GeomPlate_MakeApprox_Eval::Evaluate (Standard_Integer * Dimension,
7fd59977 64 // Dimension
65 Standard_Real * UStartEnd,
66 // StartEnd[2] in U
67 Standard_Real * VStartEnd,
68 // StartEnd[2] in V
69 Standard_Integer * FavorIso,
70 // Choice of constante, 1 for U, 2 for V
71 Standard_Real * ConstParam,
72 // Value of constant parameter
73 Standard_Integer * NbParams,
74 // Number of parameters N
75 Standard_Real * Parameters,
76 // Values of parameters,
77 Standard_Integer * UOrder,
78 // Derivative Request in U
79 Standard_Integer * VOrder,
80 // Derivative Request in V
81 Standard_Real * Result,
82 // Result[Dimension,N]
41194117 83 Standard_Integer * ErrorCode) const
7fd59977 84 // Error Code
41194117 85{
7fd59977 86 *ErrorCode = 0;
87 Standard_Integer idim,jpar;
88 Standard_Real Upar,Vpar;
89
90// Dimension incorrecte
91 if (*Dimension!=3) {
92 *ErrorCode = 1;
93 }
94
95// Parametres incorrects
96 if (*FavorIso==1) {
97 Upar = *ConstParam;
98 if (( Upar < UStartEnd[0] ) || ( Upar > UStartEnd[1] )) {
99 *ErrorCode = 2;
100 }
101 for (jpar=1;jpar<=*NbParams;jpar++) {
102 Vpar = Parameters[jpar-1];
103 if (( Vpar < VStartEnd[0] ) || ( Vpar > VStartEnd[1] )) {
104 *ErrorCode = 2;
105 }
106 }
107 }
108 else {
109 Vpar = *ConstParam;
110 if (( Vpar < VStartEnd[0] ) || ( Vpar > VStartEnd[1] )) {
111 *ErrorCode = 2;
112 }
113 for (jpar=1;jpar<=*NbParams;jpar++) {
114 Upar = Parameters[jpar-1];
115 if (( Upar < UStartEnd[0] ) || ( Upar > UStartEnd[1] )) {
116 *ErrorCode = 2;
117 }
118 }
119 }
120
121// Initialisation
122 for (idim=1;idim<=*Dimension;idim++) {
123 for (jpar=1;jpar<=*NbParams;jpar++) {
124 Result[idim-1+(jpar-1)*(*Dimension)] = 0.;
125 }
126 }
127
128
129 Standard_Integer Order = *UOrder + *VOrder;
130 gp_Pnt pnt;
131// gp_Vec vect, v1, v2, v3, v4, v5, v6, v7, v8, v9;
132 gp_Vec v1, v2, v3, v4, v5;
133
134 if (*FavorIso==1) {
135 Upar = *ConstParam;
136 switch (Order) {
137 case 0 :
138 for (jpar=1;jpar<=*NbParams;jpar++) {
139 Vpar = Parameters[jpar-1];
41194117 140 pnt = mySurf->Value (Upar, Vpar);
7fd59977 141 Result[(jpar-1)*(*Dimension)] = pnt.X();
142 Result[1+(jpar-1)*(*Dimension)] = pnt.Y();
143 Result[2+(jpar-1)*(*Dimension)] = pnt.Z();
144 }
145 break;
146 case 1 :
147 for (jpar=1;jpar<=*NbParams;jpar++) {
148 Vpar = Parameters[jpar-1];
41194117 149 mySurf->D1 (Upar, Vpar, pnt, v1, v2);
7fd59977 150 if (*UOrder==1) {
151 Result[(jpar-1)*(*Dimension)] = v1.X();
152 Result[1+(jpar-1)*(*Dimension)] = v1.Y();
153 Result[2+(jpar-1)*(*Dimension)] = v1.Z();
154 }
155 else {
156 Result[(jpar-1)*(*Dimension)] = v2.X();
157 Result[1+(jpar-1)*(*Dimension)] = v2.Y();
158 Result[2+(jpar-1)*(*Dimension)] = v2.Z();
159 }
160 }
161 break;
162 case 2 :
163 for (jpar=1;jpar<=*NbParams;jpar++) {
164 Vpar = Parameters[jpar-1];
41194117 165 mySurf->D2 (Upar, Vpar, pnt, v1, v2, v3, v4, v5);
7fd59977 166 if (*UOrder==2) {
167 Result[(jpar-1)*(*Dimension)] = v3.X();
168 Result[1+(jpar-1)*(*Dimension)] = v3.Y();
169 Result[2+(jpar-1)*(*Dimension)] = v3.Z();
170 }
171 else if (*UOrder==1) {
172 Result[(jpar-1)*(*Dimension)] = v5.X();
173 Result[1+(jpar-1)*(*Dimension)] = v5.Y();
174 Result[2+(jpar-1)*(*Dimension)] = v5.Z();
175 }
176 else if (*UOrder==0) {
177 Result[(jpar-1)*(*Dimension)] = v4.X();
178 Result[1+(jpar-1)*(*Dimension)] = v4.Y();
179 Result[2+(jpar-1)*(*Dimension)] = v4.Z();
180 }
181 }
182 break;
183 }
184 }
185 else {
186 Vpar = *ConstParam;
187 switch (Order) {
188 case 0 :
189 for (jpar=1;jpar<=*NbParams;jpar++) {
190 Upar = Parameters[jpar-1];
41194117 191 pnt = mySurf->Value (Upar, Vpar);
7fd59977 192 Result[(jpar-1)*(*Dimension)] = pnt.X();
193 Result[1+(jpar-1)*(*Dimension)] = pnt.Y();
194 Result[2+(jpar-1)*(*Dimension)] = pnt.Z();
195 }
196 break;
197 case 1 :
198 for (jpar=1;jpar<=*NbParams;jpar++) {
199 Upar = Parameters[jpar-1];
41194117 200 mySurf->D1 (Upar, Vpar, pnt, v1, v2);
7fd59977 201 if (*UOrder==1) {
202 Result[(jpar-1)*(*Dimension)] = v1.X();
203 Result[1+(jpar-1)*(*Dimension)] = v1.Y();
204 Result[2+(jpar-1)*(*Dimension)] = v1.Z();
205 }
206 else {
207 Result[(jpar-1)*(*Dimension)] = v2.X();
208 Result[1+(jpar-1)*(*Dimension)] = v2.Y();
209 Result[2+(jpar-1)*(*Dimension)] = v2.Z();
210 }
211 }
212 break;
213 case 2 :
214 for (jpar=1;jpar<=*NbParams;jpar++) {
215 Upar = Parameters[jpar-1];
41194117 216 mySurf->D2 (Upar, Vpar, pnt, v1, v2, v3, v4, v5);
7fd59977 217 if (*UOrder==2) {
218 Result[(jpar-1)*(*Dimension)] = v3.X();
219 Result[1+(jpar-1)*(*Dimension)] = v3.Y();
220 Result[2+(jpar-1)*(*Dimension)] = v3.Z();
221 }
222 else if (*UOrder==1) {
223 Result[(jpar-1)*(*Dimension)] = v5.X();
224 Result[1+(jpar-1)*(*Dimension)] = v5.Y();
225 Result[2+(jpar-1)*(*Dimension)] = v5.Z();
226 }
227 else if (*UOrder==0) {
228 Result[(jpar-1)*(*Dimension)] = v4.X();
229 Result[1+(jpar-1)*(*Dimension)] = v4.Y();
230 Result[2+(jpar-1)*(*Dimension)] = v4.Z();
231 }
232 }
233 break;
234 }
235 }
236
237}
238
239
240//=======================================================================
241//function : GeomPlate_MakeApprox
242//purpose :
243//=======================================================================
244
245GeomPlate_MakeApprox::GeomPlate_MakeApprox(const Handle(GeomPlate_Surface)& SurfPlate,
246 const AdvApp2Var_Criterion& PlateCrit,
247 const Standard_Real Tol3d,
248 const Standard_Integer Nbmax,
249 const Standard_Integer dgmax,
250 const GeomAbs_Shape Continuity,
251 const Standard_Real EnlargeCoeff)
252{
253 myPlate = SurfPlate;
7fd59977 254
255 Standard_Real U0=0., U1=0., V0=0., V1=0.;
256 myPlate->RealBounds(U0, U1, V0, V1);
257 U0 = EnlargeCoeff * U0;
258 U1 = EnlargeCoeff * U1;
259 V0 = EnlargeCoeff * V0;
260 V1 = EnlargeCoeff * V1;
261
262 Standard_Integer nb1 = 0, nb2 = 0, nb3 = 1;
263 Handle(TColStd_HArray1OfReal) nul1 =
264 new TColStd_HArray1OfReal(1,1);
265 nul1->Init(0.);
266 Handle(TColStd_HArray2OfReal) nul2 =
267 new TColStd_HArray2OfReal(1,1,1,4);
268 nul2->Init(0.);
269 Handle(TColStd_HArray1OfReal) eps3D =
270 new TColStd_HArray1OfReal(1,1);
271 eps3D->Init(Tol3d);
272 Handle(TColStd_HArray2OfReal) epsfr =
273 new TColStd_HArray2OfReal(1,1,1,4);
274 epsfr->Init(Tol3d);
275 GeomAbs_IsoType myType = GeomAbs_IsoV;
276 Standard_Integer myPrec = 0;
277
278 AdvApprox_DichoCutting myDec;
279
280//POP pour WNT
41194117 281 GeomPlate_MakeApprox_Eval ev (myPlate);
7fd59977 282 AdvApp2Var_ApproxAFunc2Var AppPlate(nb1, nb2, nb3,
283 nul1,nul1,eps3D,
284 nul2,nul2,epsfr,
285 U0,U1,V0,V1,
286 myType,
287 Continuity, Continuity,
288 myPrec,
289 dgmax,dgmax,Nbmax,ev,
290// dgmax,dgmax,Nbmax,myPlateSurfEval,
291 PlateCrit,myDec,myDec);
292 mySurface = AppPlate.Surface(1);
293 myAppError = AppPlate.MaxError(3,1);
294 myCritError = AppPlate.CritError(3,1);
9230430c 295#if PLATE_DEB
7fd59977 296 cout<<"Approximation results"<<endl;
297 cout<<" Approximation error : "<<myAppError<<endl;
298 cout<<" Criterium error : "<<myCritError<<endl;
299#endif
300}
301
302
303//=======================================================================
304//function : GeomPlate_MakeApprox
305//purpose :
306//=======================================================================
307
308GeomPlate_MakeApprox::GeomPlate_MakeApprox(const Handle(GeomPlate_Surface)& SurfPlate,
309 const Standard_Real Tol3d,
310 const Standard_Integer Nbmax,
311 const Standard_Integer dgmax,
312 const Standard_Real dmax,
313 const Standard_Integer CritOrder,
314 const GeomAbs_Shape Continuity,
315 const Standard_Real EnlargeCoeff)
316{
317 myPlate = SurfPlate;
7fd59977 318
319 TColgp_SequenceOfXY Seq2d;
320 TColgp_SequenceOfXYZ Seq3d;
321
322 if (CritOrder>=0) {
323
324// contraintes 2d d'ordre 0
325 myPlate->Constraints(Seq2d);
326
327// contraintes 3d correspondantes sur plate
328 Standard_Integer i,nbp=Seq2d.Length();
329 for(i=1;i<=nbp;i++){
330 gp_XY P2d=Seq2d.Value(i);
331 gp_Pnt PP;
332 gp_Vec v1h,v2h,v3h;
333 if (CritOrder==0) {
334// a l'ordre 0
41194117 335 myPlate->D0 (P2d.X(), P2d.Y(), PP);
7fd59977 336 gp_XYZ P3d(PP.X(),PP.Y(),PP.Z());
337 Seq3d.Append(P3d);
338 }
339 else {
340// a l'ordre 1
41194117 341 myPlate->D1 (P2d.X(), P2d.Y(), PP, v1h, v2h);
7fd59977 342 v3h=v1h^v2h;
343 gp_XYZ P3d(v3h.X(),v3h.Y(),v3h.Z());
344 Seq3d.Append(P3d);
345 }
346 }
347 }
348
349 Standard_Real U0=0., U1=0., V0=0., V1=0.;
350 myPlate->RealBounds(U0, U1, V0, V1);
351 U0 = EnlargeCoeff * U0;
352 U1 = EnlargeCoeff * U1;
353 V0 = EnlargeCoeff * V0;
354 V1 = EnlargeCoeff * V1;
355
356 Standard_Real seuil = Tol3d;
357 if (CritOrder==0&&Tol3d<10*dmax) {
358 seuil=10*dmax;
9230430c 359#if PLATE_DEB
7fd59977 360 cout<<"Seuil G0 choisi trop faible par rapport au contour. On prend "<<seuil<<endl;
361#endif
362 }
363 if (CritOrder==1&&Tol3d<10*dmax) {
364 seuil=10*dmax;
9230430c 365#if PLATE_DEB
7fd59977 366 cout<<"Seuil G1 choisi trop faible par rapport au contour. On prend "<<seuil<<endl;
367#endif
368 }
369 Standard_Integer nb1 = 0, nb2 = 0, nb3 = 1;
370 Handle(TColStd_HArray1OfReal) nul1 =
371 new TColStd_HArray1OfReal(1,1);
372 nul1->Init(0.);
373 Handle(TColStd_HArray2OfReal) nul2 =
374 new TColStd_HArray2OfReal(1,1,1,4);
375 nul2->Init(0.);
376 Handle(TColStd_HArray1OfReal) eps3D =
377 new TColStd_HArray1OfReal(1,1);
378 eps3D->Init(Tol3d);
379 Handle(TColStd_HArray2OfReal) epsfr =
380 new TColStd_HArray2OfReal(1,1,1,4);
381 epsfr->Init(Tol3d);
382
383 GeomAbs_IsoType myType = GeomAbs_IsoV;
384 Standard_Integer myPrec = 0;
385
386 AdvApprox_DichoCutting myDec;
387
388 if (CritOrder==-1) {
389 myPrec = 1;
390// POP pour NT
41194117 391 GeomPlate_MakeApprox_Eval ev (myPlate);
7fd59977 392 AdvApp2Var_ApproxAFunc2Var AppPlate(nb1, nb2, nb3,
393 nul1,nul1,eps3D,
394 nul2,nul2,epsfr,
395 U0,U1,V0,V1,
396 myType,
397 Continuity, Continuity,
398 myPrec,
399 dgmax,dgmax,Nbmax,ev,
400 myDec,myDec);
401 mySurface = AppPlate.Surface(1);
402 myAppError = AppPlate.MaxError(3,1);
403 myCritError = 0.;
9230430c 404#if PLATE_DEB
7fd59977 405 cout<<"Approximation results"<<endl;
406 cout<<" Approximation error : "<<myAppError<<endl;
407#endif
408 }
409 else if (CritOrder==0) {
410 GeomPlate_PlateG0Criterion Crit0(Seq2d,Seq3d,seuil);
411// POP pour NT
41194117 412 GeomPlate_MakeApprox_Eval ev (myPlate);
7fd59977 413 AdvApp2Var_ApproxAFunc2Var AppPlate(nb1, nb2, nb3,
414 nul1,nul1,eps3D,
415 nul2,nul2,epsfr,
416 U0,U1,V0,V1,
417 myType,
418 Continuity, Continuity,
419 myPrec,
420 dgmax,dgmax,Nbmax,ev,
421// dgmax,dgmax,Nbmax,myPlateSurfEval,
422 Crit0,myDec,myDec);
423 mySurface = AppPlate.Surface(1);
424 myAppError = AppPlate.MaxError(3,1);
425 myCritError = AppPlate.CritError(3,1);
9230430c 426#if PLATE_DEB
7fd59977 427 cout<<"Approximation results"<<endl;
428 cout<<" Approximation error : "<<myAppError<<endl;
429 cout<<" Criterium error : "<<myCritError<<endl;
430#endif
431 }
432 else if (CritOrder==1) {
433 GeomPlate_PlateG1Criterion Crit1(Seq2d,Seq3d,seuil);
434// POP pour NT
41194117 435 GeomPlate_MakeApprox_Eval ev (myPlate);
7fd59977 436 AdvApp2Var_ApproxAFunc2Var AppPlate(nb1, nb2, nb3,
437 nul1,nul1,eps3D,
438 nul2,nul2,epsfr,
439 U0,U1,V0,V1,
440 myType,
441 Continuity, Continuity,
442 myPrec,
443 dgmax,dgmax,Nbmax,ev,
444// dgmax,dgmax,Nbmax,myPlateSurfEval,
445 Crit1,myDec,myDec);
446 mySurface = AppPlate.Surface(1);
447 myAppError = AppPlate.MaxError(3,1);
448 myCritError = AppPlate.CritError(3,1);
9230430c 449#if PLATE_DEB
7fd59977 450 cout<<"Approximation results"<<endl;
451 cout<<" Approximation error : "<<myAppError<<endl;
452 cout<<" Criterium error : "<<myCritError<<endl;
453#endif
454 }
455}
456
457
458
459//=======================================================================
460//function : Surface
461//purpose :
462//=======================================================================
463
464Handle(Geom_BSplineSurface) GeomPlate_MakeApprox::Surface() const
465{
466 return mySurface;
467}
468
469
470//=======================================================================
471//function : ApproxError
472//purpose :
473//=======================================================================
474
475Standard_Real GeomPlate_MakeApprox::ApproxError() const
476{
477 return myAppError;
478}
479
480
481//=======================================================================
482//function : CriterionError
483//purpose :
484//=======================================================================
485
486Standard_Real GeomPlate_MakeApprox::CriterionError() const
487{
488 return myCritError;
489}