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