b311480e |
1 | // Created on: 1997-01-17 |
2 | // Created by: Philippe MANGIN |
3 | // Copyright (c) 1997-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 | |
18 | #include <BSplCLib.hxx> |
42cf5bc1 |
19 | #include <Law_BSpline.hxx> |
20 | #include <Law_BSplineKnotSplitting.hxx> |
21 | #include <Standard_DimensionError.hxx> |
22 | #include <Standard_RangeError.hxx> |
7fd59977 |
23 | |
7fd59977 |
24 | typedef TColStd_Array1OfInteger Array1OfInteger; |
25 | typedef TColStd_HArray1OfInteger HArray1OfInteger; |
26 | |
7fd59977 |
27 | Law_BSplineKnotSplitting:: |
c04c30b3 |
28 | Law_BSplineKnotSplitting (const Handle(Law_BSpline)& BasisCurve, |
29 | const Standard_Integer ContinuityRange) |
30 | { |
9775fa61 |
31 | if (ContinuityRange < 0) throw Standard_RangeError(); |
7fd59977 |
32 | |
33 | Standard_Integer FirstIndex = BasisCurve->FirstUKnotIndex(); |
34 | Standard_Integer LastIndex = BasisCurve->LastUKnotIndex(); |
35 | |
36 | Standard_Integer Degree = BasisCurve->Degree(); |
37 | |
38 | if (ContinuityRange == 0) { |
39 | splitIndexes = new HArray1OfInteger (1, 2); |
40 | splitIndexes->SetValue (1, FirstIndex); |
41 | splitIndexes->SetValue (2, LastIndex); |
42 | } |
43 | else { |
44 | Standard_Integer NbKnots = BasisCurve->NbKnots(); |
45 | Array1OfInteger Mults (1, NbKnots); |
46 | BasisCurve->Multiplicities (Mults); |
47 | Standard_Integer Mmax = BSplCLib::MaxKnotMult (Mults, FirstIndex, LastIndex); |
48 | if (Degree - Mmax >= ContinuityRange) { |
49 | splitIndexes = new HArray1OfInteger (1, 2); |
50 | splitIndexes->SetValue (1, FirstIndex); |
51 | splitIndexes->SetValue (2, LastIndex); |
52 | } |
53 | else { |
54 | Array1OfInteger Split (1, LastIndex - FirstIndex + 1); |
55 | Standard_Integer NbSplit = 1; |
56 | Standard_Integer Index = FirstIndex; |
57 | Split (NbSplit) = Index; |
58 | Index++; |
59 | NbSplit++; |
60 | while (Index < LastIndex) { |
61 | if (Degree - Mults (Index) < ContinuityRange) { |
62 | Split (NbSplit) = Index; |
63 | NbSplit++; |
64 | } |
65 | Index++; |
66 | } |
67 | Split (NbSplit) = Index; |
68 | splitIndexes = new HArray1OfInteger (1, NbSplit); |
69 | for (Standard_Integer i = 1; i <= NbSplit; i++) { |
70 | splitIndexes->SetValue (i, Split (i)); |
71 | } |
72 | } |
73 | } |
74 | } |
75 | |
76 | |
77 | |
78 | Standard_Integer Law_BSplineKnotSplitting::NbSplits () const { |
79 | |
80 | return splitIndexes->Length(); |
81 | } |
82 | |
83 | |
84 | Standard_Integer Law_BSplineKnotSplitting::SplitValue ( |
85 | |
86 | const Standard_Integer Index |
87 | |
88 | ) const { |
89 | |
90 | Standard_RangeError_Raise_if ( |
91 | Index < 1 || Index > splitIndexes->Length(), " "); |
92 | return splitIndexes->Value (Index); |
93 | } |
94 | |
95 | |
96 | |
97 | |
98 | void Law_BSplineKnotSplitting::Splitting ( |
99 | |
100 | Array1OfInteger& SplitValues |
101 | |
102 | ) const { |
103 | |
104 | for (Standard_Integer i = 1; i <= splitIndexes->Length(); i++){ |
105 | SplitValues (i) = splitIndexes->Value (i); |
106 | } |
107 | } |