b311480e |
1 | // Created on: 1993-03-09 |
2 | // Created by: JCV |
3 | // Copyright (c) 1993-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 | //Passage en classe persistante - 23/01/91 |
18 | //Modif suite a la deuxieme revue de projet toolkit Geometry -23/01/91 |
19 | // pmn : 21/10/95 ; Correction de la methode segment (PRO5853) |
20 | // pmn : 31-Dec-96; Bonne gestion des poids (bug PRO4622) |
21 | // xab : 07-Jul-97; le cache est instable en degree 21 |
22 | // a partir du degree 15 on ne l'utilise plus |
23 | // RBD : 15/10/98 ; Le cache est desormais defini sur [-1,1] (pro15537). |
24 | // pmn : 10/12/98 ; Update de la methode segment (suite a la modif de cache). |
25 | |
26 | #define No_Standard_OutOfRange |
27 | #define No_Standard_DimensionError |
28 | |
29 | #include <Geom_BezierSurface.ixx> |
30 | #include <Geom_BezierCurve.hxx> |
31 | |
32 | #include <gp.hxx> |
33 | #include <gp_XYZ.hxx> |
34 | #include <PLib.hxx> |
35 | #include <BSplCLib.hxx> |
36 | #include <BSplSLib.hxx> |
37 | #include <Precision.hxx> |
38 | |
39 | #include <Standard_OutOfRange.hxx> |
40 | #include <Standard_RangeError.hxx> |
41 | #include <Standard_DimensionError.hxx> |
42 | #include <Standard_ConstructionError.hxx> |
43 | #include <TColStd_Array1OfInteger.hxx> |
44 | |
45 | //======================================================================= |
46 | //function : Rational |
47 | //purpose : check rationality of an array of weights |
48 | //======================================================================= |
49 | |
50 | static void Rational(const TColStd_Array2OfReal& Weights, |
51 | Standard_Boolean& Urational, |
52 | Standard_Boolean& Vrational) |
53 | { |
54 | Standard_Integer I,J; |
55 | J = Weights.LowerCol (); |
56 | Vrational = Standard_False; |
57 | while (!Vrational && J <= Weights.UpperCol()) { |
58 | I = Weights.LowerRow(); |
59 | while (!Vrational && I <= Weights.UpperRow() - 1) { |
60 | Vrational = (Abs(Weights (I, J) - Weights (I+1, J)) |
61 | > Epsilon (Abs(Weights (I, J)))); |
62 | I++; |
63 | } |
64 | J++; |
65 | } |
66 | |
67 | I = Weights.LowerRow (); |
68 | Urational = Standard_False; |
69 | while (!Urational && I <= Weights.UpperRow()) { |
70 | J = Weights.LowerCol(); |
71 | while (!Urational && J <= Weights.UpperCol() - 1) { |
72 | Urational = (Abs(Weights (I, J) - Weights (I, J+1)) |
73 | > Epsilon (Abs(Weights (I, J)))); |
74 | J++; |
75 | } |
76 | I++; |
77 | } |
78 | } |
79 | |
80 | //======================================================================= |
81 | //function : AddPoleCol |
82 | //purpose : Internal use only. |
83 | //======================================================================= |
84 | |
85 | static void AddPoleCol |
86 | (const TColgp_Array2OfPnt& Poles, |
87 | const TColgp_Array1OfPnt& PoleCol, |
88 | const Standard_Integer AfterIndex, |
89 | TColgp_Array2OfPnt& NewPoles) |
90 | { |
91 | Standard_Integer InsertIndex = AfterIndex + NewPoles.LowerCol(); |
92 | Standard_Integer Offset = NewPoles.LowerRow() - PoleCol.Lower(); |
93 | Standard_Integer ColIndex = NewPoles.LowerCol(); |
94 | Standard_Integer RowIndex; |
95 | while (ColIndex < InsertIndex) { |
96 | RowIndex = NewPoles.LowerRow(); |
97 | while (RowIndex <= NewPoles.UpperRow()){ |
98 | NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex); |
99 | RowIndex++; |
100 | } |
101 | ColIndex++; |
102 | } |
103 | RowIndex = NewPoles.LowerRow(); |
104 | while (RowIndex <= NewPoles.UpperRow()){ |
105 | NewPoles (RowIndex, ColIndex) = PoleCol (RowIndex - Offset); |
106 | RowIndex++; |
107 | } |
108 | ColIndex++; |
109 | while (ColIndex <= NewPoles.UpperCol()) { |
110 | RowIndex = NewPoles.LowerRow(); |
111 | while (RowIndex <= NewPoles.UpperRow()){ |
112 | NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex - 1); |
113 | RowIndex++; |
114 | } |
115 | ColIndex++; |
116 | } |
117 | } |
118 | |
119 | //======================================================================= |
120 | //function : AddRatPoleCol |
121 | //purpose : Internal use only. |
122 | //======================================================================= |
123 | |
124 | static void AddRatPoleCol |
125 | (const TColgp_Array2OfPnt& Poles, |
126 | const TColStd_Array2OfReal& Weights, |
127 | const TColgp_Array1OfPnt& PoleCol, |
128 | const TColStd_Array1OfReal& PoleWeightCol, |
129 | const Standard_Integer AfterIndex, |
130 | TColgp_Array2OfPnt& NewPoles, |
131 | TColStd_Array2OfReal& NewWeights) |
132 | { |
133 | Standard_Integer InsertIndex = AfterIndex + NewPoles.LowerCol(); |
134 | Standard_Integer OffsetPol = NewPoles.LowerRow() - PoleCol.Lower(); |
135 | Standard_Integer OffsetW = NewWeights.LowerRow() - PoleWeightCol.Lower(); |
136 | |
137 | Standard_Integer ColIndex = NewPoles.LowerCol(); |
138 | Standard_Integer RowIndex; |
139 | while (ColIndex < InsertIndex) { |
140 | RowIndex = NewPoles.LowerRow(); |
141 | while (RowIndex <= NewPoles.UpperRow()){ |
142 | NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex); |
143 | NewWeights (RowIndex, ColIndex) = Weights (RowIndex, ColIndex); |
144 | RowIndex++; |
145 | } |
146 | ColIndex++; |
147 | } |
148 | RowIndex = NewPoles.LowerRow(); |
149 | while (RowIndex <= NewPoles.UpperRow()){ |
150 | NewPoles (RowIndex, ColIndex) = PoleCol (RowIndex - OffsetPol); |
151 | NewWeights (RowIndex, ColIndex) = PoleWeightCol (RowIndex - OffsetW); |
152 | RowIndex++; |
153 | } |
154 | ColIndex++; |
155 | while (ColIndex <= NewPoles.UpperCol()) { |
156 | RowIndex = NewPoles.LowerRow(); |
157 | while (RowIndex <= NewPoles.UpperRow()){ |
158 | NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex - 1); |
159 | RowIndex++; |
160 | NewWeights (RowIndex, ColIndex) = Weights (RowIndex, ColIndex - 1); |
161 | } |
162 | ColIndex++; |
163 | } |
164 | } |
165 | |
166 | //======================================================================= |
167 | //function : AddPoleRow |
168 | //purpose : Internal use only. |
169 | //======================================================================= |
170 | |
171 | static void AddPoleRow |
172 | (const TColgp_Array2OfPnt& Poles, |
173 | const TColgp_Array1OfPnt& PoleRow, |
174 | const Standard_Integer AfterIndex, |
175 | TColgp_Array2OfPnt& NewPoles) |
176 | { |
177 | Standard_Integer InsertIndex = AfterIndex + NewPoles.LowerRow(); |
178 | Standard_Integer Offset = NewPoles.LowerCol() - PoleRow.Lower(); |
179 | Standard_Integer RowIndex = NewPoles.LowerRow(); |
180 | Standard_Integer ColIndex; |
181 | while (RowIndex < InsertIndex) { |
182 | ColIndex = NewPoles.LowerCol(); |
183 | while (ColIndex <= NewPoles.UpperCol()){ |
184 | NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex); |
185 | ColIndex++; |
186 | } |
187 | RowIndex++; |
188 | } |
189 | ColIndex = NewPoles.LowerCol(); |
190 | while (ColIndex <= NewPoles.UpperCol()){ |
191 | NewPoles (RowIndex, ColIndex) = PoleRow (ColIndex - Offset); |
192 | ColIndex++; |
193 | } |
194 | RowIndex++; |
195 | while (RowIndex <= NewPoles.UpperRow()) { |
196 | ColIndex = NewPoles.LowerCol(); |
197 | while (ColIndex <= NewPoles.UpperCol()){ |
198 | NewPoles (RowIndex, ColIndex) = Poles (RowIndex - 1, ColIndex); |
199 | ColIndex++; |
200 | } |
201 | RowIndex++; |
202 | } |
203 | } |
204 | |
205 | //======================================================================= |
206 | //function : AddRatPoleRow |
207 | //purpose : |
208 | //======================================================================= |
209 | |
210 | static void AddRatPoleRow |
211 | (const TColgp_Array2OfPnt& Poles, |
212 | const TColStd_Array2OfReal& Weights, |
213 | const TColgp_Array1OfPnt& PoleRow, |
214 | const TColStd_Array1OfReal& PoleWeightRow, |
215 | const Standard_Integer AfterIndex, |
216 | TColgp_Array2OfPnt& NewPoles, |
217 | TColStd_Array2OfReal& NewWeights) |
218 | { |
219 | Standard_Integer InsertIndex = AfterIndex + NewPoles.LowerRow(); |
220 | Standard_Integer OffsetPol = NewPoles.LowerCol() - PoleRow.Lower(); |
221 | Standard_Integer OffsetW = NewWeights.LowerCol() - PoleWeightRow.Lower(); |
222 | |
223 | Standard_Integer ColIndex; |
224 | Standard_Integer RowIndex = NewPoles.LowerRow(); |
225 | while (RowIndex < InsertIndex) { |
226 | ColIndex = NewPoles.LowerCol(); |
227 | while (ColIndex <= NewPoles.UpperCol()){ |
228 | NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex); |
229 | NewWeights (RowIndex, ColIndex) = Weights (RowIndex, ColIndex); |
230 | ColIndex++; |
231 | } |
232 | RowIndex++; |
233 | } |
234 | ColIndex = NewPoles.LowerCol(); |
235 | while (ColIndex <= NewPoles.UpperCol()){ |
236 | NewPoles (RowIndex, ColIndex) = PoleRow (ColIndex - OffsetPol); |
237 | NewWeights (RowIndex, ColIndex) = PoleWeightRow (ColIndex - OffsetW); |
238 | ColIndex++; |
239 | } |
240 | RowIndex++; |
241 | while (RowIndex <= NewPoles.UpperRow()) { |
242 | ColIndex = NewPoles.LowerCol(); |
243 | while (ColIndex <= NewPoles.UpperCol()){ |
244 | NewPoles (RowIndex, ColIndex) = Poles (RowIndex - 1, ColIndex); |
245 | NewWeights (RowIndex, ColIndex) = Weights (RowIndex - 1, ColIndex); |
246 | ColIndex++; |
247 | } |
248 | RowIndex++; |
249 | } |
250 | } |
251 | |
252 | //======================================================================= |
253 | //function : DeletePoleCol |
254 | //purpose : |
255 | //======================================================================= |
256 | |
257 | static void DeletePoleCol |
258 | (const TColgp_Array2OfPnt& Poles, |
259 | const Standard_Integer Index, |
260 | TColgp_Array2OfPnt& NewPoles) |
261 | { |
262 | Standard_Integer Offset = 0; |
263 | Standard_Integer RowIndex; |
264 | Standard_Integer ColIndex = NewPoles.LowerCol(); |
265 | while (ColIndex <= NewPoles.UpperCol()) { |
266 | RowIndex = NewPoles.LowerRow(); |
267 | if (ColIndex == Index) Offset = 1; |
268 | while (RowIndex <= NewPoles.UpperRow()){ |
269 | NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex + Offset); |
270 | RowIndex++; |
271 | } |
272 | ColIndex++; |
273 | } |
274 | } |
275 | |
276 | //======================================================================= |
277 | //function : DeleteRatPoleCol |
278 | //purpose : |
279 | //======================================================================= |
280 | |
281 | static void DeleteRatPoleCol |
282 | (const TColgp_Array2OfPnt& Poles, |
283 | const TColStd_Array2OfReal& Weights, |
284 | const Standard_Integer Index, |
285 | TColgp_Array2OfPnt& NewPoles, |
286 | TColStd_Array2OfReal& NewWeights) |
287 | { |
288 | Standard_Integer Offset = 0; |
289 | Standard_Integer RowIndex; |
290 | Standard_Integer ColIndex = NewPoles.LowerCol(); |
291 | while (ColIndex <= NewPoles.UpperCol()) { |
292 | RowIndex = NewPoles.LowerRow(); |
293 | if (ColIndex == Index) Offset = 1; |
294 | while (RowIndex <= NewPoles.UpperRow()){ |
295 | NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex + Offset); |
296 | NewWeights (RowIndex, ColIndex) = Weights (RowIndex, ColIndex+Offset); |
297 | RowIndex++; |
298 | } |
299 | ColIndex++; |
300 | } |
301 | } |
302 | |
303 | //======================================================================= |
304 | //function : DeletePoleRow |
305 | //purpose : |
306 | //======================================================================= |
307 | |
308 | static void DeletePoleRow |
309 | (const TColgp_Array2OfPnt& Poles, |
310 | const Standard_Integer Index, |
311 | TColgp_Array2OfPnt& NewPoles) |
312 | { |
313 | Standard_Integer Offset = 0; |
314 | Standard_Integer ColIndex; |
315 | Standard_Integer RowIndex = NewPoles.LowerRow(); |
316 | while (RowIndex <= NewPoles.UpperRow()) { |
317 | ColIndex = NewPoles.LowerCol(); |
318 | if (RowIndex == Index) Offset = 1; |
319 | while (ColIndex <= NewPoles.UpperCol()){ |
320 | NewPoles (RowIndex, ColIndex) = Poles (RowIndex + Offset, ColIndex); |
321 | ColIndex++; |
322 | } |
323 | RowIndex++; |
324 | } |
325 | } |
326 | |
327 | //======================================================================= |
328 | //function : DeleteRatPoleRow |
329 | //purpose : |
330 | //======================================================================= |
331 | |
332 | static void DeleteRatPoleRow |
333 | (const TColgp_Array2OfPnt& Poles, |
334 | const TColStd_Array2OfReal& Weights, |
335 | const Standard_Integer Index, |
336 | TColgp_Array2OfPnt& NewPoles, |
337 | TColStd_Array2OfReal& NewWeights) |
338 | { |
339 | Standard_Integer Offset = 0; |
340 | Standard_Integer ColIndex; |
341 | Standard_Integer RowIndex = NewPoles.LowerRow(); |
342 | while (RowIndex <= NewPoles.UpperRow()) { |
343 | ColIndex = NewPoles.LowerCol(); |
344 | if (RowIndex == Index) Offset = 1; |
345 | while (ColIndex <= NewPoles.UpperCol()){ |
346 | NewPoles (RowIndex, ColIndex) = Poles (RowIndex + Offset, ColIndex); |
347 | NewWeights (RowIndex, ColIndex) = Weights (RowIndex+Offset, ColIndex); |
348 | ColIndex++; |
349 | } |
350 | RowIndex++; |
351 | } |
352 | } |
353 | |
354 | //======================================================================= |
355 | //function : Geom_BezierSurface |
356 | //purpose : |
357 | //======================================================================= |
358 | |
359 | Geom_BezierSurface::Geom_BezierSurface |
360 | (const TColgp_Array2OfPnt& SurfacePoles): |
361 | ucacheparameter(0.), |
362 | vcacheparameter(0.), |
363 | ucachespanlenght(1.), |
364 | vcachespanlenght(1.), |
365 | validcache(0), |
366 | maxderivinvok(Standard_False) |
367 | { |
368 | Standard_Integer NbUPoles = SurfacePoles.ColLength(); |
369 | Standard_Integer NbVPoles = SurfacePoles.RowLength(); |
370 | if (NbUPoles < 2 || NbUPoles > MaxDegree()+1 || |
371 | NbVPoles < 2 || NbVPoles > MaxDegree()+1) { |
372 | Standard_ConstructionError::Raise(); |
373 | } |
374 | |
375 | Handle(TColgp_HArray2OfPnt) npoles = |
376 | new TColgp_HArray2OfPnt (1, NbUPoles, 1, NbVPoles); |
377 | |
378 | urational = 0; |
379 | vrational = 0; |
380 | |
381 | npoles->ChangeArray2() = SurfacePoles; |
382 | |
383 | // Init non rational |
384 | Init(npoles, |
385 | Handle(TColStd_HArray2OfReal)()); |
386 | } |
387 | |
388 | //======================================================================= |
389 | //function : Geom_BezierSurface |
390 | //purpose : |
391 | //======================================================================= |
392 | |
393 | Geom_BezierSurface::Geom_BezierSurface |
394 | (const TColgp_Array2OfPnt& SurfacePoles, |
395 | const TColStd_Array2OfReal& PoleWeights ): |
396 | ucacheparameter(0.), |
397 | vcacheparameter(0.), |
398 | ucachespanlenght(1.), |
399 | vcachespanlenght(1.), |
400 | validcache(0), |
401 | maxderivinvok(Standard_False) |
402 | { |
403 | Standard_Integer NbUPoles = SurfacePoles.ColLength(); |
404 | Standard_Integer NbVPoles = SurfacePoles.RowLength(); |
405 | if (NbUPoles < 2 || NbUPoles > MaxDegree()+1 || |
406 | NbVPoles < 2 || NbVPoles > MaxDegree()+1 || |
407 | NbVPoles != PoleWeights.RowLength() || |
408 | NbUPoles != PoleWeights.ColLength() ) { |
409 | Standard_ConstructionError::Raise(); |
410 | } |
411 | |
412 | Standard_Integer Row = PoleWeights.LowerRow(); |
413 | Standard_Integer Col = PoleWeights.LowerCol(); |
414 | while (Col <= PoleWeights.UpperCol()) { |
415 | Row = PoleWeights.LowerRow(); |
416 | while (Row <= PoleWeights.UpperRow()) { |
417 | if (PoleWeights(Row, Col) <= gp::Resolution()) { |
418 | Standard_ConstructionError::Raise(); |
419 | } |
420 | Row++; |
421 | } |
422 | Col++; |
423 | } |
424 | |
425 | Handle(TColgp_HArray2OfPnt) |
426 | npoles = new TColgp_HArray2OfPnt (1, NbUPoles, 1, NbVPoles); |
427 | npoles->ChangeArray2() = SurfacePoles; |
428 | |
429 | Standard_Integer I, J; |
430 | urational = Standard_False; |
431 | vrational = Standard_False; |
432 | J = PoleWeights.LowerCol (); |
433 | while (!vrational && J <= PoleWeights.UpperCol()) { |
434 | I = PoleWeights.LowerRow(); |
435 | while (!vrational && I <= PoleWeights.UpperRow() - 1) { |
436 | vrational = (Abs(PoleWeights (I, J) - PoleWeights (I+1, J)) |
437 | > Epsilon (Abs(PoleWeights (I, J)))); |
438 | I++; |
439 | } |
440 | J++; |
441 | } |
442 | I = PoleWeights.LowerRow (); |
443 | while (!urational && I <= PoleWeights.UpperRow()) { |
444 | J = PoleWeights.LowerCol(); |
445 | while (!urational && J <= PoleWeights.UpperCol() - 1) { |
446 | urational = (Abs(PoleWeights (I, J) - PoleWeights (I, J+1)) |
447 | > Epsilon (Abs(PoleWeights (I, J)))); |
448 | J++; |
449 | } |
450 | I++; |
451 | } |
452 | |
453 | |
454 | Handle(TColStd_HArray2OfReal) nweights; |
455 | if (urational || vrational) { |
456 | nweights = new TColStd_HArray2OfReal (1, NbUPoles, 1, NbVPoles); |
457 | nweights->ChangeArray2() = PoleWeights; |
458 | } |
459 | |
460 | // Init |
461 | Init(npoles,nweights); |
462 | } |
463 | |
464 | //======================================================================= |
465 | //function : Geom_BezierSurface |
466 | //purpose : |
467 | //======================================================================= |
468 | |
469 | Geom_BezierSurface::Geom_BezierSurface |
470 | (const Handle(TColgp_HArray2OfPnt)& SurfacePoles, |
471 | const Handle(TColgp_HArray2OfPnt)& SurfaceCoefs, |
472 | const Handle(TColStd_HArray2OfReal)& PoleWeights, |
473 | const Handle(TColStd_HArray2OfReal)& CoefWeights, |
474 | const Standard_Boolean IsURational, |
475 | const Standard_Boolean IsVRational) |
476 | :maxderivinvok(Standard_False) |
477 | { |
478 | urational = IsURational; |
479 | vrational = IsVRational; |
480 | ucachespanlenght = 1.; |
481 | vcachespanlenght = 1.; |
482 | validcache = 1; |
483 | ucacheparameter =0.; |
484 | vcacheparameter = 0.; |
485 | Standard_Integer NbUPoles = SurfacePoles->ColLength(); |
486 | Standard_Integer NbVPoles = SurfacePoles->RowLength(); |
487 | |
488 | poles = new TColgp_HArray2OfPnt (1,NbUPoles, |
489 | 1,NbVPoles) ; |
490 | poles->ChangeArray2() = SurfacePoles->Array2(); |
491 | |
492 | coeffs = new TColgp_HArray2OfPnt (1,SurfaceCoefs->ColLength(), |
493 | 1,SurfaceCoefs->RowLength()) ; |
494 | coeffs->ChangeArray2() = SurfaceCoefs->Array2(); |
495 | |
496 | if ( urational || vrational) { |
497 | weights = new TColStd_HArray2OfReal (1,NbUPoles,1,NbVPoles); |
498 | weights->ChangeArray2() = PoleWeights->Array2(); |
499 | |
500 | wcoeffs = new TColStd_HArray2OfReal (1,SurfaceCoefs->ColLength(), |
501 | 1,SurfaceCoefs->RowLength()) ; |
502 | wcoeffs->ChangeArray2() = CoefWeights->Array2(); |
503 | } |
504 | } |
505 | |
506 | //======================================================================= |
507 | //function : MaxDegree |
508 | //purpose : |
509 | //======================================================================= |
510 | |
511 | Standard_Integer Geom_BezierSurface::MaxDegree () |
512 | { |
513 | return BSplCLib::MaxDegree(); |
514 | } |
515 | |
516 | //======================================================================= |
517 | //function : ExchangeUV |
518 | //purpose : |
519 | //======================================================================= |
520 | |
521 | void Geom_BezierSurface::ExchangeUV () |
522 | { |
523 | Standard_Integer LC = poles->LowerCol(); |
524 | Standard_Integer UC = poles->UpperCol(); |
525 | Standard_Integer LR = poles->LowerRow(); |
526 | Standard_Integer UR = poles->UpperRow(); |
527 | |
528 | Handle(TColgp_HArray2OfPnt) npoles = |
529 | new TColgp_HArray2OfPnt (LC, UC, LR, UR); |
530 | Handle(TColStd_HArray2OfReal) nweights = |
531 | new TColStd_HArray2OfReal (LC, UC, LR, UR); |
532 | |
533 | const TColgp_Array2OfPnt & spoles = poles->Array2(); |
534 | const TColStd_Array2OfReal & sweights = weights->Array2(); |
535 | |
536 | TColgp_Array2OfPnt& snpoles = npoles->ChangeArray2(); |
537 | TColStd_Array2OfReal& snweights = nweights->ChangeArray2(); |
538 | |
539 | Standard_Integer i, j; |
540 | for (i = LC; i <= UC; i++) { |
541 | for (j = LR; j <= UR; j++) { |
542 | snpoles (i,j) = spoles (j,i); |
543 | snweights (i,j) = sweights (j,i); |
544 | } |
545 | } |
546 | |
547 | poles = npoles; |
548 | weights = nweights; |
549 | |
550 | Standard_Boolean temp = urational; |
551 | urational = vrational; |
552 | vrational = temp; |
553 | coeffs = new TColgp_HArray2OfPnt (LC, UC, LR, UR); |
554 | wcoeffs = new TColStd_HArray2OfReal (LC, UC, LR, UR); |
555 | |
556 | UpdateCoefficients(); |
557 | } |
558 | |
559 | //======================================================================= |
560 | //function : Increase |
561 | //purpose : |
562 | //======================================================================= |
563 | |
564 | void Geom_BezierSurface::Increase (const Standard_Integer UDeg, |
565 | const Standard_Integer VDeg) |
566 | { |
567 | if (UDeg < UDegree() || UDeg > Geom_BezierSurface::MaxDegree() || |
568 | VDeg < VDegree() || VDeg > Geom_BezierSurface::MaxDegree() ) { |
569 | Standard_ConstructionError::Raise(); |
570 | } |
571 | |
572 | Standard_Integer oldUDeg = UDegree(); |
573 | Standard_Integer oldVDeg = VDegree(); |
574 | Standard_Integer IncUDeg = UDeg - oldUDeg; |
575 | Standard_Integer IncVDeg = VDeg - oldVDeg; |
576 | if (IncUDeg == 0 && IncVDeg == 0) return; |
577 | |
578 | TColStd_Array1OfReal biduknots(1,2); biduknots(1) = 0.; biduknots(2) = 1.; |
579 | TColStd_Array1OfInteger bidumults(1,2); bidumults.Init(UDegree() + 1); |
580 | TColStd_Array1OfReal bidvknots(1,2); bidvknots(1) = 0.; bidvknots(2) = 1.; |
581 | TColStd_Array1OfInteger bidvmults(1,2); bidvmults.Init(VDegree() + 1); |
582 | Handle(TColgp_HArray2OfPnt) npoles; |
583 | Handle(TColStd_HArray2OfReal) nweights; |
584 | |
585 | if(IncUDeg > 0){ |
586 | npoles = new TColgp_HArray2OfPnt( 1, UDeg + 1, 1, oldVDeg + 1); |
587 | |
588 | if ( urational || vrational) { |
589 | nweights = new TColStd_HArray2OfReal( 1, UDeg + 1, 1, VDegree() + 1); |
590 | |
591 | BSplSLib::IncreaseDegree(1, oldUDeg, UDeg, 0, |
592 | poles->Array2(), |
593 | weights->Array2(), |
594 | biduknots, bidumults, |
595 | npoles->ChangeArray2(), |
596 | nweights->ChangeArray2(), |
597 | biduknots, bidumults); |
598 | weights = nweights; |
599 | } |
600 | else { |
601 | BSplSLib::IncreaseDegree(1, oldUDeg, UDeg, 0, |
602 | poles->Array2(), |
603 | *((TColStd_Array2OfReal*) NULL), |
604 | biduknots, bidumults, |
605 | npoles->ChangeArray2(), |
606 | *((TColStd_Array2OfReal*) NULL), |
607 | biduknots, bidumults); |
608 | } |
609 | poles = npoles; |
610 | } |
611 | if(IncVDeg > 0){ |
612 | npoles = new TColgp_HArray2OfPnt( 1, UDeg + 1, 1, VDeg + 1); |
613 | |
614 | if ( urational || vrational) { |
615 | nweights = new TColStd_HArray2OfReal( 1, UDeg + 1, 1, VDeg + 1); |
616 | |
617 | BSplSLib::IncreaseDegree(0, oldVDeg, VDeg, 0, |
618 | poles->Array2(), |
619 | weights->Array2(), |
620 | bidvknots, bidvmults, |
621 | npoles->ChangeArray2(), |
622 | nweights->ChangeArray2(), |
623 | bidvknots, bidvmults); |
624 | weights = nweights; |
625 | } |
626 | else { |
627 | BSplSLib::IncreaseDegree(0, oldVDeg, VDeg, 0, |
628 | poles->Array2(), |
629 | *((TColStd_Array2OfReal*) NULL), |
630 | bidvknots, bidvmults, |
631 | npoles->ChangeArray2(), |
632 | *((TColStd_Array2OfReal*) NULL), |
633 | bidvknots, bidvmults); |
634 | |
635 | } |
636 | poles = npoles; |
637 | } |
638 | Init(npoles,nweights); |
639 | } |
640 | |
641 | //======================================================================= |
642 | //function : InsertPoleColAfter |
643 | //purpose : |
644 | //======================================================================= |
645 | |
646 | void Geom_BezierSurface::InsertPoleColAfter |
647 | (const Standard_Integer VIndex, |
648 | const TColgp_Array1OfPnt& CPoles) |
649 | { |
650 | const TColgp_Array2OfPnt & Poles = poles->Array2(); |
651 | if (VIndex < 1 || VIndex > Poles.RowLength()) Standard_OutOfRange::Raise(); |
652 | if (CPoles.Length() != Poles.ColLength()) { |
653 | Standard_ConstructionError::Raise(); |
654 | } |
655 | |
656 | Handle(TColgp_HArray2OfPnt) npoles = |
657 | new TColgp_HArray2OfPnt(1,poles->ColLength(),1,poles->RowLength()+1); |
658 | |
659 | Handle(TColStd_HArray2OfReal) nweights; |
660 | |
661 | if (urational || vrational) { |
662 | nweights = |
663 | new TColStd_HArray2OfReal(1,poles->ColLength(),1,poles->RowLength()+1); |
664 | |
665 | TColStd_Array1OfReal CWeights(nweights->LowerRow(),nweights->UpperRow()); |
666 | CWeights.Init(1.); |
667 | |
668 | AddRatPoleCol (poles->Array2(), weights->Array2(), |
669 | CPoles, CWeights, VIndex, |
670 | npoles->ChangeArray2(), nweights->ChangeArray2()); |
671 | } |
672 | else { |
673 | AddPoleCol (poles->Array2(), |
674 | CPoles, VIndex, |
675 | npoles->ChangeArray2()); |
676 | } |
677 | poles = npoles; |
678 | weights = nweights; |
679 | coeffs = new TColgp_HArray2OfPnt(1,poles->ColLength(), |
680 | 1,poles->RowLength()); |
681 | wcoeffs = new TColStd_HArray2OfReal(1,poles->ColLength(), |
682 | 1,poles->RowLength()); |
683 | UpdateCoefficients(); |
684 | } |
685 | |
686 | //======================================================================= |
687 | //function : InsertPoleColAfter |
688 | //purpose : |
689 | //======================================================================= |
690 | |
691 | void Geom_BezierSurface::InsertPoleColAfter |
692 | (const Standard_Integer VIndex, |
693 | const TColgp_Array1OfPnt& CPoles, |
694 | const TColStd_Array1OfReal& CPoleWeights) |
695 | { |
696 | const TColgp_Array2OfPnt & Poles = poles->Array2(); |
697 | if (VIndex < 1 || VIndex > Poles.RowLength()) Standard_OutOfRange::Raise(); |
698 | if (CPoles.Length() != Poles.ColLength() || |
699 | CPoleWeights.Length() != CPoles.Length()) { |
700 | Standard_ConstructionError::Raise(); |
701 | } |
702 | Standard_Integer Index = CPoleWeights.Lower(); |
703 | while (Index <= CPoleWeights.Upper()) { |
704 | if (CPoleWeights (Index) <= gp::Resolution()) { |
705 | Standard_ConstructionError::Raise(); |
706 | } |
707 | Index++; |
708 | } |
709 | |
710 | Handle(TColgp_HArray2OfPnt) npoles = |
711 | new TColgp_HArray2OfPnt(1,poles->ColLength(),1,poles->RowLength()+1); |
712 | |
713 | Handle(TColStd_HArray2OfReal) nweights = |
714 | new TColStd_HArray2OfReal(1,poles->ColLength(),1,poles->RowLength()+1); |
715 | |
716 | AddRatPoleCol (poles->Array2(), weights->Array2(), |
717 | CPoles, CPoleWeights, VIndex, |
718 | npoles->ChangeArray2(), nweights->ChangeArray2()); |
719 | |
720 | poles = npoles; |
721 | weights = nweights; |
722 | coeffs = new TColgp_HArray2OfPnt(1,poles->ColLength(), |
723 | 1,poles->RowLength()); |
724 | wcoeffs = new TColStd_HArray2OfReal(1,poles->ColLength(), |
725 | 1,poles->RowLength()); |
726 | |
727 | Rational(weights->Array2(), urational, vrational); |
728 | |
729 | UpdateCoefficients(); |
730 | } |
731 | |
732 | //======================================================================= |
733 | //function : InsertPoleColBefore |
734 | //purpose : |
735 | //======================================================================= |
736 | |
737 | void Geom_BezierSurface::InsertPoleColBefore (const Standard_Integer VIndex, |
738 | const TColgp_Array1OfPnt& CPoles) |
739 | { |
740 | InsertPoleColAfter(VIndex - 1, CPoles); |
741 | } |
742 | |
743 | //======================================================================= |
744 | //function : InsertPoleColBefore |
745 | //purpose : |
746 | //======================================================================= |
747 | |
748 | void Geom_BezierSurface::InsertPoleColBefore |
749 | (const Standard_Integer VIndex, |
750 | const TColgp_Array1OfPnt& CPoles, |
751 | const TColStd_Array1OfReal& CPoleWeights) |
752 | { |
753 | InsertPoleColAfter( VIndex - 1, CPoles, CPoleWeights); |
754 | } |
755 | |
756 | //======================================================================= |
757 | //function : InsertPoleRowAfter |
758 | //purpose : |
759 | //======================================================================= |
760 | |
761 | void Geom_BezierSurface::InsertPoleRowAfter (const Standard_Integer UIndex, |
762 | const TColgp_Array1OfPnt& CPoles) |
763 | { |
764 | const TColgp_Array2OfPnt & Poles = poles->Array2(); |
765 | if (UIndex < 1 || UIndex > Poles.ColLength()) Standard_OutOfRange::Raise(); |
766 | if (CPoles.Length() != Poles.RowLength()) { |
767 | Standard_ConstructionError::Raise(); |
768 | } |
769 | |
770 | Handle(TColgp_HArray2OfPnt) npoles = |
771 | new TColgp_HArray2OfPnt(1,poles->ColLength()+1,1,poles->RowLength()); |
772 | |
773 | Handle(TColStd_HArray2OfReal) nweights; |
774 | |
775 | if (urational || vrational) { |
776 | nweights = |
777 | new TColStd_HArray2OfReal(1,poles->ColLength()+1,1,poles->RowLength()); |
778 | |
779 | // TColStd_Array1OfReal CWeights(nweights->LowerCol(),nweights->UpperCol(), |
780 | // 1.0); ??????????? |
781 | TColStd_Array1OfReal CWeights(1.0, |
782 | nweights->LowerCol(),nweights->UpperCol()); |
783 | |
784 | AddRatPoleRow (poles->Array2(), weights->Array2(), |
785 | CPoles, CWeights, UIndex, |
786 | npoles->ChangeArray2(), nweights->ChangeArray2()); |
787 | } |
788 | else { |
789 | AddPoleRow (poles->Array2(), |
790 | CPoles, UIndex, |
791 | npoles->ChangeArray2()); |
792 | } |
793 | poles = npoles; |
794 | weights = nweights; |
795 | coeffs = new TColgp_HArray2OfPnt(1,poles->ColLength(), |
796 | 1,poles->RowLength()); |
797 | wcoeffs = new TColStd_HArray2OfReal(1,poles->ColLength(), |
798 | 1,poles->RowLength()); |
799 | |
800 | UpdateCoefficients(); |
801 | } |
802 | |
803 | //======================================================================= |
804 | //function : InsertPoleRowAfter |
805 | //purpose : |
806 | //======================================================================= |
807 | |
808 | void Geom_BezierSurface::InsertPoleRowAfter |
809 | (const Standard_Integer UIndex, |
810 | const TColgp_Array1OfPnt& CPoles, |
811 | const TColStd_Array1OfReal& CPoleWeights) |
812 | { |
813 | const TColgp_Array2OfPnt & Poles = poles->Array2(); |
814 | if (UIndex < 1 || UIndex > Poles.ColLength()) Standard_OutOfRange::Raise(); |
815 | if (CPoles.Length() != Poles.RowLength() || |
816 | CPoleWeights.Length() != CPoles.Length()) { |
817 | Standard_ConstructionError::Raise(); |
818 | } |
819 | Standard_Integer Index = CPoleWeights.Lower(); |
820 | while (Index <= CPoleWeights.Upper()) { |
821 | if (CPoleWeights(Index) <= gp::Resolution()) { |
822 | Standard_ConstructionError::Raise(); |
823 | } |
824 | Index++; |
825 | } |
826 | |
827 | Handle(TColgp_HArray2OfPnt) npoles = |
828 | new TColgp_HArray2OfPnt(1,poles->ColLength()+1,1,poles->RowLength()); |
829 | |
830 | Handle(TColStd_HArray2OfReal) nweights = |
831 | new TColStd_HArray2OfReal(1,poles->ColLength()+1,1,poles->RowLength()); |
832 | |
833 | AddRatPoleCol (poles->Array2(), weights->Array2(), |
834 | CPoles, CPoleWeights, UIndex, |
835 | npoles->ChangeArray2(), nweights->ChangeArray2()); |
836 | |
837 | poles = npoles; |
838 | weights = nweights; |
839 | coeffs = new TColgp_HArray2OfPnt(1,poles->ColLength(), |
840 | 1,poles->RowLength()); |
841 | wcoeffs = new TColStd_HArray2OfReal(1,poles->ColLength(), |
842 | 1,poles->RowLength()); |
843 | |
844 | Rational(weights->Array2(), urational, vrational); |
845 | |
846 | UpdateCoefficients(); |
847 | } |
848 | |
849 | //======================================================================= |
850 | //function : InsertPoleRowBefore |
851 | //purpose : |
852 | //======================================================================= |
853 | |
854 | void Geom_BezierSurface::InsertPoleRowBefore (const Standard_Integer UIndex, |
855 | const TColgp_Array1OfPnt& CPoles) |
856 | { |
857 | InsertPoleRowAfter( UIndex - 1, CPoles); |
858 | } |
859 | |
860 | //======================================================================= |
861 | //function : InsertPoleRowBefore |
862 | //purpose : |
863 | //======================================================================= |
864 | |
865 | void Geom_BezierSurface::InsertPoleRowBefore |
866 | (const Standard_Integer UIndex, |
867 | const TColgp_Array1OfPnt& CPoles, |
868 | const TColStd_Array1OfReal& CPoleWeights) |
869 | { |
870 | InsertPoleRowAfter( UIndex - 1, CPoles, CPoleWeights); |
871 | } |
872 | |
873 | //======================================================================= |
874 | //function : RemovePoleCol |
875 | //purpose : |
876 | //======================================================================= |
877 | |
878 | void Geom_BezierSurface::RemovePoleCol (const Standard_Integer VIndex) |
879 | { |
880 | const TColgp_Array2OfPnt & Poles = poles->Array2(); |
881 | if (VIndex < 1 || VIndex > Poles.RowLength()) Standard_OutOfRange::Raise(); |
882 | if (Poles.RowLength() <= 2) Standard_ConstructionError::Raise(); |
883 | |
884 | Handle(TColgp_HArray2OfPnt) npoles = |
885 | new TColgp_HArray2OfPnt(1,poles->ColLength(),1,poles->RowLength()-1); |
886 | |
887 | Handle(TColStd_HArray2OfReal) nweights; |
888 | |
889 | if (urational || vrational) { |
890 | nweights = |
891 | new TColStd_HArray2OfReal(1,poles->ColLength(),1,poles->RowLength()-1); |
892 | |
893 | DeleteRatPoleCol (poles->Array2(), weights->Array2(), |
894 | VIndex, |
895 | npoles->ChangeArray2(), nweights->ChangeArray2()); |
896 | // Mise a jour de la rationalite |
897 | Rational(nweights->Array2(), urational, vrational); |
898 | } |
899 | else { |
900 | DeletePoleCol (poles->Array2(), |
901 | VIndex, |
902 | npoles->ChangeArray2()); |
903 | } |
904 | poles = npoles; |
905 | weights = nweights; |
906 | coeffs = new TColgp_HArray2OfPnt(1,poles->ColLength(), |
907 | 1,poles->RowLength()); |
908 | wcoeffs = new TColStd_HArray2OfReal(1,poles->ColLength(), |
909 | 1,poles->RowLength()); |
910 | UpdateCoefficients(); |
911 | } |
912 | |
913 | //======================================================================= |
914 | //function : RemovePoleRow |
915 | //purpose : |
916 | //======================================================================= |
917 | |
918 | void Geom_BezierSurface::RemovePoleRow (const Standard_Integer UIndex) |
919 | { |
920 | const TColgp_Array2OfPnt & Poles = poles->Array2(); |
921 | if (UIndex < 1 || UIndex > Poles.ColLength()) Standard_OutOfRange::Raise(); |
922 | if (Poles.ColLength() <= 2) Standard_ConstructionError::Raise(); |
923 | |
924 | Handle(TColgp_HArray2OfPnt) npoles = |
925 | new TColgp_HArray2OfPnt(1,poles->ColLength()-1,1,poles->RowLength()); |
926 | |
927 | Handle(TColStd_HArray2OfReal) nweights; |
928 | |
929 | if (urational || vrational) { |
930 | nweights = |
931 | new TColStd_HArray2OfReal(1,poles->ColLength()-1,1,poles->RowLength()); |
932 | |
933 | DeleteRatPoleRow (poles->Array2(), weights->Array2(), |
934 | UIndex, |
935 | npoles->ChangeArray2(), nweights->ChangeArray2()); |
936 | |
937 | // Mise a jour de la rationalite |
938 | Rational(nweights->Array2(), urational, vrational); |
939 | } |
940 | else { |
941 | DeletePoleRow (poles->Array2(), |
942 | UIndex, |
943 | npoles->ChangeArray2()); |
944 | } |
945 | poles = npoles; |
946 | weights = nweights; |
947 | coeffs = new TColgp_HArray2OfPnt(1,poles->ColLength(), |
948 | 1,poles->RowLength()); |
949 | wcoeffs = new TColStd_HArray2OfReal(1,poles->ColLength(), |
950 | 1,poles->RowLength()); |
951 | UpdateCoefficients(); |
952 | } |
953 | |
954 | //======================================================================= |
955 | //function : Segment |
956 | //purpose : |
957 | //======================================================================= |
958 | |
959 | void Geom_BezierSurface::Segment |
960 | (const Standard_Real U1, |
961 | const Standard_Real U2, |
962 | const Standard_Real V1, |
963 | const Standard_Real V2) |
964 | { |
965 | Standard_Boolean rat = (urational || vrational); |
966 | Handle(TColgp_HArray2OfPnt) Coefs; |
967 | Handle(TColStd_HArray2OfReal) WCoefs; |
968 | |
969 | if (validcache == 0) UpdateCoefficients(0., 0.); |
970 | |
971 | // Attention si udeg <= vdeg u et v sont intervertis |
972 | // dans les coeffs, il faut donc tout transposer. |
973 | if(UDegree() <= VDegree()) { |
974 | Standard_Integer ii, jj; |
975 | Coefs = new (TColgp_HArray2OfPnt)(1,UDegree()+1,1,VDegree()+1); |
976 | if (rat) { |
977 | WCoefs = new (TColStd_HArray2OfReal)(1,UDegree()+1,1,VDegree()+1); |
978 | } |
979 | for (ii=1; ii<=UDegree()+1; ii++) |
980 | for (jj=1; jj<=VDegree()+1; jj++) { |
981 | Coefs->SetValue(ii, jj, coeffs->Value(jj,ii)); |
982 | if (rat) WCoefs->SetValue(ii, jj, wcoeffs->Value(jj,ii)); |
983 | } |
984 | } |
985 | else { |
986 | Coefs = coeffs; |
987 | if (rat) {WCoefs = wcoeffs;} |
988 | } |
989 | |
990 | // Trim dans la base cannonique et Update des Poles et Coeffs |
991 | |
992 | // PMN : tranfo sur les parametres |
993 | Standard_Real ufirst = 2*(U1 - 0.5), |
994 | ulast = 2*(U2 - 0.5), |
995 | vfirst = 2*(V1 - 0.5), |
996 | vlast = 2*(V2 - 0.5); |
997 | if (rat) { |
998 | PLib::UTrimming (ufirst, ulast, Coefs->ChangeArray2(), |
999 | WCoefs->ChangeArray2()); |
1000 | PLib::VTrimming (vfirst, vlast, Coefs->ChangeArray2(), |
1001 | WCoefs->ChangeArray2()); |
1002 | PLib::CoefficientsPoles(Coefs->Array2(), |
1003 | WCoefs->Array2(), |
1004 | poles->ChangeArray2(), |
1005 | weights->ChangeArray2()); |
1006 | } |
1007 | else { |
1008 | PLib::UTrimming (ufirst, ulast, Coefs->ChangeArray2(), |
1009 | *((TColStd_Array2OfReal*) NULL)); |
1010 | PLib::VTrimming (vfirst, vlast, Coefs->ChangeArray2(), |
1011 | *((TColStd_Array2OfReal*) NULL)); |
1012 | PLib::CoefficientsPoles (Coefs->Array2(), |
1013 | *((TColStd_Array2OfReal*) NULL), |
1014 | poles->ChangeArray2(), |
1015 | *((TColStd_Array2OfReal*) NULL)); |
1016 | } |
1017 | UpdateCoefficients(); |
1018 | } |
1019 | |
1020 | //======================================================================= |
1021 | //function : SetPole |
1022 | //purpose : |
1023 | //======================================================================= |
1024 | |
1025 | void Geom_BezierSurface::SetPole |
1026 | (const Standard_Integer UIndex, |
1027 | const Standard_Integer VIndex, |
1028 | const gp_Pnt& P) |
1029 | { |
1030 | TColgp_Array2OfPnt & Poles = poles->ChangeArray2(); |
1031 | if (UIndex < 1 || |
1032 | UIndex > Poles.ColLength() || |
1033 | VIndex < 1 || |
1034 | VIndex > Poles.RowLength() ) Standard_OutOfRange::Raise(); |
1035 | |
1036 | Poles (UIndex, VIndex) = P; |
1037 | UpdateCoefficients(); |
1038 | } |
1039 | |
1040 | //======================================================================= |
1041 | //function : SetPole |
1042 | //purpose : |
1043 | //======================================================================= |
1044 | |
1045 | void Geom_BezierSurface::SetPole |
1046 | (const Standard_Integer UIndex, |
1047 | const Standard_Integer VIndex, |
1048 | const gp_Pnt& P, |
1049 | const Standard_Real Weight) |
1050 | { |
1051 | |
1052 | if (Weight <= gp::Resolution()) |
1053 | Standard_ConstructionError::Raise("Geom_BezierSurface::SetPole"); |
1054 | if (UIndex < 1 || |
1055 | UIndex > poles->ColLength() || |
1056 | VIndex < 1 || |
1057 | VIndex > poles->RowLength()) |
1058 | Standard_OutOfRange::Raise("Geom_BezierSurface::SetPole"); |
1059 | |
1060 | poles->SetValue(UIndex, VIndex, P); |
1061 | |
1062 | SetWeight(UIndex, VIndex, Weight); //L'update des coeff est fait la dedans |
1063 | } |
1064 | |
1065 | //======================================================================= |
1066 | //function : SetPoleCol |
1067 | //purpose : |
1068 | //======================================================================= |
1069 | |
1070 | void Geom_BezierSurface::SetPoleCol |
1071 | (const Standard_Integer VIndex, |
1072 | const TColgp_Array1OfPnt& CPoles, |
1073 | const TColStd_Array1OfReal& CPoleWeights) |
1074 | { |
1075 | TColgp_Array2OfPnt & Poles = poles->ChangeArray2(); |
1076 | if (VIndex < 1 || VIndex > Poles.RowLength()) Standard_OutOfRange::Raise(); |
1077 | |
1078 | if (CPoles.Lower() < 1 || |
1079 | CPoles.Lower() > Poles.ColLength() || |
1080 | CPoles.Upper() < 1 || |
1081 | CPoles.Upper() > Poles.ColLength() || |
1082 | CPoleWeights.Lower() != CPoles.Lower() || |
1083 | CPoleWeights.Upper() != CPoles.Upper()) { |
1084 | Standard_ConstructionError::Raise(); |
1085 | } |
1086 | |
1087 | Standard_Integer I; |
1088 | for (I = CPoles.Lower(); I <= CPoles.Upper(); I++) { |
1089 | Poles (I, VIndex) = CPoles (I); |
1090 | } |
1091 | SetWeightCol(VIndex, CPoleWeights); //Avec l'update |
1092 | } |
1093 | |
1094 | //======================================================================= |
1095 | //function : SetPoleCol |
1096 | //purpose : |
1097 | //======================================================================= |
1098 | |
1099 | void Geom_BezierSurface::SetPoleCol (const Standard_Integer VIndex, |
1100 | const TColgp_Array1OfPnt& CPoles) |
1101 | { |
1102 | TColgp_Array2OfPnt & Poles = poles->ChangeArray2(); |
1103 | if (VIndex < 1 || VIndex > Poles.RowLength()) Standard_OutOfRange::Raise(); |
1104 | |
1105 | if (CPoles.Lower() < 1 || |
1106 | CPoles.Lower() > Poles.ColLength() || |
1107 | CPoles.Upper() < 1 || |
1108 | CPoles.Upper() > Poles.ColLength()) { |
1109 | Standard_ConstructionError::Raise(); |
1110 | } |
1111 | for (Standard_Integer I = CPoles.Lower(); I <= CPoles.Upper(); I++) { |
1112 | Poles (I, VIndex) = CPoles (I); |
1113 | } |
1114 | |
1115 | UpdateCoefficients(); |
1116 | } |
1117 | |
1118 | //======================================================================= |
1119 | //function : SetPoleRow |
1120 | //purpose : |
1121 | //======================================================================= |
1122 | |
1123 | void Geom_BezierSurface::SetPoleRow (const Standard_Integer UIndex, |
1124 | const TColgp_Array1OfPnt& CPoles) |
1125 | { |
1126 | TColgp_Array2OfPnt & Poles = poles->ChangeArray2(); |
1127 | if (UIndex < 1 || UIndex > Poles.ColLength()) Standard_OutOfRange::Raise(); |
1128 | |
1129 | if (CPoles.Lower() < 1 || |
1130 | CPoles.Lower() > Poles.RowLength() || |
1131 | CPoles.Upper() < 1 || |
1132 | CPoles.Upper() > Poles.RowLength()) Standard_ConstructionError::Raise(); |
1133 | |
1134 | for (Standard_Integer I = CPoles.Lower(); I <= CPoles.Upper(); I++) { |
1135 | Poles (UIndex, I) = CPoles (I); |
1136 | } |
1137 | UpdateCoefficients(); |
1138 | } |
1139 | |
1140 | //======================================================================= |
1141 | //function : SetPoleRow |
1142 | //purpose : |
1143 | //======================================================================= |
1144 | |
1145 | void Geom_BezierSurface::SetPoleRow |
1146 | (const Standard_Integer UIndex, |
1147 | const TColgp_Array1OfPnt& CPoles, |
1148 | const TColStd_Array1OfReal& CPoleWeights) |
1149 | { |
1150 | TColgp_Array2OfPnt & Poles = poles->ChangeArray2(); |
1151 | if (UIndex < 1 || UIndex > Poles.ColLength()) Standard_OutOfRange::Raise(); |
1152 | |
1153 | if (CPoles.Lower() < 1 || |
1154 | CPoles.Lower() > Poles.RowLength() || |
1155 | CPoles.Upper() < 1 || |
1156 | CPoles.Upper() > Poles.RowLength() || |
1157 | CPoleWeights.Lower() != CPoles.Lower() || |
1158 | CPoleWeights.Upper() != CPoles.Upper()) { |
1159 | Standard_ConstructionError::Raise(); |
1160 | } |
1161 | |
1162 | Standard_Integer I; |
1163 | |
1164 | for (I = CPoles.Lower(); I <= CPoles.Upper(); I++) { |
1165 | Poles (UIndex, I) = CPoles (I); |
1166 | } |
1167 | |
1168 | SetWeightRow(UIndex, CPoleWeights); //Avec l'update |
1169 | } |
1170 | |
1171 | //======================================================================= |
1172 | //function : SetWeight |
1173 | //purpose : |
1174 | //======================================================================= |
1175 | |
1176 | void Geom_BezierSurface::SetWeight (const Standard_Integer UIndex, |
1177 | const Standard_Integer VIndex, |
1178 | const Standard_Real Weight) |
1179 | { |
1180 | // compute new rationality |
1181 | Standard_Boolean wasrat = (urational||vrational); |
1182 | if (!wasrat) { |
1183 | // a weight of 1. does not turn to rational |
1184 | if (Abs(Weight - 1.) <= gp::Resolution()) { |
1185 | UpdateCoefficients(); //Pour l'appel via SetPole |
1186 | return; |
1187 | } |
1188 | |
1189 | // set weights of 1. |
1190 | weights = new TColStd_HArray2OfReal (1, poles->ColLength(), |
1191 | 1, poles->RowLength(), 1.); |
1192 | wcoeffs = new TColStd_HArray2OfReal (1, poles->ColLength(), |
1193 | 1, poles->RowLength()); |
1194 | } |
1195 | |
1196 | TColStd_Array2OfReal & Weights = weights->ChangeArray2(); |
1197 | if (Weight <= gp::Resolution()) |
1198 | Standard_ConstructionError::Raise("Geom_BezierSurface::SetWeight"); |
1199 | |
1200 | if (UIndex < 1 || |
1201 | UIndex > Weights.ColLength() || |
1202 | VIndex < 1 || |
1203 | VIndex > Weights.RowLength()) Standard_OutOfRange::Raise(); |
1204 | |
1205 | if (Abs (Weight - Weights (UIndex, VIndex)) > gp::Resolution()) { |
1206 | Weights (UIndex, VIndex) = Weight; |
1207 | Rational(Weights, urational, vrational); |
1208 | } |
1209 | |
1210 | // is it turning into non rational |
1211 | if (wasrat) { |
1212 | if (!(urational || vrational)) { |
1213 | weights.Nullify(); |
1214 | wcoeffs.Nullify(); |
1215 | } |
1216 | } |
1217 | |
1218 | UpdateCoefficients(); //Dans tous cas :Attention a SetPoleCol ! |
1219 | } |
1220 | |
1221 | //======================================================================= |
1222 | //function : SetWeightCol |
1223 | //purpose : |
1224 | //======================================================================= |
1225 | |
1226 | void Geom_BezierSurface::SetWeightCol |
1227 | (const Standard_Integer VIndex, |
1228 | const TColStd_Array1OfReal& CPoleWeights) |
1229 | { |
1230 | Standard_Integer I; |
1231 | // compute new rationality |
1232 | Standard_Boolean wasrat = (urational||vrational); |
1233 | if (!wasrat) { |
1234 | // set weights of 1. |
1235 | weights = new TColStd_HArray2OfReal (1, poles->ColLength(), |
1236 | 1, poles->RowLength(), 1.); |
1237 | wcoeffs = new TColStd_HArray2OfReal (1, poles->ColLength(), |
1238 | 1, poles->RowLength()); |
1239 | } |
1240 | |
1241 | TColStd_Array2OfReal & Weights = weights->ChangeArray2(); |
1242 | if (VIndex < 1 || VIndex > Weights.RowLength()) Standard_OutOfRange::Raise(); |
1243 | |
1244 | if (CPoleWeights.Length() != Weights.ColLength()) { |
1245 | Standard_ConstructionError::Raise("Geom_BezierSurface::SetWeightCol"); |
1246 | } |
1247 | |
1248 | I = CPoleWeights.Lower(); |
1249 | while (I <= CPoleWeights.Upper()) { |
1250 | if (CPoleWeights(I) <= gp::Resolution()) { |
1251 | Standard_ConstructionError::Raise(); |
1252 | } |
1253 | Weights (I, VIndex) = CPoleWeights (I); |
1254 | I++; |
1255 | } |
1256 | |
1257 | Rational(Weights, urational, vrational); |
1258 | |
1259 | // is it turning into non rational |
1260 | if (wasrat) { |
1261 | if (!(urational || vrational)) { |
1262 | weights.Nullify(); |
1263 | wcoeffs.Nullify(); |
1264 | } |
1265 | } |
1266 | |
1267 | UpdateCoefficients(); |
1268 | } |
1269 | |
1270 | //======================================================================= |
1271 | //function : SetWeightRow |
1272 | //purpose : |
1273 | //======================================================================= |
1274 | |
1275 | void Geom_BezierSurface::SetWeightRow |
1276 | (const Standard_Integer UIndex, |
1277 | const TColStd_Array1OfReal& CPoleWeights) |
1278 | { |
1279 | Standard_Integer I; |
1280 | // compute new rationality |
1281 | Standard_Boolean wasrat = (urational||vrational); |
1282 | if (!wasrat) { |
1283 | // set weights of 1. |
1284 | weights = new TColStd_HArray2OfReal (1, poles->ColLength(), |
1285 | 1, poles->RowLength(), 1.); |
1286 | wcoeffs = new TColStd_HArray2OfReal (1, poles->ColLength(), |
1287 | 1, poles->RowLength()); |
1288 | } |
1289 | |
1290 | TColStd_Array2OfReal & Weights = weights->ChangeArray2(); |
1291 | if (UIndex < 1 || UIndex > Weights.ColLength()) |
1292 | Standard_OutOfRange::Raise("Geom_BezierSurface::SetWeightRow"); |
1293 | if (CPoleWeights.Lower() < 1 || |
1294 | CPoleWeights.Lower() > Weights.RowLength() || |
1295 | CPoleWeights.Upper() < 1 || |
1296 | CPoleWeights.Upper() > Weights.RowLength() ) { |
1297 | Standard_ConstructionError::Raise("Geom_BezierSurface::SetWeightRow"); |
1298 | } |
1299 | |
1300 | I = CPoleWeights.Lower(); |
1301 | while (I <= CPoleWeights.Upper()) { |
1302 | if (CPoleWeights(I) <= gp::Resolution()) { |
1303 | Standard_ConstructionError::Raise(); |
1304 | } |
1305 | Weights (UIndex, I) = CPoleWeights (I); |
1306 | I++; |
1307 | } |
1308 | |
1309 | Rational(Weights, urational, vrational); |
1310 | |
1311 | // is it turning into non rational |
1312 | if (wasrat) { |
1313 | if (!(urational || vrational)) { |
1314 | weights.Nullify(); |
1315 | wcoeffs.Nullify(); |
1316 | } |
1317 | } |
1318 | |
1319 | UpdateCoefficients(); |
1320 | } |
1321 | |
1322 | //======================================================================= |
1323 | //function : UReverse |
1324 | //purpose : |
1325 | //======================================================================= |
1326 | |
1327 | void Geom_BezierSurface::UReverse () |
1328 | { |
1329 | gp_Pnt Pol; |
1330 | Standard_Integer Row,Col; |
1331 | TColgp_Array2OfPnt & Poles = poles->ChangeArray2(); |
1332 | if (urational || vrational) { |
1333 | TColStd_Array2OfReal & Weights = weights->ChangeArray2(); |
1334 | Standard_Real W; |
1335 | for (Col = 1; Col <= Poles.RowLength(); Col++) { |
1336 | for (Row = 1; Row <= IntegerPart (Poles.ColLength() / 2); Row++) { |
1337 | W = Weights (Row, Col); |
1338 | Weights (Row, Col) = Weights (Poles.ColLength()- Row + 1, Col); |
1339 | Weights (Poles.ColLength() - Row + 1, Col) = W; |
1340 | Pol = Poles (Row, Col); |
1341 | Poles (Row, Col) = Poles (Poles.ColLength() - Row + 1, Col); |
1342 | Poles (Poles.ColLength() - Row + 1, Col) = Pol; |
1343 | } |
1344 | } |
1345 | } |
1346 | else { |
1347 | for (Col = 1; Col <= Poles.RowLength(); Col++) { |
1348 | for (Row = 1; Row <= IntegerPart (Poles.ColLength() / 2); Row++) { |
1349 | Pol = Poles (Row, Col); |
1350 | Poles (Row, Col) = Poles (Poles.ColLength() - Row + 1, Col); |
1351 | Poles (Poles.ColLength() - Row + 1, Col) = Pol; |
1352 | } |
1353 | } |
1354 | } |
1355 | UpdateCoefficients(); |
1356 | } |
1357 | |
1358 | //======================================================================= |
1359 | //function : UReversedParameter |
1360 | //purpose : |
1361 | //======================================================================= |
1362 | |
1363 | Standard_Real Geom_BezierSurface::UReversedParameter |
1364 | ( const Standard_Real U) const |
1365 | { |
1366 | return ( 1. - U); |
1367 | } |
1368 | |
1369 | //======================================================================= |
1370 | //function : VReverse |
1371 | //purpose : |
1372 | //======================================================================= |
1373 | |
1374 | void Geom_BezierSurface::VReverse () |
1375 | { |
1376 | gp_Pnt Pol; |
1377 | Standard_Integer Row,Col; |
1378 | TColgp_Array2OfPnt & Poles = poles->ChangeArray2(); |
1379 | if (urational || vrational) { |
1380 | TColStd_Array2OfReal & Weights = weights->ChangeArray2(); |
1381 | Standard_Real W; |
1382 | for (Row = 1; Row <= Poles.ColLength(); Row++) { |
1383 | for (Col = 1; Col <= IntegerPart (Poles.RowLength()/2); Col++) { |
1384 | W = Weights (Row, Col); |
1385 | Weights (Row, Col) = Weights (Row, Poles.RowLength() - Col + 1); |
1386 | Weights (Row, Poles.RowLength() - Col + 1) = W; |
1387 | Pol = Poles (Row, Col); |
1388 | Poles (Row, Col) = Poles (Row, Poles.RowLength() - Col + 1); |
1389 | Poles (Row, Poles.RowLength() - Col + 1) = Pol; |
1390 | } |
1391 | } |
1392 | } |
1393 | else { |
1394 | for (Row = 1; Row <= Poles.ColLength(); Row++) { |
1395 | for (Col = 1; Col <= IntegerPart(Poles.RowLength()/2); Col++) { |
1396 | Pol = Poles (Row, Col); |
1397 | Poles (Row, Col)= Poles (Row, Poles.RowLength() - Col + 1); |
1398 | Poles (Row, Poles.RowLength() - Col + 1) = Pol; |
1399 | } |
1400 | } |
1401 | } |
1402 | UpdateCoefficients(); |
1403 | } |
1404 | |
1405 | //======================================================================= |
1406 | //function : VReversedParameter |
1407 | //purpose : |
1408 | //======================================================================= |
1409 | |
1410 | Standard_Real Geom_BezierSurface::VReversedParameter |
1411 | ( const Standard_Real V) const |
1412 | { |
1413 | return ( 1. - V); |
1414 | } |
1415 | |
1416 | //======================================================================= |
1417 | //function : Bounds |
1418 | //purpose : |
1419 | //======================================================================= |
1420 | |
1421 | void Geom_BezierSurface::Bounds (Standard_Real& U1, |
1422 | Standard_Real& U2, |
1423 | Standard_Real& V1, |
1424 | Standard_Real& V2) const |
1425 | { |
1426 | U1 = 0.0; |
1427 | U2 = 1.0; |
1428 | V1 = 0.0; |
1429 | V2 = 1.0; |
1430 | } |
1431 | |
1432 | //======================================================================= |
1433 | //function : Continuity |
1434 | //purpose : |
1435 | //======================================================================= |
1436 | |
1437 | GeomAbs_Shape Geom_BezierSurface::Continuity () const |
1438 | { |
1439 | return GeomAbs_CN; |
1440 | } |
1441 | |
1442 | //======================================================================= |
1443 | //function : D0 |
1444 | //purpose : |
1445 | //======================================================================= |
1446 | |
1447 | void Geom_BezierSurface::D0 (const Standard_Real U, |
1448 | const Standard_Real V, |
1449 | gp_Pnt& P ) const |
1450 | { |
1451 | |
1452 | if (validcache == 1) { |
1453 | // |
1454 | // XAB : cet algorithme devient instable pour les hauts degres |
1455 | // RBD : Beaucoup moins maintenant avec le calcul d'un nouveau cache |
1456 | // sur [-1,1]. |
1457 | // |
1458 | Standard_Real uparameter_11 = (2*ucacheparameter + ucachespanlenght)/2, |
1459 | uspanlenght_11 = ucachespanlenght/2, |
1460 | vparameter_11 = (2*vcacheparameter + vcachespanlenght)/2, |
1461 | vspanlenght_11 = vcachespanlenght/2 ; |
1462 | if (urational || vrational) { |
1463 | BSplSLib::CacheD0(U, V, UDegree(), VDegree(), |
1464 | uparameter_11, vparameter_11, |
1465 | uspanlenght_11, vspanlenght_11, |
1466 | coeffs->Array2(), |
1467 | wcoeffs->Array2(), |
1468 | P); |
1469 | } |
1470 | else { |
1471 | BSplSLib::CacheD0(U, V, UDegree(), VDegree(), |
1472 | uparameter_11, vparameter_11, |
1473 | uspanlenght_11, vspanlenght_11, |
1474 | coeffs->Array2(), |
1475 | *((TColStd_Array2OfReal*) NULL), |
1476 | P); |
1477 | } |
1478 | } |
1479 | else { |
1480 | Standard_Real array_u[2] ; |
1481 | Standard_Real array_v[2] ; |
1482 | Standard_Integer mult_u[2] ; |
1483 | Standard_Integer mult_v[2] ; |
1484 | TColStd_Array1OfReal biduknots(array_u[0],1,2); biduknots(1) = 0.; biduknots(2) = 1.; |
1485 | TColStd_Array1OfInteger bidumults(mult_u[0],1,2); bidumults.Init(UDegree() + 1); |
1486 | TColStd_Array1OfReal bidvknots(array_v[0],1,2); bidvknots(1) = 0.; bidvknots(2) = 1.; |
1487 | TColStd_Array1OfInteger bidvmults(mult_v[0],1,2); bidvmults.Init(VDegree() + 1); |
1488 | if (urational || vrational) { |
1489 | BSplSLib::D0(U, V, 1,1,poles->Array2(), |
1490 | weights->Array2(), |
1491 | biduknots,bidvknots,bidumults,bidvmults, |
1492 | UDegree(),VDegree(), |
1493 | urational,vrational,Standard_False,Standard_False, |
1494 | P) ; |
1495 | } |
1496 | else { |
1497 | |
1498 | BSplSLib::D0(U, V, 1,1,poles->Array2(), |
1499 | *((TColStd_Array2OfReal*) NULL), |
1500 | biduknots,bidvknots,bidumults,bidvmults, |
1501 | UDegree(),VDegree(), |
1502 | urational,vrational,Standard_False,Standard_False, |
1503 | P) ; |
1504 | } |
1505 | } |
1506 | } |
1507 | |
1508 | //======================================================================= |
1509 | //function : D1 |
1510 | //purpose : |
1511 | //======================================================================= |
1512 | |
1513 | void Geom_BezierSurface::D1 |
1514 | (const Standard_Real U, |
1515 | const Standard_Real V, |
1516 | gp_Pnt& P, |
1517 | gp_Vec& D1U, |
1518 | gp_Vec& D1V ) const |
1519 | { |
1520 | |
1521 | if (validcache == 1) { |
1522 | // |
1523 | // XAB : cet algorithme devient instable pour les hauts degres |
1524 | // RBD : Beaucoup moins maintenant avec le calcul d'un nouveau cache |
1525 | // sur [-1,1]. |
1526 | // |
1527 | Standard_Real uparameter_11 = (2*ucacheparameter + ucachespanlenght)/2, |
1528 | uspanlenght_11 = ucachespanlenght/2, |
1529 | vparameter_11 = (2*vcacheparameter + vcachespanlenght)/2, |
1530 | vspanlenght_11 = vcachespanlenght/2 ; |
1531 | if (urational || vrational) { |
1532 | BSplSLib::CacheD1(U, V, UDegree(), VDegree(), |
1533 | uparameter_11, vparameter_11, |
1534 | uspanlenght_11, vspanlenght_11, |
1535 | coeffs->Array2(), |
1536 | wcoeffs->Array2(), |
1537 | P, D1U, D1V); |
1538 | } |
1539 | else { |
1540 | BSplSLib::CacheD1(U, V, UDegree(), VDegree(), |
1541 | uparameter_11, vparameter_11, |
1542 | uspanlenght_11, vspanlenght_11, |
1543 | coeffs->Array2(), |
1544 | *((TColStd_Array2OfReal*) NULL), |
1545 | P, D1U, D1V); |
1546 | } |
1547 | } |
1548 | else { |
1549 | Standard_Real array_u[2] ; |
1550 | Standard_Real array_v[2] ; |
1551 | Standard_Integer mult_u[2] ; |
1552 | Standard_Integer mult_v[2] ; |
1553 | TColStd_Array1OfReal biduknots(array_u[0],1,2); biduknots(1) = 0.; biduknots(2) = 1.; |
1554 | TColStd_Array1OfInteger bidumults(mult_u[0],1,2); bidumults.Init(UDegree() + 1); |
1555 | TColStd_Array1OfReal bidvknots(array_v[0],1,2); bidvknots(1) = 0.; bidvknots(2) = 1.; |
1556 | TColStd_Array1OfInteger bidvmults(mult_v[0],1,2); bidvmults.Init(VDegree() + 1); |
1557 | if (urational || vrational) { |
1558 | BSplSLib::D1(U, V, 1,1,poles->Array2(), |
1559 | weights->Array2(), |
1560 | biduknots,bidvknots,bidumults,bidvmults, |
1561 | UDegree(),VDegree(), |
1562 | urational,vrational,Standard_False,Standard_False, |
1563 | P,D1U, D1V) ; |
1564 | } |
1565 | else { |
1566 | BSplSLib::D1(U, V, 1,1,poles->Array2(), |
1567 | *((TColStd_Array2OfReal*) NULL), |
1568 | biduknots,bidvknots,bidumults,bidvmults, |
1569 | UDegree(),VDegree(), |
1570 | urational,vrational,Standard_False,Standard_False, |
1571 | P,D1U, D1V) ; |
1572 | } |
1573 | } |
1574 | } |
1575 | |
1576 | //======================================================================= |
1577 | //function : D2 |
1578 | //purpose : |
1579 | //======================================================================= |
1580 | |
1581 | void Geom_BezierSurface::D2 |
1582 | (const Standard_Real U, |
1583 | const Standard_Real V, |
1584 | gp_Pnt& P, |
1585 | gp_Vec& D1U, gp_Vec& D1V, |
1586 | gp_Vec& D2U, gp_Vec& D2V, gp_Vec& D2UV ) const |
1587 | { |
1588 | |
1589 | if (validcache == 1) { |
1590 | // |
1591 | // XAB : cet algorithme devient instable pour les hauts degres |
1592 | // RBD : Beaucoup moins maintenant avec le calcul d'un nouveau cache |
1593 | // sur [-1,1]. |
1594 | // |
1595 | Standard_Real uparameter_11 = (2*ucacheparameter + ucachespanlenght)/2, |
1596 | uspanlenght_11 = ucachespanlenght/2, |
1597 | vparameter_11 = (2*vcacheparameter + vcachespanlenght)/2, |
1598 | vspanlenght_11 = vcachespanlenght/2 ; |
1599 | if (urational || vrational) { |
1600 | //-- ATTENTION a l'ORDRE d'appel ds BSPLSLIB |
1601 | BSplSLib::CacheD2(U, V, UDegree(), VDegree(), |
1602 | uparameter_11, vparameter_11, |
1603 | uspanlenght_11, vspanlenght_11, |
1604 | coeffs->Array2(), |
1605 | wcoeffs->Array2(), |
1606 | P, D1U, D1V, D2U, D2UV , D2V); |
1607 | } |
1608 | else { |
1609 | //-- ATTENTION a l'ORDRE d'appel ds BSPLSLIB |
1610 | BSplSLib::CacheD2(U, V, UDegree(), VDegree(), |
1611 | uparameter_11, vparameter_11, |
1612 | uspanlenght_11, vspanlenght_11, |
1613 | coeffs->Array2(), |
1614 | *((TColStd_Array2OfReal*) NULL), |
1615 | P, D1U, D1V, D2U, D2UV , D2V); |
1616 | } |
1617 | } |
1618 | else { |
1619 | Standard_Real array_u[2] ; |
1620 | Standard_Real array_v[2] ; |
1621 | Standard_Integer mult_u[2] ; |
1622 | Standard_Integer mult_v[2] ; |
1623 | TColStd_Array1OfReal biduknots(array_u[0],1,2); biduknots(1) = 0.; biduknots(2) = 1.; |
1624 | TColStd_Array1OfInteger bidumults(mult_u[0],1,2); bidumults.Init(UDegree() + 1); |
1625 | TColStd_Array1OfReal bidvknots(array_v[0],1,2); bidvknots(1) = 0.; bidvknots(2) = 1.; |
1626 | TColStd_Array1OfInteger bidvmults(mult_v[0],1,2); bidvmults.Init(VDegree() + 1); |
1627 | if (urational || vrational) { |
1628 | //-- ATTENTION a l'ORDRE d'appel ds BSPLSLIB |
1629 | BSplSLib::D2(U, V, 1,1,poles->Array2(), |
1630 | weights->Array2(), |
1631 | biduknots,bidvknots,bidumults,bidvmults, |
1632 | UDegree(),VDegree(), |
1633 | urational,vrational,Standard_False,Standard_False, |
1634 | P,D1U, D1V, D2U, D2V , D2UV) ; |
1635 | } |
1636 | else { |
1637 | //-- ATTENTION a l'ORDRE d'appel ds BSPLSLIB |
1638 | BSplSLib::D2(U, V, 1,1,poles->Array2(), |
1639 | *((TColStd_Array2OfReal*) NULL), |
1640 | biduknots,bidvknots,bidumults,bidvmults, |
1641 | UDegree(),VDegree(), |
1642 | urational,vrational,Standard_False,Standard_False, |
1643 | P,D1U, D1V, D2U, D2V, D2UV ) ; |
1644 | } |
1645 | } |
1646 | } |
1647 | |
1648 | //======================================================================= |
1649 | //function : D3 |
1650 | //purpose : |
1651 | //======================================================================= |
1652 | |
1653 | void Geom_BezierSurface::D3 |
1654 | (const Standard_Real U, const Standard_Real V, |
1655 | gp_Pnt& P, |
1656 | gp_Vec& D1U, gp_Vec& D1V, |
1657 | gp_Vec& D2U, gp_Vec& D2V, gp_Vec& D2UV, |
1658 | gp_Vec& D3U, gp_Vec& D3V, gp_Vec& D3UUV, gp_Vec& D3UVV) const |
1659 | { |
1660 | TColStd_Array1OfReal biduknots(1,2); biduknots(1) = 0.; biduknots(2) = 1.; |
1661 | TColStd_Array1OfInteger bidumults(1,2); bidumults.Init(UDegree() + 1); |
1662 | TColStd_Array1OfReal bidvknots(1,2); bidvknots(1) = 0.; bidvknots(2) = 1.; |
1663 | TColStd_Array1OfInteger bidvmults(1,2); bidvmults.Init(VDegree() + 1); |
1664 | if (urational || vrational) { |
1665 | BSplSLib::D3 (U, V, 0, 0, poles->Array2(), |
1666 | weights->Array2(), |
1667 | biduknots, bidvknots, bidumults, bidvmults, |
1668 | UDegree(), VDegree(), urational, vrational, 0, 0, |
1669 | P, |
1670 | D1U, D1V, |
1671 | D2U, D2V, D2UV, |
1672 | D3U, D3V, D3UUV, D3UVV); |
1673 | } |
1674 | else { |
1675 | BSplSLib::D3 (U, V, 0, 0, poles->Array2(), |
1676 | *((TColStd_Array2OfReal*) NULL), |
1677 | biduknots, bidvknots, bidumults, bidvmults, |
1678 | UDegree(), VDegree(), urational, vrational, 0, 0, |
1679 | P, |
1680 | D1U, D1V, |
1681 | D2U, D2V, D2UV, |
1682 | D3U, D3V, D3UUV, D3UVV); |
1683 | } |
1684 | } |
1685 | |
1686 | //======================================================================= |
1687 | //function : DN |
1688 | //purpose : |
1689 | //======================================================================= |
1690 | |
1691 | gp_Vec Geom_BezierSurface::DN |
1692 | (const Standard_Real U, |
1693 | const Standard_Real V, |
1694 | const Standard_Integer Nu, |
1695 | const Standard_Integer Nv) const |
1696 | { |
1697 | Standard_RangeError_Raise_if (Nu + Nv < 1 || Nv < 0 || Nu <0, " "); |
1698 | gp_Vec Derivative; |
1699 | TColStd_Array1OfReal biduknots(1,2); biduknots(1) = 0.; biduknots(2) = 1.; |
1700 | TColStd_Array1OfInteger bidumults(1,2); bidumults.Init(UDegree() + 1); |
1701 | TColStd_Array1OfReal bidvknots(1,2); bidvknots(1) = 0.; bidvknots(2) = 1.; |
1702 | TColStd_Array1OfInteger bidvmults(1,2); bidvmults.Init(VDegree() + 1); |
1703 | if (urational || vrational) { |
1704 | BSplSLib::DN (U, V, Nu, Nv, 0, 0, poles->Array2(), |
1705 | weights->Array2(), |
1706 | biduknots, bidvknots, bidumults, bidvmults, |
1707 | UDegree(), VDegree(), urational, vrational, 0, 0, |
1708 | Derivative); |
1709 | } |
1710 | else { |
1711 | BSplSLib::DN (U, V, Nu, Nv, 0, 0, poles->Array2(), |
1712 | *((TColStd_Array2OfReal*) NULL), |
1713 | biduknots, bidvknots, bidumults, bidvmults, |
1714 | UDegree(), VDegree(), urational, vrational, 0, 0, |
1715 | Derivative); |
1716 | } |
1717 | return Derivative; |
1718 | } |
1719 | |
1720 | //======================================================================= |
1721 | //function : NbUPoles |
1722 | //purpose : |
1723 | //======================================================================= |
1724 | |
1725 | Standard_Integer Geom_BezierSurface::NbUPoles () const |
1726 | { |
1727 | return poles->ColLength(); |
1728 | } |
1729 | |
1730 | //======================================================================= |
1731 | //function : NbVPoles |
1732 | //purpose : |
1733 | //======================================================================= |
1734 | |
1735 | Standard_Integer Geom_BezierSurface::NbVPoles () const |
1736 | { |
1737 | return poles->RowLength(); |
1738 | } |
1739 | |
1740 | //======================================================================= |
1741 | //function : Pole |
1742 | //purpose : |
1743 | //======================================================================= |
1744 | |
1745 | gp_Pnt Geom_BezierSurface::Pole (const Standard_Integer UIndex, |
1746 | const Standard_Integer VIndex) const |
1747 | { |
1748 | Standard_OutOfRange_Raise_if |
1749 | (UIndex < 1 || UIndex > poles->ColLength() || |
1750 | VIndex < 1 || VIndex > poles->RowLength(), " "); |
1751 | return poles->Value (UIndex + poles->LowerRow() - 1, |
1752 | VIndex + poles->LowerCol() - 1); |
1753 | } |
1754 | |
1755 | //======================================================================= |
1756 | //function : Poles |
1757 | //purpose : |
1758 | //======================================================================= |
1759 | |
1760 | void Geom_BezierSurface::Poles (TColgp_Array2OfPnt& P) const |
1761 | { |
1762 | Standard_DimensionError_Raise_if |
1763 | (P.RowLength() != poles->RowLength() || |
1764 | P.ColLength() != poles->ColLength(), " "); |
1765 | P = poles->Array2(); |
1766 | } |
1767 | |
1768 | //======================================================================= |
1769 | //function : UDegree |
1770 | //purpose : |
1771 | //======================================================================= |
1772 | |
1773 | Standard_Integer Geom_BezierSurface::UDegree () const |
1774 | { |
1775 | return poles->ColLength() - 1; |
1776 | } |
1777 | |
1778 | //======================================================================= |
1779 | //function : UIso |
1780 | //purpose : |
1781 | //======================================================================= |
1782 | |
1783 | Handle(Geom_Curve) Geom_BezierSurface::UIso (const Standard_Real U) const |
1784 | { |
1785 | TColStd_Array1OfReal biduknots(1,2); biduknots(1) = 0.; biduknots(2) = 1.; |
1786 | TColStd_Array1OfInteger bidumults(1,2); bidumults.Init(UDegree() + 1); |
1787 | |
1788 | Handle(Geom_BezierCurve) UIsoCurve; |
1789 | const TColgp_Array2OfPnt & Poles = poles->Array2(); |
1790 | TColgp_Array1OfPnt VCurvePoles (Poles.LowerCol() , Poles.UpperCol()); |
1791 | if (urational || vrational) { |
1792 | const TColStd_Array2OfReal & Weights = weights->Array2(); |
1793 | TColStd_Array1OfReal VCurveWeights |
1794 | (Weights.LowerCol() , Weights.UpperCol()); |
1795 | BSplSLib::Iso (U, 1, Poles, |
1796 | Weights, |
1797 | biduknots, bidumults, |
1798 | UDegree(), 0, VCurvePoles, VCurveWeights); |
1799 | if (urational) |
1800 | UIsoCurve = new Geom_BezierCurve (VCurvePoles, VCurveWeights); |
1801 | else |
1802 | UIsoCurve = new Geom_BezierCurve (VCurvePoles); |
1803 | } |
1804 | else { |
1805 | BSplSLib::Iso (U, 1, Poles, |
1806 | *((TColStd_Array2OfReal*) NULL), |
1807 | biduknots, bidumults, |
1808 | UDegree(), 0, VCurvePoles, PLib::NoWeights()); |
1809 | UIsoCurve = new Geom_BezierCurve (VCurvePoles); |
1810 | } |
1811 | return UIsoCurve; |
1812 | } |
1813 | |
1814 | //======================================================================= |
1815 | //function : VDegree |
1816 | //purpose : |
1817 | //======================================================================= |
1818 | |
1819 | Standard_Integer Geom_BezierSurface::VDegree () const |
1820 | { |
1821 | return poles->RowLength() - 1; |
1822 | } |
1823 | |
1824 | //======================================================================= |
1825 | //function : VIso |
1826 | //purpose : |
1827 | //======================================================================= |
1828 | |
1829 | Handle(Geom_Curve) Geom_BezierSurface::VIso (const Standard_Real V) const |
1830 | { |
1831 | TColStd_Array1OfReal bidvknots(1,2); bidvknots(1) = 0.; bidvknots(2) = 1.; |
1832 | TColStd_Array1OfInteger bidvmults(1,2); bidvmults.Init(VDegree() + 1); |
1833 | |
1834 | Handle(Geom_BezierCurve) VIsoCurve; |
1835 | const TColgp_Array2OfPnt & Poles = poles->Array2(); |
1836 | TColgp_Array1OfPnt VCurvePoles (Poles.LowerRow() , Poles.UpperRow()); |
1837 | if (vrational || urational) { |
1838 | const TColStd_Array2OfReal & Weights = weights->Array2(); |
1839 | TColStd_Array1OfReal VCurveWeights |
1840 | (Weights.LowerRow() , Weights.UpperRow()); |
1841 | BSplSLib::Iso (V, 0, Poles, |
1842 | Weights, |
1843 | bidvknots, bidvmults, |
1844 | VDegree(), 0, VCurvePoles, VCurveWeights); |
1845 | if (vrational) |
1846 | VIsoCurve = new Geom_BezierCurve (VCurvePoles, VCurveWeights); |
1847 | else |
1848 | VIsoCurve = new Geom_BezierCurve (VCurvePoles); |
1849 | } |
1850 | else { |
1851 | BSplSLib::Iso (V, 0, Poles, |
1852 | *((TColStd_Array2OfReal*) NULL), |
1853 | bidvknots, bidvmults, |
1854 | VDegree(), 0, VCurvePoles, PLib::NoWeights()); |
1855 | VIsoCurve = new Geom_BezierCurve (VCurvePoles); |
1856 | } |
1857 | return VIsoCurve; |
1858 | } |
1859 | |
1860 | //======================================================================= |
1861 | //function : Weight |
1862 | //purpose : |
1863 | //======================================================================= |
1864 | |
1865 | Standard_Real Geom_BezierSurface::Weight (const Standard_Integer UIndex, |
1866 | const Standard_Integer VIndex) const |
1867 | { |
1868 | Standard_OutOfRange_Raise_if ( |
1869 | UIndex < 1 || UIndex > weights->ColLength() || |
1870 | VIndex < 1 || VIndex > weights->RowLength(), " "); |
1871 | |
1872 | if (urational || vrational) |
1873 | return weights->Value (UIndex, VIndex); |
1874 | else |
1875 | return 1; |
1876 | } |
1877 | |
1878 | //======================================================================= |
1879 | //function : Weights |
1880 | //purpose : |
1881 | //======================================================================= |
1882 | |
1883 | void Geom_BezierSurface::Weights (TColStd_Array2OfReal& W ) const |
1884 | { |
1885 | Standard_DimensionError_Raise_if ( |
1886 | W.RowLength() != weights->RowLength() || |
1887 | W.ColLength() != weights->ColLength(), " " ); |
1888 | if (urational || vrational) |
1889 | W = weights->Array2(); |
1890 | else |
1891 | W.Init(1.); |
1892 | } |
1893 | |
1894 | //======================================================================= |
1895 | //function : IsCNu |
1896 | //purpose : |
1897 | //======================================================================= |
1898 | |
1899 | Standard_Boolean Geom_BezierSurface::IsCNu (const Standard_Integer ) const |
1900 | { |
1901 | return Standard_True; |
1902 | } |
1903 | |
1904 | //======================================================================= |
1905 | //function : IsCNv |
1906 | //purpose : |
1907 | //======================================================================= |
1908 | |
1909 | Standard_Boolean Geom_BezierSurface::IsCNv (const Standard_Integer ) const |
1910 | { |
1911 | return Standard_True; |
1912 | } |
1913 | |
1914 | //======================================================================= |
1915 | //function : IsURational |
1916 | //purpose : |
1917 | //======================================================================= |
1918 | |
1919 | Standard_Boolean Geom_BezierSurface::IsURational () const |
1920 | { |
1921 | return urational; |
1922 | } |
1923 | |
1924 | //======================================================================= |
1925 | //function : IsVRational |
1926 | //purpose : |
1927 | //======================================================================= |
1928 | |
1929 | Standard_Boolean Geom_BezierSurface::IsVRational () const |
1930 | { |
1931 | return vrational; |
1932 | } |
1933 | |
1934 | //======================================================================= |
1935 | //function : Transform |
1936 | //purpose : |
1937 | //======================================================================= |
1938 | |
1939 | void Geom_BezierSurface::Transform (const gp_Trsf& T) |
1940 | { |
1941 | TColgp_Array2OfPnt & Poles = poles->ChangeArray2(); |
1942 | |
1943 | for (Standard_Integer I = 1; I <= Poles.ColLength(); I++) { |
1944 | |
1945 | for (Standard_Integer J = 1; J <= Poles.RowLength(); J++) { |
1946 | Poles (I, J).Transform (T); |
1947 | } |
1948 | } |
1949 | UpdateCoefficients(); |
1950 | } |
1951 | |
1952 | //======================================================================= |
1953 | //function : IsUClosed |
1954 | //purpose : |
1955 | //======================================================================= |
1956 | |
1957 | Standard_Boolean Geom_BezierSurface::IsUClosed () const |
1958 | { |
1959 | const TColgp_Array2OfPnt & Poles = poles->Array2(); |
1960 | Standard_Boolean Closed = Standard_True; |
1961 | Standard_Integer Lower = Poles.LowerRow(); |
1962 | Standard_Integer Upper = Poles.UpperRow(); |
1963 | Standard_Integer Length = Poles.RowLength(); |
1964 | Standard_Integer j = Poles.LowerCol(); |
1965 | |
1966 | while (Closed && j <= Length) { |
1967 | Closed = (Poles (Lower,j).Distance (Poles (Upper,j)) <= Precision::Confusion()); |
1968 | j++; |
1969 | } |
1970 | return Closed; |
1971 | } |
1972 | |
1973 | //======================================================================= |
1974 | //function : IsVClosed |
1975 | //purpose : |
1976 | //======================================================================= |
1977 | |
1978 | Standard_Boolean Geom_BezierSurface::IsVClosed () const |
1979 | { |
1980 | const TColgp_Array2OfPnt & Poles = poles->Array2(); |
1981 | Standard_Boolean Closed = Standard_True; |
1982 | Standard_Integer Lower = Poles.LowerCol(); |
1983 | Standard_Integer Upper = Poles.UpperCol(); |
1984 | Standard_Integer Length = Poles.ColLength(); |
1985 | Standard_Integer i = Poles.LowerRow(); |
1986 | while (Closed && i <= Length) { |
1987 | Closed = (Poles (i,Lower).Distance (Poles (i,Upper)) <= Precision::Confusion()); |
1988 | i++; |
1989 | } |
1990 | return Closed; |
1991 | } |
1992 | |
1993 | //======================================================================= |
1994 | //function : IsUPeriodic |
1995 | //purpose : |
1996 | //======================================================================= |
1997 | |
1998 | Standard_Boolean Geom_BezierSurface::IsUPeriodic () const |
1999 | { |
2000 | return Standard_False; |
2001 | } |
2002 | |
2003 | //======================================================================= |
2004 | //function : IsVPeriodic |
2005 | //purpose : |
2006 | //======================================================================= |
2007 | |
2008 | Standard_Boolean Geom_BezierSurface::IsVPeriodic () const |
2009 | { |
2010 | return Standard_False; |
2011 | } |
2012 | |
2013 | //======================================================================= |
2014 | //function : Resolution |
2015 | //purpose : |
2016 | //======================================================================= |
2017 | |
2018 | void Geom_BezierSurface::Resolution(const Standard_Real Tolerance3D, |
2019 | Standard_Real& UTolerance, |
2020 | Standard_Real& VTolerance) |
2021 | { |
2022 | if(!maxderivinvok){ |
2023 | TColStd_Array1OfReal biduknots(1,2); biduknots(1) = 0.; biduknots(2) = 1.; |
2024 | TColStd_Array1OfInteger bidumults(1,2); bidumults.Init(UDegree() + 1); |
2025 | TColStd_Array1OfReal bidvknots(1,2); bidvknots(1) = 0.; bidvknots(2) = 1.; |
2026 | TColStd_Array1OfInteger bidvmults(1,2); bidvmults.Init(VDegree() + 1); |
2027 | if(urational || vrational){ |
2028 | BSplSLib::Resolution(poles->Array2(), |
2029 | weights->Array2(), |
2030 | biduknots, |
2031 | bidvknots, |
2032 | bidumults, |
2033 | bidvmults, |
2034 | UDegree(), |
2035 | VDegree(), |
2036 | urational, |
2037 | vrational, |
2038 | 0, |
2039 | 0, |
2040 | 1., |
2041 | umaxderivinv, |
2042 | vmaxderivinv) ; |
2043 | } |
2044 | else{ |
2045 | BSplSLib::Resolution(poles->Array2(), |
2046 | *((TColStd_Array2OfReal*) NULL), |
2047 | biduknots, |
2048 | bidvknots, |
2049 | bidumults, |
2050 | bidvmults, |
2051 | UDegree(), |
2052 | VDegree(), |
2053 | urational, |
2054 | vrational, |
2055 | 0, |
2056 | 0, |
2057 | 1., |
2058 | umaxderivinv, |
2059 | vmaxderivinv) ; |
2060 | } |
2061 | maxderivinvok = 1; |
2062 | } |
2063 | UTolerance = Tolerance3D * umaxderivinv; |
2064 | VTolerance = Tolerance3D * vmaxderivinv; |
2065 | } |
2066 | |
2067 | //======================================================================= |
2068 | //function : Copy |
2069 | //purpose : |
2070 | //======================================================================= |
2071 | |
2072 | Handle(Geom_Geometry) Geom_BezierSurface::Copy() const |
2073 | { |
2074 | Handle(Geom_BezierSurface) S = new Geom_BezierSurface |
2075 | (poles, coeffs, weights, wcoeffs, urational, vrational); |
2076 | return S; |
2077 | } |
2078 | |
2079 | //======================================================================= |
2080 | //function : Init |
2081 | //purpose : |
2082 | //======================================================================= |
2083 | |
2084 | void Geom_BezierSurface::Init |
2085 | (const Handle(TColgp_HArray2OfPnt)& Poles, |
2086 | const Handle(TColStd_HArray2OfReal)& Weights) |
2087 | { |
2088 | Standard_Integer NbUPoles = Poles->ColLength(); |
2089 | Standard_Integer NbVPoles = Poles->RowLength(); |
2090 | |
2091 | Standard_Integer maxcls = Max(NbUPoles, NbVPoles); |
2092 | Standard_Integer mincls = Min(NbUPoles, NbVPoles); |
2093 | |
2094 | // set fields |
2095 | poles = Poles; |
2096 | coeffs = new TColgp_HArray2OfPnt (1,maxcls,1,mincls); |
2097 | |
2098 | if (urational || vrational) { |
2099 | weights = Weights; |
2100 | wcoeffs = new TColStd_HArray2OfReal (1,maxcls,1,mincls); |
2101 | } |
2102 | else { |
2103 | weights.Nullify(); |
2104 | wcoeffs.Nullify(); |
2105 | } |
2106 | |
2107 | UpdateCoefficients(); |
2108 | } |
2109 | |
2110 | |
2111 | //======================================================================= |
2112 | //function : UpdateCoefficients |
2113 | //purpose : |
2114 | //======================================================================= |
2115 | |
2116 | void Geom_BezierSurface::UpdateCoefficients(const Standard_Real , |
2117 | const Standard_Real ) |
2118 | { |
2119 | maxderivinvok = Standard_False; |
2120 | ucacheparameter = 0.; |
2121 | TColStd_Array1OfReal biduflatknots(BSplCLib::FlatBezierKnots(UDegree()), |
2122 | 1, 2*(UDegree()+1)); |
2123 | vcacheparameter = 0.; |
2124 | TColStd_Array1OfReal bidvflatknots(BSplCLib::FlatBezierKnots(VDegree()), |
2125 | 1, 2*(VDegree()+1)); |
2126 | |
2127 | Standard_Real uparameter_11 = (2*ucacheparameter + ucachespanlenght)/2, |
2128 | uspanlenght_11 = ucachespanlenght/2, |
2129 | vparameter_11 = (2*vcacheparameter + vcachespanlenght)/2, |
2130 | vspanlenght_11 = vcachespanlenght/2 ; |
2131 | |
2132 | if ( urational || vrational ) { |
2133 | BSplSLib::BuildCache(uparameter_11,vparameter_11, |
2134 | uspanlenght_11,vspanlenght_11,0,0, |
2135 | UDegree(),VDegree(),0,0, |
2136 | biduflatknots,bidvflatknots, |
2137 | poles->Array2(), |
2138 | weights->Array2(), |
2139 | coeffs->ChangeArray2(), |
2140 | wcoeffs->ChangeArray2()); |
2141 | } |
2142 | else { |
2143 | BSplSLib::BuildCache(uparameter_11,vparameter_11, |
2144 | uspanlenght_11,vspanlenght_11,0,0, |
2145 | UDegree(),VDegree(),0,0, |
2146 | biduflatknots,bidvflatknots, |
2147 | poles->Array2(), |
2148 | *((TColStd_Array2OfReal*) NULL), |
2149 | coeffs->ChangeArray2(), |
2150 | *((TColStd_Array2OfReal*) NULL)); |
2151 | } |
2152 | validcache = 1; |
2153 | } |
2154 | |