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