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