0024624: Lost word in license statement in source files
[occt.git] / src / Law / Law_BSplineKnotSplitting.cxx
1 // Created on: 1997-01-17
2 // Created by: Philippe MANGIN
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <Law_BSplineKnotSplitting.ixx>
18
19
20 #include <Law_BSplineKnotSplitting.ixx>
21 #include <Standard_RangeError.hxx>
22
23 #include <BSplCLib.hxx>
24
25 typedef Handle(Law_BSpline)             Handle(BSplineCurve);
26 typedef TColStd_Array1OfInteger         Array1OfInteger;
27 typedef TColStd_HArray1OfInteger        HArray1OfInteger;
28
29
30
31
32 Law_BSplineKnotSplitting::
33 Law_BSplineKnotSplitting (
34
35 const Handle(BSplineCurve)& BasisCurve, 
36 const Standard_Integer               ContinuityRange
37
38 ) {
39
40
41   if (ContinuityRange < 0)  Standard_RangeError::Raise();
42
43   Standard_Integer FirstIndex = BasisCurve->FirstUKnotIndex();
44   Standard_Integer LastIndex  = BasisCurve->LastUKnotIndex();
45
46   Standard_Integer Degree = BasisCurve->Degree();
47
48   if (ContinuityRange == 0) {
49     splitIndexes = new HArray1OfInteger (1, 2);
50     splitIndexes->SetValue (1, FirstIndex);
51     splitIndexes->SetValue (2, LastIndex);
52   }
53   else {
54     Standard_Integer NbKnots = BasisCurve->NbKnots();
55     Array1OfInteger Mults (1, NbKnots);
56     BasisCurve->Multiplicities (Mults);
57     Standard_Integer Mmax = BSplCLib::MaxKnotMult (Mults, FirstIndex, LastIndex);
58     if (Degree - Mmax >= ContinuityRange) {
59       splitIndexes = new HArray1OfInteger (1, 2);
60       splitIndexes->SetValue (1, FirstIndex);
61       splitIndexes->SetValue (2, LastIndex);
62     }
63     else {
64       Array1OfInteger Split (1, LastIndex - FirstIndex + 1);
65       Standard_Integer NbSplit = 1;
66       Standard_Integer Index   = FirstIndex;
67       Split (NbSplit) = Index;
68       Index++;
69       NbSplit++;
70       while (Index < LastIndex) {
71         if (Degree - Mults (Index) < ContinuityRange) {
72           Split (NbSplit) = Index;
73           NbSplit++;
74         }
75         Index++;
76       }
77       Split (NbSplit) = Index;
78       splitIndexes = new HArray1OfInteger (1, NbSplit);
79       for (Standard_Integer i = 1; i <= NbSplit; i++) {
80          splitIndexes->SetValue (i, Split (i));
81       }
82     }
83   }
84 }
85
86
87
88 Standard_Integer Law_BSplineKnotSplitting::NbSplits () const {
89
90    return splitIndexes->Length();
91 }
92
93
94 Standard_Integer Law_BSplineKnotSplitting::SplitValue (
95
96 const Standard_Integer Index
97
98 ) const {
99
100    Standard_RangeError_Raise_if (
101                        Index < 1 || Index > splitIndexes->Length(), " ");
102    return splitIndexes->Value (Index);
103 }
104
105
106
107
108 void Law_BSplineKnotSplitting::Splitting (
109
110 Array1OfInteger& SplitValues
111
112 ) const {
113
114   for (Standard_Integer i = 1; i <= splitIndexes->Length(); i++){
115     SplitValues (i) = splitIndexes->Value (i);
116   }
117 }