Warnings on vc14 were eliminated
[occt.git] / src / AppParCurves / AppParCurves_MultiCurve.cxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
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
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.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15
16 #include <AppParCurves_MultiCurve.hxx>
17 #include <AppParCurves_MultiPoint.hxx>
18 #include <BSplCLib.hxx>
19 #include <gp_Pnt.hxx>
20 #include <gp_Pnt2d.hxx>
21 #include <gp_Vec.hxx>
22 #include <gp_Vec2d.hxx>
23 #include <PLib.hxx>
24 #include <Standard_ConstructionError.hxx>
25 #include <Standard_DimensionError.hxx>
26 #include <Standard_OutOfRange.hxx>
27 #include <TColgp_Array1OfPnt.hxx>
28 #include <TColgp_Array1OfPnt2d.hxx>
29
30 AppParCurves_MultiCurve::AppParCurves_MultiCurve() {}
31
32
33 AppParCurves_MultiCurve::AppParCurves_MultiCurve (const Standard_Integer NbPol) 
34 {
35   tabPoint = new AppParCurves_HArray1OfMultiPoint(1, NbPol);
36 }
37
38
39
40 AppParCurves_MultiCurve::AppParCurves_MultiCurve (const AppParCurves_Array1OfMultiPoint& tabMU)
41 {
42   tabPoint = new AppParCurves_HArray1OfMultiPoint(1, tabMU.Length());
43   Standard_Integer i, Lower = tabMU.Lower();
44   for (i = 1; i <= tabMU.Length(); i++) {
45     tabPoint->SetValue(i, tabMU.Value(Lower+i-1));
46   }
47
48 }
49
50 AppParCurves_MultiCurve::~AppParCurves_MultiCurve()
51 {
52 }
53
54 Standard_Integer AppParCurves_MultiCurve::Dimension (const Standard_Integer Index) const {
55   Standard_Integer Lo = tabPoint->Lower();
56   Standard_Integer nb = tabPoint->Value(Lo).NbPoints() + tabPoint->Value(Lo).NbPoints2d();
57   if ((Index <= 0) || (Index > nb)) {
58     throw Standard_OutOfRange();
59   }
60   return tabPoint->Value(Lo).Dimension(Index);
61 }
62
63
64 Standard_Integer AppParCurves_MultiCurve::NbCurves () const {
65   if (tabPoint.IsNull())
66     return 0;
67   AppParCurves_MultiPoint MP = tabPoint->Value(1);
68   return MP.NbPoints() + MP.NbPoints2d();
69 }
70
71
72 Standard_Integer AppParCurves_MultiCurve::NbPoles() const {
73   if (tabPoint.IsNull())
74     return 0;
75   return tabPoint->Length();
76 }
77
78
79 Standard_Integer AppParCurves_MultiCurve::Degree() const {
80   return tabPoint->Length()-1;
81 }
82
83
84 void AppParCurves_MultiCurve::SetNbPoles(const Standard_Integer nbPoles) 
85 {
86   tabPoint = new AppParCurves_HArray1OfMultiPoint(1, nbPoles);
87 }
88
89
90 void AppParCurves_MultiCurve::SetValue (const Standard_Integer Index, 
91                                   const AppParCurves_MultiPoint& MPoint) {
92
93   if ((Index <= 0) || (Index > tabPoint->Length())) {
94     throw Standard_OutOfRange();
95   }
96   tabPoint->SetValue(Index, MPoint);
97 }
98
99
100 void AppParCurves_MultiCurve::Curve (const Standard_Integer CuIndex,
101                                TColgp_Array1OfPnt& TabPnt) const {
102   if ((CuIndex <= 0)) {
103     throw Standard_OutOfRange();
104   }
105   for ( Standard_Integer i = 1; i <= tabPoint->Length(); i++) {
106     TabPnt(i) = tabPoint->Value(i).Point(CuIndex);
107   }
108 }
109
110
111 void AppParCurves_MultiCurve::Curve (const Standard_Integer CuIndex,
112                                TColgp_Array1OfPnt2d& TabPnt2d) const {
113   if ((CuIndex <= 0)) {
114     throw Standard_OutOfRange();
115   }
116   for ( Standard_Integer i = 1; i <= tabPoint->Length(); i++) {
117     TabPnt2d(i) = tabPoint->Value(i).Point2d(CuIndex);
118   }
119 }
120
121
122
123 const gp_Pnt& AppParCurves_MultiCurve::Pole(const Standard_Integer CuIndex,
124                                             const Standard_Integer Nieme) const
125 {
126   if ((CuIndex <= 0) && Nieme <= 0) {
127     throw Standard_OutOfRange();
128   }
129   return tabPoint->Value(Nieme).Point(CuIndex);
130 }
131
132 const gp_Pnt2d& AppParCurves_MultiCurve::Pole2d(const Standard_Integer CuIndex,
133                                             const Standard_Integer Nieme)const
134 {
135   if ((CuIndex <= 0) && Nieme <= 0) {
136     throw Standard_OutOfRange();
137   }
138   return tabPoint->Value(Nieme).Point2d(CuIndex);
139 }
140
141
142
143 const AppParCurves_MultiPoint& AppParCurves_MultiCurve::Value (const Standard_Integer Index) const {
144   if ((Index <= 0) || (Index > tabPoint->Length())) {
145     throw Standard_OutOfRange();
146   }
147   return tabPoint->Value(Index);
148 }
149
150 void AppParCurves_MultiCurve::Transform(const Standard_Integer CuIndex,
151                                         const Standard_Real    x,
152                                         const Standard_Real    dx,
153                                         const Standard_Real    y,
154                                         const Standard_Real    dy,
155                                         const Standard_Real    z,
156                                         const Standard_Real    dz) 
157 {
158   if (Dimension(CuIndex) != 3) throw Standard_OutOfRange();
159
160   for (Standard_Integer i = 1 ; i <= tabPoint->Length(); i++) {
161     (tabPoint->ChangeValue(i)).Transform(CuIndex, x, dx, y, dy, z, dz);
162   } 
163 }
164
165 void AppParCurves_MultiCurve::Transform2d(const Standard_Integer CuIndex,
166                                           const Standard_Real    x,
167                                           const Standard_Real    dx,
168                                           const Standard_Real    y,
169                                           const Standard_Real    dy) 
170 {
171   if (Dimension(CuIndex) != 2) throw Standard_OutOfRange();
172
173   for (Standard_Integer i = 1 ; i <= tabPoint->Length(); i++) {
174     (tabPoint->ChangeValue(i)).Transform2d(CuIndex, x, dx, y, dy);
175   } 
176 }
177
178
179 void AppParCurves_MultiCurve::Value (const Standard_Integer CuIndex, 
180                               const Standard_Real U, gp_Pnt& Pt) const {
181   
182   if (Dimension(CuIndex) != 3)throw Standard_OutOfRange();
183
184   TColgp_Array1OfPnt TabPoles(1, tabPoint->Length());
185   
186   for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) {
187     TabPoles(i) = tabPoint->Value(i).Point(CuIndex);
188   } 
189   
190   BSplCLib::D0 (U, TabPoles,BSplCLib::NoWeights(), Pt);
191 }
192
193
194 void AppParCurves_MultiCurve::Value (const Standard_Integer CuIndex, 
195                               const Standard_Real U, gp_Pnt2d& Pt) const {
196   if (Dimension(CuIndex) != 2) {
197     throw Standard_OutOfRange();
198   }
199
200   TColgp_Array1OfPnt2d TabPole(1, tabPoint->Length());
201
202   for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) {
203     TabPole(i) = tabPoint->Value(i).Point2d(CuIndex);
204   }
205   
206   BSplCLib::D0 (U, TabPole, BSplCLib::NoWeights(), Pt);
207 }
208
209
210 void AppParCurves_MultiCurve::D1 (const Standard_Integer CuIndex, 
211                                   const Standard_Real U, 
212                                   gp_Pnt& Pt, 
213                                   gp_Vec& V1) const {
214
215   if (Dimension(CuIndex) != 3) {
216     throw Standard_OutOfRange();
217   }
218
219   TColgp_Array1OfPnt TabPole(1, tabPoint->Length());
220
221   for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) {
222     TabPole(i) = tabPoint->Value(i).Point(CuIndex);
223   }
224
225   BSplCLib::D1 (U, TabPole, BSplCLib::NoWeights(), Pt, V1);
226 }
227
228
229 void AppParCurves_MultiCurve::D2 (const Standard_Integer CuIndex, 
230                             const Standard_Real U, 
231                             gp_Pnt& Pt,
232                             gp_Vec& V1,
233                             gp_Vec& V2) const {
234
235   if (Dimension(CuIndex) != 3) {
236     throw Standard_OutOfRange();
237   }
238
239   TColgp_Array1OfPnt TabPole(1, tabPoint->Length());
240
241   for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) {
242     TabPole(i) = tabPoint->Value(i).Point(CuIndex);
243   }
244
245   BSplCLib::D2 (U, TabPole, BSplCLib::NoWeights(), Pt, V1, V2);
246 }
247
248
249 void AppParCurves_MultiCurve::D1 (const Standard_Integer CuIndex,
250                        const Standard_Real U, gp_Pnt2d& Pt, gp_Vec2d& V1) const {
251
252   if (Dimension(CuIndex) != 2) {
253     throw Standard_OutOfRange();
254   }
255
256   TColgp_Array1OfPnt2d TabPole(1, tabPoint->Length());
257
258   for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) {
259     TabPole(i) = tabPoint->Value(i).Point2d(CuIndex);
260   }
261
262   BSplCLib::D1 (U, TabPole, BSplCLib::NoWeights(), Pt, V1);
263 }
264
265
266 void AppParCurves_MultiCurve::D2 (const Standard_Integer CuIndex,
267                             const Standard_Real U, 
268                             gp_Pnt2d& Pt, 
269                             gp_Vec2d& V1,
270                             gp_Vec2d& V2) const {
271
272   if (Dimension(CuIndex) != 2) {
273     throw Standard_OutOfRange();
274   }
275
276   TColgp_Array1OfPnt2d TabPole(1, tabPoint->Length());
277
278   for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) {
279     TabPole(i) = tabPoint->Value(i).Point2d(CuIndex);
280   }
281
282   BSplCLib::D2(U, TabPole, BSplCLib::NoWeights(), Pt, V1, V2);
283 }
284
285
286
287 void AppParCurves_MultiCurve::Dump(Standard_OStream& o) const
288 {
289   o << "AppParCurves_MultiCurve dump:" << endl;
290   o << " It contains " << NbCurves() << " Bezier curves of degree " << tabPoint->Length()-1 << endl;
291   o << " The poles are: " << endl;
292 /*  for (Standard_Integer i = 1; i <= NbCurves(); i++) {
293     o << " Curve No. " << i << endl;
294     if (Dimension(i) == 3) {
295       for (Standard_Integer j = 1; j <= tabPoint->Length(); j++) {
296         o << " Pole No. " << j << ": " << endl;
297         o << " Pole x = " << (tabPoint->Value(j)->Point(i)).X() << endl;
298         o << " Pole y = " << (tabPoint->Value(j)->Point(i)).Y() << endl;
299         o << " Pole z = " << (tabPoint->Value(j)->Point(i)).Z() << endl;
300       }
301     }
302     else {
303       for (Standard_Integer j = 1; j <= tabPoint->Length(); j++) {
304         o << " Pole No. " << j << ": " << endl;
305         o << " Pole x = " << (tabPoint->Value(j)->Point2d(i)).X() << endl;
306         o << " Pole y = " << (tabPoint->Value(j)->Point2d(i)).Y() << endl;
307       }
308     }
309   }
310 */
311 }