1 //File Convert_TorusToBSplineSurface.cxx
4 #include <Convert_TorusToBSplineSurface.ixx>
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 = 4;
13 static const Standard_Integer MaxNbUPoles = 7;
14 static const Standard_Integer MaxNbVPoles = 7;
17 static void ComputePoles ( const Standard_Real R,
18 const Standard_Real r,
19 const Standard_Real U1,
20 const Standard_Real U2,
21 const Standard_Real V1,
22 const Standard_Real V2,
23 TColgp_Array2OfPnt& Poles)
25 Standard_Real deltaU = U2 - U1;
26 Standard_Real deltaV = V2 - V1;
28 Standard_Integer i, j;
30 // Number of spans : maximum opening = 150 degrees ( = PI / 1.2 rds)
32 nbUSpans = (Standard_Integer)IntegerPart( 1.2 * deltaU / PI) + 1;
34 nbVSpans = (Standard_Integer)IntegerPart( 1.2 * deltaV / PI) + 1;
35 Standard_Real AlfaU = deltaU / ( nbUSpans * 2);
36 Standard_Real AlfaV = deltaV / ( nbVSpans * 2);
38 Standard_Integer nbVP = 2 * nbVSpans + 1;
40 Standard_Real x[MaxNbVPoles];
41 Standard_Real z[MaxNbVPoles];
43 x[0] = R + r * Cos( V1);
46 Standard_Real VStart = V1;
47 for ( i = 1; i <= nbVSpans; i++) {
48 x[2*i-1] = R + r * Cos( VStart + AlfaV) / Cos( AlfaV);
49 z[2*i-1] = r * Sin( VStart + AlfaV) / Cos( AlfaV);
50 x[2*i] = R + r * Cos( VStart + 2 * AlfaV);
51 z[2*i] = r * Sin( VStart + 2 * AlfaV);
55 Standard_Real UStart = U1;
56 for ( j = 0; j <= nbVP-1; j++) {
57 Poles( 1, j+1) = gp_Pnt(x[j]*Cos(UStart),x[j]*Sin(UStart),z[j]);
60 for ( i = 1; i <= nbUSpans; i++) {
61 for ( j = 0; j<= nbVP-1; j++) {
62 Poles( 2*i, j+1) = gp_Pnt( x[j] * Cos(UStart+AlfaU) / Cos(AlfaU),
63 x[j] * Sin(UStart+AlfaU) / Cos(AlfaU),
65 Poles(2*i+1,j+1) = gp_Pnt( x[j] * Cos(UStart+2*AlfaU),
66 x[j] * Sin(UStart+2*AlfaU),
74 //=======================================================================
75 //function : Convert_TorusToBSplineSurface
77 //=======================================================================
79 Convert_TorusToBSplineSurface::Convert_TorusToBSplineSurface
81 const Standard_Real U1,
82 const Standard_Real U2,
83 const Standard_Real V1,
84 const Standard_Real V2)
85 : Convert_ElementarySurfaceToBSplineSurface (MaxNbUPoles, MaxNbVPoles,
86 MaxNbUKnots, MaxNbVKnots,
87 TheUDegree , TheVDegree)
89 Standard_Real deltaU = U2 - U1;
90 Standard_Real deltaV = V2 - V1;
91 Standard_DomainError_Raise_if( (deltaU>2*PI) || (deltaU<0.) ||
92 (deltaV>2*PI) || (deltaV<0.),
93 "Convert_TorusToBSplineSurface");
95 isuperiodic = Standard_False;
96 isvperiodic = Standard_False;
99 // construction of the torus in the reference mark xOy.
101 // Number of spans : maximum opening = 150 degrees ( = PI / 1.2 rds)
103 nbUSpans = (Standard_Integer)IntegerPart( 1.2 * deltaU / PI) + 1;
105 nbVSpans = (Standard_Integer)IntegerPart( 1.2 * deltaV / PI) + 1;
106 Standard_Real AlfaU = deltaU / ( nbUSpans * 2);
107 Standard_Real AlfaV = deltaV / ( nbVSpans * 2);
109 nbUPoles = 2 * nbUSpans + 1;
110 nbVPoles = 2 * nbVSpans + 1;
111 nbUKnots = nbUSpans + 1;
112 nbVKnots = nbVSpans + 1;
114 Standard_Real R = T.MajorRadius();
115 Standard_Real r = T.MinorRadius();
117 ComputePoles( R, r, U1, U2, V1, V2, poles);
119 for ( i = 1; i<= nbUKnots; i++) {
120 uknots(i) = U1 + (i-1) * 2 * AlfaU;
123 umults(1)++; umults(nbUKnots)++;
124 for ( i = 1; i<= nbVKnots; i++) {
125 vknots(i) = V1 + (i-1) * 2 * AlfaV;
128 vmults(1)++; vmults(nbVKnots)++;
131 // Replace the bspline in the reference of the torus.
132 // and calculate the weight of the bspline.
133 Standard_Real W1, W2;
135 Trsf.SetTransformation( T.Position(), gp::XOY());
137 for ( i = 1; i <= nbUPoles; i++) {
138 if ( i % 2 == 0) W1 = Cos(AlfaU);
141 for ( j = 1; j <= nbVPoles; j++) {
142 if ( j % 2 == 0) W2 = Cos(AlfaV);
145 weights( i, j) = W1 * W2;
146 poles( i, j).Transform( Trsf);
152 //=======================================================================
153 //function : Convert_TorusToBSplineSurface
155 //=======================================================================
157 Convert_TorusToBSplineSurface::Convert_TorusToBSplineSurface
159 const Standard_Real Param1,
160 const Standard_Real Param2,
161 const Standard_Boolean UTrim )
162 : Convert_ElementarySurfaceToBSplineSurface (MaxNbUPoles, MaxNbVPoles,
163 MaxNbUKnots, MaxNbVKnots,
164 TheUDegree , TheVDegree)
167 Standard_Real delta = Param2 - Param1;
169 Standard_DomainError_Raise_if( (delta>2*PI) || (delta<0.),
170 "Convert_TorusToBSplineSurface");
172 Standard_Integer i, j;
173 Standard_Real deltaU, deltaV;
175 isuperiodic = !UTrim;
178 Standard_Real R = T.MajorRadius();
179 Standard_Real r = T.MinorRadius();
181 Standard_Real W1, W2, CosU, CosV;
184 ComputePoles(R, r, 0, 2.*PI, Param1, Param2, poles);
189 deltaV = Param2 - Param1;
191 nbVSpans = (Standard_Integer)IntegerPart( 1.2 * deltaV / PI) + 1;
192 Standard_Real AlfaV = deltaV / ( nbVSpans * 2);
193 nbVPoles = 2 * nbVSpans + 1;
194 nbVKnots = nbVSpans + 1;
196 for ( i = 1; i <= nbUKnots; i++) {
197 uknots(i) = ( i-1) * 2. * PI /3.;
200 for ( i = 1; i <= nbVKnots; i++) {
201 vknots(i) = Param1 + (i-1) * 2 * AlfaV;
204 vmults(1)++; vmults(nbVKnots)++;
206 CosU = 0.5; // = Cos(pi /3)
210 ComputePoles(R, r, Param1, Param2, 0., 2.*PI, poles);
215 deltaU = Param2 - Param1;
217 nbUSpans = (Standard_Integer)IntegerPart( 1.2 * deltaU / PI) + 1;
218 Standard_Real AlfaU = deltaU / ( nbUSpans * 2);
219 nbUPoles = 2 * nbUSpans + 1;
220 nbUKnots = nbUSpans + 1;
222 for ( i = 1; i <= nbVKnots; i++) {
223 vknots(i) = ( i-1) * 2. * PI /3.;
226 for ( i = 1; i <= nbUKnots; i++) {
227 uknots(i) = Param1 + (i-1) * 2 * AlfaU;
230 umults(1)++; umults(nbUKnots)++;
232 CosV = 0.5; // = Cos(pi /3)
236 // Replace the bspline in the reference of the torus.
237 // and calculate the weight of the bspline.
239 Trsf.SetTransformation( T.Position(), gp::XOY());
241 for ( i = 1; i <= nbUPoles; i++) {
242 if ( i % 2 == 0) W1 = CosU;
245 for ( j = 1; j <= nbVPoles; j++) {
246 if ( j % 2 == 0) W2 = CosV;
249 weights( i, j) = W1 * W2;
250 poles( i, j).Transform( Trsf);
257 //=======================================================================
258 //function : Convert_TorusToBSplineSurface
260 //=======================================================================
262 Convert_TorusToBSplineSurface::Convert_TorusToBSplineSurface
264 : Convert_ElementarySurfaceToBSplineSurface (MaxNbUPoles, MaxNbVPoles,
265 MaxNbUKnots, MaxNbVKnots,
266 TheUDegree , TheVDegree )
268 isuperiodic = Standard_True;
269 isvperiodic = Standard_True;
271 Standard_Real W1, W2;
272 Standard_Integer i, j;
279 // Construction of the Torus in the reference mark xOy.
281 Standard_Real R = T.MajorRadius();
282 Standard_Real r = T.MinorRadius();
284 ComputePoles( R, r, 0., 2.*PI, 0., 2.*PI, poles);
286 uknots( 1) = vknots( 1) = 0.;
287 uknots( 2) = vknots( 2) = 2. * PI / 3.;
288 uknots( 3) = vknots( 3) = 4. * PI / 3.;
289 uknots( 4) = vknots( 4) = 2. * PI;
290 for ( i = 1; i <= 4; i++) {
291 umults( i) = vmults( i) = 2;
294 // Replace the bspline in the mark of the torus.
295 // and calculate the weight of the bspline.
297 Trsf.SetTransformation( T.Position(), gp::XOY());
299 for ( i = 1; i <= nbUPoles; i++) {
300 if ( i % 2 == 0) W1 = 0.5;
303 for ( j = 1; j <= nbVPoles; j++) {
304 if ( j % 2 == 0) W2 = 0.5;
307 weights( i, j) = W1 * W2;
308 poles( i, j).Transform( Trsf);