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