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.
16 #include <AppParCurves_MultiCurve.hxx>
17 #include <AppParCurves_MultiPoint.hxx>
18 #include <BSplCLib.hxx>
20 #include <gp_Pnt2d.hxx>
22 #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>
30 AppParCurves_MultiCurve::AppParCurves_MultiCurve() {}
33 AppParCurves_MultiCurve::AppParCurves_MultiCurve (const Standard_Integer NbPol)
35 tabPoint = new AppParCurves_HArray1OfMultiPoint(1, NbPol);
40 AppParCurves_MultiCurve::AppParCurves_MultiCurve (const AppParCurves_Array1OfMultiPoint& tabMU)
42 tabPoint = new AppParCurves_HArray1OfMultiPoint(1, tabMU.Length());
43 Standard_Integer i, Lower = tabMU.Lower();
44 for (i = 1; i <= tabMU.Length(); i++) {
45 tabPoint->SetValue(i, tabMU.Value(Lower+i-1));
50 AppParCurves_MultiCurve::~AppParCurves_MultiCurve()
54 Standard_Integer AppParCurves_MultiCurve::Dimension (const Standard_Integer Index) const {
55 Standard_Integer Lo = tabPoint->Lower();
56 Standard_Integer nb = tabPoint->Value(Lo).NbPoints() + tabPoint->Value(Lo).NbPoints2d();
57 if ((Index <= 0) || (Index > nb)) {
58 throw Standard_OutOfRange();
60 return tabPoint->Value(Lo).Dimension(Index);
64 Standard_Integer AppParCurves_MultiCurve::NbCurves () const {
65 if (tabPoint.IsNull())
67 AppParCurves_MultiPoint MP = tabPoint->Value(1);
68 return MP.NbPoints() + MP.NbPoints2d();
72 Standard_Integer AppParCurves_MultiCurve::NbPoles() const {
73 if (tabPoint.IsNull())
75 return tabPoint->Length();
79 Standard_Integer AppParCurves_MultiCurve::Degree() const {
80 return tabPoint->Length()-1;
84 void AppParCurves_MultiCurve::SetNbPoles(const Standard_Integer nbPoles)
86 tabPoint = new AppParCurves_HArray1OfMultiPoint(1, nbPoles);
90 void AppParCurves_MultiCurve::SetValue (const Standard_Integer Index,
91 const AppParCurves_MultiPoint& MPoint) {
93 if ((Index <= 0) || (Index > tabPoint->Length())) {
94 throw Standard_OutOfRange();
96 tabPoint->SetValue(Index, MPoint);
100 void AppParCurves_MultiCurve::Curve (const Standard_Integer CuIndex,
101 TColgp_Array1OfPnt& TabPnt) const {
102 if ((CuIndex <= 0)) {
103 throw Standard_OutOfRange();
105 for ( Standard_Integer i = 1; i <= tabPoint->Length(); i++) {
106 TabPnt(i) = tabPoint->Value(i).Point(CuIndex);
111 void AppParCurves_MultiCurve::Curve (const Standard_Integer CuIndex,
112 TColgp_Array1OfPnt2d& TabPnt2d) const {
113 if ((CuIndex <= 0)) {
114 throw Standard_OutOfRange();
116 for ( Standard_Integer i = 1; i <= tabPoint->Length(); i++) {
117 TabPnt2d(i) = tabPoint->Value(i).Point2d(CuIndex);
123 const gp_Pnt& AppParCurves_MultiCurve::Pole(const Standard_Integer CuIndex,
124 const Standard_Integer Nieme) const
126 if ((CuIndex <= 0) && Nieme <= 0) {
127 throw Standard_OutOfRange();
129 return tabPoint->Value(Nieme).Point(CuIndex);
132 const gp_Pnt2d& AppParCurves_MultiCurve::Pole2d(const Standard_Integer CuIndex,
133 const Standard_Integer Nieme)const
135 if ((CuIndex <= 0) && Nieme <= 0) {
136 throw Standard_OutOfRange();
138 return tabPoint->Value(Nieme).Point2d(CuIndex);
143 const AppParCurves_MultiPoint& AppParCurves_MultiCurve::Value (const Standard_Integer Index) const {
144 if ((Index <= 0) || (Index > tabPoint->Length())) {
145 throw Standard_OutOfRange();
147 return tabPoint->Value(Index);
150 void AppParCurves_MultiCurve::Transform(const Standard_Integer CuIndex,
151 const Standard_Real x,
152 const Standard_Real dx,
153 const Standard_Real y,
154 const Standard_Real dy,
155 const Standard_Real z,
156 const Standard_Real dz)
158 if (Dimension(CuIndex) != 3) throw Standard_OutOfRange();
160 for (Standard_Integer i = 1 ; i <= tabPoint->Length(); i++) {
161 (tabPoint->ChangeValue(i)).Transform(CuIndex, x, dx, y, dy, z, dz);
165 void AppParCurves_MultiCurve::Transform2d(const Standard_Integer CuIndex,
166 const Standard_Real x,
167 const Standard_Real dx,
168 const Standard_Real y,
169 const Standard_Real dy)
171 if (Dimension(CuIndex) != 2) throw Standard_OutOfRange();
173 for (Standard_Integer i = 1 ; i <= tabPoint->Length(); i++) {
174 (tabPoint->ChangeValue(i)).Transform2d(CuIndex, x, dx, y, dy);
179 void AppParCurves_MultiCurve::Value (const Standard_Integer CuIndex,
180 const Standard_Real U, gp_Pnt& Pt) const {
182 if (Dimension(CuIndex) != 3)throw Standard_OutOfRange();
184 TColgp_Array1OfPnt TabPoles(1, tabPoint->Length());
186 for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) {
187 TabPoles(i) = tabPoint->Value(i).Point(CuIndex);
190 BSplCLib::D0 (U, TabPoles,BSplCLib::NoWeights(), Pt);
194 void AppParCurves_MultiCurve::Value (const Standard_Integer CuIndex,
195 const Standard_Real U, gp_Pnt2d& Pt) const {
196 if (Dimension(CuIndex) != 2) {
197 throw Standard_OutOfRange();
200 TColgp_Array1OfPnt2d TabPole(1, tabPoint->Length());
202 for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) {
203 TabPole(i) = tabPoint->Value(i).Point2d(CuIndex);
206 BSplCLib::D0 (U, TabPole, BSplCLib::NoWeights(), Pt);
210 void AppParCurves_MultiCurve::D1 (const Standard_Integer CuIndex,
211 const Standard_Real U,
215 if (Dimension(CuIndex) != 3) {
216 throw Standard_OutOfRange();
219 TColgp_Array1OfPnt TabPole(1, tabPoint->Length());
221 for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) {
222 TabPole(i) = tabPoint->Value(i).Point(CuIndex);
225 BSplCLib::D1 (U, TabPole, BSplCLib::NoWeights(), Pt, V1);
229 void AppParCurves_MultiCurve::D2 (const Standard_Integer CuIndex,
230 const Standard_Real U,
235 if (Dimension(CuIndex) != 3) {
236 throw Standard_OutOfRange();
239 TColgp_Array1OfPnt TabPole(1, tabPoint->Length());
241 for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) {
242 TabPole(i) = tabPoint->Value(i).Point(CuIndex);
245 BSplCLib::D2 (U, TabPole, BSplCLib::NoWeights(), Pt, V1, V2);
249 void AppParCurves_MultiCurve::D1 (const Standard_Integer CuIndex,
250 const Standard_Real U, gp_Pnt2d& Pt, gp_Vec2d& V1) const {
252 if (Dimension(CuIndex) != 2) {
253 throw Standard_OutOfRange();
256 TColgp_Array1OfPnt2d TabPole(1, tabPoint->Length());
258 for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) {
259 TabPole(i) = tabPoint->Value(i).Point2d(CuIndex);
262 BSplCLib::D1 (U, TabPole, BSplCLib::NoWeights(), Pt, V1);
266 void AppParCurves_MultiCurve::D2 (const Standard_Integer CuIndex,
267 const Standard_Real U,
270 gp_Vec2d& V2) const {
272 if (Dimension(CuIndex) != 2) {
273 throw Standard_OutOfRange();
276 TColgp_Array1OfPnt2d TabPole(1, tabPoint->Length());
278 for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) {
279 TabPole(i) = tabPoint->Value(i).Point2d(CuIndex);
282 BSplCLib::D2(U, TabPole, BSplCLib::NoWeights(), Pt, V1, V2);
287 void AppParCurves_MultiCurve::Dump(Standard_OStream& o) const
289 o << "AppParCurves_MultiCurve dump:" << endl;
290 o << " It contains " << NbCurves() << " Bezier curves of degree " << tabPoint->Length()-1 << 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;
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;