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