Commit | Line | Data |
---|---|---|
7fd59977 | 1 | //File Convert_SphereToBSplineSurface.cxx |
2 | //JCV 16/10/91 | |
3 | ||
4 | #include <Convert_SphereToBSplineSurface.ixx> | |
5 | ||
6 | #include <gp.hxx> | |
7 | #include <gp_Trsf.hxx> | |
8 | ||
9 | static const Standard_Integer TheUDegree = 2; | |
10 | static const Standard_Integer TheVDegree = 2; | |
11 | static const Standard_Integer MaxNbUKnots = 4; | |
12 | static const Standard_Integer MaxNbVKnots = 3; | |
13 | static const Standard_Integer MaxNbUPoles = 7; | |
14 | static const Standard_Integer MaxNbVPoles = 5; | |
15 | ||
16 | ||
17 | static void ComputePoles ( const Standard_Real R, | |
18 | const Standard_Real U1, | |
19 | const Standard_Real U2, | |
20 | const Standard_Real V1, | |
21 | const Standard_Real V2, | |
22 | TColgp_Array2OfPnt& Poles) | |
23 | { | |
24 | Standard_Real deltaU = U2 - U1; | |
25 | Standard_Real deltaV = V2 - V1; | |
26 | ||
27 | Standard_Integer i, j; | |
28 | ||
0d969553 | 29 | // Number of spans : maximum opening = 150 degrees ( = PI / 1.2 rds) |
7fd59977 | 30 | Standard_Integer |
c6541a0c | 31 | nbUSpans = (Standard_Integer)IntegerPart( 1.2 * deltaU / M_PI) + 1; |
7fd59977 | 32 | Standard_Integer |
c6541a0c | 33 | nbVSpans = (Standard_Integer)IntegerPart( 1.2 * deltaV / M_PI) + 1; |
7fd59977 | 34 | Standard_Real AlfaU = deltaU / ( nbUSpans * 2); |
35 | Standard_Real AlfaV = deltaV / ( nbVSpans * 2); | |
36 | ||
37 | Standard_Integer nbVP = 2 * nbVSpans + 1; | |
38 | ||
39 | Standard_Real x[MaxNbVPoles]; | |
40 | Standard_Real z[MaxNbVPoles]; | |
41 | ||
42 | x[0] = R * Cos( V1); | |
43 | z[0] = R * Sin( V1); | |
44 | ||
45 | Standard_Real VStart = V1; | |
46 | for ( i = 1; i <= nbVSpans; i++) { | |
47 | x[2*i-1] = R * Cos( VStart + AlfaV) / Cos( AlfaV); | |
48 | z[2*i-1] = R * Sin( VStart + AlfaV) / Cos( AlfaV); | |
49 | x[2*i] = R * Cos( VStart + 2 * AlfaV); | |
50 | z[2*i] = R * Sin( VStart + 2 * AlfaV); | |
51 | VStart += 2*AlfaV; | |
52 | } | |
53 | ||
54 | Standard_Real UStart = U1; | |
55 | for ( j = 0; j <= nbVP-1; j++) { | |
56 | Poles( 1, j+1) = gp_Pnt(x[j]*Cos(UStart),x[j]*Sin(UStart),z[j]); | |
57 | } | |
58 | ||
59 | for ( i = 1; i <= nbUSpans; i++) { | |
60 | for ( j = 0; j<= nbVP-1; j++) { | |
61 | Poles( 2*i, j+1) = gp_Pnt( x[j] * Cos(UStart+AlfaU) / Cos(AlfaU), | |
62 | x[j] * Sin(UStart+AlfaU) / Cos(AlfaU), | |
63 | z[j] ); | |
64 | Poles(2*i+1,j+1) = gp_Pnt( x[j] * Cos(UStart+2*AlfaU), | |
65 | x[j] * Sin(UStart+2*AlfaU), | |
66 | z[j] ); | |
67 | } | |
68 | UStart += 2*AlfaU; | |
69 | } | |
70 | } | |
71 | ||
72 | //======================================================================= | |
73 | //function : Convert_SphereToBSplineSurface | |
74 | //purpose : | |
75 | //======================================================================= | |
76 | ||
77 | Convert_SphereToBSplineSurface::Convert_SphereToBSplineSurface | |
78 | (const gp_Sphere& Sph, | |
79 | const Standard_Real U1 , | |
80 | const Standard_Real U2 , | |
81 | const Standard_Real V1 , | |
82 | const Standard_Real V2 ) | |
83 | : Convert_ElementarySurfaceToBSplineSurface (MaxNbUPoles, MaxNbVPoles, | |
84 | MaxNbUKnots, MaxNbVKnots, | |
85 | TheUDegree , TheVDegree) | |
86 | { | |
87 | Standard_Real deltaU = U2 - U1; | |
88 | Standard_Real deltaV = V2 - V1; | |
c6541a0c D |
89 | Standard_DomainError_Raise_if( (deltaU>2*M_PI) || (deltaU<0.) || |
90 | (V1 < -M_PI/2.0) || (V2 > M_PI/2), | |
7fd59977 | 91 | "Convert_SphereToBSplineSurface"); |
92 | ||
93 | isuperiodic = Standard_False; | |
94 | isvperiodic = Standard_False; | |
95 | ||
96 | Standard_Integer i,j; | |
0d969553 | 97 | // construction of the sphere in the reference mark xOy. |
7fd59977 | 98 | |
0d969553 | 99 | // Number of spans : maximum opening = 150 degrees ( = PI / 1.2 rds) |
7fd59977 | 100 | Standard_Integer |
c6541a0c | 101 | nbUSpans = (Standard_Integer)IntegerPart( 1.2 * deltaU / M_PI) + 1; |
7fd59977 | 102 | Standard_Integer |
c6541a0c | 103 | nbVSpans = (Standard_Integer)IntegerPart( 1.2 * deltaV / M_PI) + 1; |
7fd59977 | 104 | Standard_Real AlfaU = deltaU / ( nbUSpans * 2); |
105 | Standard_Real AlfaV = deltaV / ( nbVSpans * 2); | |
106 | ||
107 | nbUPoles = 2 * nbUSpans + 1; | |
108 | nbVPoles = 2 * nbVSpans + 1; | |
109 | nbUKnots = nbUSpans + 1; | |
110 | nbVKnots = nbVSpans + 1; | |
111 | ||
112 | Standard_Real R = Sph.Radius(); | |
113 | ||
114 | ComputePoles( R, U1, U2, V1, V2, poles); | |
115 | ||
116 | for ( i = 1; i<= nbUKnots; i++) { | |
117 | uknots(i) = U1 + (i-1) * 2 * AlfaU; | |
118 | umults(i) = 2; | |
119 | } | |
120 | umults(1)++; umults(nbUKnots)++; | |
121 | for ( i = 1; i<= nbVKnots; i++) { | |
122 | vknots(i) = V1 + (i-1) * 2 * AlfaV; | |
123 | vmults(i) = 2; | |
124 | } | |
125 | vmults(1)++; vmults(nbVKnots)++; | |
126 | ||
127 | ||
0d969553 Y |
128 | // Replace the bspline in the reference of the sphere. |
129 | // and calculate the weight of the bspline. | |
7fd59977 | 130 | Standard_Real W1, W2; |
131 | gp_Trsf Trsf; | |
132 | Trsf.SetTransformation( Sph.Position(), gp::XOY()); | |
133 | ||
134 | for ( i = 1; i <= nbUPoles; i++) { | |
135 | if ( i % 2 == 0) W1 = Cos(AlfaU); | |
136 | else W1 = 1.; | |
137 | ||
138 | for ( j = 1; j <= nbVPoles; j++) { | |
139 | if ( j % 2 == 0) W2 = Cos(AlfaV); | |
140 | else W2 = 1.; | |
141 | ||
142 | weights( i, j) = W1 * W2; | |
143 | poles( i, j).Transform( Trsf); | |
144 | } | |
145 | } | |
146 | } | |
147 | ||
148 | ||
149 | //======================================================================= | |
150 | //function : Convert_SphereToBSplineSurface | |
151 | //purpose : | |
152 | //======================================================================= | |
153 | ||
154 | Convert_SphereToBSplineSurface::Convert_SphereToBSplineSurface | |
155 | (const gp_Sphere& Sph , | |
156 | const Standard_Real Param1, | |
157 | const Standard_Real Param2, | |
158 | const Standard_Boolean UTrim ) | |
159 | : Convert_ElementarySurfaceToBSplineSurface (MaxNbUPoles, MaxNbVPoles, | |
160 | MaxNbUKnots, MaxNbVKnots, | |
161 | TheUDegree , TheVDegree) | |
162 | { | |
163 | #ifndef No_Exception | |
164 | Standard_Real delta = Param2 - Param1; | |
165 | #endif | |
c6541a0c | 166 | Standard_DomainError_Raise_if( (delta>2*M_PI) || (delta<0.), |
7fd59977 | 167 | "Convert_SphereToBSplineSurface"); |
168 | ||
169 | Standard_Integer i, j; | |
170 | Standard_Real deltaU, deltaV; | |
171 | ||
172 | isuperiodic = !UTrim; | |
173 | isvperiodic = Standard_False; | |
174 | ||
175 | Standard_Real R = Sph.Radius(); | |
176 | ||
177 | Standard_Real W1, W2, CosU, CosV; | |
178 | ||
179 | if ( isuperiodic) { | |
c6541a0c | 180 | ComputePoles(R, 0., 2.*M_PI, Param1, Param2, poles); |
7fd59977 | 181 | |
182 | nbUPoles = 6; | |
183 | nbUKnots = 4; | |
184 | ||
185 | deltaV = Param2 - Param1; | |
186 | Standard_Integer | |
c6541a0c | 187 | nbVSpans = (Standard_Integer)IntegerPart( 1.2 * deltaV / M_PI) + 1; |
7fd59977 | 188 | Standard_Real AlfaV = deltaV / ( nbVSpans * 2); |
189 | nbVPoles = 2 * nbVSpans + 1; | |
190 | nbVKnots = nbVSpans + 1; | |
191 | ||
192 | for ( i = 1; i <= nbUKnots; i++) { | |
c6541a0c | 193 | uknots(i) = ( i-1) * 2. * M_PI /3.; |
7fd59977 | 194 | umults(i) = 2; |
195 | } | |
196 | for ( i = 1; i <= nbVKnots; i++) { | |
197 | vknots(i) = Param1 + (i-1) * 2 * AlfaV; | |
198 | vmults(i) = 2; | |
199 | } | |
200 | vmults(1)++; vmults(nbVKnots)++; | |
201 | ||
202 | CosU = 0.5; // = Cos(pi /3) | |
203 | CosV = Cos(AlfaV); | |
204 | } | |
205 | else { | |
c6541a0c | 206 | ComputePoles(R, Param1, Param2, -M_PI/2., M_PI/2., poles); |
7fd59977 | 207 | |
208 | nbVPoles = 5; | |
209 | nbVKnots = 3; | |
210 | ||
211 | deltaU = Param2 - Param1; | |
212 | Standard_Integer | |
c6541a0c | 213 | nbUSpans = (Standard_Integer)IntegerPart( 1.2 * deltaU / M_PI) + 1; |
7fd59977 | 214 | Standard_Real AlfaU = deltaU / ( nbUSpans * 2); |
215 | nbUPoles = 2 * nbUSpans + 1; | |
216 | nbUKnots = nbUSpans + 1; | |
217 | ||
c6541a0c | 218 | vknots(1) = -M_PI/2.; vmults(1) = 3; |
7fd59977 | 219 | vknots(2) = 0.; vmults(2) = 2; |
c6541a0c | 220 | vknots(3) = M_PI/2.; vmults(3) = 3; |
7fd59977 | 221 | for ( i = 1; i <= nbUKnots; i++) { |
222 | uknots(i) = Param1 + (i-1) * 2 * AlfaU; | |
223 | umults(i) = 2; | |
224 | } | |
225 | umults(1)++; umults(nbUKnots)++; | |
226 | ||
227 | CosV = 0.5; // = Cos(pi /3) | |
228 | CosU = Cos(AlfaU); | |
229 | } | |
230 | ||
0d969553 Y |
231 | // Replace the bspline in the mark of the sphere. |
232 | // and calculate the weight of bspline. | |
7fd59977 | 233 | gp_Trsf Trsf; |
234 | Trsf.SetTransformation( Sph.Position(), gp::XOY()); | |
235 | ||
236 | for ( i = 1; i <= nbUPoles; i++) { | |
237 | if ( i % 2 == 0) W1 = CosU; | |
238 | else W1 = 1.; | |
239 | ||
240 | for ( j = 1; j <= nbVPoles; j++) { | |
241 | if ( j % 2 == 0) W2 = CosV; | |
242 | else W2 = 1.; | |
243 | ||
244 | weights( i, j) = W1 * W2; | |
245 | poles( i, j).Transform( Trsf); | |
246 | } | |
247 | } | |
248 | } | |
249 | ||
250 | ||
251 | //======================================================================= | |
252 | //function : Convert_SphereToBSplineSurface | |
253 | //purpose : | |
254 | //======================================================================= | |
255 | ||
256 | Convert_SphereToBSplineSurface::Convert_SphereToBSplineSurface | |
257 | (const gp_Sphere& Sph) | |
258 | : Convert_ElementarySurfaceToBSplineSurface (MaxNbUPoles, MaxNbVPoles, | |
259 | MaxNbUKnots, MaxNbVKnots, | |
260 | TheUDegree , TheVDegree) | |
261 | { | |
262 | isuperiodic = Standard_True; | |
263 | isvperiodic = Standard_False; | |
264 | ||
265 | Standard_Real W1, W2; | |
266 | Standard_Integer i, j; | |
267 | ||
268 | nbUPoles = 6; | |
269 | nbVPoles = 5; | |
270 | nbUKnots = 4; | |
271 | nbVKnots = 3; | |
272 | ||
0d969553 | 273 | // Construction of the sphere in the reference mark xOy. |
7fd59977 | 274 | |
275 | Standard_Real R = Sph.Radius(); | |
276 | ||
c6541a0c | 277 | ComputePoles( R, 0., 2.*M_PI, -M_PI/2., M_PI/2., poles); |
7fd59977 | 278 | |
279 | uknots( 1) = 0.; | |
c6541a0c D |
280 | uknots( 2) = 2. * M_PI / 3.; |
281 | uknots( 3) = 4. * M_PI / 3.; | |
282 | uknots( 4) = 2. * M_PI; | |
283 | vknots( 1) = -M_PI/2.; | |
7fd59977 | 284 | vknots( 2) = 0.; |
c6541a0c | 285 | vknots( 3) = M_PI/2.; |
7fd59977 | 286 | for ( i = 1; i <= 4; i++) { |
287 | umults( i) = 2; | |
288 | } | |
289 | vmults(1) = vmults(3) = 3; | |
290 | vmults(2) = 2; | |
291 | ||
0d969553 Y |
292 | // Replace the bspline in the mark of the sphere. |
293 | // and calculate the weight of the bspline. | |
7fd59977 | 294 | gp_Trsf Trsf; |
295 | Trsf.SetTransformation( Sph.Position(), gp::XOY()); | |
296 | ||
297 | for ( i = 1; i <= nbUPoles; i++) { | |
298 | if ( i % 2 == 0) W1 = 0.5; | |
299 | else W1 = 1.; | |
300 | ||
301 | for ( j = 1; j <= nbVPoles; j++) { | |
302 | if ( j % 2 == 0) W2 = Sqrt(2.) /2.; | |
303 | else W2 = 1.; | |
304 | ||
305 | weights( i, j) = W1 * W2; | |
306 | poles( i, j).Transform( Trsf); | |
307 | } | |
308 | } | |
309 | } | |
310 |