1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <AppParCurves_MultiCurve.ixx>
16 #include <TColgp_Array1OfPnt.hxx>
17 #include <TColgp_Array1OfPnt2d.hxx>
18 #include <Standard_OutOfRange.hxx>
19 #include <BSplCLib.hxx>
23 AppParCurves_MultiCurve::AppParCurves_MultiCurve() {}
26 AppParCurves_MultiCurve::AppParCurves_MultiCurve (const Standard_Integer NbPol)
28 tabPoint = new AppParCurves_HArray1OfMultiPoint(1, NbPol);
33 AppParCurves_MultiCurve::AppParCurves_MultiCurve (const AppParCurves_Array1OfMultiPoint& tabMU)
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));
43 void AppParCurves_MultiCurve::Delete()
46 Standard_Integer AppParCurves_MultiCurve::Dimension (const Standard_Integer Index) const {
47 Standard_Integer Lo = tabPoint->Lower();
48 Standard_Integer nb = tabPoint->Value(Lo).NbPoints() + tabPoint->Value(Lo).NbPoints2d();
49 if ((Index <= 0) || (Index > nb)) {
50 Standard_OutOfRange::Raise();
52 return tabPoint->Value(Lo).Dimension(Index);
56 Standard_Integer AppParCurves_MultiCurve::NbCurves () const {
57 if (tabPoint.IsNull())
59 AppParCurves_MultiPoint MP = tabPoint->Value(1);
60 return MP.NbPoints() + MP.NbPoints2d();
64 Standard_Integer AppParCurves_MultiCurve::NbPoles() const {
65 if (tabPoint.IsNull())
67 return tabPoint->Length();
71 Standard_Integer AppParCurves_MultiCurve::Degree() const {
72 return tabPoint->Length()-1;
76 void AppParCurves_MultiCurve::SetNbPoles(const Standard_Integer nbPoles)
78 tabPoint = new AppParCurves_HArray1OfMultiPoint(1, nbPoles);
82 void AppParCurves_MultiCurve::SetValue (const Standard_Integer Index,
83 const AppParCurves_MultiPoint& MPoint) {
85 if ((Index <= 0) || (Index > tabPoint->Length())) {
86 Standard_OutOfRange::Raise();
88 tabPoint->SetValue(Index, MPoint);
92 void AppParCurves_MultiCurve::Curve (const Standard_Integer CuIndex,
93 TColgp_Array1OfPnt& TabPnt) const {
95 Standard_OutOfRange::Raise();
97 for ( Standard_Integer i = 1; i <= tabPoint->Length(); i++) {
98 TabPnt(i) = tabPoint->Value(i).Point(CuIndex);
103 void AppParCurves_MultiCurve::Curve (const Standard_Integer CuIndex,
104 TColgp_Array1OfPnt2d& TabPnt2d) const {
105 if ((CuIndex <= 0)) {
106 Standard_OutOfRange::Raise();
108 for ( Standard_Integer i = 1; i <= tabPoint->Length(); i++) {
109 TabPnt2d(i) = tabPoint->Value(i).Point2d(CuIndex);
115 const gp_Pnt& AppParCurves_MultiCurve::Pole(const Standard_Integer CuIndex,
116 const Standard_Integer Nieme) const
118 if ((CuIndex <= 0) && Nieme <= 0) {
119 Standard_OutOfRange::Raise();
121 return tabPoint->Value(Nieme).Point(CuIndex);
124 const gp_Pnt2d& AppParCurves_MultiCurve::Pole2d(const Standard_Integer CuIndex,
125 const Standard_Integer Nieme)const
127 if ((CuIndex <= 0) && Nieme <= 0) {
128 Standard_OutOfRange::Raise();
130 return tabPoint->Value(Nieme).Point2d(CuIndex);
135 const AppParCurves_MultiPoint& AppParCurves_MultiCurve::Value (const Standard_Integer Index) const {
136 if ((Index <= 0) || (Index > tabPoint->Length())) {
137 Standard_OutOfRange::Raise();
139 return tabPoint->Value(Index);
142 void AppParCurves_MultiCurve::Transform(const Standard_Integer CuIndex,
143 const Standard_Real x,
144 const Standard_Real dx,
145 const Standard_Real y,
146 const Standard_Real dy,
147 const Standard_Real z,
148 const Standard_Real dz)
150 if (Dimension(CuIndex) != 3) Standard_OutOfRange::Raise();
152 for (Standard_Integer i = 1 ; i <= tabPoint->Length(); i++) {
153 (tabPoint->ChangeValue(i)).Transform(CuIndex, x, dx, y, dy, z, dz);
157 void AppParCurves_MultiCurve::Transform2d(const Standard_Integer CuIndex,
158 const Standard_Real x,
159 const Standard_Real dx,
160 const Standard_Real y,
161 const Standard_Real dy)
163 if (Dimension(CuIndex) != 2) Standard_OutOfRange::Raise();
165 for (Standard_Integer i = 1 ; i <= tabPoint->Length(); i++) {
166 (tabPoint->ChangeValue(i)).Transform2d(CuIndex, x, dx, y, dy);
171 void AppParCurves_MultiCurve::Value (const Standard_Integer CuIndex,
172 const Standard_Real U, gp_Pnt& Pt) const {
174 if (Dimension(CuIndex) != 3)Standard_OutOfRange::Raise();
176 TColgp_Array1OfPnt TabPoles(1, tabPoint->Length());
178 for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) {
179 TabPoles(i) = tabPoint->Value(i).Point(CuIndex);
182 BSplCLib::D0 (U, TabPoles,PLib::NoWeights(), Pt);
186 void AppParCurves_MultiCurve::Value (const Standard_Integer CuIndex,
187 const Standard_Real U, gp_Pnt2d& Pt) const {
188 if (Dimension(CuIndex) != 2) {
189 Standard_OutOfRange::Raise();
192 TColgp_Array1OfPnt2d TabPole(1, tabPoint->Length());
194 for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) {
195 TabPole(i) = tabPoint->Value(i).Point2d(CuIndex);
198 BSplCLib::D0 (U, TabPole, PLib::NoWeights(), Pt);
202 void AppParCurves_MultiCurve::D1 (const Standard_Integer CuIndex,
203 const Standard_Real U,
207 if (Dimension(CuIndex) != 3) {
208 Standard_OutOfRange::Raise();
211 TColgp_Array1OfPnt TabPole(1, tabPoint->Length());
213 for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) {
214 TabPole(i) = tabPoint->Value(i).Point(CuIndex);
217 BSplCLib::D1 (U, TabPole, PLib::NoWeights(), Pt, V1);
221 void AppParCurves_MultiCurve::D2 (const Standard_Integer CuIndex,
222 const Standard_Real U,
227 if (Dimension(CuIndex) != 3) {
228 Standard_OutOfRange::Raise();
231 TColgp_Array1OfPnt TabPole(1, tabPoint->Length());
233 for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) {
234 TabPole(i) = tabPoint->Value(i).Point(CuIndex);
237 BSplCLib::D2 (U, TabPole, PLib::NoWeights(), Pt, V1, V2);
241 void AppParCurves_MultiCurve::D1 (const Standard_Integer CuIndex,
242 const Standard_Real U, gp_Pnt2d& Pt, gp_Vec2d& V1) const {
244 if (Dimension(CuIndex) != 2) {
245 Standard_OutOfRange::Raise();
248 TColgp_Array1OfPnt2d TabPole(1, tabPoint->Length());
250 for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) {
251 TabPole(i) = tabPoint->Value(i).Point2d(CuIndex);
254 BSplCLib::D1 (U, TabPole, PLib::NoWeights(), Pt, V1);
258 void AppParCurves_MultiCurve::D2 (const Standard_Integer CuIndex,
259 const Standard_Real U,
262 gp_Vec2d& V2) const {
264 if (Dimension(CuIndex) != 2) {
265 Standard_OutOfRange::Raise();
268 TColgp_Array1OfPnt2d TabPole(1, tabPoint->Length());
270 for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) {
271 TabPole(i) = tabPoint->Value(i).Point2d(CuIndex);
274 BSplCLib::D2(U, TabPole, PLib::NoWeights(), Pt, V1, V2);
279 void AppParCurves_MultiCurve::Dump(Standard_OStream& o) const
281 o << "AppParCurves_MultiCurve dump:" << endl;
282 o << " It contains " << NbCurves() << " Bezier curves of degree " << tabPoint->Length()-1 << endl;
283 o << " The poles are: " << endl;
284 /* for (Standard_Integer i = 1; i <= NbCurves(); i++) {
285 o << " Curve No. " << i << endl;
286 if (Dimension(i) == 3) {
287 for (Standard_Integer j = 1; j <= tabPoint->Length(); j++) {
288 o << " Pole No. " << j << ": " << endl;
289 o << " Pole x = " << (tabPoint->Value(j)->Point(i)).X() << endl;
290 o << " Pole y = " << (tabPoint->Value(j)->Point(i)).Y() << endl;
291 o << " Pole z = " << (tabPoint->Value(j)->Point(i)).Z() << endl;
295 for (Standard_Integer j = 1; j <= tabPoint->Length(); j++) {
296 o << " Pole No. " << j << ": " << endl;
297 o << " Pole x = " << (tabPoint->Value(j)->Point2d(i)).X() << endl;
298 o << " Pole y = " << (tabPoint->Value(j)->Point2d(i)).Y() << endl;