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