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. |
7fd59977 |
14 | |
42cf5bc1 |
15 | |
7fd59977 |
16 | #include <AppParCurves_HArray1OfMultiPoint.hxx> |
42cf5bc1 |
17 | #include <AppParCurves_MultiBSpCurve.hxx> |
18 | #include <AppParCurves_MultiCurve.hxx> |
7fd59977 |
19 | #include <BSplCLib.hxx> |
42cf5bc1 |
20 | #include <gp_Pnt.hxx> |
21 | #include <gp_Pnt2d.hxx> |
22 | #include <gp_Vec.hxx> |
23 | #include <gp_Vec2d.hxx> |
42cf5bc1 |
24 | #include <Standard_OutOfRange.hxx> |
25 | #include <TColgp_Array1OfPnt.hxx> |
26 | #include <TColgp_Array1OfPnt2d.hxx> |
7fd59977 |
27 | |
28 | //======================================================================= |
29 | //function : ComputeDegree |
30 | //purpose : |
31 | //======================================================================= |
7fd59977 |
32 | static Standard_Integer ComputeDegree(const TColStd_Array1OfInteger& mults, |
33 | const Standard_Integer nbPoles) |
34 | { |
35 | Standard_Integer i, sum = 0; |
36 | for (i = mults.Lower(); i <= mults.Upper(); i++) { |
37 | sum += mults(i); |
38 | } |
39 | return sum - nbPoles -1; |
40 | } |
41 | |
42 | //======================================================================= |
43 | //function : AppParCurves_MultiBSpCurve |
44 | //purpose : |
45 | //======================================================================= |
46 | |
d533dafb |
47 | AppParCurves_MultiBSpCurve::AppParCurves_MultiBSpCurve() |
48 | : myDegree(0) |
49 | { |
50 | } |
7fd59977 |
51 | |
52 | |
53 | //======================================================================= |
54 | //function : AppParCurves_MultiBSpCurve |
55 | //purpose : |
56 | //======================================================================= |
57 | |
58 | AppParCurves_MultiBSpCurve::AppParCurves_MultiBSpCurve |
59 | (const Standard_Integer NbPol): |
d533dafb |
60 | AppParCurves_MultiCurve(NbPol), |
61 | myDegree(0) |
7fd59977 |
62 | { |
63 | } |
64 | |
65 | |
66 | |
67 | //======================================================================= |
68 | //function : AppParCurves_MultiBSpCurve |
69 | //purpose : |
70 | //======================================================================= |
71 | |
72 | AppParCurves_MultiBSpCurve::AppParCurves_MultiBSpCurve |
73 | (const AppParCurves_Array1OfMultiPoint& tabMU, |
74 | const TColStd_Array1OfReal& Knots, |
75 | const TColStd_Array1OfInteger& Mults): |
76 | AppParCurves_MultiCurve(tabMU) |
77 | { |
78 | myknots = new TColStd_HArray1OfReal(Knots.Lower(), Knots.Upper()); |
79 | myknots->ChangeArray1() = Knots; |
80 | mymults = new TColStd_HArray1OfInteger(Mults.Lower(), Mults.Upper()); |
81 | mymults->ChangeArray1() = Mults; |
82 | myDegree = ComputeDegree(Mults,NbPoles()); |
83 | } |
84 | |
85 | |
86 | //======================================================================= |
87 | //function : AppParCurves_MultiBSpCurve |
88 | //purpose : |
89 | //======================================================================= |
90 | |
91 | AppParCurves_MultiBSpCurve::AppParCurves_MultiBSpCurve |
92 | (const AppParCurves_MultiCurve& SC, |
93 | const TColStd_Array1OfReal& Knots, |
94 | const TColStd_Array1OfInteger& Mults): |
95 | AppParCurves_MultiCurve(SC) |
96 | { |
97 | myknots = new TColStd_HArray1OfReal(Knots.Lower(), Knots.Upper()); |
98 | myknots->ChangeArray1() = Knots; |
99 | mymults = new TColStd_HArray1OfInteger(Mults.Lower(), Mults.Upper()); |
100 | mymults->ChangeArray1() = Mults; |
101 | myDegree = ComputeDegree(Mults,NbPoles()); |
102 | } |
103 | |
104 | |
105 | //======================================================================= |
106 | //function : SetKnots |
107 | //purpose : |
108 | //======================================================================= |
109 | |
110 | void AppParCurves_MultiBSpCurve::SetKnots(const TColStd_Array1OfReal& theKnots) |
111 | { |
112 | myknots = new TColStd_HArray1OfReal(theKnots.Lower(), theKnots.Upper()); |
113 | myknots->ChangeArray1() = theKnots; |
114 | } |
115 | |
116 | //======================================================================= |
117 | //function : SetMultiplicities |
118 | //purpose : |
119 | //======================================================================= |
120 | |
121 | void AppParCurves_MultiBSpCurve::SetMultiplicities(const TColStd_Array1OfInteger& theMults) |
122 | { |
123 | mymults = new TColStd_HArray1OfInteger(theMults.Lower(), theMults.Upper()); |
124 | mymults->ChangeArray1() = theMults; |
125 | myDegree = ComputeDegree(theMults,NbPoles()); |
126 | } |
127 | |
128 | |
129 | //======================================================================= |
130 | //function : Knots |
131 | //purpose : |
132 | //======================================================================= |
133 | |
134 | const TColStd_Array1OfReal& AppParCurves_MultiBSpCurve::Knots() const |
135 | { |
136 | return myknots->Array1(); |
137 | } |
138 | |
139 | //======================================================================= |
140 | //function : Multiplicities |
141 | //purpose : |
142 | //======================================================================= |
143 | |
144 | const TColStd_Array1OfInteger& AppParCurves_MultiBSpCurve::Multiplicities() const |
145 | { |
146 | return mymults->Array1(); |
147 | } |
148 | |
149 | |
150 | //======================================================================= |
151 | //function : Degree |
152 | //purpose : |
153 | //======================================================================= |
154 | |
155 | Standard_Integer AppParCurves_MultiBSpCurve::Degree() const |
156 | { |
157 | return myDegree; |
158 | } |
159 | |
160 | |
161 | //======================================================================= |
162 | //function : Value |
163 | //purpose : |
164 | //======================================================================= |
165 | |
166 | void AppParCurves_MultiBSpCurve::Value (const Standard_Integer CuIndex, |
167 | const Standard_Real U, gp_Pnt& Pt) const { |
168 | |
169 | if (Dimension(CuIndex) != 3) { |
9775fa61 |
170 | throw Standard_OutOfRange(); |
7fd59977 |
171 | } |
172 | |
173 | TColgp_Array1OfPnt TabPoles(1, tabPoint->Length()); |
174 | Curve(CuIndex, TabPoles); |
175 | |
176 | BSplCLib::D0(U,0,myDegree,Standard_False,TabPoles,BSplCLib::NoWeights(), |
0e14656b |
177 | myknots->Array1(),&mymults->Array1(),Pt); |
7fd59977 |
178 | } |
179 | |
180 | |
181 | //======================================================================= |
182 | //function : Value |
183 | //purpose : |
184 | //======================================================================= |
185 | |
186 | void AppParCurves_MultiBSpCurve::Value (const Standard_Integer CuIndex, |
187 | const Standard_Real U, gp_Pnt2d& Pt) const { |
188 | |
189 | if (Dimension(CuIndex) != 2) { |
9775fa61 |
190 | throw Standard_OutOfRange(); |
7fd59977 |
191 | } |
192 | |
193 | TColgp_Array1OfPnt2d TabPoles(1, tabPoint->Length()); |
194 | Curve(CuIndex, TabPoles); |
195 | |
196 | BSplCLib::D0(U,0,myDegree,Standard_False,TabPoles,BSplCLib::NoWeights(), |
0e14656b |
197 | myknots->Array1(),&mymults->Array1(),Pt); |
7fd59977 |
198 | } |
199 | |
200 | |
201 | //======================================================================= |
202 | //function : D1 |
203 | //purpose : |
204 | //======================================================================= |
205 | |
206 | void AppParCurves_MultiBSpCurve::D1 (const Standard_Integer CuIndex, |
207 | const Standard_Real U, gp_Pnt& Pt, gp_Vec& V1) const { |
208 | if (Dimension(CuIndex) != 3) { |
9775fa61 |
209 | throw Standard_OutOfRange(); |
7fd59977 |
210 | } |
211 | |
212 | TColgp_Array1OfPnt TabPoles(1, tabPoint->Length()); |
213 | Curve(CuIndex, TabPoles); |
214 | |
215 | BSplCLib::D1(U,0,myDegree,Standard_False,TabPoles,BSplCLib::NoWeights(), |
0e14656b |
216 | myknots->Array1(),&mymults->Array1(),Pt,V1); |
7fd59977 |
217 | } |
218 | |
219 | |
220 | //======================================================================= |
221 | //function : D2 |
222 | //purpose : |
223 | //======================================================================= |
224 | |
225 | void AppParCurves_MultiBSpCurve::D2 (const Standard_Integer CuIndex, |
226 | const Standard_Real U, |
227 | gp_Pnt& Pt, |
228 | gp_Vec& V1, |
229 | gp_Vec& V2) const { |
230 | if (Dimension(CuIndex) != 3) { |
9775fa61 |
231 | throw Standard_OutOfRange(); |
7fd59977 |
232 | } |
233 | |
234 | TColgp_Array1OfPnt TabPoles(1, tabPoint->Length()); |
235 | Curve(CuIndex, TabPoles); |
236 | |
237 | BSplCLib::D2(U,0,myDegree,Standard_False,TabPoles,BSplCLib::NoWeights(), |
0e14656b |
238 | myknots->Array1(),&mymults->Array1(),Pt,V1,V2); |
7fd59977 |
239 | } |
240 | |
241 | |
242 | //======================================================================= |
243 | //function : D1 |
244 | //purpose : |
245 | //======================================================================= |
246 | |
247 | void AppParCurves_MultiBSpCurve::D1 (const Standard_Integer CuIndex, |
248 | const Standard_Real U, gp_Pnt2d& Pt, gp_Vec2d& V1) const { |
249 | if (Dimension(CuIndex) != 2) { |
9775fa61 |
250 | throw Standard_OutOfRange(); |
7fd59977 |
251 | } |
252 | |
253 | TColgp_Array1OfPnt2d TabPoles(1, tabPoint->Length()); |
254 | Curve(CuIndex, TabPoles); |
255 | |
256 | BSplCLib::D1(U,0,myDegree,Standard_False,TabPoles,BSplCLib::NoWeights(), |
0e14656b |
257 | myknots->Array1(),&mymults->Array1(),Pt,V1); |
7fd59977 |
258 | } |
259 | |
260 | |
261 | //======================================================================= |
262 | //function : D2 |
263 | //purpose : |
264 | //======================================================================= |
265 | |
266 | void AppParCurves_MultiBSpCurve::D2 (const Standard_Integer CuIndex, |
267 | const Standard_Real U, |
268 | gp_Pnt2d& Pt, |
269 | gp_Vec2d& V1, |
270 | gp_Vec2d& V2) const { |
271 | if (Dimension(CuIndex) != 2) { |
9775fa61 |
272 | throw Standard_OutOfRange(); |
7fd59977 |
273 | } |
274 | |
275 | TColgp_Array1OfPnt2d TabPoles(1, tabPoint->Length()); |
276 | Curve(CuIndex, TabPoles); |
277 | |
278 | BSplCLib::D2(U,0,myDegree,Standard_False,TabPoles,BSplCLib::NoWeights(), |
0e14656b |
279 | myknots->Array1(),&mymults->Array1(),Pt,V1,V2); |
7fd59977 |
280 | } |
281 | |
282 | |
283 | |
284 | //======================================================================= |
285 | //function : Dump |
286 | //purpose : |
287 | //======================================================================= |
288 | |
289 | void AppParCurves_MultiBSpCurve::Dump(Standard_OStream& o) const |
290 | { |
04232180 |
291 | o << "AppParCurves_MultiBSpCurve dump:" << std::endl; |
292 | o << " It contains " << NbCurves() << " BSpline curves "<< std::endl; |
293 | o << " The poles are: " << std::endl; |
7fd59977 |
294 | /* for (Standard_Integer i = 1; i <= NbCurves(); i++) { |
04232180 |
295 | o << " Curve No. " << i << std::endl; |
7fd59977 |
296 | if (Dimension(i) == 3) { |
297 | for (Standard_Integer j = 1; j <= tabPoint->Length(); j++) { |
04232180 |
298 | o << " Pole No. " << j << ": " << std::endl; |
299 | o << " Pole x = " << (tabPoint->Value(j)->Point(i)).X() << std::endl; |
300 | o << " Pole y = " << (tabPoint->Value(j)->Point(i)).Y() << std::endl; |
301 | o << " Pole z = " << (tabPoint->Value(j)->Point(i)).Z() << std::endl; |
7fd59977 |
302 | } |
303 | } |
304 | else { |
305 | for (Standard_Integer j = 1; j <= tabPoint->Length(); j++) { |
04232180 |
306 | o << " Pole No. " << j << ": " << std::endl; |
307 | o << " Pole x = " << (tabPoint->Value(j)->Point2d(i)).X() << std::endl; |
308 | o << " Pole y = " << (tabPoint->Value(j)->Point2d(i)).Y() << std::endl; |
7fd59977 |
309 | } |
310 | } |
311 | } |
312 | */ |
313 | } |
314 | |
315 | |
316 | |