b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
2 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
3 | // |
4 | // The content of this file is subject to the Open CASCADE Technology Public |
5 | // License Version 6.5 (the "License"). You may not use the content of this file |
6 | // except in compliance with the License. Please obtain a copy of the License |
7 | // at http://www.opencascade.org and read it completely before using this file. |
8 | // |
9 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
10 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
11 | // |
12 | // The Original Code and all software distributed under the License is |
13 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
14 | // Initial Developer hereby disclaims all such warranties, including without |
15 | // limitation, any warranties of merchantability, fitness for a particular |
16 | // purpose or non-infringement. Please see the License for the specific terms |
17 | // and conditions governing the rights and limitations under the License. |
18 | |
0d969553 |
19 | |
7fd59977 |
20 | |
21 | #include <AppParCurves_MultiCurve.ixx> |
22 | #include <TColgp_Array1OfPnt.hxx> |
23 | #include <TColgp_Array1OfPnt2d.hxx> |
24 | #include <Standard_OutOfRange.hxx> |
25 | #include <BSplCLib.hxx> |
26 | #include <PLib.hxx> |
27 | |
28 | |
29 | AppParCurves_MultiCurve::AppParCurves_MultiCurve() {} |
30 | |
31 | |
32 | AppParCurves_MultiCurve::AppParCurves_MultiCurve (const Standard_Integer NbPol) |
33 | { |
34 | tabPoint = new AppParCurves_HArray1OfMultiPoint(1, NbPol); |
35 | } |
36 | |
37 | |
38 | |
39 | AppParCurves_MultiCurve::AppParCurves_MultiCurve (const AppParCurves_Array1OfMultiPoint& tabMU) |
40 | { |
41 | tabPoint = new AppParCurves_HArray1OfMultiPoint(1, tabMU.Length()); |
42 | Standard_Integer i, Lower = tabMU.Lower(); |
43 | for (i = 1; i <= tabMU.Length(); i++) { |
44 | tabPoint->SetValue(i, tabMU.Value(Lower+i-1)); |
45 | } |
46 | |
47 | } |
48 | |
49 | void AppParCurves_MultiCurve::Delete() |
50 | {} |
51 | |
52 | Standard_Integer AppParCurves_MultiCurve::Dimension (const Standard_Integer Index) const { |
53 | Standard_Integer Lo = tabPoint->Lower(); |
54 | Standard_Integer nb = tabPoint->Value(Lo).NbPoints() + tabPoint->Value(Lo).NbPoints2d(); |
55 | if ((Index <= 0) || (Index > nb)) { |
56 | Standard_OutOfRange::Raise(); |
57 | } |
58 | return tabPoint->Value(Lo).Dimension(Index); |
59 | } |
60 | |
61 | |
62 | Standard_Integer AppParCurves_MultiCurve::NbCurves () const { |
63 | if (tabPoint.IsNull()) |
64 | return 0; |
65 | AppParCurves_MultiPoint MP = tabPoint->Value(1); |
66 | return MP.NbPoints() + MP.NbPoints2d(); |
67 | } |
68 | |
69 | |
70 | Standard_Integer AppParCurves_MultiCurve::NbPoles() const { |
71 | if (tabPoint.IsNull()) |
72 | return 0; |
73 | return tabPoint->Length(); |
74 | } |
75 | |
76 | |
77 | Standard_Integer AppParCurves_MultiCurve::Degree() const { |
78 | return tabPoint->Length()-1; |
79 | } |
80 | |
81 | |
82 | void AppParCurves_MultiCurve::SetNbPoles(const Standard_Integer nbPoles) |
83 | { |
84 | tabPoint = new AppParCurves_HArray1OfMultiPoint(1, nbPoles); |
85 | } |
86 | |
87 | |
88 | void AppParCurves_MultiCurve::SetValue (const Standard_Integer Index, |
89 | const AppParCurves_MultiPoint& MPoint) { |
90 | |
91 | if ((Index <= 0) || (Index > tabPoint->Length())) { |
92 | Standard_OutOfRange::Raise(); |
93 | } |
94 | tabPoint->SetValue(Index, MPoint); |
95 | } |
96 | |
97 | |
98 | void AppParCurves_MultiCurve::Curve (const Standard_Integer CuIndex, |
99 | TColgp_Array1OfPnt& TabPnt) const { |
100 | if ((CuIndex <= 0)) { |
101 | Standard_OutOfRange::Raise(); |
102 | } |
103 | for ( Standard_Integer i = 1; i <= tabPoint->Length(); i++) { |
104 | TabPnt(i) = tabPoint->Value(i).Point(CuIndex); |
105 | } |
106 | } |
107 | |
108 | |
109 | void AppParCurves_MultiCurve::Curve (const Standard_Integer CuIndex, |
110 | TColgp_Array1OfPnt2d& TabPnt2d) const { |
111 | if ((CuIndex <= 0)) { |
112 | Standard_OutOfRange::Raise(); |
113 | } |
114 | for ( Standard_Integer i = 1; i <= tabPoint->Length(); i++) { |
115 | TabPnt2d(i) = tabPoint->Value(i).Point2d(CuIndex); |
116 | } |
117 | } |
118 | |
119 | |
120 | |
121 | const gp_Pnt& AppParCurves_MultiCurve::Pole(const Standard_Integer CuIndex, |
122 | const Standard_Integer Nieme) const |
123 | { |
124 | if ((CuIndex <= 0) && Nieme <= 0) { |
125 | Standard_OutOfRange::Raise(); |
126 | } |
127 | return tabPoint->Value(Nieme).Point(CuIndex); |
128 | } |
129 | |
130 | const gp_Pnt2d& AppParCurves_MultiCurve::Pole2d(const Standard_Integer CuIndex, |
131 | const Standard_Integer Nieme)const |
132 | { |
133 | if ((CuIndex <= 0) && Nieme <= 0) { |
134 | Standard_OutOfRange::Raise(); |
135 | } |
136 | return tabPoint->Value(Nieme).Point2d(CuIndex); |
137 | } |
138 | |
139 | |
140 | |
141 | const AppParCurves_MultiPoint& AppParCurves_MultiCurve::Value (const Standard_Integer Index) const { |
142 | if ((Index <= 0) || (Index > tabPoint->Length())) { |
143 | Standard_OutOfRange::Raise(); |
144 | } |
145 | return tabPoint->Value(Index); |
146 | } |
147 | |
148 | void AppParCurves_MultiCurve::Transform(const Standard_Integer CuIndex, |
149 | const Standard_Real x, |
150 | const Standard_Real dx, |
151 | const Standard_Real y, |
152 | const Standard_Real dy, |
153 | const Standard_Real z, |
154 | const Standard_Real dz) |
155 | { |
156 | if (Dimension(CuIndex) != 3) Standard_OutOfRange::Raise(); |
157 | |
158 | for (Standard_Integer i = 1 ; i <= tabPoint->Length(); i++) { |
159 | (tabPoint->ChangeValue(i)).Transform(CuIndex, x, dx, y, dy, z, dz); |
160 | } |
161 | } |
162 | |
163 | void AppParCurves_MultiCurve::Transform2d(const Standard_Integer CuIndex, |
164 | const Standard_Real x, |
165 | const Standard_Real dx, |
166 | const Standard_Real y, |
167 | const Standard_Real dy) |
168 | { |
169 | if (Dimension(CuIndex) != 2) Standard_OutOfRange::Raise(); |
170 | |
171 | for (Standard_Integer i = 1 ; i <= tabPoint->Length(); i++) { |
172 | (tabPoint->ChangeValue(i)).Transform2d(CuIndex, x, dx, y, dy); |
173 | } |
174 | } |
175 | |
176 | |
177 | void AppParCurves_MultiCurve::Value (const Standard_Integer CuIndex, |
178 | const Standard_Real U, gp_Pnt& Pt) const { |
179 | |
180 | if (Dimension(CuIndex) != 3)Standard_OutOfRange::Raise(); |
181 | |
182 | TColgp_Array1OfPnt TabPoles(1, tabPoint->Length()); |
183 | |
184 | for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) { |
185 | TabPoles(i) = tabPoint->Value(i).Point(CuIndex); |
186 | } |
187 | |
188 | BSplCLib::D0 (U, TabPoles,PLib::NoWeights(), Pt); |
189 | } |
190 | |
191 | |
192 | void AppParCurves_MultiCurve::Value (const Standard_Integer CuIndex, |
193 | const Standard_Real U, gp_Pnt2d& Pt) const { |
194 | if (Dimension(CuIndex) != 2) { |
195 | Standard_OutOfRange::Raise(); |
196 | } |
197 | |
198 | TColgp_Array1OfPnt2d TabPole(1, tabPoint->Length()); |
199 | |
200 | for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) { |
201 | TabPole(i) = tabPoint->Value(i).Point2d(CuIndex); |
202 | } |
203 | |
204 | BSplCLib::D0 (U, TabPole, PLib::NoWeights(), Pt); |
205 | } |
206 | |
207 | |
208 | void AppParCurves_MultiCurve::D1 (const Standard_Integer CuIndex, |
209 | const Standard_Real U, |
210 | gp_Pnt& Pt, |
211 | gp_Vec& V1) const { |
212 | |
213 | if (Dimension(CuIndex) != 3) { |
214 | Standard_OutOfRange::Raise(); |
215 | } |
216 | |
217 | TColgp_Array1OfPnt TabPole(1, tabPoint->Length()); |
218 | |
219 | for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) { |
220 | TabPole(i) = tabPoint->Value(i).Point(CuIndex); |
221 | } |
222 | |
223 | BSplCLib::D1 (U, TabPole, PLib::NoWeights(), Pt, V1); |
224 | } |
225 | |
226 | |
227 | void AppParCurves_MultiCurve::D2 (const Standard_Integer CuIndex, |
228 | const Standard_Real U, |
229 | gp_Pnt& Pt, |
230 | gp_Vec& V1, |
231 | gp_Vec& V2) const { |
232 | |
233 | if (Dimension(CuIndex) != 3) { |
234 | Standard_OutOfRange::Raise(); |
235 | } |
236 | |
237 | TColgp_Array1OfPnt TabPole(1, tabPoint->Length()); |
238 | |
239 | for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) { |
240 | TabPole(i) = tabPoint->Value(i).Point(CuIndex); |
241 | } |
242 | |
243 | BSplCLib::D2 (U, TabPole, PLib::NoWeights(), Pt, V1, V2); |
244 | } |
245 | |
246 | |
247 | void AppParCurves_MultiCurve::D1 (const Standard_Integer CuIndex, |
248 | const Standard_Real U, gp_Pnt2d& Pt, gp_Vec2d& V1) const { |
249 | |
250 | if (Dimension(CuIndex) != 2) { |
251 | Standard_OutOfRange::Raise(); |
252 | } |
253 | |
254 | TColgp_Array1OfPnt2d TabPole(1, tabPoint->Length()); |
255 | |
256 | for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) { |
257 | TabPole(i) = tabPoint->Value(i).Point2d(CuIndex); |
258 | } |
259 | |
260 | BSplCLib::D1 (U, TabPole, PLib::NoWeights(), Pt, V1); |
261 | } |
262 | |
263 | |
264 | void AppParCurves_MultiCurve::D2 (const Standard_Integer CuIndex, |
265 | const Standard_Real U, |
266 | gp_Pnt2d& Pt, |
267 | gp_Vec2d& V1, |
268 | gp_Vec2d& V2) const { |
269 | |
270 | if (Dimension(CuIndex) != 2) { |
271 | Standard_OutOfRange::Raise(); |
272 | } |
273 | |
274 | TColgp_Array1OfPnt2d TabPole(1, tabPoint->Length()); |
275 | |
276 | for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) { |
277 | TabPole(i) = tabPoint->Value(i).Point2d(CuIndex); |
278 | } |
279 | |
280 | BSplCLib::D2(U, TabPole, PLib::NoWeights(), Pt, V1, V2); |
281 | } |
282 | |
283 | |
284 | |
285 | void AppParCurves_MultiCurve::Dump(Standard_OStream& o) const |
286 | { |
287 | o << "AppParCurves_MultiCurve dump:" << endl; |
288 | o << " It contains " << NbCurves() << " Bezier curves of degree " << tabPoint->Length()-1 << endl; |
289 | o << " The poles are: " << endl; |
290 | /* for (Standard_Integer i = 1; i <= NbCurves(); i++) { |
291 | o << " Curve No. " << i << endl; |
292 | if (Dimension(i) == 3) { |
293 | for (Standard_Integer j = 1; j <= tabPoint->Length(); j++) { |
294 | o << " Pole No. " << j << ": " << endl; |
295 | o << " Pole x = " << (tabPoint->Value(j)->Point(i)).X() << endl; |
296 | o << " Pole y = " << (tabPoint->Value(j)->Point(i)).Y() << endl; |
297 | o << " Pole z = " << (tabPoint->Value(j)->Point(i)).Z() << endl; |
298 | } |
299 | } |
300 | else { |
301 | for (Standard_Integer j = 1; j <= tabPoint->Length(); j++) { |
302 | o << " Pole No. " << j << ": " << endl; |
303 | o << " Pole x = " << (tabPoint->Value(j)->Point2d(i)).X() << endl; |
304 | o << " Pole y = " << (tabPoint->Value(j)->Point2d(i)).Y() << endl; |
305 | } |
306 | } |
307 | } |
308 | */ |
309 | } |