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