0023604: Uninitialized variables in debug mode
[occt.git] / src / GeomliteTest / GeomliteTest_ApproxCommands.cxx
1 // Created on: 1993-08-12
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22 // PMN : Ajout de la commande smooth
23 // PMN : 11/07/97 Passage a GeomliteTest de bsmooth.
24
25 #include <Standard_Stream.hxx>
26
27 #include <GeomliteTest.hxx>
28 #include <DrawTrSurf.hxx>
29 #include <Draw.hxx>
30 #include <Draw_Appli.hxx>
31 #include <Draw_Interpretor.hxx>
32 #include <Precision.hxx>
33 #include <Draw_Marker3D.hxx>
34 #include <Draw_Marker2D.hxx>
35 #include <TColgp_HArray1OfPnt.hxx>
36 #include <TColgp_SequenceOfPnt.hxx>
37 #include <Geom_BSplineCurve.hxx>
38 #include <Geom_BezierCurve.hxx>
39 #include <TColgp_HArray1OfPnt2d.hxx>
40 #include <TColgp_SequenceOfPnt2d.hxx>
41
42 #include <Geom2d_BSplineCurve.hxx>
43 #include <Geom2d_BezierCurve.hxx>
44 #include <DrawTrSurf_BSplineCurve.hxx>
45 #include <DrawTrSurf_BezierCurve.hxx>
46 #include <DrawTrSurf_BSplineCurve2d.hxx>
47 #include <DrawTrSurf_BezierCurve2d.hxx>
48 #include <TColgp_HArray1OfPnt.hxx>
49 #include <TColgp_Array1OfPnt.hxx>
50 #include <TColgp_Array1OfPnt2d.hxx>
51 #include <TColgp_HArray1OfVec.hxx>
52 #include <TColgp_Array1OfVec.hxx>
53 #include <TColStd_Array1OfReal.hxx>
54 #include <TColStd_HArray1OfReal.hxx>
55 #include <TColStd_HArray1OfBoolean.hxx>
56 #include <Handle_TColStd_HArray1OfReal.hxx>
57 #include <Handle_TColStd_HArray1OfBoolean.hxx>
58
59 #include <AppParCurves_MultiBSpCurve.hxx>
60 #include <AppParCurves_MultiCurve.hxx>
61 #include <AppDef_MultiLine.hxx>
62 #include <AppDef_TheVariational.hxx>
63 #include <AppDef_Compute.hxx>
64 #include <AppParCurves_HArray1OfConstraintCouple.hxx>
65 #include <AppParCurves_ConstraintCouple.hxx>
66 #include <AppDef_HArray1OfMultiPointConstraint.hxx>
67 #include <AppDef_Array1OfMultiPointConstraint.hxx>
68 #include <math_Vector.hxx>
69
70 #ifdef WNT
71 #include <stdio.h>
72 Standard_IMPORT Draw_Viewer dout;
73 #endif
74
75 //Draw_Color DrawTrSurf_CurveColor(const Draw_Color);
76
77 //=======================================================================
78 //function :  NbConstraint
79 //=======================================================================
80 static Standard_Integer  NbConstraint(const AppParCurves_Constraint C1,
81                                       const AppParCurves_Constraint C2)
82 {
83    Standard_Integer N =0;
84    switch (C1) {
85    case  AppParCurves_PassPoint : 
86      {
87        N = 1;
88        break;
89      }
90    case  AppParCurves_TangencyPoint : 
91      {
92        N =2;
93        break;
94      }
95    case  AppParCurves_CurvaturePoint : 
96      {
97        N = 3;
98        break;
99      }     
100    default:
101        break;
102    }
103
104    switch (C2) {
105    case  AppParCurves_PassPoint : 
106      {
107        N++;
108        break;
109      }
110    case  AppParCurves_TangencyPoint : 
111      {
112        N += 2;
113        break;
114      }
115    case  AppParCurves_CurvaturePoint : 
116      {
117        N += 3;
118        break;
119      }     
120    default:
121        break;
122    }
123    return N;
124 }
125 //=======================================================================
126 //function : PointsByPick
127 //=======================================================================
128 static Standard_Integer PointsByPick
129        (Handle(AppDef_HArray1OfMultiPointConstraint)& MPC, Draw_Interpretor& di)
130 {
131  Standard_Integer id,XX,YY,b, i;
132  
133  di << "Pick points "<< "\n";
134  dout.Select(id, XX, YY, b);
135  Standard_Real zoom = dout.Zoom(id);
136  if (b != 1) return 0;
137  if (id < 0) return 0;
138  gp_Pnt P;
139  gp_Pnt2d P2d;
140
141  //Standard_Boolean newcurve;
142     
143  if (dout.Is3D(id)) {
144    // Cas du 3D -------
145    Handle(Draw_Marker3D) mark;
146    TColgp_SequenceOfPnt ThePoints;
147    P.SetCoord((Standard_Real)XX/zoom,(Standard_Real)YY/zoom, 0.0);
148    ThePoints.Append (P);
149    mark = new Draw_Marker3D(P, Draw_X, Draw_orange);
150    dout << mark;
151    dout.Flush();
152    i = 1;
153       
154    while (b != 3) {
155      dout.Select(id,XX,YY,b, Standard_False);
156      if (b == 1) { 
157        i++;
158        P.SetCoord( (Standard_Real)XX/zoom,
159                   (Standard_Real)YY/zoom, 0.0);
160        ThePoints.Append(P);
161        mark = new Draw_Marker3D(P, Draw_X, Draw_orange);
162        dout << mark;
163        dout.Flush();
164      }
165    }
166
167    MPC = new (AppDef_HArray1OfMultiPointConstraint)(1, ThePoints.Length());
168    AppDef_MultiPointConstraint mpc(1,0);
169    MPC->ChangeArray1().Init(mpc);
170    for (i=1; i<=ThePoints.Length(); i++) {
171       AppDef_MultiPointConstraint mpc(1,0);
172       mpc.SetPoint(1, ThePoints.Value(i));
173       MPC->SetValue(i, mpc); 
174    }  
175  }
176  
177  else {
178    // Cas du 2D -------
179    Handle(Draw_Marker2D) mark;
180    TColgp_SequenceOfPnt2d ThePoints;
181    P2d.SetCoord((Standard_Real)XX/zoom,(Standard_Real)YY/zoom);
182    ThePoints.Append(P2d);
183    mark = new Draw_Marker2D(P2d, Draw_X, Draw_orange);
184    dout << mark;
185    dout.Flush();
186    i = 1;
187       
188    while (b != 3) {
189      dout.Select(id,XX,YY,b, Standard_False);
190      
191      if (b == 1) { 
192        i++;
193        P2d.SetCoord( (Standard_Real)XX/zoom, (Standard_Real)YY/zoom );
194        ThePoints.Append (P2d);
195        mark = new Draw_Marker2D(P2d, Draw_X, Draw_orange);
196        dout << mark;
197        dout.Flush();
198      }
199    }
200
201    MPC = new (AppDef_HArray1OfMultiPointConstraint)(1, ThePoints.Length());
202    for (i=1; i<=ThePoints.Length(); i++) {
203      AppDef_MultiPointConstraint mpc(0,1);
204      mpc.SetPoint2d(1, ThePoints.Value(i));
205      MPC->SetValue(i,  mpc);
206    }
207  }
208  return id;
209 }
210
211 //=======================================================================
212 //function : PointsByFile
213 //=======================================================================
214 static void PointsByFile(Handle(AppDef_HArray1OfMultiPointConstraint)& MPC,
215                          Handle(AppParCurves_HArray1OfConstraintCouple)& TABofCC,
216                          ifstream& iFile,
217                          Draw_Interpretor& di)
218 {
219   Standard_Integer nbp, i, nbc;
220   char c;
221   Standard_Real x, y, z;
222
223   iFile >> nbp;
224   char dimen[3];
225   iFile >> dimen;
226
227   if (!strcmp(dimen,"3d")) {
228     Handle(Draw_Marker3D) mark;
229     MPC = new (AppDef_HArray1OfMultiPointConstraint)(1, nbp);
230
231     for (i = 1; i <= nbp; i++) {
232       iFile >> x >> y >> z;
233       AppDef_MultiPointConstraint mpc(1,0);
234       mpc.SetPoint(1, gp_Pnt(x, y, z));
235       MPC->SetValue(i,mpc);
236       mark = new Draw_Marker3D(gp_Pnt(x, y, z), Draw_X, Draw_orange);
237       dout << mark;
238     }
239     Standard_Boolean HasConstrainte = Standard_False;
240     if (iFile.get(c)) {
241       if ( IsControl( (Standard_Character)c) ) {   
242         if (iFile.get(c))  HasConstrainte = Standard_True;
243       }
244       else  HasConstrainte = Standard_True;
245     }
246
247     if (HasConstrainte) {
248       Standard_Integer num, ordre;
249       iFile >> nbc;
250       if ((nbc < 1) || (nbc>nbp)) return; // Y a comme un probleme
251       AppParCurves_Constraint  Constraint = AppParCurves_NoConstraint;
252       TABofCC = new AppParCurves_HArray1OfConstraintCouple(1, nbp);
253       for(i=1; i<=nbp; i++){
254         AppParCurves_ConstraintCouple ACC(i,Constraint);
255         TABofCC->SetValue(i,ACC);
256       }
257       for(i=1; i<=nbc; i++) {
258         iFile >> num >> ordre;
259         if ((num<1)||(num>nbp)) {
260           di << "Error on point Index in constrainte" << "\n";
261           return;
262         }
263         Constraint = (AppParCurves_Constraint) (ordre+1);
264         TABofCC->ChangeValue(num).SetConstraint(Constraint);
265         if (Constraint >=  AppParCurves_TangencyPoint) {
266           iFile >> x >> y >> z;
267           MPC->ChangeValue(num).SetTang(1, gp_Vec(x,y,z));
268         }
269         if (Constraint >=  AppParCurves_CurvaturePoint) {
270           iFile >> x >> y >> z;
271           MPC->ChangeValue(num).SetCurv(1, gp_Vec(x,y,z));
272         }
273       }
274     }
275     
276   }
277   else if (!strcmp(dimen,"2d")) {
278     Handle(Draw_Marker2D) mark;
279     MPC = new (AppDef_HArray1OfMultiPointConstraint)(1, nbp);
280
281     for (i = 1; i <= nbp; i++) {
282       iFile >> x >> y;
283       AppDef_MultiPointConstraint mpc(0,1);
284       mpc.SetPoint2d(1, gp_Pnt2d(x, y));
285       MPC->SetValue(i, mpc);
286       mark = new Draw_Marker2D(gp_Pnt2d(x, y), Draw_X, Draw_orange);
287       dout << mark;
288     }
289
290     Standard_Boolean HasConstrainte = Standard_False;
291     if (iFile.get(c)) {
292       if ( IsControl( (Standard_Character)c) )  {
293         if (iFile.get(c))  HasConstrainte = Standard_True;
294       }
295       else  HasConstrainte = Standard_True;
296     }
297
298     if (HasConstrainte) {
299       Standard_Integer num, ordre;
300       iFile >> nbc;
301       if ((nbc < 1) || (nbc>nbp)) return; // Y a comme un probleme
302       AppParCurves_Constraint  Constraint = AppParCurves_NoConstraint;
303       TABofCC = new AppParCurves_HArray1OfConstraintCouple(1, nbp);
304       for(i=1; i<=nbp; i++){
305         AppParCurves_ConstraintCouple ACC(i,Constraint);
306         TABofCC->SetValue(i,ACC);
307       }
308       for(i=1; i<=nbc; i++) {
309         iFile >> num >> ordre;
310         if ((num<1)||(num>nbp)) {
311           di << "Error on point Index in constrainte" << "\n";
312           return;
313         }
314         Constraint = (AppParCurves_Constraint) (ordre+1);
315         TABofCC->ChangeValue(num).SetConstraint(Constraint);
316         if (Constraint >=  AppParCurves_TangencyPoint) {
317           iFile >> x >> y;
318           MPC->ChangeValue(num).SetTang2d(1, gp_Vec2d(x,y));
319         }
320         if (Constraint >=  AppParCurves_CurvaturePoint) {
321           iFile >> x >> y;
322           MPC->ChangeValue(num).SetCurv2d(1, gp_Vec2d(x,y));
323         }
324       }
325     }
326   }  
327 }
328
329
330
331 //==================================================================================
332 static Standard_Integer smoothing (Draw_Interpretor& di,Standard_Integer n, const char** a)
333 //==================================================================================
334 //  Tolerance < 0 lissage "filtre"
335 //  Tolerance > 0 lissage avec respect de l'erreur max
336 //  Tolerance = 0 interpolation.
337 //
338 {
339   Standard_Real Tolerance=0;
340 #ifdef DEB
341   AppParCurves_Constraint  Constraint;
342 #else
343   AppParCurves_Constraint  Constraint=AppParCurves_NoConstraint;
344 #endif
345   Handle(AppParCurves_HArray1OfConstraintCouple)TABofCC;
346   TABofCC.Nullify();
347   Handle(AppDef_HArray1OfMultiPointConstraint) Points;
348   Standard_Integer id = 0, DegMax = -1;
349
350   if (n == 1) {
351     di <<"give a name to your curve !" << "\n";
352     return 0;
353   }
354   if (n == 2) {
355     di <<"give a tolerance to your curve !" << "\n";
356     return 0;
357   }
358   if (n == 3) {
359     Tolerance = atof(a[2]);
360     if (Abs(Tolerance) < Precision::Confusion()*1.e-7)  {
361       Constraint = AppParCurves_PassPoint;
362     }
363     else {
364       Constraint = AppParCurves_NoConstraint;
365     } 
366     // Designation Graphique ------------------------
367     id = PointsByPick(Points, di);
368   }
369   else if (n >= 4) {
370     Standard_Integer ific = 3;
371     Tolerance = atof(a[2]);
372     if (Abs(Tolerance) < Precision::Confusion()*1.e-7)  {
373       Constraint = AppParCurves_PassPoint;
374     }
375     else {
376       Constraint = AppParCurves_NoConstraint;
377     }
378
379     if (! strcmp(a[3],"-D")) {
380        DegMax = atoi(a[4]);
381        ific = 5;
382     }
383     
384     if (n > ific) {
385       // lecture du fichier.
386     // nbpoints, 2d ou 3d, puis valeurs.
387       const char* nomfic = a[ific];
388       ifstream iFile(nomfic, ios::in);
389       if (!iFile) { 
390         di << a[ific] <<"do not exist !" << "\n";
391         return 1;
392       }
393       PointsByFile(Points, TABofCC, iFile, di);
394     }
395     else {
396     // Designation Graphique
397     id = PointsByPick(Points, di);
398     }
399   }
400
401   AppDef_MultiLine AML(Points->Array1());
402
403   // Compute --------------
404   Standard_Integer i;
405   if (Points->Value(1).NbPoints()==0){
406     // Cas 2d
407     Handle(TColgp_HArray1OfPnt2d) ThePoints;
408     // Calcul du lissage
409     Standard_Integer NbPoints = Points->Length();
410     if (TABofCC.IsNull()) {
411       TABofCC = new AppParCurves_HArray1OfConstraintCouple(1, NbPoints);
412       for(i=1; i<=NbPoints; i++){
413         AppParCurves_ConstraintCouple ACC(i,Constraint);
414         TABofCC->SetValue(i,ACC);
415       }
416     }
417
418     AppDef_TheVariational Variation(AML, 
419                                     1, NbPoints,
420                                     TABofCC);
421     
422     if (DegMax > 0) {
423       if (DegMax < 3) Variation.SetContinuity(GeomAbs_C0);
424       else if (DegMax <5) Variation.SetContinuity(GeomAbs_C1);
425       Variation.SetMaxDegree(DegMax);
426     }
427     Variation.SetTolerance( Abs(Tolerance));
428     if (Tolerance>0) { Variation.SetWithMinMax(Standard_True);}
429     Variation.Approximate();
430
431 #  ifdef DEB
432     //Variation.Dump(cout);
433     Standard_SStream aSStream;
434     Variation.Dump(aSStream);
435     di << aSStream;
436 #   endif
437
438     AppParCurves_MultiBSpCurve AnMuC = Variation.Value();
439
440     TColgp_Array1OfPnt2d ThePoles (1,  AnMuC.NbPoles() ); 
441     AnMuC.Curve(1, ThePoles);    
442     Handle(Geom2d_BSplineCurve) Cvliss = new (Geom2d_BSplineCurve)
443       (ThePoles,
444        AnMuC.Knots(),
445        AnMuC. Multiplicities(),
446        AnMuC.Degree() );
447
448     Handle(DrawTrSurf_BSplineCurve2d) 
449       DC = new DrawTrSurf_BSplineCurve2d(Cvliss);
450     DC->ClearPoles();
451     Draw::Set(a[1], DC);
452     if (id!=0) dout.RepaintView(id); 
453   }
454   else {
455     Standard_Integer NbPoints = Points->Length();
456     if (TABofCC.IsNull()) {
457       TABofCC = new AppParCurves_HArray1OfConstraintCouple(1, NbPoints);
458       for(i=1; i<=NbPoints; i++){
459         AppParCurves_ConstraintCouple ACC(i,Constraint);
460         TABofCC->SetValue(i,ACC);
461       }
462     } 
463
464     AppDef_TheVariational Variation(AML, 
465                                     1,  NbPoints,
466                                     TABofCC);
467
468     if (DegMax > 0) {
469       if (DegMax < 3) Variation.SetContinuity(GeomAbs_C0);
470       else if (DegMax <5) Variation.SetContinuity(GeomAbs_C1);
471       Variation.SetMaxDegree(DegMax);
472     }
473     Variation.SetTolerance( Abs(Tolerance));
474     if (Tolerance>0) { Variation.SetWithMinMax(Standard_True);}
475     Variation.Approximate();
476 #     ifdef DEB
477     //Variation.Dump(cout);
478     Standard_SStream aSStream;
479     Variation.Dump(aSStream);
480     di << aSStream;
481 #     endif
482
483     AppParCurves_MultiBSpCurve AnMuC = Variation.Value();
484
485     TColgp_Array1OfPnt ThePoles (1,  AnMuC.NbPoles() ); 
486     AnMuC.Curve(1, ThePoles);    
487     Handle(Geom_BSplineCurve) Cvliss = new (Geom_BSplineCurve)
488       (ThePoles,
489        AnMuC.Knots(),
490        AnMuC. Multiplicities(),
491        AnMuC.Degree() );
492
493     Handle(DrawTrSurf_BSplineCurve) 
494       DC = new DrawTrSurf_BSplineCurve(Cvliss);
495     DC->ClearPoles();
496     Draw::Set(a[1], DC);
497     if (id!=0) dout.RepaintView(id);
498   }
499   return 0;
500 }
501
502 //=============================================================================
503 static Standard_Integer smoothingbybezier (Draw_Interpretor& di,
504                                            Standard_Integer n, 
505                                            const char** a)
506 //============================================================================
507 {
508   Standard_Real Tolerance=0;
509 #ifdef DEB
510   AppParCurves_Constraint  Constraint;
511 #else
512   AppParCurves_Constraint  Constraint=AppParCurves_NoConstraint;
513 #endif
514   Handle(AppParCurves_HArray1OfConstraintCouple)TABofCC;
515   Handle(AppDef_HArray1OfMultiPointConstraint) Points;
516
517   Standard_Integer id = 0;
518   Standard_Integer methode=0;
519   Standard_Integer Degree = 8;
520
521   if (n == 1) {
522     di <<"give a name to your curve !" << "\n";
523     return 0;
524   }
525   if (n == 2) {
526     di <<"give a tolerance to your curve !" << "\n";
527     return 0;
528   }
529  if (n == 3) {
530     di <<"give a max degree!" << "\n";
531     return 0;
532   }
533
534   if (n == 4) {
535     di <<"give an option!" << "\n";
536     return 0;
537   }
538   if (n >= 5) {
539     Tolerance = atof(a[2]);
540     Degree = atoi(a[3]);
541     if (! strcmp(a[4],"-GR")) {
542       methode = 1;
543     }
544     else if (! strcmp(a[4],"-PR")) {
545       methode = 2;
546     }
547     else { methode = 3;}
548     
549     if (Abs(Tolerance) < Precision::Confusion()*1.e-7)  {
550       Constraint = AppParCurves_PassPoint;
551     }
552     else {
553       Constraint = AppParCurves_NoConstraint;
554     } 
555     if (n==5)
556       // Designation Graphique ------------------------
557      id = PointsByPick(Points, di);
558     else {
559       // lecture du fichier.
560       // nbpoints, 2d ou 3d, puis valeurs.
561       const char* nomfic = a[5];
562       ifstream iFile(nomfic, ios::in);
563       if (!iFile) { 
564         di << a[6] <<"do not exist !" << "\n";
565         return 1;
566       }
567       PointsByFile(Points, TABofCC, iFile, di);
568     }
569   }
570     
571   AppDef_MultiLine AML(Points->Array1());  
572
573   // Compute --------------
574   Standard_Integer i;
575   if (Points->Value(1).NbPoints()==0){
576     // Cas 2d
577     Handle(TColgp_HArray1OfPnt2d) ThePoints;
578     // Calcul du lissage
579     Standard_Integer NbPoints = Points->Length();
580     if (TABofCC.IsNull()) {
581       TABofCC = new AppParCurves_HArray1OfConstraintCouple(1, NbPoints);
582       for(i=1; i<=NbPoints; i++){
583         AppParCurves_ConstraintCouple ACC(i,Constraint);
584         TABofCC->SetValue(i,ACC);
585       }
586
587       AppParCurves_ConstraintCouple AC1(1, AppParCurves_PassPoint);
588       if (TABofCC->Value(1).Constraint()<AppParCurves_PassPoint)
589         TABofCC->SetValue(1, AC1);
590     
591       AppParCurves_ConstraintCouple AC2(NbPoints, AppParCurves_PassPoint);
592       if (TABofCC->Value(NbPoints).Constraint()<AppParCurves_PassPoint)
593         TABofCC->SetValue(NbPoints, AC2);
594     }
595
596     if (methode < 3) {
597       Standard_Boolean mySquare = (methode == 2);
598       Standard_Integer degmin = 4;
599       Standard_Integer NbIteration = 5;
600       
601       if (Degree < 4) degmin = Max(1, Degree -1);
602       degmin = Max(degmin, NbConstraint(TABofCC->Value(1).Constraint(),  
603                                         TABofCC->Value(NbPoints).Constraint()) );
604       
605       AppDef_Compute Appr(degmin, Degree,
606                           Abs(Tolerance),  Abs(Tolerance),
607                           NbIteration, Standard_False, 
608                           Approx_ChordLength, mySquare);
609
610      Appr.SetConstraints(TABofCC->Value(1).Constraint(), 
611                           TABofCC->Value(NbPoints).Constraint());
612    
613       Appr.Perform (AML);
614       
615       if (! Appr.IsAllApproximated()) {
616         di << " No result" << "\n";
617       }
618       AppParCurves_MultiCurve AnMuC = Appr.Value();
619       ThePoints = new (TColgp_HArray1OfPnt2d) (1,  AnMuC.NbPoles() );
620       AnMuC.Curve(1, ThePoints->ChangeArray1());
621       Standard_Real err, err2d;
622       Appr.Error(1, err, err2d);
623       di <<" Error2D is : " << err2d << "\n";
624     }
625     else {
626       AppDef_TheVariational Varia(AML, 
627                                   1,  NbPoints,
628                                   TABofCC,
629                                   Degree, 1);
630       Varia.SetTolerance(Abs(Tolerance));
631       Varia.Approximate();
632
633       if (! Varia.IsDone()) {
634         di << " No result" << "\n";
635       }
636
637       AppParCurves_MultiBSpCurve  AnMuC = Varia.Value();
638       di <<" Error2D is : " << Varia.MaxError() << "\n";
639       ThePoints = new (TColgp_HArray1OfPnt2d) (1,  AnMuC.NbPoles() );
640       AnMuC.Curve(1, ThePoints->ChangeArray1());    
641  }
642     
643     Handle(Geom2d_BezierCurve) Cvliss = 
644       new (Geom2d_BezierCurve)(ThePoints->Array1());
645
646     Handle(DrawTrSurf_BezierCurve2d) DC = 
647       new (DrawTrSurf_BezierCurve2d) (Cvliss);
648     Draw::Set(a[1], DC);
649     if (id!=0) dout.RepaintView(id); 
650   }
651   else {
652     // Cas 3d
653     Handle(TColgp_HArray1OfPnt) ThePoints;
654     Standard_Integer NbPoints = Points->Length();
655     if (TABofCC.IsNull()) {
656       TABofCC = new AppParCurves_HArray1OfConstraintCouple(1, NbPoints);
657       for(i=1; i<=NbPoints; i++){
658         AppParCurves_ConstraintCouple ACC(i,Constraint);
659         TABofCC->SetValue(i,ACC);
660       }
661     
662
663       AppParCurves_ConstraintCouple AC1(1, AppParCurves_PassPoint);
664       if (TABofCC->Value(1).Constraint()<AppParCurves_PassPoint)
665         TABofCC->SetValue(1, AC1);
666     
667       AppParCurves_ConstraintCouple AC2(NbPoints, AppParCurves_PassPoint);
668       if (TABofCC->Value(NbPoints).Constraint()<AppParCurves_PassPoint)
669         TABofCC->SetValue(NbPoints, AC2);
670     }
671
672     if (methode < 3) {
673       Standard_Boolean mySquare = (methode == 2);
674       Standard_Integer degmin = 4;
675       Standard_Integer NbIteration = 5;
676       if (Degree < 4) degmin = Max(1, Degree - 1);
677       degmin = Max(degmin, NbConstraint(TABofCC->Value(1).Constraint(),  
678                                         TABofCC->Value(NbPoints).Constraint()) );
679       
680       AppDef_Compute Appr(degmin, Degree,
681                           Abs(Tolerance),  Abs(Tolerance),
682                           NbIteration, Standard_False, 
683                           Approx_ChordLength, mySquare);
684
685       Appr.SetConstraints(TABofCC->Value(1).Constraint(), 
686                           TABofCC->Value(NbPoints).Constraint());
687    
688       Appr.Perform (AML);
689       
690       if (! Appr.IsAllApproximated()) {
691         di << " No result" << "\n";
692       }
693       AppParCurves_MultiCurve AnMuC = Appr.Value();
694       ThePoints = new (TColgp_HArray1OfPnt) (1,  AnMuC.NbPoles() );
695       AnMuC.Curve(1, ThePoints->ChangeArray1());
696       Standard_Real err, err2d;
697       Appr.Error(1, err, err2d);
698       di <<" Error3D is : " << err << "\n";
699     }
700     else {
701       AppDef_TheVariational Varia(AML, 
702                                   1,  NbPoints,
703                                   TABofCC,
704                                   Degree, 1);
705
706       Varia.SetTolerance(Abs(Tolerance));
707       Varia.Approximate();
708       if (! Varia.IsDone()) {
709         di << " No result" << "\n";
710       }
711
712       AppParCurves_MultiBSpCurve  AnMuC = Varia.Value();
713       di <<" Error3D is : " << Varia.MaxError() << "\n";
714       ThePoints = new (TColgp_HArray1OfPnt) (1,  AnMuC.NbPoles() );
715       AnMuC.Curve(1, ThePoints->ChangeArray1());    
716     }    
717
718     Handle(Geom_BezierCurve) Cvliss = 
719       new (Geom_BezierCurve)(ThePoints->Array1());
720
721     Handle(DrawTrSurf_BezierCurve) 
722       DC = new DrawTrSurf_BezierCurve(Cvliss);
723     Draw::Set(a[1], DC);
724     if (id!=0) dout.RepaintView(id);
725   }
726   return 0;
727 }
728
729 //=======================================================================
730 //function : ConstraintCommands
731 //purpose  : 
732 //=======================================================================
733
734
735 void  GeomliteTest::ApproxCommands(Draw_Interpretor& theCommands)
736 {
737
738   static Standard_Boolean loaded = Standard_False;
739   if (loaded) return;
740   loaded = Standard_True;
741
742   DrawTrSurf::BasicCommands(theCommands);
743
744   const char* g;
745   // constrained constructs
746   g = "GEOMETRY Constraints";
747
748
749   theCommands.Add("bsmooth",
750                   "bsmooth cname tol [-D degree] [fic]", 
751                   __FILE__,
752                   smoothing, g);
753
754   theCommands.Add("bzsmooth",
755                   "bzsmooth cname tol degree option [fic]", 
756                   __FILE__,
757                   smoothingbybezier, g);
758 }
759