b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
973c2be1 |
6 | // This library is free software; you can redistribute it and / or modify it |
7 | // under the terms of the GNU Lesser General Public version 2.1 as published |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
b311480e |
14 | |
7fd59977 |
15 | //Jean-Claude Vauthier 27 November 1991 |
16 | //Passage sur C1 Aout 1992 |
17 | |
18 | #include <Geom2dConvert_BSplineCurveKnotSplitting.ixx> |
19 | #include <Standard_RangeError.hxx> |
20 | |
21 | #include <BSplCLib.hxx> |
22 | |
23 | typedef Handle(Geom2d_BSplineCurve) Handle(BSplineCurve); |
24 | typedef TColStd_Array1OfInteger Array1OfInteger; |
25 | typedef TColStd_HArray1OfInteger HArray1OfInteger; |
26 | |
27 | |
28 | |
29 | |
30 | Geom2dConvert_BSplineCurveKnotSplitting:: |
31 | Geom2dConvert_BSplineCurveKnotSplitting ( |
32 | |
33 | const Handle(BSplineCurve)& BasisCurve, |
34 | const Standard_Integer ContinuityRange |
35 | |
36 | ) { |
37 | |
38 | |
39 | if (ContinuityRange < 0) Standard_RangeError::Raise(); |
40 | |
41 | Standard_Integer FirstIndex = BasisCurve->FirstUKnotIndex(); |
42 | Standard_Integer LastIndex = BasisCurve->LastUKnotIndex(); |
43 | |
44 | Standard_Integer Degree = BasisCurve->Degree(); |
45 | |
46 | if (ContinuityRange == 0) { |
47 | splitIndexes = new HArray1OfInteger (1, 2); |
48 | splitIndexes->SetValue (1, FirstIndex); |
49 | splitIndexes->SetValue (2, LastIndex); |
50 | } |
51 | else { |
52 | Standard_Integer NbKnots = BasisCurve->NbKnots(); |
53 | Array1OfInteger Mults (1, NbKnots); |
54 | BasisCurve->Multiplicities (Mults); |
55 | Standard_Integer Mmax = BSplCLib::MaxKnotMult (Mults, FirstIndex, LastIndex); |
56 | if (Degree - Mmax >= ContinuityRange) { |
57 | splitIndexes = new HArray1OfInteger (1, 2); |
58 | splitIndexes->SetValue (1, FirstIndex); |
59 | splitIndexes->SetValue (2, LastIndex); |
60 | } |
61 | else { |
62 | Array1OfInteger Split (1, LastIndex - FirstIndex + 1); |
63 | Standard_Integer NbSplit = 1; |
64 | Standard_Integer Index = FirstIndex; |
65 | Split (NbSplit) = Index; |
66 | Index++; |
67 | NbSplit++; |
68 | while (Index < LastIndex) { |
69 | if (Degree - Mults (Index) < ContinuityRange) { |
70 | Split (NbSplit) = Index; |
71 | NbSplit++; |
72 | } |
73 | Index++; |
74 | } |
75 | Split (NbSplit) = Index; |
76 | splitIndexes = new HArray1OfInteger (1, NbSplit); |
77 | for (Standard_Integer i = 1; i <= NbSplit; i++) { |
78 | splitIndexes->SetValue (i, Split (i)); |
79 | } |
80 | } |
81 | } |
82 | } |
83 | |
84 | |
85 | |
86 | Standard_Integer Geom2dConvert_BSplineCurveKnotSplitting::NbSplits () const { |
87 | |
88 | return splitIndexes->Length(); |
89 | } |
90 | |
91 | |
92 | Standard_Integer Geom2dConvert_BSplineCurveKnotSplitting::SplitValue ( |
93 | |
94 | const Standard_Integer Index |
95 | |
96 | ) const { |
97 | |
98 | Standard_RangeError_Raise_if ( |
99 | Index < 1 || Index > splitIndexes->Length(), " "); |
100 | return splitIndexes->Value (Index); |
101 | } |
102 | |
103 | |
104 | |
105 | |
106 | void Geom2dConvert_BSplineCurveKnotSplitting::Splitting ( |
107 | |
108 | Array1OfInteger& SplitValues |
109 | |
110 | ) const { |
111 | |
112 | for (Standard_Integer i = 1; i <= splitIndexes->Length(); i++){ |
113 | SplitValues (i) = splitIndexes->Value (i); |
114 | } |
115 | } |