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