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