summaryrefslogtreecommitdiff
path: root/src/GeomAPI/GeomAPI_PointsToBSplineSurface.cxx
blob: 75d4ae96c39837c8419a5d3a2bdd49b1593d2876 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
// File:	GeomAPI_PointsToBSplineSurface.cxx
// Created:	Tue Jan 17 17:02:05 1995
// Author:	Remi LEQUETTE
//		<rle@bravox>


#include <GeomAPI_PointsToBSplineSurface.ixx>

#include <Geom_BSplineCurve.hxx>
#include <GeomFill_SectionGenerator.hxx>
#include <GeomFill_Line.hxx>
#include <GeomFill_AppSurf.hxx>
#include <GeomAPI_PointsToBSpline.hxx>
#include <AppDef_BSplineCompute.hxx>
#include <AppDef_MultiLine.hxx>
#include <AppDef_MultiPointConstraint.hxx>
#include <BSplCLib.hxx>
#include <Precision.hxx>
#include <gp_Pnt.hxx>
#include <TColgp_Array1OfPnt.hxx>
#include <math_Vector.hxx>
#include <AppParCurves_HArray1OfConstraintCouple.hxx>
#include <AppParCurves_ConstraintCouple.hxx>
#include <AppDef_TheVariational.hxx>


//=======================================================================
//function : GeomAPI_PointsToBSplineSurface
//purpose  : 
//=======================================================================

GeomAPI_PointsToBSplineSurface::GeomAPI_PointsToBSplineSurface()
: myIsDone ( Standard_False)
{
}


//=======================================================================
//function : GeomAPI_PointsToBSplineSurface
//purpose  : 
//=======================================================================

GeomAPI_PointsToBSplineSurface::GeomAPI_PointsToBSplineSurface
(const TColgp_Array2OfPnt& Points, 
 const Standard_Integer DegMin,
 const Standard_Integer DegMax,
 const GeomAbs_Shape Continuity, 
 const Standard_Real Tol3D)
: myIsDone ( Standard_False)
{
  Init(Points,DegMin,DegMax,Continuity,Tol3D);
}

//=======================================================================
//function : GeomAPI_PointsToBSplineSurface
//purpose  : 
//=======================================================================

GeomAPI_PointsToBSplineSurface::GeomAPI_PointsToBSplineSurface
(const TColgp_Array2OfPnt& Points, 
 const Approx_ParametrizationType ParType,
 const Standard_Integer DegMin,
 const Standard_Integer DegMax,
 const GeomAbs_Shape Continuity, 
 const Standard_Real Tol3D)
: myIsDone ( Standard_False)
{
  Init(Points,ParType,DegMin,DegMax,Continuity,Tol3D);
}

//=======================================================================
//function : GeomAPI_PointsToBSplineSurface
//purpose  : 
//=======================================================================

GeomAPI_PointsToBSplineSurface::GeomAPI_PointsToBSplineSurface
(const TColgp_Array2OfPnt& Points, 
 const Standard_Real Weight1,
 const Standard_Real Weight2,
 const Standard_Real Weight3,
 const Standard_Integer DegMax,
 const GeomAbs_Shape Continuity, 
 const Standard_Real Tol3D)
: myIsDone ( Standard_False)
{
  Init(Points,Weight1,Weight2,Weight3,DegMax,Continuity,Tol3D);
}



//=======================================================================
//function : GeomAPI_PointsToBSplineSurface
//purpose  : 
//=======================================================================

GeomAPI_PointsToBSplineSurface::GeomAPI_PointsToBSplineSurface
(const TColStd_Array2OfReal& ZPoints, 
 const Standard_Real X0, 
 const Standard_Real dX, 
 const Standard_Real Y0,
 const Standard_Real dY, 
 const Standard_Integer DegMin, 
 const Standard_Integer DegMax, 
 const GeomAbs_Shape Continuity, 
 const Standard_Real Tol3D)
: myIsDone ( Standard_False)
{
  Init(ZPoints,X0,dX,Y0,dY,DegMin,DegMax,Continuity,Tol3D);
}



//=======================================================================
//function : Interpolate
//purpose  : 
//=======================================================================

void GeomAPI_PointsToBSplineSurface::Interpolate(const TColgp_Array2OfPnt& Points)
{
  Interpolate(Points, Approx_ChordLength);
}

//=======================================================================
//function : Interpolate
//purpose  : 
//=======================================================================

void GeomAPI_PointsToBSplineSurface::Interpolate(const TColgp_Array2OfPnt& Points,
						 const Approx_ParametrizationType ParType)
{
  Standard_Integer DegMin, DegMax;
  DegMin = DegMax = 3;
  GeomAbs_Shape CC  = GeomAbs_C2;
  Standard_Real Tol3d = -1.0;
  Init(Points, ParType, DegMin, DegMax, CC, Tol3d);
}


//=======================================================================
//function : Init
//purpose  : 
//=======================================================================

void GeomAPI_PointsToBSplineSurface::Init(const TColgp_Array2OfPnt& Points,
					  const Standard_Integer DegMin, 
					  const Standard_Integer DegMax, 
					  const GeomAbs_Shape Continuity,
					  const Standard_Real Tol3D)
{
  Init(Points, Approx_ChordLength, DegMin, DegMax, Continuity, Tol3D);
}
//=======================================================================
//function : Init
//purpose  : 
//=======================================================================

void GeomAPI_PointsToBSplineSurface::Init(const TColgp_Array2OfPnt& Points,
					  const Approx_ParametrizationType ParType,
					  const Standard_Integer DegMin, 
					  const Standard_Integer DegMax, 
					  const GeomAbs_Shape Continuity,
					  const Standard_Real Tol3D)
{
  Standard_Integer Imin = Points.LowerRow();
  Standard_Integer Imax = Points.UpperRow();
  Standard_Integer Jmin = Points.LowerCol();
  Standard_Integer Jmax = Points.UpperCol();

  Standard_Real Tol2D = Tol3D;

  // first approximate the V isos:
  AppDef_MultiLine Line(Jmax-Jmin+1);
  Standard_Integer i, j;
//  Standard_Real X, Y;

  for (j = Jmin; j <= Jmax; j++) {
    AppDef_MultiPointConstraint MP(Imax-Imin+1, 0);
    for (i = Imin; i <= Imax; i++) {
      MP.SetPoint(i, Points(i,j));
    }
    Line.SetValue(j, MP);
  }

  Standard_Integer nbit = 2;
  Standard_Boolean UseSquares = Standard_False;
  if(Tol3D <= 1.e-3) UseSquares = Standard_True;

  AppDef_BSplineCompute TheComputer
    (DegMin,DegMax,Tol3D,Tol2D,nbit,Standard_True,ParType,UseSquares);

  switch( Continuity) {
  case GeomAbs_C0:
    TheComputer.SetContinuity(0); break;

  case GeomAbs_G1: 
  case GeomAbs_C1: 
    TheComputer.SetContinuity(1); break;

  case GeomAbs_G2:
  case GeomAbs_C2:
    TheComputer.SetContinuity(2); break;

  default: 
    TheComputer.SetContinuity(3);
  }
  
  if (Tol3D <= 0.0) {
    TheComputer.Interpol(Line);
  }
  else {
    TheComputer.Perform(Line);
  }

  const AppParCurves_MultiBSpCurve& TheCurve = TheComputer.Value();
  
  Standard_Integer VDegree = TheCurve.Degree();
  TColgp_Array1OfPnt Poles(1,TheCurve.NbPoles());
  const TColStd_Array1OfReal& VKnots = TheCurve.Knots();
  const TColStd_Array1OfInteger& VMults = TheCurve.Multiplicities();
  

  Standard_Integer nbisosu = Imax-Imin+1;
  AppDef_MultiLine Line2(nbisosu);

  for (i = 1; i <= nbisosu; i++) {
    TheCurve.Curve(i, Poles);
    AppDef_MultiPointConstraint MP(Poles.Upper(),0);
    for (j = 1; j <= Poles.Upper(); j++) {
      MP.SetPoint(j, Poles(j));
    }
    Line2.SetValue(i, MP);
  }


  // approximate the resulting poles:
  
  AppDef_BSplineCompute TheComputer2
    (DegMin,DegMax,Tol3D,Tol2D,nbit,Standard_True,ParType,UseSquares);
  if (Tol3D <= 0.0) {
    TheComputer2.Interpol(Line2);
  }
  else {
    TheComputer2.Perform(Line2);
  }
  
  const AppParCurves_MultiBSpCurve& TheCurve2 = TheComputer2.Value();
  
  Standard_Integer UDegree = TheCurve2.Degree();
  TColgp_Array1OfPnt Poles2(1,TheCurve2.NbPoles());
  const TColStd_Array1OfReal& UKnots = TheCurve2.Knots();
  const TColStd_Array1OfInteger& UMults = TheCurve2.Multiplicities();
  

  // computing the surface
  TColgp_Array2OfPnt ThePoles(1, Poles2.Upper(), 1, Poles.Upper());
  for ( j = 1; j <= Poles.Upper(); j++) {
    TheCurve2.Curve(j, Poles2);
    for (i = 1; i<= Poles2.Upper(); i++) {
      ThePoles(i, j) = Poles2(i);
    }
  }


  mySurface = new Geom_BSplineSurface(ThePoles, UKnots, VKnots, UMults, VMults,
				      UDegree, VDegree);

  myIsDone = Standard_True;
}


//=======================================================================
//function : Init
//purpose  : 
//=======================================================================

void GeomAPI_PointsToBSplineSurface::Init(const TColgp_Array2OfPnt& Points,
					  const Standard_Real Weight1,
					  const Standard_Real Weight2,
					  const Standard_Real Weight3,
					  const Standard_Integer DegMax, 
					  const GeomAbs_Shape Continuity,
					  const Standard_Real Tol3D)
{
  Standard_Integer Imin = Points.LowerRow();
  Standard_Integer Imax = Points.UpperRow();
  Standard_Integer Jmin = Points.LowerCol();
  Standard_Integer Jmax = Points.UpperCol();

  Standard_Integer nbit = 2;
  if(Tol3D <= 1.e-3) nbit = 0;

  // first approximate the V isos:
  Standard_Integer NbPointJ = Jmax-Jmin+1;
  Standard_Integer NbPointI = Imax-Imin+1;
  Standard_Integer i, j;

  AppDef_MultiLine Line(NbPointJ);

  for (j = Jmin; j <= Jmax; j++) {
    AppDef_MultiPointConstraint MP(NbPointI, 0);
    for (i = Imin; i <= Imax; i++) {
      MP.SetPoint(i, Points(i,j));
    }
    Line.SetValue(j, MP);
  }


  Handle(AppParCurves_HArray1OfConstraintCouple) TABofCC = 
    new AppParCurves_HArray1OfConstraintCouple(1, NbPointJ);
  AppParCurves_Constraint  Constraint=AppParCurves_NoConstraint;
  
  for(i = 1; i <= NbPointJ; ++i) {
    AppParCurves_ConstraintCouple ACC(i,Constraint);
    TABofCC->SetValue(i,ACC);
  }
  

  AppDef_TheVariational Variation(Line, 1, NbPointJ, TABofCC);

//===================================
  Standard_Integer theMaxSegments = 1000;
  Standard_Boolean theWithMinMax = Standard_False;
//===================================      

  Variation.SetMaxDegree(DegMax);
  Variation.SetContinuity(Continuity);
  Variation.SetMaxSegment(theMaxSegments);

  Variation.SetTolerance(Tol3D);
  Variation.SetWithMinMax(theWithMinMax);
  Variation.SetNbIterations(nbit);

  Variation.SetCriteriumWeight(Weight1, Weight2, Weight3);

  if(!Variation.IsCreated()) {
    return;
  }
  
  if(Variation.IsOverConstrained()) {
    return;
  }

  try {
    Variation.Approximate();
  }
  catch (Standard_Failure) {
    return;
  }

  if(!Variation.IsDone()) {
    return;
  }

  const AppParCurves_MultiBSpCurve& TheCurve = Variation.Value();
  
  Standard_Integer VDegree = TheCurve.Degree();
  TColgp_Array1OfPnt Poles(1,TheCurve.NbPoles());
  const TColStd_Array1OfReal& VKnots = TheCurve.Knots();
  const TColStd_Array1OfInteger& VMults = TheCurve.Multiplicities();
  

  AppDef_MultiLine Line2(NbPointI);

  for (i = 1; i <= NbPointI; i++) {
    TheCurve.Curve(i, Poles);
    AppDef_MultiPointConstraint MP(Poles.Upper(),0);
    for (j = 1; j <= Poles.Upper(); j++) {
      MP.SetPoint(j, Poles(j));
    }
    Line2.SetValue(i, MP);
  }


  Handle(AppParCurves_HArray1OfConstraintCouple) TABofCC2 = 
    new AppParCurves_HArray1OfConstraintCouple(1, NbPointI);
  
  for(i = 1; i <= NbPointI; ++i) {
    AppParCurves_ConstraintCouple ACC(i,Constraint);
    TABofCC2->SetValue(i,ACC);
  }
  

  AppDef_TheVariational Variation2(Line2, 1, NbPointI, TABofCC2);

  Variation2.SetMaxDegree(DegMax);
  Variation2.SetContinuity(Continuity);
  Variation2.SetMaxSegment(theMaxSegments);

  Variation2.SetTolerance(Tol3D);
  Variation2.SetWithMinMax(theWithMinMax);
  Variation2.SetNbIterations(nbit);

  Variation2.SetCriteriumWeight(Weight1, Weight2, Weight3);

  if(!Variation2.IsCreated()) {
    return;
  }
  
  if(Variation2.IsOverConstrained()) {
    return;
  }

  try {
    Variation2.Approximate();
  }
  catch (Standard_Failure) {
    return;
  }

  if(!Variation2.IsDone()) {
    return;
  }

  const AppParCurves_MultiBSpCurve& TheCurve2 = Variation2.Value();  
  
  Standard_Integer UDegree = TheCurve2.Degree();
  TColgp_Array1OfPnt Poles2(1,TheCurve2.NbPoles());
  const TColStd_Array1OfReal& UKnots = TheCurve2.Knots();
  const TColStd_Array1OfInteger& UMults = TheCurve2.Multiplicities();
  

  // computing the surface
  TColgp_Array2OfPnt ThePoles(1, Poles2.Upper(), 1, Poles.Upper());
  for ( j = 1; j <= Poles.Upper(); j++) {
    TheCurve2.Curve(j, Poles2);
    for (i = 1; i<= Poles2.Upper(); i++) {
      ThePoles(i, j) = Poles2(i);
    }
  }


  mySurface = new Geom_BSplineSurface(ThePoles, UKnots, VKnots, UMults, VMults,
				      UDegree, VDegree);

  myIsDone = Standard_True;
}
//=======================================================================
//function : Init
//purpose  : 
//=======================================================================

void GeomAPI_PointsToBSplineSurface::Interpolate(const TColStd_Array2OfReal& ZPoints,
						 const Standard_Real X0, 
						 const Standard_Real dX, 
						 const Standard_Real Y0, 
						 const Standard_Real dY)
{
  Standard_Integer DegMin, DegMax;
  DegMin = DegMax = 3;
  Standard_Real Tol3D  = -1.0;
  GeomAbs_Shape CC = GeomAbs_C2;
  Init(ZPoints, X0, dX, Y0, dY, DegMin, DegMax, CC, Tol3D);
}

//=======================================================================
//function : Init
//purpose  : 
//=======================================================================

void GeomAPI_PointsToBSplineSurface::Init(const TColStd_Array2OfReal& ZPoints,
					  const Standard_Real X0, 
					  const Standard_Real dX, 
					  const Standard_Real Y0, 
					  const Standard_Real dY, 
					  const Standard_Integer DegMin,
					  const Standard_Integer DegMax,
					  const GeomAbs_Shape Continuity,
					  const Standard_Real Tol3D)
{
  Standard_Integer Imin = ZPoints.LowerRow();
  Standard_Integer Imax = ZPoints.UpperRow();
  Standard_Integer Jmin = ZPoints.LowerCol();
  Standard_Integer Jmax = ZPoints.UpperCol();
  Standard_Real length;

  Standard_Real Tol2D = Tol3D;

  // first approximate the V isos:
  AppDef_MultiLine Line(Jmax-Jmin+1);
  math_Vector Param(Jmin, Jmax);
  Standard_Integer i, j;
//  Standard_Real X, Y;
  length = dY * (Jmax-Jmin);

  for (j = Jmin; j <= Jmax; j++) {
    AppDef_MultiPointConstraint MP(0, Imax-Imin+1);
    for (i = Imin; i <= Imax; i++) {
      MP.SetPoint2d(i, gp_Pnt2d(0.0, ZPoints(i, j)));
    }
    Param(j) = (Standard_Real)(j-Jmin)/(Standard_Real)(Jmax-Jmin);
    Line.SetValue(j, MP);
  }

  AppDef_BSplineCompute TheComputer
    (Param, DegMin,DegMax,Tol3D,Tol2D,0, Standard_True, Standard_True);

  switch( Continuity) {
  case GeomAbs_C0:
    TheComputer.SetContinuity(0); break;

  case GeomAbs_G1: 
  case GeomAbs_C1: 
    TheComputer.SetContinuity(1); break;

  case GeomAbs_G2:
  case GeomAbs_C2:
    TheComputer.SetContinuity(2); break;

  default: 
    TheComputer.SetContinuity(3);
  }
  
  if (Tol3D <= 0.0) {
    TheComputer.Interpol(Line);
  }
  else {
    TheComputer.Perform(Line);
  }


  const AppParCurves_MultiBSpCurve& TheCurve = TheComputer.Value();
  
  Standard_Integer VDegree = TheCurve.Degree();
  TColgp_Array1OfPnt2d Poles(1,TheCurve.NbPoles());
  Standard_Integer nk = TheCurve.Knots().Length();
  TColStd_Array1OfReal VKnots(1,nk);
  TColStd_Array1OfInteger VMults(1,nk);
  

  // compute Y values for the poles
  TColStd_Array1OfReal YPoles(1,Poles.Upper());
  
  // start with a line
  TColStd_Array1OfReal    TempPoles(1,2);
  TColStd_Array1OfReal    TempKnots(1,2);
  TColStd_Array1OfInteger TempMults(1,2);
  TempMults.Init(2);
  TempPoles(1) = Y0;
  TempPoles(2) = Y0 + length;
  TempKnots(1) = 0.;
  TempKnots(2) = 1.;
  
  // increase the Degree
  TColStd_Array1OfReal    NewTempPoles(1,VDegree+1);
  TColStd_Array1OfReal    NewTempKnots(1,2);
  TColStd_Array1OfInteger NewTempMults(1,2);
  BSplCLib::IncreaseDegree(1,VDegree,Standard_False,1,
			   TempPoles,TempKnots,TempMults,
			   NewTempPoles,NewTempKnots,NewTempMults);
  
  
  // insert the Knots
  BSplCLib::InsertKnots(VDegree,Standard_False,1,
			NewTempPoles,NewTempKnots,NewTempMults,
			TheCurve.Knots(),TheCurve.Multiplicities(),
			YPoles,VKnots,VMults,
			Epsilon(1));
  
  // scale the knots
  for (i = 1; i <= nk; i++) {
    VKnots(i) = Y0 + length * VKnots(i);
  }
  

  Standard_Integer nbisosu = Imax-Imin+1;
  AppDef_MultiLine Line2(nbisosu);
  math_Vector Param2(1, nbisosu);
  length = dX*(Imax-Imin);

  for (i = 1; i <= nbisosu; i++) {
    TheCurve.Curve(i, Poles);
    AppDef_MultiPointConstraint MP(0, Poles.Upper());
    for (j = 1; j <= Poles.Upper(); j++) {
      MP.SetPoint2d(j, gp_Pnt2d(0.0, Poles(j).Y()));
    }
    Param2(i) = (Standard_Real)(i-1)/(Standard_Real)(nbisosu-1);
    Line2.SetValue(i, MP);
  }


  // approximate the resulting poles:
  
  AppDef_BSplineCompute TheComputer2
    (Param2, DegMin,DegMax,Tol3D,Tol2D,0, Standard_True, Standard_True);
  if (Tol3D <= 0.0) {
    TheComputer2.Interpol(Line2);
  }
  else {
    TheComputer2.Perform(Line2);
  }
  
  const AppParCurves_MultiBSpCurve& TheCurve2 = TheComputer2.Value();
  
  Standard_Integer UDegree = TheCurve2.Degree();
  TColgp_Array1OfPnt2d Poles2(1,TheCurve2.NbPoles());
  Standard_Integer nk2 = TheCurve2.Knots().Length();
  TColStd_Array1OfReal UKnots(1,nk2);
  TColStd_Array1OfInteger UMults(1,nk2);
  

  // compute X values for the poles
  TColStd_Array1OfReal XPoles(1,Poles2.Upper());
  
  // start with a line
  TempPoles(1) = X0;
  TempPoles(2) = X0 + length;
  TempKnots(1) = 0.;
  TempKnots(2) = 1.;
  TempMults(1) = TempMults(2) = 2;
  
  // increase the Degree
  TColStd_Array1OfReal    NewTempPoles2(1,UDegree+1);
  BSplCLib::IncreaseDegree(1,UDegree,Standard_False,1,
			   TempPoles,TempKnots,TempMults,
			   NewTempPoles2,NewTempKnots,NewTempMults);
  
  
  // insert the Knots
  BSplCLib::InsertKnots(UDegree,Standard_False,1,
			NewTempPoles2,NewTempKnots,NewTempMults,
			TheCurve2.Knots(),TheCurve2.Multiplicities(),
			XPoles,UKnots,UMults,
			Epsilon(1));
  
  // scale the knots
  for (i = 1; i <= nk2; i++) {
    UKnots(i) = X0 + length * UKnots(i);
  }
  
  // creating the surface
  TColgp_Array2OfPnt ThePoles(1, Poles2.Upper(), 1, Poles.Upper());

  for ( j = 1; j <= Poles.Upper(); j++) {
    TheCurve2.Curve(j, Poles2);
    for (i = 1; i<= Poles2.Upper(); i++) {
      ThePoles(i, j).SetCoord(XPoles(i), YPoles(j), Poles2(i).Y());
    }
  }


  mySurface = new Geom_BSplineSurface(ThePoles, UKnots, VKnots, UMults, VMults,
				      UDegree, VDegree);

  myIsDone = Standard_True;
  
}


//=======================================================================
//function : Handle_Geom_BSplineSurface&
//purpose  : 
//=======================================================================

const Handle(Geom_BSplineSurface)& GeomAPI_PointsToBSplineSurface::Surface()
const 
{
  StdFail_NotDone_Raise_if
    ( !myIsDone,
     "GeomAPI_PointsToBSplineSurface: Surface not done");

  return mySurface;
}



//=======================================================================
//function : Handle
//purpose  : 
//=======================================================================

GeomAPI_PointsToBSplineSurface::operator Handle(Geom_BSplineSurface)() const
{
  return Surface();
}

//=======================================================================
//function : IsDone
//purpose  : 
//=======================================================================

Standard_Boolean GeomAPI_PointsToBSplineSurface::IsDone () const
{
  return myIsDone;
}