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