0024428: Implementation of LGPL license
[occt.git] / src / Approx / Approx_MCurvesToBSpCurve.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//
973c2be1 6// This library is free software; you can redistribute it and / or modify it
7// under the terms of the GNU Lesser General Public 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.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
7fd59977 15#include <Approx_MCurvesToBSpCurve.ixx>
16#include <Convert_CompBezierCurvesToBSplineCurve.hxx>
17#include <Convert_CompBezierCurves2dToBSplineCurve2d.hxx>
18#include <TColgp_Array1OfPnt.hxx>
19#include <TColgp_Array1OfPnt2d.hxx>
20#include <AppParCurves_MultiCurve.hxx>
21#include <AppParCurves_MultiPoint.hxx>
22#include <AppParCurves_Array1OfMultiPoint.hxx>
23#include <TColStd_Array1OfInteger.hxx>
24#include <TColStd_Array1OfReal.hxx>
25#include <BSplCLib.hxx>
26#include <PLib.hxx>
27
28#ifdef DEB
29static void DEBUG(const AppParCurves_MultiCurve& MC) {
30 Standard_Integer i, j;
31 Standard_Integer nbcu = MC.NbCurves();
32 Standard_Integer nbpoles = MC.NbPoles();
33 TColgp_Array1OfPnt Poles(1, nbpoles);
34 TColgp_Array1OfPnt2d Poles2d(1, nbpoles);
35
36 for (i = 1; i <= nbcu; i++) {
37 cout << " Curve No. " << i << endl;
38 if (MC.Dimension(i) == 3) {
39 MC.Curve(i, Poles);
40 for (j = 1; j <= nbpoles; j++) {
41 cout<< " Pole = " << Poles(j).X() <<" "<<Poles(j).Y()<<" "<<Poles(j).Z()<< endl;
42 }
43 }
44 else {
45 MC.Curve(i, Poles2d);
46 for (j = 1; j <= nbpoles; j++) {
47 cout<< " Pole = " << Poles2d(j).X() <<" "<<Poles2d(j).Y()<< endl;
48 }
49 }
50 }
51
52}
53#endif
54
55
56
57Approx_MCurvesToBSpCurve::Approx_MCurvesToBSpCurve()
58{
59 myDone = Standard_False;
60}
61
62void Approx_MCurvesToBSpCurve::Reset()
63{
64 myDone = Standard_False;
65 myCurves.Clear();
66}
67
68void Approx_MCurvesToBSpCurve::Append(const AppParCurves_MultiCurve& MC)
69{
70 myCurves.Append(MC);
71}
72
73
74void Approx_MCurvesToBSpCurve::Perform()
75{
76 Perform(myCurves);
77}
78
79void Approx_MCurvesToBSpCurve::Perform
80 (const AppParCurves_SequenceOfMultiCurve& TheSeq)
81{
82
83 Standard_Integer i, j, deg=0;
84 Standard_Integer nbcu = TheSeq.Length();
85 AppParCurves_MultiCurve CU;
86 Standard_Integer nbpolesspl=0, nbknots=0;
87#ifdef DEB
88 Standard_Boolean debug = Standard_False;
89#endif
90
91 if (nbcu == 1) {
92 CU = TheSeq.Value(1);
93 deg = CU.Degree();
94 TColStd_Array1OfReal Knots(1, 2);
95 TColStd_Array1OfInteger Mults(1, 2);
96 Knots(1) = 0.0;
97 Knots(2) = 1.0;
98 Mults(1) = Mults(2) = deg+1;
99 mySpline = AppParCurves_MultiBSpCurve (CU, Knots, Mults);
100 }
101 else {
102
103 AppParCurves_MultiPoint P = TheSeq.Value(nbcu).Value(1);
104 Standard_Integer nb3d = P.NbPoints();
105 Standard_Integer nb2d = P.NbPoints2d();
106
107 Convert_CompBezierCurvesToBSplineCurve conv;
108 Convert_CompBezierCurves2dToBSplineCurve2d conv2d;
109
110 if (nb3d != 0) {
111 for (i = 1; i <= nbcu; i++) {
112 CU = TheSeq.Value(i);
113 TColgp_Array1OfPnt ThePoles3d(1, CU.NbPoles());
114 CU.Curve(1, ThePoles3d);
115 conv.AddCurve(ThePoles3d);
116 }
117 conv.Perform();
118 }
119
120
121 else if (nb2d != 0) {
122 for (i = 1; i <= nbcu; i++) {
123 CU = TheSeq.Value(i);
124 TColgp_Array1OfPnt2d ThePoles2d(1, CU.NbPoles());
125 CU.Curve(1+nb3d, ThePoles2d);
126 conv2d.AddCurve(ThePoles2d);
127 }
128 conv2d.Perform();
129 }
130
131
132 // Recuperation:
133 if (nb3d != 0) {
134 nbpolesspl = conv.NbPoles();
135 nbknots = conv.NbKnots();
136 }
137 else if (nb2d != 0) {
138 nbpolesspl = conv2d.NbPoles();
139 nbknots = conv2d.NbKnots();
140 }
141
142 AppParCurves_Array1OfMultiPoint tabMU(1, nbpolesspl);
143 TColgp_Array1OfPnt PolesSpl(1, nbpolesspl);
144 TColgp_Array1OfPnt2d PolesSpl2d(1, nbpolesspl);
145 TColStd_Array1OfInteger TheMults(1, nbknots);
146 TColStd_Array1OfReal TheKnots(1, nbknots);
147
148 if (nb3d != 0) {
149 conv.KnotsAndMults(TheKnots, TheMults);
150 conv.Poles(PolesSpl);
151 deg = conv.Degree();
152 }
153 else if (nb2d != 0) {
154 conv2d.KnotsAndMults(TheKnots, TheMults);
155 conv2d.Poles(PolesSpl2d);
156 deg = conv2d.Degree();
157 }
158
159
160 for (j = 1; j <= nbpolesspl; j++) {
161 AppParCurves_MultiPoint MP(nb3d, nb2d);
162 if (nb3d!=0) {
163 MP.SetPoint(1, PolesSpl(j));
164 }
165 else if (nb2d!=0) {
166 MP.SetPoint2d(1+nb3d, PolesSpl2d(j));
167 }
168 tabMU.SetValue(j, MP);
169 }
170
171 Standard_Integer kpol = 1, kpoles3d=1, kpoles2d=1;
172 Standard_Integer mydegre, k;
173 Standard_Integer first, last, Inc, thefirst;
174 if (nb3d != 0) thefirst = 1;
175 else thefirst = 2;
176
177 for (i = 1; i <= nbcu; i++) {
178 CU = TheSeq.Value(i);
179 mydegre = CU.Degree();
180 if (TheMults(i+1) == deg) last = deg+1; // Continuite C0
181 else last = deg; // Continuite C1
182 if (i==nbcu) {last = deg+1;}
183 first = 1;
184 if (i==1) first = 1;
185 else if ((TheMults(i)== deg-1) || (TheMults(i)==deg)) first = 2;
186
187 for (j = 2; j <= nb3d; j++) {
188 kpol = kpoles3d;
189 TColgp_Array1OfPnt ThePoles(1, CU.NbPoles());
190 CU.Curve(j, ThePoles);
191
192 Inc = deg-mydegre;
193 TColgp_Array1OfPnt Points(1, deg+1);
194 if (Inc > 0) {
195 BSplCLib::IncreaseDegree(deg, ThePoles, PLib::NoWeights(),
196 Points, PLib::NoWeights());
197 }
198 else {
199 Points = ThePoles;
200 }
201
202 for (k = first; k <= last; k++) {
203 tabMU.ChangeValue(kpol++).SetPoint(j, Points(k));
204 }
205 }
206 kpoles3d = kpol;
207
208 for (j = thefirst; j <= nb2d; j++) {
209 kpol = kpoles2d;
210 TColgp_Array1OfPnt2d ThePoles2d(1, CU.NbPoles());
211 CU.Curve(j+nb3d, ThePoles2d);
212
213 Inc = deg-mydegre;
214 TColgp_Array1OfPnt2d Points2d(1, deg+1);
215 if (Inc > 0) {
216 BSplCLib::IncreaseDegree(deg, ThePoles2d, PLib::NoWeights(),
217 Points2d, PLib::NoWeights());
218 }
219 else {
220 Points2d = ThePoles2d;
221 }
222 for (k = first; k <= last; k++) {
223 tabMU.ChangeValue(kpol++).SetPoint2d(j+nb3d, Points2d(k));
224 }
225 }
226 kpoles2d = kpol;
227 }
228
229 mySpline = AppParCurves_MultiBSpCurve(tabMU, TheKnots, TheMults);
230 }
231#ifdef DEB
232if(debug) DEBUG(mySpline);
233#endif
234
235 myDone = Standard_True;
236}
237
238
239const AppParCurves_MultiBSpCurve& Approx_MCurvesToBSpCurve::Value() const
240{
241 return mySpline;
242}
243
244
245const AppParCurves_MultiBSpCurve& Approx_MCurvesToBSpCurve::ChangeValue()
246{
247 return mySpline;
248}
249
250