/
BSplCLib.cxx
4379 lines (3803 loc) · 122 KB
/
BSplCLib.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Created on: 1991-08-09
// Created by: JCV
// Copyright (c) 1991-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
// Modified RLE 9 Sep 1993
// pmn : modified 28-01-97 : fixed a mistake in LocateParameter (PRO6973)
// pmn : modified 4-11-96 : fixed a mistake in BuildKnots (PRO6124)
// pmn : modified 28-Jun-96 : fixed a mistake in AntiBoorScheme
// xab : modified 15-Jun-95 : fixed a mistake in IsRational
// xab : modified 15-Mar-95 : removed Epsilon comparison in IsRational
// added RationalDerivatives.
// xab : 30-Mar-95 : fixed coupling with lti in RationalDerivatives
// xab : 15-Mar-96 : fixed a typo in Eval with extrapolation
// jct : 15-Apr-97 : added TangExtendToConstraint
// jct : 24-Apr-97 : correction on computation of Tbord and NewFlatKnots
// in TangExtendToConstraint; Continuity can be equal to 0
#include <BSplCLib.hxx>
#include <ElCLib.hxx>
#include <gp_Pnt.hxx>
#include <math_Matrix.hxx>
#include <NCollection_LocalArray.hxx>
#include <PLib.hxx>
#include <Precision.hxx>
#include <Standard_NotImplemented.hxx>
#include <math_Vector.hxx>
typedef gp_Pnt Pnt;
typedef gp_Vec Vec;
typedef TColgp_Array1OfPnt Array1OfPnt;
typedef TColStd_Array1OfReal Array1OfReal;
typedef TColStd_Array1OfInteger Array1OfInteger;
//=======================================================================
//class : BSplCLib_LocalMatrix
//purpose: Auxiliary class optimizing creation of matrix buffer for
// evaluation of bspline (using stack allocation for main matrix)
//=======================================================================
class BSplCLib_LocalMatrix : public math_Matrix
{
public:
BSplCLib_LocalMatrix (Standard_Integer DerivativeRequest, Standard_Integer Order)
: math_Matrix (myBuffer, 1, DerivativeRequest + 1, 1, Order)
{
Standard_OutOfRange_Raise_if (DerivativeRequest > BSplCLib::MaxDegree() ||
Order > BSplCLib::MaxDegree()+1 || BSplCLib::MaxDegree() > 25,
"BSplCLib: bspline degree is greater than maximum supported");
}
private:
// local buffer, to be sufficient for addressing by index [Degree+1][Degree+1]
// (see math_Matrix implementation)
Standard_Real myBuffer[27*27];
};
//=======================================================================
//function : Hunt
//purpose :
//=======================================================================
void BSplCLib::Hunt (const TColStd_Array1OfReal& theArray,
const Standard_Real theX,
Standard_Integer& theXPos)
{
// replaced by simple dichotomy (RLE)
if (theArray.First() > theX)
{
theXPos = theArray.Lower() - 1;
return;
}
else if (theArray.Last() < theX)
{
theXPos = theArray.Upper() + 1;
return;
}
theXPos = theArray.Lower();
if (theArray.Length() <= 1)
{
return;
}
Standard_Integer aHi = theArray.Upper();
while (aHi - theXPos != 1)
{
const Standard_Integer aMid = (aHi + theXPos) / 2;
if (theArray.Value (aMid) < theX)
{
theXPos = aMid;
}
else
{
aHi = aMid;
}
}
}
//=======================================================================
//function : FirstUKnotIndex
//purpose :
//=======================================================================
Standard_Integer BSplCLib::FirstUKnotIndex (const Standard_Integer Degree,
const TColStd_Array1OfInteger& Mults)
{
Standard_Integer Index = Mults.Lower();
Standard_Integer SigmaMult = Mults(Index);
while (SigmaMult <= Degree) {
Index++;
SigmaMult += Mults (Index);
}
return Index;
}
//=======================================================================
//function : LastUKnotIndex
//purpose :
//=======================================================================
Standard_Integer BSplCLib::LastUKnotIndex (const Standard_Integer Degree,
const Array1OfInteger& Mults)
{
Standard_Integer Index = Mults.Upper();
Standard_Integer SigmaMult = Mults(Index);
while (SigmaMult <= Degree) {
Index--;
SigmaMult += Mults.Value (Index);
}
return Index;
}
//=======================================================================
//function : FlatIndex
//purpose :
//=======================================================================
Standard_Integer BSplCLib::FlatIndex
(const Standard_Integer Degree,
const Standard_Integer Index,
const TColStd_Array1OfInteger& Mults,
const Standard_Boolean Periodic)
{
Standard_Integer i, index = Index;
const Standard_Integer MLower = Mults.Lower();
const Standard_Integer *pmu = &Mults(MLower);
pmu -= MLower;
for (i = MLower + 1; i <= Index; i++)
index += pmu[i] - 1;
if ( Periodic)
index += Degree;
else
index += pmu[MLower] - 1;
return index;
}
//=======================================================================
//function : LocateParameter
//purpose : Processing of nodes with multiplicities
//pmn 28-01-97 -> compute eventual of the period.
//=======================================================================
void BSplCLib::LocateParameter
(const Standard_Integer , //Degree,
const Array1OfReal& Knots,
const Array1OfInteger& , //Mults,
const Standard_Real U,
const Standard_Boolean IsPeriodic,
const Standard_Integer FromK1,
const Standard_Integer ToK2,
Standard_Integer& KnotIndex,
Standard_Real& NewU)
{
Standard_Real uf = 0, ul=1;
if (IsPeriodic) {
uf = Knots(Knots.Lower());
ul = Knots(Knots.Upper());
}
BSplCLib::LocateParameter(Knots,U,IsPeriodic,FromK1,ToK2,
KnotIndex,NewU, uf, ul);
}
//=======================================================================
//function : LocateParameter
//purpose : For plane nodes
// pmn 28-01-97 -> There is a need of the degre to calculate
// the eventual period
//=======================================================================
void BSplCLib::LocateParameter
(const Standard_Integer Degree,
const Array1OfReal& Knots,
const Standard_Real U,
const Standard_Boolean IsPeriodic,
const Standard_Integer FromK1,
const Standard_Integer ToK2,
Standard_Integer& KnotIndex,
Standard_Real& NewU)
{
if (IsPeriodic)
BSplCLib::LocateParameter(Knots, U, IsPeriodic, FromK1, ToK2,
KnotIndex, NewU,
Knots(Knots.Lower() + Degree),
Knots(Knots.Upper() - Degree));
else
BSplCLib::LocateParameter(Knots, U, IsPeriodic, FromK1, ToK2,
KnotIndex, NewU,
0.,
1.);
}
//=======================================================================
//function : LocateParameter
//purpose : Effective computation
// pmn 28-01-97 : Add limits of the period as input argument,
// as it is impossible to produce them at this level.
//=======================================================================
void BSplCLib::LocateParameter
(const TColStd_Array1OfReal& Knots,
const Standard_Real U,
const Standard_Boolean IsPeriodic,
const Standard_Integer FromK1,
const Standard_Integer ToK2,
Standard_Integer& KnotIndex,
Standard_Real& NewU,
const Standard_Real UFirst,
const Standard_Real ULast)
{
/*
Let Knots are distributed as follows (the array is sorted in ascending order):
K1, K1,..., K1, K1, K2, K2,..., K2, K2,..., Kn, Kn,..., Kn
M1 times M2 times Mn times
NbKnots = sum(M1+M2+...+Mn)
If U <= K1 then KnotIndex should be equal to M1.
If U >= Kn then KnotIndex should be equal to NbKnots-Mn-1.
If Ki <= U < K(i+1) then KnotIndex should be equal to sum (M1+M2+...+Mi).
*/
Standard_Integer First,Last;
if (FromK1 < ToK2) {
First = FromK1;
Last = ToK2;
}
else {
First = ToK2;
Last = FromK1;
}
Standard_Integer Last1 = Last - 1;
NewU = U;
if (IsPeriodic && (NewU < UFirst || NewU > ULast))
NewU = ElCLib::InPeriod(NewU, UFirst, ULast);
BSplCLib::Hunt (Knots, NewU, KnotIndex);
Standard_Real val;
const Standard_Integer KLower = Knots.Lower(),
KUpper = Knots.Upper();
const Standard_Real Eps = Epsilon(Min(Abs(Knots(KUpper)), Abs(U)));
const Standard_Real *knots = &Knots(KLower);
knots -= KLower;
if ( KnotIndex < Knots.Upper()) {
val = NewU - knots[KnotIndex + 1];
if (val < 0) val = - val;
// <= to be coherent with Segment where Eps corresponds to a bit of error.
if (val <= Eps) KnotIndex++;
}
if (KnotIndex < First) KnotIndex = First;
if (KnotIndex > Last1) KnotIndex = Last1;
if (KnotIndex != Last1) {
Standard_Real K1 = knots[KnotIndex];
Standard_Real K2 = knots[KnotIndex + 1];
val = K2 - K1;
if (val < 0) val = - val;
while (val <= Eps) {
KnotIndex++;
if(KnotIndex >= Knots.Upper())
break;
K1 = K2;
K2 = knots[KnotIndex + 1];
val = K2 - K1;
if (val < 0) val = - val;
}
}
}
//=======================================================================
//function : LocateParameter
//purpose : the index is recomputed only if out of range
//pmn 28-01-97 -> eventual computation of the period.
//=======================================================================
void BSplCLib::LocateParameter
(const Standard_Integer Degree,
const TColStd_Array1OfReal& Knots,
const TColStd_Array1OfInteger* Mults,
const Standard_Real U,
const Standard_Boolean Periodic,
Standard_Integer& KnotIndex,
Standard_Real& NewU)
{
Standard_Integer first,last;
if (Mults) {
if (Periodic) {
first = Knots.Lower();
last = Knots.Upper();
}
else {
first = FirstUKnotIndex(Degree,*Mults);
last = LastUKnotIndex (Degree,*Mults);
}
}
else {
first = Knots.Lower() + Degree;
last = Knots.Upper() - Degree;
}
if ( KnotIndex < first || KnotIndex > last)
BSplCLib::LocateParameter(Knots, U, Periodic, first, last,
KnotIndex, NewU, Knots(first), Knots(last));
else
NewU = U;
}
//=======================================================================
//function : MaxKnotMult
//purpose :
//=======================================================================
Standard_Integer BSplCLib::MaxKnotMult
(const Array1OfInteger& Mults,
const Standard_Integer FromK1,
const Standard_Integer ToK2)
{
Standard_Integer MLower = Mults.Lower();
const Standard_Integer *pmu = &Mults(MLower);
pmu -= MLower;
Standard_Integer MaxMult = pmu[FromK1];
for (Standard_Integer i = FromK1; i <= ToK2; i++) {
if (MaxMult < pmu[i]) MaxMult = pmu[i];
}
return MaxMult;
}
//=======================================================================
//function : MinKnotMult
//purpose :
//=======================================================================
Standard_Integer BSplCLib::MinKnotMult
(const Array1OfInteger& Mults,
const Standard_Integer FromK1,
const Standard_Integer ToK2)
{
Standard_Integer MLower = Mults.Lower();
const Standard_Integer *pmu = &Mults(MLower);
pmu -= MLower;
Standard_Integer MinMult = pmu[FromK1];
for (Standard_Integer i = FromK1; i <= ToK2; i++) {
if (MinMult > pmu[i]) MinMult = pmu[i];
}
return MinMult;
}
//=======================================================================
//function : NbPoles
//purpose :
//=======================================================================
Standard_Integer BSplCLib::NbPoles(const Standard_Integer Degree,
const Standard_Boolean Periodic,
const TColStd_Array1OfInteger& Mults)
{
Standard_Integer i,sigma = 0;
Standard_Integer f = Mults.Lower();
Standard_Integer l = Mults.Upper();
const Standard_Integer * pmu = &Mults(f);
pmu -= f;
Standard_Integer Mf = pmu[f];
Standard_Integer Ml = pmu[l];
if (Mf <= 0) return 0;
if (Ml <= 0) return 0;
if (Periodic) {
if (Mf > Degree) return 0;
if (Ml > Degree) return 0;
if (Mf != Ml ) return 0;
sigma = Mf;
}
else {
Standard_Integer Deg1 = Degree + 1;
if (Mf > Deg1) return 0;
if (Ml > Deg1) return 0;
sigma = Mf + Ml - Deg1;
}
for (i = f + 1; i < l; i++) {
if (pmu[i] <= 0 ) return 0;
if (pmu[i] > Degree) return 0;
sigma += pmu[i];
}
return sigma;
}
//=======================================================================
//function : KnotSequenceLength
//purpose :
//=======================================================================
Standard_Integer BSplCLib::KnotSequenceLength
(const TColStd_Array1OfInteger& Mults,
const Standard_Integer Degree,
const Standard_Boolean Periodic)
{
Standard_Integer i,l = 0;
Standard_Integer MLower = Mults.Lower();
Standard_Integer MUpper = Mults.Upper();
const Standard_Integer * pmu = &Mults(MLower);
pmu -= MLower;
for (i = MLower; i <= MUpper; i++)
l += pmu[i];
if (Periodic) l += 2 * (Degree + 1 - pmu[MLower]);
return l;
}
//=======================================================================
//function : KnotSequence
//purpose :
//=======================================================================
void BSplCLib::KnotSequence
(const TColStd_Array1OfReal& Knots,
const TColStd_Array1OfInteger& Mults,
TColStd_Array1OfReal& KnotSeq,
const Standard_Boolean Periodic)
{
BSplCLib::KnotSequence(Knots,Mults,0,Periodic,KnotSeq);
}
//=======================================================================
//function : KnotSequence
//purpose :
//=======================================================================
void BSplCLib::KnotSequence
(const TColStd_Array1OfReal& Knots,
const TColStd_Array1OfInteger& Mults,
const Standard_Integer Degree,
const Standard_Boolean Periodic,
TColStd_Array1OfReal& KnotSeq)
{
Standard_Real K;
Standard_Integer Mult;
Standard_Integer MLower = Mults.Lower();
const Standard_Integer * pmu = &Mults(MLower);
pmu -= MLower;
Standard_Integer KLower = Knots.Lower();
Standard_Integer KUpper = Knots.Upper();
const Standard_Real * pkn = &Knots(KLower);
pkn -= KLower;
Standard_Integer M1 = Degree + 1 - pmu[MLower]; // for periodic
Standard_Integer i,j,index = Periodic ? M1 + 1 : 1;
for (i = KLower; i <= KUpper; i++) {
Mult = pmu[i];
K = pkn[i];
for (j = 1; j <= Mult; j++) {
KnotSeq (index) = K;
index++;
}
}
if (Periodic) {
Standard_Real period = pkn[KUpper] - pkn[KLower];
Standard_Integer m;
m = 1;
j = KUpper - 1;
for (i = M1; i >= 1; i--) {
KnotSeq(i) = pkn[j] - period;
m++;
if (m > pmu[j]) {
j--;
m = 1;
}
}
m = 1;
j = KLower + 1;
for (i = index; i <= KnotSeq.Upper(); i++) {
KnotSeq(i) = pkn[j] + period;
m++;
if (m > pmu[j]) {
j++;
m = 1;
}
}
}
}
//=======================================================================
//function : KnotsLength
//purpose :
//=======================================================================
Standard_Integer BSplCLib::KnotsLength(const TColStd_Array1OfReal& SeqKnots,
// const Standard_Boolean Periodic)
const Standard_Boolean )
{
Standard_Integer sizeMult = 1;
Standard_Real val = SeqKnots(1);
for (Standard_Integer jj=2;
jj<=SeqKnots.Length();jj++)
{
// test on strict equality on nodes
if (SeqKnots(jj)!=val)
{
val = SeqKnots(jj);
sizeMult++;
}
}
return sizeMult;
}
//=======================================================================
//function : Knots
//purpose :
//=======================================================================
void BSplCLib::Knots(const TColStd_Array1OfReal& SeqKnots,
TColStd_Array1OfReal &knots,
TColStd_Array1OfInteger &mult,
// const Standard_Boolean Periodic)
const Standard_Boolean )
{
Standard_Real val = SeqKnots(1);
Standard_Integer kk=1;
knots(kk) = val;
mult(kk) = 1;
for (Standard_Integer jj=2;jj<=SeqKnots.Length();jj++)
{
// test on strict equality on nodes
if (SeqKnots(jj)!=val)
{
val = SeqKnots(jj);
kk++;
knots(kk) = val;
mult(kk) = 1;
}
else
{
mult(kk)++;
}
}
}
//=======================================================================
//function : KnotForm
//purpose :
//=======================================================================
BSplCLib_KnotDistribution BSplCLib::KnotForm
(const Array1OfReal& Knots,
const Standard_Integer FromK1,
const Standard_Integer ToK2)
{
Standard_Real DU0,DU1,Ui,Uj,Eps0,val;
BSplCLib_KnotDistribution KForm = BSplCLib_Uniform;
if (FromK1 + 1 > Knots.Upper())
{
return BSplCLib_Uniform;
}
Ui = Knots(FromK1);
if (Ui < 0) Ui = - Ui;
Uj = Knots(FromK1 + 1);
if (Uj < 0) Uj = - Uj;
DU0 = Uj - Ui;
if (DU0 < 0) DU0 = - DU0;
Eps0 = Epsilon (Ui) + Epsilon (Uj) + Epsilon (DU0);
Standard_Integer i = FromK1 + 1;
while (KForm != BSplCLib_NonUniform && i < ToK2) {
Ui = Knots(i);
if (Ui < 0) Ui = - Ui;
i++;
Uj = Knots(i);
if (Uj < 0) Uj = - Uj;
DU1 = Uj - Ui;
if (DU1 < 0) DU1 = - DU1;
val = DU1 - DU0;
if (val < 0) val = -val;
if (val > Eps0) KForm = BSplCLib_NonUniform;
DU0 = DU1;
Eps0 = Epsilon (Ui) + Epsilon (Uj) + Epsilon (DU0);
}
return KForm;
}
//=======================================================================
//function : MultForm
//purpose :
//=======================================================================
BSplCLib_MultDistribution BSplCLib::MultForm
(const Array1OfInteger& Mults,
const Standard_Integer FromK1,
const Standard_Integer ToK2)
{
Standard_Integer First,Last;
if (FromK1 < ToK2) {
First = FromK1;
Last = ToK2;
}
else {
First = ToK2;
Last = FromK1;
}
if (First + 1 > Mults.Upper())
{
return BSplCLib_Constant;
}
Standard_Integer FirstMult = Mults(First);
BSplCLib_MultDistribution MForm = BSplCLib_Constant;
Standard_Integer i = First + 1;
Standard_Integer Mult = Mults(i);
// while (MForm != BSplCLib_NonUniform && i <= Last) { ???????????JR????????
while (MForm != BSplCLib_NonConstant && i <= Last) {
if (i == First + 1) {
if (Mult != FirstMult) MForm = BSplCLib_QuasiConstant;
}
else if (i == Last) {
if (MForm == BSplCLib_QuasiConstant) {
if (FirstMult != Mults(i)) MForm = BSplCLib_NonConstant;
}
else {
if (Mult != Mults(i)) MForm = BSplCLib_NonConstant;
}
}
else {
if (Mult != Mults(i)) MForm = BSplCLib_NonConstant;
Mult = Mults(i);
}
i++;
}
return MForm;
}
//=======================================================================
//function : KnotAnalysis
//purpose :
//=======================================================================
void BSplCLib::KnotAnalysis (const Standard_Integer Degree,
const Standard_Boolean Periodic,
const TColStd_Array1OfReal& CKnots,
const TColStd_Array1OfInteger& CMults,
GeomAbs_BSplKnotDistribution& KnotForm,
Standard_Integer& MaxKnotMult)
{
KnotForm = GeomAbs_NonUniform;
BSplCLib_KnotDistribution KSet =
BSplCLib::KnotForm (CKnots, 1, CKnots.Length());
if (KSet == BSplCLib_Uniform) {
BSplCLib_MultDistribution MSet =
BSplCLib::MultForm (CMults, 1, CMults.Length());
switch (MSet) {
case BSplCLib_NonConstant :
break;
case BSplCLib_Constant :
if (CKnots.Length() == 2) {
KnotForm = GeomAbs_PiecewiseBezier;
}
else {
if (CMults (1) == 1) KnotForm = GeomAbs_Uniform;
}
break;
case BSplCLib_QuasiConstant :
if (CMults (1) == Degree + 1) {
Standard_Real M = CMults (2);
if (M == Degree ) KnotForm = GeomAbs_PiecewiseBezier;
else if (M == 1) KnotForm = GeomAbs_QuasiUniform;
}
break;
}
}
Standard_Integer FirstKM =
Periodic ? CKnots.Lower() : BSplCLib::FirstUKnotIndex (Degree,CMults);
Standard_Integer LastKM =
Periodic ? CKnots.Upper() : BSplCLib::LastUKnotIndex (Degree,CMults);
MaxKnotMult = 0;
if (LastKM - FirstKM != 1) {
Standard_Integer Multi;
for (Standard_Integer i = FirstKM + 1; i < LastKM; i++) {
Multi = CMults (i);
MaxKnotMult = Max (MaxKnotMult, Multi);
}
}
}
//=======================================================================
//function : Reparametrize
//purpose :
//=======================================================================
void BSplCLib::Reparametrize
(const Standard_Real U1,
const Standard_Real U2,
Array1OfReal& Knots)
{
Standard_Integer Lower = Knots.Lower();
Standard_Integer Upper = Knots.Upper();
Standard_Real UFirst = Min (U1, U2);
Standard_Real ULast = Max (U1, U2);
Standard_Real NewLength = ULast - UFirst;
BSplCLib_KnotDistribution KSet = BSplCLib::KnotForm (Knots, Lower, Upper);
if (KSet == BSplCLib_Uniform) {
Standard_Real DU = NewLength / (Upper - Lower);
Knots (Lower) = UFirst;
for (Standard_Integer i = Lower + 1; i <= Upper; i++) {
Knots (i) = Knots (i-1) + DU;
}
}
else {
Standard_Real K2;
Standard_Real Ratio;
Standard_Real K1 = Knots (Lower);
Standard_Real Length = Knots (Upper) - Knots (Lower);
Knots (Lower) = UFirst;
for (Standard_Integer i = Lower + 1; i <= Upper; i++) {
K2 = Knots (i);
Ratio = (K2 - K1) / Length;
Knots (i) = Knots (i-1) + (NewLength * Ratio);
//for CheckCurveData
Standard_Real Eps = Epsilon( Abs(Knots(i-1)) );
if (Knots(i) - Knots(i-1) <= Eps)
Knots(i) = NextAfter (Knots(i-1) + Eps, RealLast());
K1 = K2;
}
}
}
//=======================================================================
//function : Reverse
//purpose :
//=======================================================================
void BSplCLib::Reverse(TColStd_Array1OfReal& Knots)
{
Standard_Integer first = Knots.Lower();
Standard_Integer last = Knots.Upper();
Standard_Real kfirst = Knots(first);
Standard_Real klast = Knots(last);
Standard_Real tfirst = kfirst;
Standard_Real tlast = klast;
first++;
last--;
while (first <= last) {
tfirst += klast - Knots(last);
tlast -= Knots(first) - kfirst;
kfirst = Knots(first);
klast = Knots(last);
Knots(first) = tfirst;
Knots(last) = tlast;
first++;
last--;
}
}
//=======================================================================
//function : Reverse
//purpose :
//=======================================================================
void BSplCLib::Reverse(TColStd_Array1OfInteger& Mults)
{
Standard_Integer first = Mults.Lower();
Standard_Integer last = Mults.Upper();
Standard_Integer temp;
while (first < last) {
temp = Mults(first);
Mults(first) = Mults(last);
Mults(last) = temp;
first++;
last--;
}
}
//=======================================================================
//function : Reverse
//purpose :
//=======================================================================
void BSplCLib::Reverse(TColStd_Array1OfReal& Weights,
const Standard_Integer L)
{
Standard_Integer i, l = L;
l = Weights.Lower()+(l-Weights.Lower())%(Weights.Upper()-Weights.Lower()+1);
TColStd_Array1OfReal temp(0,Weights.Length()-1);
for (i = Weights.Lower(); i <= l; i++)
temp(l-i) = Weights(i);
for (i = l+1; i <= Weights.Upper(); i++)
temp(l-Weights.Lower()+Weights.Upper()-i+1) = Weights(i);
for (i = Weights.Lower(); i <= Weights.Upper(); i++)
Weights(i) = temp(i-Weights.Lower());
}
//=======================================================================
//function : IsRational
//purpose :
//=======================================================================
Standard_Boolean BSplCLib::IsRational(const TColStd_Array1OfReal& Weights,
const Standard_Integer I1,
const Standard_Integer I2,
// const Standard_Real Epsi)
const Standard_Real )
{
Standard_Integer i, f = Weights.Lower(), l = Weights.Length();
Standard_Integer I3 = I2 - f;
const Standard_Real * WG = &Weights(f);
WG -= f;
for (i = I1 - f; i < I3; i++) {
if (WG[f + (i % l)] != WG[f + ((i + 1) % l)]) return Standard_True;
}
return Standard_False ;
}
//=======================================================================
//function : Eval
//purpose : evaluate point and derivatives
//=======================================================================
void BSplCLib::Eval(const Standard_Real U,
const Standard_Integer Degree,
Standard_Real& Knots,
const Standard_Integer Dimension,
Standard_Real& Poles)
{
Standard_Integer step,i,Dms,Dm1,Dpi,Sti;
Standard_Real X, Y, *poles, *knots = &Knots;
Dm1 = Dms = Degree;
Dm1--;
Dms++;
switch (Dimension) {
case 1 : {
for (step = - 1; step < Dm1; step++) {
Dms--;
poles = &Poles;
Dpi = Dm1;
Sti = step;
for (i = 0; i < Dms; i++) {
Dpi++;
Sti++;
X = (knots[Dpi] - U) / (knots[Dpi] - knots[Sti]);
Y = 1 - X;
poles[0] *= X; poles[0] += Y * poles[1];
poles += 1;
}
}
break;
}
case 2 : {
for (step = - 1; step < Dm1; step++) {
Dms--;
poles = &Poles;
Dpi = Dm1;
Sti = step;
for (i = 0; i < Dms; i++) {
Dpi++;
Sti++;
X = (knots[Dpi] - U) / (knots[Dpi] - knots[Sti]);
Y = 1 - X;
poles[0] *= X; poles[0] += Y * poles[2];
poles[1] *= X; poles[1] += Y * poles[3];
poles += 2;
}
}
break;
}
case 3 : {
for (step = - 1; step < Dm1; step++) {
Dms--;
poles = &Poles;
Dpi = Dm1;
Sti = step;
for (i = 0; i < Dms; i++) {
Dpi++;
Sti++;
X = (knots[Dpi] - U) / (knots[Dpi] - knots[Sti]);
Y = 1 - X;
poles[0] *= X; poles[0] += Y * poles[3];
poles[1] *= X; poles[1] += Y * poles[4];
poles[2] *= X; poles[2] += Y * poles[5];
poles += 3;
}
}
break;
}
case 4 : {
for (step = - 1; step < Dm1; step++) {
Dms--;
poles = &Poles;
Dpi = Dm1;
Sti = step;
for (i = 0; i < Dms; i++) {
Dpi++;
Sti++;
X = (knots[Dpi] - U) / (knots[Dpi] - knots[Sti]);
Y = 1 - X;
poles[0] *= X; poles[0] += Y * poles[4];
poles[1] *= X; poles[1] += Y * poles[5];
poles[2] *= X; poles[2] += Y * poles[6];
poles[3] *= X; poles[3] += Y * poles[7];
poles += 4;
}
}
break;
}
default : {
Standard_Integer k;
for (step = - 1; step < Dm1; step++) {
Dms--;
poles = &Poles;
Dpi = Dm1;
Sti = step;
for (i = 0; i < Dms; i++) {
Dpi++;
Sti++;
X = (knots[Dpi] - U) / (knots[Dpi] - knots[Sti]);
Y = 1 - X;
for (k = 0; k < Dimension; k++) {
poles[k] *= X;
poles[k] += Y * poles[k + Dimension];
}
poles += Dimension;
}
}
}
}
}
//=======================================================================
//function : BoorScheme
//purpose :
//=======================================================================