1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
21 #include <AppParCurves_MultiCurve.ixx>
22 #include <TColgp_Array1OfPnt.hxx>
23 #include <TColgp_Array1OfPnt2d.hxx>
24 #include <Standard_OutOfRange.hxx>
25 #include <BSplCLib.hxx>
29 AppParCurves_MultiCurve::AppParCurves_MultiCurve() {}
32 AppParCurves_MultiCurve::AppParCurves_MultiCurve (const Standard_Integer NbPol)
34 tabPoint = new AppParCurves_HArray1OfMultiPoint(1, NbPol);
39 AppParCurves_MultiCurve::AppParCurves_MultiCurve (const AppParCurves_Array1OfMultiPoint& tabMU)
41 tabPoint = new AppParCurves_HArray1OfMultiPoint(1, tabMU.Length());
42 Standard_Integer i, Lower = tabMU.Lower();
43 for (i = 1; i <= tabMU.Length(); i++) {
44 tabPoint->SetValue(i, tabMU.Value(Lower+i-1));
49 void AppParCurves_MultiCurve::Delete()
52 Standard_Integer AppParCurves_MultiCurve::Dimension (const Standard_Integer Index) const {
53 Standard_Integer Lo = tabPoint->Lower();
54 Standard_Integer nb = tabPoint->Value(Lo).NbPoints() + tabPoint->Value(Lo).NbPoints2d();
55 if ((Index <= 0) || (Index > nb)) {
56 Standard_OutOfRange::Raise();
58 return tabPoint->Value(Lo).Dimension(Index);
62 Standard_Integer AppParCurves_MultiCurve::NbCurves () const {
63 if (tabPoint.IsNull())
65 AppParCurves_MultiPoint MP = tabPoint->Value(1);
66 return MP.NbPoints() + MP.NbPoints2d();
70 Standard_Integer AppParCurves_MultiCurve::NbPoles() const {
71 if (tabPoint.IsNull())
73 return tabPoint->Length();
77 Standard_Integer AppParCurves_MultiCurve::Degree() const {
78 return tabPoint->Length()-1;
82 void AppParCurves_MultiCurve::SetNbPoles(const Standard_Integer nbPoles)
84 tabPoint = new AppParCurves_HArray1OfMultiPoint(1, nbPoles);
88 void AppParCurves_MultiCurve::SetValue (const Standard_Integer Index,
89 const AppParCurves_MultiPoint& MPoint) {
91 if ((Index <= 0) || (Index > tabPoint->Length())) {
92 Standard_OutOfRange::Raise();
94 tabPoint->SetValue(Index, MPoint);
98 void AppParCurves_MultiCurve::Curve (const Standard_Integer CuIndex,
99 TColgp_Array1OfPnt& TabPnt) const {
100 if ((CuIndex <= 0)) {
101 Standard_OutOfRange::Raise();
103 for ( Standard_Integer i = 1; i <= tabPoint->Length(); i++) {
104 TabPnt(i) = tabPoint->Value(i).Point(CuIndex);
109 void AppParCurves_MultiCurve::Curve (const Standard_Integer CuIndex,
110 TColgp_Array1OfPnt2d& TabPnt2d) const {
111 if ((CuIndex <= 0)) {
112 Standard_OutOfRange::Raise();
114 for ( Standard_Integer i = 1; i <= tabPoint->Length(); i++) {
115 TabPnt2d(i) = tabPoint->Value(i).Point2d(CuIndex);
121 const gp_Pnt& AppParCurves_MultiCurve::Pole(const Standard_Integer CuIndex,
122 const Standard_Integer Nieme) const
124 if ((CuIndex <= 0) && Nieme <= 0) {
125 Standard_OutOfRange::Raise();
127 return tabPoint->Value(Nieme).Point(CuIndex);
130 const gp_Pnt2d& AppParCurves_MultiCurve::Pole2d(const Standard_Integer CuIndex,
131 const Standard_Integer Nieme)const
133 if ((CuIndex <= 0) && Nieme <= 0) {
134 Standard_OutOfRange::Raise();
136 return tabPoint->Value(Nieme).Point2d(CuIndex);
141 const AppParCurves_MultiPoint& AppParCurves_MultiCurve::Value (const Standard_Integer Index) const {
142 if ((Index <= 0) || (Index > tabPoint->Length())) {
143 Standard_OutOfRange::Raise();
145 return tabPoint->Value(Index);
148 void AppParCurves_MultiCurve::Transform(const Standard_Integer CuIndex,
149 const Standard_Real x,
150 const Standard_Real dx,
151 const Standard_Real y,
152 const Standard_Real dy,
153 const Standard_Real z,
154 const Standard_Real dz)
156 if (Dimension(CuIndex) != 3) Standard_OutOfRange::Raise();
158 for (Standard_Integer i = 1 ; i <= tabPoint->Length(); i++) {
159 (tabPoint->ChangeValue(i)).Transform(CuIndex, x, dx, y, dy, z, dz);
163 void AppParCurves_MultiCurve::Transform2d(const Standard_Integer CuIndex,
164 const Standard_Real x,
165 const Standard_Real dx,
166 const Standard_Real y,
167 const Standard_Real dy)
169 if (Dimension(CuIndex) != 2) Standard_OutOfRange::Raise();
171 for (Standard_Integer i = 1 ; i <= tabPoint->Length(); i++) {
172 (tabPoint->ChangeValue(i)).Transform2d(CuIndex, x, dx, y, dy);
177 void AppParCurves_MultiCurve::Value (const Standard_Integer CuIndex,
178 const Standard_Real U, gp_Pnt& Pt) const {
180 if (Dimension(CuIndex) != 3)Standard_OutOfRange::Raise();
182 TColgp_Array1OfPnt TabPoles(1, tabPoint->Length());
184 for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) {
185 TabPoles(i) = tabPoint->Value(i).Point(CuIndex);
188 BSplCLib::D0 (U, TabPoles,PLib::NoWeights(), Pt);
192 void AppParCurves_MultiCurve::Value (const Standard_Integer CuIndex,
193 const Standard_Real U, gp_Pnt2d& Pt) const {
194 if (Dimension(CuIndex) != 2) {
195 Standard_OutOfRange::Raise();
198 TColgp_Array1OfPnt2d TabPole(1, tabPoint->Length());
200 for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) {
201 TabPole(i) = tabPoint->Value(i).Point2d(CuIndex);
204 BSplCLib::D0 (U, TabPole, PLib::NoWeights(), Pt);
208 void AppParCurves_MultiCurve::D1 (const Standard_Integer CuIndex,
209 const Standard_Real U,
213 if (Dimension(CuIndex) != 3) {
214 Standard_OutOfRange::Raise();
217 TColgp_Array1OfPnt TabPole(1, tabPoint->Length());
219 for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) {
220 TabPole(i) = tabPoint->Value(i).Point(CuIndex);
223 BSplCLib::D1 (U, TabPole, PLib::NoWeights(), Pt, V1);
227 void AppParCurves_MultiCurve::D2 (const Standard_Integer CuIndex,
228 const Standard_Real U,
233 if (Dimension(CuIndex) != 3) {
234 Standard_OutOfRange::Raise();
237 TColgp_Array1OfPnt TabPole(1, tabPoint->Length());
239 for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) {
240 TabPole(i) = tabPoint->Value(i).Point(CuIndex);
243 BSplCLib::D2 (U, TabPole, PLib::NoWeights(), Pt, V1, V2);
247 void AppParCurves_MultiCurve::D1 (const Standard_Integer CuIndex,
248 const Standard_Real U, gp_Pnt2d& Pt, gp_Vec2d& V1) const {
250 if (Dimension(CuIndex) != 2) {
251 Standard_OutOfRange::Raise();
254 TColgp_Array1OfPnt2d TabPole(1, tabPoint->Length());
256 for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) {
257 TabPole(i) = tabPoint->Value(i).Point2d(CuIndex);
260 BSplCLib::D1 (U, TabPole, PLib::NoWeights(), Pt, V1);
264 void AppParCurves_MultiCurve::D2 (const Standard_Integer CuIndex,
265 const Standard_Real U,
268 gp_Vec2d& V2) const {
270 if (Dimension(CuIndex) != 2) {
271 Standard_OutOfRange::Raise();
274 TColgp_Array1OfPnt2d TabPole(1, tabPoint->Length());
276 for (Standard_Integer i =1 ; i <= tabPoint->Length(); i++) {
277 TabPole(i) = tabPoint->Value(i).Point2d(CuIndex);
280 BSplCLib::D2(U, TabPole, PLib::NoWeights(), Pt, V1, V2);
285 void AppParCurves_MultiCurve::Dump(Standard_OStream& o) const
287 o << "AppParCurves_MultiCurve dump:" << endl;
288 o << " It contains " << NbCurves() << " Bezier curves of degree " << tabPoint->Length()-1 << endl;
289 o << " The poles are: " << endl;
290 /* for (Standard_Integer i = 1; i <= NbCurves(); i++) {
291 o << " Curve No. " << i << endl;
292 if (Dimension(i) == 3) {
293 for (Standard_Integer j = 1; j <= tabPoint->Length(); j++) {
294 o << " Pole No. " << j << ": " << endl;
295 o << " Pole x = " << (tabPoint->Value(j)->Point(i)).X() << endl;
296 o << " Pole y = " << (tabPoint->Value(j)->Point(i)).Y() << endl;
297 o << " Pole z = " << (tabPoint->Value(j)->Point(i)).Z() << endl;
301 for (Standard_Integer j = 1; j <= tabPoint->Length(); j++) {
302 o << " Pole No. " << j << ": " << endl;
303 o << " Pole x = " << (tabPoint->Value(j)->Point2d(i)).X() << endl;
304 o << " Pole y = " << (tabPoint->Value(j)->Point2d(i)).Y() << endl;