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 | // |
d5f74e42 |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
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 | |
7fd59977 |
18 | #include <BSplCLib.hxx> |
42cf5bc1 |
19 | #include <Geom2d_BSplineCurve.hxx> |
20 | #include <Geom2dConvert_BSplineCurveKnotSplitting.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 | Geom2dConvert_BSplineCurveKnotSplitting:: |
28 | Geom2dConvert_BSplineCurveKnotSplitting ( |
29 | |
c04c30b3 |
30 | const Handle(Geom2d_BSplineCurve)& BasisCurve, |
7fd59977 |
31 | const Standard_Integer ContinuityRange |
32 | |
33 | ) { |
34 | |
35 | |
36 | if (ContinuityRange < 0) Standard_RangeError::Raise(); |
37 | |
38 | Standard_Integer FirstIndex = BasisCurve->FirstUKnotIndex(); |
39 | Standard_Integer LastIndex = BasisCurve->LastUKnotIndex(); |
40 | |
41 | Standard_Integer Degree = BasisCurve->Degree(); |
42 | |
43 | if (ContinuityRange == 0) { |
44 | splitIndexes = new HArray1OfInteger (1, 2); |
45 | splitIndexes->SetValue (1, FirstIndex); |
46 | splitIndexes->SetValue (2, LastIndex); |
47 | } |
48 | else { |
49 | Standard_Integer NbKnots = BasisCurve->NbKnots(); |
50 | Array1OfInteger Mults (1, NbKnots); |
51 | BasisCurve->Multiplicities (Mults); |
52 | Standard_Integer Mmax = BSplCLib::MaxKnotMult (Mults, FirstIndex, LastIndex); |
53 | if (Degree - Mmax >= ContinuityRange) { |
54 | splitIndexes = new HArray1OfInteger (1, 2); |
55 | splitIndexes->SetValue (1, FirstIndex); |
56 | splitIndexes->SetValue (2, LastIndex); |
57 | } |
58 | else { |
59 | Array1OfInteger Split (1, LastIndex - FirstIndex + 1); |
60 | Standard_Integer NbSplit = 1; |
61 | Standard_Integer Index = FirstIndex; |
62 | Split (NbSplit) = Index; |
63 | Index++; |
64 | NbSplit++; |
65 | while (Index < LastIndex) { |
66 | if (Degree - Mults (Index) < ContinuityRange) { |
67 | Split (NbSplit) = Index; |
68 | NbSplit++; |
69 | } |
70 | Index++; |
71 | } |
72 | Split (NbSplit) = Index; |
73 | splitIndexes = new HArray1OfInteger (1, NbSplit); |
74 | for (Standard_Integer i = 1; i <= NbSplit; i++) { |
75 | splitIndexes->SetValue (i, Split (i)); |
76 | } |
77 | } |
78 | } |
79 | } |
80 | |
81 | |
82 | |
83 | Standard_Integer Geom2dConvert_BSplineCurveKnotSplitting::NbSplits () const { |
84 | |
85 | return splitIndexes->Length(); |
86 | } |
87 | |
88 | |
89 | Standard_Integer Geom2dConvert_BSplineCurveKnotSplitting::SplitValue ( |
90 | |
91 | const Standard_Integer Index |
92 | |
93 | ) const { |
94 | |
95 | Standard_RangeError_Raise_if ( |
96 | Index < 1 || Index > splitIndexes->Length(), " "); |
97 | return splitIndexes->Value (Index); |
98 | } |
99 | |
100 | |
101 | |
102 | |
103 | void Geom2dConvert_BSplineCurveKnotSplitting::Splitting ( |
104 | |
105 | Array1OfInteger& SplitValues |
106 | |
107 | ) const { |
108 | |
109 | for (Standard_Integer i = 1; i <= splitIndexes->Length(); i++){ |
110 | SplitValues (i) = splitIndexes->Value (i); |
111 | } |
112 | } |