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