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 28 Novembre 1991 |
16 | //Passage sur C1 Aout 1992 |
17 | |
7fd59977 |
18 | #include <BSplCLib.hxx> |
42cf5bc1 |
19 | #include <Geom_BSplineSurface.hxx> |
20 | #include <GeomConvert_BSplineSurfaceKnotSplitting.hxx> |
21 | #include <Standard_DimensionError.hxx> |
22 | #include <Standard_RangeError.hxx> |
c04c30b3 |
23 | |
7fd59977 |
24 | typedef TColStd_Array1OfInteger Array1OfInteger; |
25 | typedef TColStd_HArray1OfInteger HArray1OfInteger; |
26 | |
7fd59977 |
27 | GeomConvert_BSplineSurfaceKnotSplitting:: |
28 | GeomConvert_BSplineSurfaceKnotSplitting ( |
29 | |
c04c30b3 |
30 | const Handle(Geom_BSplineSurface)& BasisSurface, |
7fd59977 |
31 | const Standard_Integer UContinuityRange, |
32 | const Standard_Integer VContinuityRange |
33 | |
34 | ) { |
35 | |
36 | |
37 | if (UContinuityRange < 0 || VContinuityRange < 0) { |
9775fa61 |
38 | throw Standard_RangeError(); |
7fd59977 |
39 | } |
40 | |
41 | Standard_Integer FirstUIndex = BasisSurface->FirstUKnotIndex (); |
42 | Standard_Integer LastUIndex = BasisSurface->LastUKnotIndex (); |
43 | Standard_Integer FirstVIndex = BasisSurface->FirstVKnotIndex (); |
44 | Standard_Integer LastVIndex = BasisSurface->LastVKnotIndex (); |
45 | Standard_Integer UDegree = BasisSurface->UDegree (); |
46 | Standard_Integer VDegree = BasisSurface->VDegree (); |
47 | Standard_Integer i; |
48 | |
49 | |
50 | |
51 | if (UContinuityRange == 0) { |
52 | usplitIndexes = new HArray1OfInteger (1, 2); |
53 | usplitIndexes->SetValue (1, FirstUIndex); |
54 | usplitIndexes->SetValue (2, LastUIndex); |
55 | } |
56 | else { |
57 | Standard_Integer NbUKnots = BasisSurface->NbUKnots(); |
58 | Array1OfInteger UMults (1, NbUKnots); |
59 | BasisSurface->UMultiplicities (UMults); |
60 | Standard_Integer Mmax = BSplCLib::MaxKnotMult (UMults, FirstUIndex, LastUIndex); |
61 | if (UDegree - Mmax >= UContinuityRange) { |
62 | usplitIndexes = new HArray1OfInteger (1, 2); |
63 | usplitIndexes->SetValue (1, FirstUIndex); |
64 | usplitIndexes->SetValue (2, LastUIndex); |
65 | } |
66 | else { |
67 | Array1OfInteger USplit (1, LastUIndex - FirstUIndex + 1); |
68 | Standard_Integer NbUSplit = 1; |
69 | Standard_Integer UIndex = FirstUIndex; |
70 | USplit (NbUSplit) = UIndex; |
71 | UIndex++; |
72 | NbUSplit++; |
73 | while (UIndex < LastUIndex) { |
74 | if (UDegree - UMults(UIndex) < UContinuityRange) { |
75 | USplit (NbUSplit) = UIndex; |
76 | NbUSplit++; |
77 | } |
78 | UIndex++; |
79 | } |
80 | USplit (NbUSplit) = UIndex; |
81 | usplitIndexes = new HArray1OfInteger (1, NbUSplit); |
82 | for (i = 1; i <= NbUSplit; i++) { |
83 | usplitIndexes->SetValue (i, USplit (i)); |
84 | } |
85 | } |
86 | } |
87 | |
88 | |
89 | |
90 | if (VContinuityRange == 0) { |
91 | vsplitIndexes = new HArray1OfInteger (1, 2); |
92 | vsplitIndexes->SetValue (1, FirstVIndex); |
93 | vsplitIndexes->SetValue (2, LastVIndex); |
94 | } |
95 | else { |
96 | Standard_Integer NbVKnots = BasisSurface->NbVKnots(); |
97 | Array1OfInteger VMults (1, NbVKnots); |
98 | BasisSurface->VMultiplicities (VMults); |
99 | Standard_Integer Mmax = BSplCLib::MaxKnotMult (VMults, FirstVIndex, LastVIndex); |
100 | if (VDegree - Mmax >= VContinuityRange) { |
101 | usplitIndexes = new HArray1OfInteger (1, 2); |
102 | usplitIndexes->SetValue (1, FirstVIndex); |
103 | usplitIndexes->SetValue (2, LastVIndex); |
104 | } |
105 | else { |
106 | Array1OfInteger VSplit (1, LastVIndex - FirstVIndex + 1); |
107 | Standard_Integer NbVSplit = 1; |
108 | Standard_Integer VIndex = FirstVIndex; |
109 | VSplit (NbVSplit) = VIndex; |
110 | VIndex++; |
111 | NbVSplit++; |
112 | while (VIndex < LastVIndex) { |
113 | if (VDegree - VMults (VIndex) < VContinuityRange) { |
114 | VSplit (NbVSplit) = VIndex; |
115 | NbVSplit++; |
116 | } |
117 | VIndex++; |
118 | } |
119 | VSplit (NbVSplit) = VIndex; |
120 | vsplitIndexes = new HArray1OfInteger (1, NbVSplit); |
121 | for (i = 1; i <= NbVSplit; i++) { |
122 | vsplitIndexes->SetValue (i, VSplit (i)); |
123 | } |
124 | } |
125 | } |
126 | } |
127 | |
128 | |
129 | |
130 | Standard_Integer GeomConvert_BSplineSurfaceKnotSplitting::NbUSplits () const { |
131 | return usplitIndexes->Length(); |
132 | } |
133 | |
134 | |
135 | Standard_Integer GeomConvert_BSplineSurfaceKnotSplitting::NbVSplits () const { |
136 | return vsplitIndexes->Length(); |
137 | } |
138 | |
139 | |
140 | Standard_Integer GeomConvert_BSplineSurfaceKnotSplitting::USplitValue ( |
141 | |
142 | const Standard_Integer UIndex |
143 | |
144 | ) const { |
145 | |
146 | Standard_RangeError_Raise_if ( |
147 | UIndex < 1 || UIndex > usplitIndexes->Length(), " "); |
148 | return usplitIndexes->Value (UIndex); |
149 | } |
150 | |
151 | |
152 | |
153 | Standard_Integer GeomConvert_BSplineSurfaceKnotSplitting::VSplitValue ( |
154 | |
155 | const Standard_Integer VIndex |
156 | |
157 | ) const { |
158 | |
159 | Standard_RangeError_Raise_if ( |
160 | VIndex < 1 || VIndex > vsplitIndexes->Length(), " "); |
161 | return vsplitIndexes->Value (VIndex); |
162 | } |
163 | |
164 | |
165 | void GeomConvert_BSplineSurfaceKnotSplitting::Splitting ( |
166 | |
167 | Array1OfInteger& USplit, |
168 | Array1OfInteger& VSplit |
169 | |
170 | ) const { |
171 | Standard_Integer i ; |
172 | for ( i = 1; i <= usplitIndexes->Length(); i++){ |
173 | USplit (i) = usplitIndexes->Value (i); |
174 | } |
175 | for (i = 1; i <= vsplitIndexes->Length(); i++){ |
176 | VSplit (i) = vsplitIndexes->Value (i); |
177 | } |
178 | } |