b311480e |
1 | // Created on: 1995-01-17 |
2 | // Created by: Remi LEQUETTE |
3 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
7fd59977 |
17 | |
7fd59977 |
18 | #include <AppDef_BSplineCompute.hxx> |
19 | #include <AppDef_MultiLine.hxx> |
20 | #include <AppDef_MultiPointConstraint.hxx> |
42cf5bc1 |
21 | #include <AppDef_Variational.hxx> |
22 | #include <AppParCurves_ConstraintCouple.hxx> |
23 | #include <AppParCurves_HArray1OfConstraintCouple.hxx> |
7fd59977 |
24 | #include <BSplCLib.hxx> |
42cf5bc1 |
25 | #include <Geom_BSplineCurve.hxx> |
26 | #include <Geom_BSplineSurface.hxx> |
27 | #include <GeomAPI_PointsToBSpline.hxx> |
28 | #include <GeomAPI_PointsToBSplineSurface.hxx> |
29 | #include <GeomFill_AppSurf.hxx> |
30 | #include <GeomFill_Line.hxx> |
31 | #include <GeomFill_SectionGenerator.hxx> |
7fd59977 |
32 | #include <gp_Pnt.hxx> |
7fd59977 |
33 | #include <math_Vector.hxx> |
42cf5bc1 |
34 | #include <Precision.hxx> |
35 | #include <StdFail_NotDone.hxx> |
36 | #include <TColgp_Array1OfPnt.hxx> |
7fd59977 |
37 | |
38 | //======================================================================= |
39 | //function : GeomAPI_PointsToBSplineSurface |
40 | //purpose : |
41 | //======================================================================= |
7fd59977 |
42 | GeomAPI_PointsToBSplineSurface::GeomAPI_PointsToBSplineSurface() |
43 | : myIsDone ( Standard_False) |
44 | { |
45 | } |
46 | |
47 | |
48 | //======================================================================= |
49 | //function : GeomAPI_PointsToBSplineSurface |
50 | //purpose : |
51 | //======================================================================= |
52 | |
53 | GeomAPI_PointsToBSplineSurface::GeomAPI_PointsToBSplineSurface |
54 | (const TColgp_Array2OfPnt& Points, |
55 | const Standard_Integer DegMin, |
56 | const Standard_Integer DegMax, |
57 | const GeomAbs_Shape Continuity, |
58 | const Standard_Real Tol3D) |
59 | : myIsDone ( Standard_False) |
60 | { |
61 | Init(Points,DegMin,DegMax,Continuity,Tol3D); |
62 | } |
63 | |
64 | //======================================================================= |
65 | //function : GeomAPI_PointsToBSplineSurface |
66 | //purpose : |
67 | //======================================================================= |
68 | |
69 | GeomAPI_PointsToBSplineSurface::GeomAPI_PointsToBSplineSurface |
70 | (const TColgp_Array2OfPnt& Points, |
71 | const Approx_ParametrizationType ParType, |
72 | const Standard_Integer DegMin, |
73 | const Standard_Integer DegMax, |
74 | const GeomAbs_Shape Continuity, |
75 | const Standard_Real Tol3D) |
76 | : myIsDone ( Standard_False) |
77 | { |
78 | Init(Points,ParType,DegMin,DegMax,Continuity,Tol3D); |
79 | } |
80 | |
81 | //======================================================================= |
82 | //function : GeomAPI_PointsToBSplineSurface |
83 | //purpose : |
84 | //======================================================================= |
85 | |
86 | GeomAPI_PointsToBSplineSurface::GeomAPI_PointsToBSplineSurface |
87 | (const TColgp_Array2OfPnt& Points, |
88 | const Standard_Real Weight1, |
89 | const Standard_Real Weight2, |
90 | const Standard_Real Weight3, |
91 | const Standard_Integer DegMax, |
92 | const GeomAbs_Shape Continuity, |
93 | const Standard_Real Tol3D) |
94 | : myIsDone ( Standard_False) |
95 | { |
96 | Init(Points,Weight1,Weight2,Weight3,DegMax,Continuity,Tol3D); |
97 | } |
98 | |
99 | |
100 | |
101 | //======================================================================= |
102 | //function : GeomAPI_PointsToBSplineSurface |
103 | //purpose : |
104 | //======================================================================= |
105 | |
106 | GeomAPI_PointsToBSplineSurface::GeomAPI_PointsToBSplineSurface |
107 | (const TColStd_Array2OfReal& ZPoints, |
108 | const Standard_Real X0, |
109 | const Standard_Real dX, |
110 | const Standard_Real Y0, |
111 | const Standard_Real dY, |
112 | const Standard_Integer DegMin, |
113 | const Standard_Integer DegMax, |
114 | const GeomAbs_Shape Continuity, |
115 | const Standard_Real Tol3D) |
116 | : myIsDone ( Standard_False) |
117 | { |
118 | Init(ZPoints,X0,dX,Y0,dY,DegMin,DegMax,Continuity,Tol3D); |
119 | } |
120 | |
121 | |
122 | |
123 | //======================================================================= |
124 | //function : Interpolate |
125 | //purpose : |
126 | //======================================================================= |
127 | |
128 | void GeomAPI_PointsToBSplineSurface::Interpolate(const TColgp_Array2OfPnt& Points) |
129 | { |
130 | Interpolate(Points, Approx_ChordLength); |
131 | } |
132 | |
133 | //======================================================================= |
134 | //function : Interpolate |
135 | //purpose : |
136 | //======================================================================= |
137 | |
138 | void GeomAPI_PointsToBSplineSurface::Interpolate(const TColgp_Array2OfPnt& Points, |
139 | const Approx_ParametrizationType ParType) |
140 | { |
141 | Standard_Integer DegMin, DegMax; |
142 | DegMin = DegMax = 3; |
143 | GeomAbs_Shape CC = GeomAbs_C2; |
144 | Standard_Real Tol3d = -1.0; |
145 | Init(Points, ParType, DegMin, DegMax, CC, Tol3d); |
146 | } |
147 | |
148 | |
149 | //======================================================================= |
150 | //function : Init |
151 | //purpose : |
152 | //======================================================================= |
153 | |
154 | void GeomAPI_PointsToBSplineSurface::Init(const TColgp_Array2OfPnt& Points, |
155 | const Standard_Integer DegMin, |
156 | const Standard_Integer DegMax, |
157 | const GeomAbs_Shape Continuity, |
158 | const Standard_Real Tol3D) |
159 | { |
160 | Init(Points, Approx_ChordLength, DegMin, DegMax, Continuity, Tol3D); |
161 | } |
162 | //======================================================================= |
163 | //function : Init |
164 | //purpose : |
165 | //======================================================================= |
166 | |
167 | void GeomAPI_PointsToBSplineSurface::Init(const TColgp_Array2OfPnt& Points, |
168 | const Approx_ParametrizationType ParType, |
169 | const Standard_Integer DegMin, |
170 | const Standard_Integer DegMax, |
171 | const GeomAbs_Shape Continuity, |
172 | const Standard_Real Tol3D) |
173 | { |
174 | Standard_Integer Imin = Points.LowerRow(); |
175 | Standard_Integer Imax = Points.UpperRow(); |
176 | Standard_Integer Jmin = Points.LowerCol(); |
177 | Standard_Integer Jmax = Points.UpperCol(); |
178 | |
179 | Standard_Real Tol2D = Tol3D; |
180 | |
181 | // first approximate the V isos: |
182 | AppDef_MultiLine Line(Jmax-Jmin+1); |
183 | Standard_Integer i, j; |
184 | // Standard_Real X, Y; |
185 | |
186 | for (j = Jmin; j <= Jmax; j++) { |
187 | AppDef_MultiPointConstraint MP(Imax-Imin+1, 0); |
188 | for (i = Imin; i <= Imax; i++) { |
189 | MP.SetPoint(i, Points(i,j)); |
190 | } |
191 | Line.SetValue(j, MP); |
192 | } |
193 | |
194 | Standard_Integer nbit = 2; |
195 | Standard_Boolean UseSquares = Standard_False; |
196 | if(Tol3D <= 1.e-3) UseSquares = Standard_True; |
197 | |
198 | AppDef_BSplineCompute TheComputer |
199 | (DegMin,DegMax,Tol3D,Tol2D,nbit,Standard_True,ParType,UseSquares); |
200 | |
201 | switch( Continuity) { |
202 | case GeomAbs_C0: |
203 | TheComputer.SetContinuity(0); break; |
204 | |
205 | case GeomAbs_G1: |
206 | case GeomAbs_C1: |
207 | TheComputer.SetContinuity(1); break; |
208 | |
209 | case GeomAbs_G2: |
210 | case GeomAbs_C2: |
211 | TheComputer.SetContinuity(2); break; |
212 | |
213 | default: |
214 | TheComputer.SetContinuity(3); |
215 | } |
216 | |
217 | if (Tol3D <= 0.0) { |
218 | TheComputer.Interpol(Line); |
219 | } |
220 | else { |
221 | TheComputer.Perform(Line); |
222 | } |
223 | |
224 | const AppParCurves_MultiBSpCurve& TheCurve = TheComputer.Value(); |
225 | |
226 | Standard_Integer VDegree = TheCurve.Degree(); |
227 | TColgp_Array1OfPnt Poles(1,TheCurve.NbPoles()); |
228 | const TColStd_Array1OfReal& VKnots = TheCurve.Knots(); |
229 | const TColStd_Array1OfInteger& VMults = TheCurve.Multiplicities(); |
230 | |
231 | |
232 | Standard_Integer nbisosu = Imax-Imin+1; |
233 | AppDef_MultiLine Line2(nbisosu); |
234 | |
235 | for (i = 1; i <= nbisosu; i++) { |
236 | TheCurve.Curve(i, Poles); |
237 | AppDef_MultiPointConstraint MP(Poles.Upper(),0); |
238 | for (j = 1; j <= Poles.Upper(); j++) { |
239 | MP.SetPoint(j, Poles(j)); |
240 | } |
241 | Line2.SetValue(i, MP); |
242 | } |
243 | |
244 | |
245 | // approximate the resulting poles: |
246 | |
247 | AppDef_BSplineCompute TheComputer2 |
248 | (DegMin,DegMax,Tol3D,Tol2D,nbit,Standard_True,ParType,UseSquares); |
249 | if (Tol3D <= 0.0) { |
250 | TheComputer2.Interpol(Line2); |
251 | } |
252 | else { |
253 | TheComputer2.Perform(Line2); |
254 | } |
255 | |
256 | const AppParCurves_MultiBSpCurve& TheCurve2 = TheComputer2.Value(); |
257 | |
258 | Standard_Integer UDegree = TheCurve2.Degree(); |
259 | TColgp_Array1OfPnt Poles2(1,TheCurve2.NbPoles()); |
260 | const TColStd_Array1OfReal& UKnots = TheCurve2.Knots(); |
261 | const TColStd_Array1OfInteger& UMults = TheCurve2.Multiplicities(); |
262 | |
263 | |
264 | // computing the surface |
265 | TColgp_Array2OfPnt ThePoles(1, Poles2.Upper(), 1, Poles.Upper()); |
266 | for ( j = 1; j <= Poles.Upper(); j++) { |
267 | TheCurve2.Curve(j, Poles2); |
268 | for (i = 1; i<= Poles2.Upper(); i++) { |
269 | ThePoles(i, j) = Poles2(i); |
270 | } |
271 | } |
272 | |
273 | |
274 | mySurface = new Geom_BSplineSurface(ThePoles, UKnots, VKnots, UMults, VMults, |
275 | UDegree, VDegree); |
276 | |
277 | myIsDone = Standard_True; |
278 | } |
279 | |
280 | |
281 | //======================================================================= |
282 | //function : Init |
283 | //purpose : |
284 | //======================================================================= |
285 | |
286 | void GeomAPI_PointsToBSplineSurface::Init(const TColgp_Array2OfPnt& Points, |
287 | const Standard_Real Weight1, |
288 | const Standard_Real Weight2, |
289 | const Standard_Real Weight3, |
290 | const Standard_Integer DegMax, |
291 | const GeomAbs_Shape Continuity, |
292 | const Standard_Real Tol3D) |
293 | { |
294 | Standard_Integer Imin = Points.LowerRow(); |
295 | Standard_Integer Imax = Points.UpperRow(); |
296 | Standard_Integer Jmin = Points.LowerCol(); |
297 | Standard_Integer Jmax = Points.UpperCol(); |
298 | |
299 | Standard_Integer nbit = 2; |
300 | if(Tol3D <= 1.e-3) nbit = 0; |
301 | |
302 | // first approximate the V isos: |
303 | Standard_Integer NbPointJ = Jmax-Jmin+1; |
304 | Standard_Integer NbPointI = Imax-Imin+1; |
305 | Standard_Integer i, j; |
306 | |
307 | AppDef_MultiLine Line(NbPointJ); |
308 | |
309 | for (j = Jmin; j <= Jmax; j++) { |
310 | AppDef_MultiPointConstraint MP(NbPointI, 0); |
311 | for (i = Imin; i <= Imax; i++) { |
312 | MP.SetPoint(i, Points(i,j)); |
313 | } |
314 | Line.SetValue(j, MP); |
315 | } |
316 | |
317 | |
318 | Handle(AppParCurves_HArray1OfConstraintCouple) TABofCC = |
319 | new AppParCurves_HArray1OfConstraintCouple(1, NbPointJ); |
320 | AppParCurves_Constraint Constraint=AppParCurves_NoConstraint; |
321 | |
322 | for(i = 1; i <= NbPointJ; ++i) { |
323 | AppParCurves_ConstraintCouple ACC(i,Constraint); |
324 | TABofCC->SetValue(i,ACC); |
325 | } |
326 | |
327 | |
f62de372 |
328 | AppDef_Variational Variation(Line, 1, NbPointJ, TABofCC); |
7fd59977 |
329 | |
330 | //=================================== |
331 | Standard_Integer theMaxSegments = 1000; |
332 | Standard_Boolean theWithMinMax = Standard_False; |
333 | //=================================== |
334 | |
335 | Variation.SetMaxDegree(DegMax); |
336 | Variation.SetContinuity(Continuity); |
337 | Variation.SetMaxSegment(theMaxSegments); |
338 | |
339 | Variation.SetTolerance(Tol3D); |
340 | Variation.SetWithMinMax(theWithMinMax); |
341 | Variation.SetNbIterations(nbit); |
342 | |
343 | Variation.SetCriteriumWeight(Weight1, Weight2, Weight3); |
344 | |
345 | if(!Variation.IsCreated()) { |
346 | return; |
347 | } |
348 | |
349 | if(Variation.IsOverConstrained()) { |
350 | return; |
351 | } |
352 | |
353 | try { |
354 | Variation.Approximate(); |
355 | } |
356 | catch (Standard_Failure) { |
357 | return; |
358 | } |
359 | |
360 | if(!Variation.IsDone()) { |
361 | return; |
362 | } |
363 | |
364 | const AppParCurves_MultiBSpCurve& TheCurve = Variation.Value(); |
365 | |
366 | Standard_Integer VDegree = TheCurve.Degree(); |
367 | TColgp_Array1OfPnt Poles(1,TheCurve.NbPoles()); |
368 | const TColStd_Array1OfReal& VKnots = TheCurve.Knots(); |
369 | const TColStd_Array1OfInteger& VMults = TheCurve.Multiplicities(); |
370 | |
371 | |
372 | AppDef_MultiLine Line2(NbPointI); |
373 | |
374 | for (i = 1; i <= NbPointI; i++) { |
375 | TheCurve.Curve(i, Poles); |
376 | AppDef_MultiPointConstraint MP(Poles.Upper(),0); |
377 | for (j = 1; j <= Poles.Upper(); j++) { |
378 | MP.SetPoint(j, Poles(j)); |
379 | } |
380 | Line2.SetValue(i, MP); |
381 | } |
382 | |
383 | |
384 | Handle(AppParCurves_HArray1OfConstraintCouple) TABofCC2 = |
385 | new AppParCurves_HArray1OfConstraintCouple(1, NbPointI); |
386 | |
387 | for(i = 1; i <= NbPointI; ++i) { |
388 | AppParCurves_ConstraintCouple ACC(i,Constraint); |
389 | TABofCC2->SetValue(i,ACC); |
390 | } |
391 | |
392 | |
f62de372 |
393 | AppDef_Variational Variation2(Line2, 1, NbPointI, TABofCC2); |
7fd59977 |
394 | |
395 | Variation2.SetMaxDegree(DegMax); |
396 | Variation2.SetContinuity(Continuity); |
397 | Variation2.SetMaxSegment(theMaxSegments); |
398 | |
399 | Variation2.SetTolerance(Tol3D); |
400 | Variation2.SetWithMinMax(theWithMinMax); |
401 | Variation2.SetNbIterations(nbit); |
402 | |
403 | Variation2.SetCriteriumWeight(Weight1, Weight2, Weight3); |
404 | |
405 | if(!Variation2.IsCreated()) { |
406 | return; |
407 | } |
408 | |
409 | if(Variation2.IsOverConstrained()) { |
410 | return; |
411 | } |
412 | |
413 | try { |
414 | Variation2.Approximate(); |
415 | } |
416 | catch (Standard_Failure) { |
417 | return; |
418 | } |
419 | |
420 | if(!Variation2.IsDone()) { |
421 | return; |
422 | } |
423 | |
424 | const AppParCurves_MultiBSpCurve& TheCurve2 = Variation2.Value(); |
425 | |
426 | Standard_Integer UDegree = TheCurve2.Degree(); |
427 | TColgp_Array1OfPnt Poles2(1,TheCurve2.NbPoles()); |
428 | const TColStd_Array1OfReal& UKnots = TheCurve2.Knots(); |
429 | const TColStd_Array1OfInteger& UMults = TheCurve2.Multiplicities(); |
430 | |
431 | |
432 | // computing the surface |
433 | TColgp_Array2OfPnt ThePoles(1, Poles2.Upper(), 1, Poles.Upper()); |
434 | for ( j = 1; j <= Poles.Upper(); j++) { |
435 | TheCurve2.Curve(j, Poles2); |
436 | for (i = 1; i<= Poles2.Upper(); i++) { |
437 | ThePoles(i, j) = Poles2(i); |
438 | } |
439 | } |
440 | |
441 | |
442 | mySurface = new Geom_BSplineSurface(ThePoles, UKnots, VKnots, UMults, VMults, |
443 | UDegree, VDegree); |
444 | |
445 | myIsDone = Standard_True; |
446 | } |
447 | //======================================================================= |
448 | //function : Init |
449 | //purpose : |
450 | //======================================================================= |
451 | |
452 | void GeomAPI_PointsToBSplineSurface::Interpolate(const TColStd_Array2OfReal& ZPoints, |
453 | const Standard_Real X0, |
454 | const Standard_Real dX, |
455 | const Standard_Real Y0, |
456 | const Standard_Real dY) |
457 | { |
458 | Standard_Integer DegMin, DegMax; |
459 | DegMin = DegMax = 3; |
460 | Standard_Real Tol3D = -1.0; |
461 | GeomAbs_Shape CC = GeomAbs_C2; |
462 | Init(ZPoints, X0, dX, Y0, dY, DegMin, DegMax, CC, Tol3D); |
463 | } |
464 | |
465 | //======================================================================= |
466 | //function : Init |
467 | //purpose : |
468 | //======================================================================= |
469 | |
470 | void GeomAPI_PointsToBSplineSurface::Init(const TColStd_Array2OfReal& ZPoints, |
471 | const Standard_Real X0, |
472 | const Standard_Real dX, |
473 | const Standard_Real Y0, |
474 | const Standard_Real dY, |
475 | const Standard_Integer DegMin, |
476 | const Standard_Integer DegMax, |
477 | const GeomAbs_Shape Continuity, |
478 | const Standard_Real Tol3D) |
479 | { |
480 | Standard_Integer Imin = ZPoints.LowerRow(); |
481 | Standard_Integer Imax = ZPoints.UpperRow(); |
482 | Standard_Integer Jmin = ZPoints.LowerCol(); |
483 | Standard_Integer Jmax = ZPoints.UpperCol(); |
484 | Standard_Real length; |
485 | |
486 | Standard_Real Tol2D = Tol3D; |
487 | |
488 | // first approximate the V isos: |
489 | AppDef_MultiLine Line(Jmax-Jmin+1); |
490 | math_Vector Param(Jmin, Jmax); |
491 | Standard_Integer i, j; |
492 | // Standard_Real X, Y; |
493 | length = dY * (Jmax-Jmin); |
494 | |
495 | for (j = Jmin; j <= Jmax; j++) { |
496 | AppDef_MultiPointConstraint MP(0, Imax-Imin+1); |
497 | for (i = Imin; i <= Imax; i++) { |
498 | MP.SetPoint2d(i, gp_Pnt2d(0.0, ZPoints(i, j))); |
499 | } |
500 | Param(j) = (Standard_Real)(j-Jmin)/(Standard_Real)(Jmax-Jmin); |
501 | Line.SetValue(j, MP); |
502 | } |
503 | |
504 | AppDef_BSplineCompute TheComputer |
505 | (Param, DegMin,DegMax,Tol3D,Tol2D,0, Standard_True, Standard_True); |
506 | |
507 | switch( Continuity) { |
508 | case GeomAbs_C0: |
509 | TheComputer.SetContinuity(0); break; |
510 | |
511 | case GeomAbs_G1: |
512 | case GeomAbs_C1: |
513 | TheComputer.SetContinuity(1); break; |
514 | |
515 | case GeomAbs_G2: |
516 | case GeomAbs_C2: |
517 | TheComputer.SetContinuity(2); break; |
518 | |
519 | default: |
520 | TheComputer.SetContinuity(3); |
521 | } |
522 | |
523 | if (Tol3D <= 0.0) { |
524 | TheComputer.Interpol(Line); |
525 | } |
526 | else { |
527 | TheComputer.Perform(Line); |
528 | } |
529 | |
530 | |
531 | const AppParCurves_MultiBSpCurve& TheCurve = TheComputer.Value(); |
532 | |
533 | Standard_Integer VDegree = TheCurve.Degree(); |
534 | TColgp_Array1OfPnt2d Poles(1,TheCurve.NbPoles()); |
535 | Standard_Integer nk = TheCurve.Knots().Length(); |
536 | TColStd_Array1OfReal VKnots(1,nk); |
537 | TColStd_Array1OfInteger VMults(1,nk); |
538 | |
539 | |
540 | // compute Y values for the poles |
541 | TColStd_Array1OfReal YPoles(1,Poles.Upper()); |
542 | |
543 | // start with a line |
544 | TColStd_Array1OfReal TempPoles(1,2); |
545 | TColStd_Array1OfReal TempKnots(1,2); |
546 | TColStd_Array1OfInteger TempMults(1,2); |
547 | TempMults.Init(2); |
548 | TempPoles(1) = Y0; |
549 | TempPoles(2) = Y0 + length; |
550 | TempKnots(1) = 0.; |
551 | TempKnots(2) = 1.; |
552 | |
553 | // increase the Degree |
554 | TColStd_Array1OfReal NewTempPoles(1,VDegree+1); |
555 | TColStd_Array1OfReal NewTempKnots(1,2); |
556 | TColStd_Array1OfInteger NewTempMults(1,2); |
557 | BSplCLib::IncreaseDegree(1,VDegree,Standard_False,1, |
558 | TempPoles,TempKnots,TempMults, |
559 | NewTempPoles,NewTempKnots,NewTempMults); |
560 | |
561 | |
562 | // insert the Knots |
563 | BSplCLib::InsertKnots(VDegree,Standard_False,1, |
564 | NewTempPoles,NewTempKnots,NewTempMults, |
0e14656b |
565 | TheCurve.Knots(),&TheCurve.Multiplicities(), |
7fd59977 |
566 | YPoles,VKnots,VMults, |
567 | Epsilon(1)); |
568 | |
569 | // scale the knots |
570 | for (i = 1; i <= nk; i++) { |
571 | VKnots(i) = Y0 + length * VKnots(i); |
572 | } |
573 | |
574 | |
575 | Standard_Integer nbisosu = Imax-Imin+1; |
576 | AppDef_MultiLine Line2(nbisosu); |
577 | math_Vector Param2(1, nbisosu); |
578 | length = dX*(Imax-Imin); |
579 | |
580 | for (i = 1; i <= nbisosu; i++) { |
581 | TheCurve.Curve(i, Poles); |
582 | AppDef_MultiPointConstraint MP(0, Poles.Upper()); |
583 | for (j = 1; j <= Poles.Upper(); j++) { |
584 | MP.SetPoint2d(j, gp_Pnt2d(0.0, Poles(j).Y())); |
585 | } |
586 | Param2(i) = (Standard_Real)(i-1)/(Standard_Real)(nbisosu-1); |
587 | Line2.SetValue(i, MP); |
588 | } |
589 | |
590 | |
591 | // approximate the resulting poles: |
592 | |
593 | AppDef_BSplineCompute TheComputer2 |
594 | (Param2, DegMin,DegMax,Tol3D,Tol2D,0, Standard_True, Standard_True); |
595 | if (Tol3D <= 0.0) { |
596 | TheComputer2.Interpol(Line2); |
597 | } |
598 | else { |
599 | TheComputer2.Perform(Line2); |
600 | } |
601 | |
602 | const AppParCurves_MultiBSpCurve& TheCurve2 = TheComputer2.Value(); |
603 | |
604 | Standard_Integer UDegree = TheCurve2.Degree(); |
605 | TColgp_Array1OfPnt2d Poles2(1,TheCurve2.NbPoles()); |
606 | Standard_Integer nk2 = TheCurve2.Knots().Length(); |
607 | TColStd_Array1OfReal UKnots(1,nk2); |
608 | TColStd_Array1OfInteger UMults(1,nk2); |
609 | |
610 | |
611 | // compute X values for the poles |
612 | TColStd_Array1OfReal XPoles(1,Poles2.Upper()); |
613 | |
614 | // start with a line |
615 | TempPoles(1) = X0; |
616 | TempPoles(2) = X0 + length; |
617 | TempKnots(1) = 0.; |
618 | TempKnots(2) = 1.; |
619 | TempMults(1) = TempMults(2) = 2; |
620 | |
621 | // increase the Degree |
622 | TColStd_Array1OfReal NewTempPoles2(1,UDegree+1); |
623 | BSplCLib::IncreaseDegree(1,UDegree,Standard_False,1, |
624 | TempPoles,TempKnots,TempMults, |
625 | NewTempPoles2,NewTempKnots,NewTempMults); |
626 | |
627 | |
628 | // insert the Knots |
629 | BSplCLib::InsertKnots(UDegree,Standard_False,1, |
630 | NewTempPoles2,NewTempKnots,NewTempMults, |
0e14656b |
631 | TheCurve2.Knots(),&TheCurve2.Multiplicities(), |
7fd59977 |
632 | XPoles,UKnots,UMults, |
633 | Epsilon(1)); |
634 | |
635 | // scale the knots |
636 | for (i = 1; i <= nk2; i++) { |
637 | UKnots(i) = X0 + length * UKnots(i); |
638 | } |
639 | |
640 | // creating the surface |
641 | TColgp_Array2OfPnt ThePoles(1, Poles2.Upper(), 1, Poles.Upper()); |
642 | |
643 | for ( j = 1; j <= Poles.Upper(); j++) { |
644 | TheCurve2.Curve(j, Poles2); |
645 | for (i = 1; i<= Poles2.Upper(); i++) { |
646 | ThePoles(i, j).SetCoord(XPoles(i), YPoles(j), Poles2(i).Y()); |
647 | } |
648 | } |
649 | |
650 | |
651 | mySurface = new Geom_BSplineSurface(ThePoles, UKnots, VKnots, UMults, VMults, |
652 | UDegree, VDegree); |
653 | |
654 | myIsDone = Standard_True; |
655 | |
656 | } |
657 | |
658 | |
659 | //======================================================================= |
857ffd5e |
660 | //function : Handle(Geom_BSplineSurface)& |
7fd59977 |
661 | //purpose : |
662 | //======================================================================= |
663 | |
664 | const Handle(Geom_BSplineSurface)& GeomAPI_PointsToBSplineSurface::Surface() |
665 | const |
666 | { |
667 | StdFail_NotDone_Raise_if |
668 | ( !myIsDone, |
669 | "GeomAPI_PointsToBSplineSurface: Surface not done"); |
670 | |
671 | return mySurface; |
672 | } |
673 | |
674 | |
675 | |
676 | //======================================================================= |
677 | //function : Handle |
678 | //purpose : |
679 | //======================================================================= |
680 | |
681 | GeomAPI_PointsToBSplineSurface::operator Handle(Geom_BSplineSurface)() const |
682 | { |
683 | return Surface(); |
684 | } |
685 | |
686 | //======================================================================= |
687 | //function : IsDone |
688 | //purpose : |
689 | //======================================================================= |
690 | |
691 | Standard_Boolean GeomAPI_PointsToBSplineSurface::IsDone () const |
692 | { |
693 | return myIsDone; |
694 | } |
695 | |
696 | |