summaryrefslogtreecommitdiff
path: root/src/Geom2dConvert/Geom2dConvert_BSplineCurveKnotSplitting.cxx
blob: 1e5810b42145d65f56409dc1c17b67eefb56b624 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//File Geom2dConvert_BSplineCurveKnotSplitting.cxx
//Jean-Claude Vauthier 27 November 1991
//Passage sur C1 Aout 1992

#include <Geom2dConvert_BSplineCurveKnotSplitting.ixx>
#include <Standard_RangeError.hxx>

#include <BSplCLib.hxx>

typedef Handle(Geom2d_BSplineCurve)     Handle(BSplineCurve);
typedef TColStd_Array1OfInteger         Array1OfInteger;
typedef TColStd_HArray1OfInteger         HArray1OfInteger;




Geom2dConvert_BSplineCurveKnotSplitting::
Geom2dConvert_BSplineCurveKnotSplitting (

const Handle(BSplineCurve)& BasisCurve, 
const Standard_Integer      ContinuityRange

) {


  if (ContinuityRange < 0)  Standard_RangeError::Raise();

  Standard_Integer FirstIndex = BasisCurve->FirstUKnotIndex();
  Standard_Integer LastIndex  = BasisCurve->LastUKnotIndex();

  Standard_Integer Degree = BasisCurve->Degree();

  if (ContinuityRange == 0) {
    splitIndexes = new HArray1OfInteger (1, 2);
    splitIndexes->SetValue (1, FirstIndex);
    splitIndexes->SetValue (2, LastIndex);
  }
  else {
    Standard_Integer NbKnots = BasisCurve->NbKnots();
    Array1OfInteger Mults (1, NbKnots);
    BasisCurve->Multiplicities (Mults);
    Standard_Integer Mmax = BSplCLib::MaxKnotMult (Mults, FirstIndex, LastIndex);
    if (Degree - Mmax >= ContinuityRange) {
      splitIndexes = new HArray1OfInteger (1, 2);
      splitIndexes->SetValue (1, FirstIndex);
      splitIndexes->SetValue (2, LastIndex);
    }
    else {
      Array1OfInteger Split (1, LastIndex - FirstIndex + 1);
      Standard_Integer NbSplit = 1;
      Standard_Integer Index   = FirstIndex;
      Split (NbSplit) = Index;
      Index++;
      NbSplit++;
      while (Index < LastIndex) {
        if (Degree - Mults (Index) < ContinuityRange) {
          Split (NbSplit) = Index;
          NbSplit++;
        }
        Index++;
      }
      Split (NbSplit) = Index;
      splitIndexes = new HArray1OfInteger (1, NbSplit);
      for (Standard_Integer i = 1; i <= NbSplit; i++) {
         splitIndexes->SetValue (i, Split (i));
      }
    }
  }
}



Standard_Integer Geom2dConvert_BSplineCurveKnotSplitting::NbSplits () const {

   return splitIndexes->Length();
}


Standard_Integer Geom2dConvert_BSplineCurveKnotSplitting::SplitValue (

const Standard_Integer Index

) const {

   Standard_RangeError_Raise_if (
                       Index < 1 || Index > splitIndexes->Length(), " ");
   return splitIndexes->Value (Index);
}




void Geom2dConvert_BSplineCurveKnotSplitting::Splitting (

Array1OfInteger& SplitValues

) const {

  for (Standard_Integer i = 1; i <= splitIndexes->Length(); i++){
    SplitValues (i) = splitIndexes->Value (i);
  }
}