1 //File Convert_CylinderToBSplineSurface.cxx
5 #include <Convert_CylinderToBSplineSurface.ixx>
10 static const Standard_Integer TheUDegree = 2;
11 static const Standard_Integer TheVDegree = 1;
12 static const Standard_Integer TheNbUKnots = 5;
13 static const Standard_Integer TheNbVKnots = 2;
14 static const Standard_Integer TheNbUPoles = 9;
15 static const Standard_Integer TheNbVPoles = 2;
18 static void ComputePoles( 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;
29 // Nombre de spans : ouverture maximale = 150 degres ( = PI / 1.2 rds)
31 nbUSpans = (Standard_Integer)IntegerPart( 1.2 * deltaU / PI) + 1;
32 Standard_Real AlfaU = deltaU / ( nbUSpans * 2);
34 Standard_Real UStart = U1;
35 Poles(1,1) = gp_Pnt(R*Cos(UStart),R*Sin(UStart),V1);
36 Poles(1,2) = gp_Pnt(R*Cos(UStart),R*Sin(UStart),V2);
38 for ( i = 1; i <= nbUSpans; i++) {
39 Poles( 2*i, 1) = gp_Pnt( R * Cos(UStart+AlfaU) / Cos(AlfaU),
40 R * Sin(UStart+AlfaU) / Cos(AlfaU),
42 Poles( 2*i, 2) = gp_Pnt( R * Cos(UStart+AlfaU) / Cos(AlfaU),
43 R * Sin(UStart+AlfaU) / Cos(AlfaU),
45 Poles(2*i+1,1) = gp_Pnt( R * Cos(UStart+2*AlfaU),
46 R * Sin(UStart+2*AlfaU),
48 Poles(2*i+1,2) = gp_Pnt( R * Cos(UStart+2*AlfaU),
49 R * Sin(UStart+2*AlfaU),
56 //=======================================================================
57 //function : Convert_CylinderToBSplineSurface
59 //=======================================================================
61 Convert_CylinderToBSplineSurface::Convert_CylinderToBSplineSurface
62 (const gp_Cylinder& Cyl,
63 const Standard_Real U1 ,
64 const Standard_Real U2 ,
65 const Standard_Real V1 ,
66 const Standard_Real V2 )
67 : Convert_ElementarySurfaceToBSplineSurface (TheNbUPoles, TheNbVPoles,
68 TheNbUKnots, TheNbVKnots,
69 TheUDegree , TheVDegree )
71 Standard_Real deltaU = U2 - U1;
72 Standard_DomainError_Raise_if( (Abs(V2-V1) <= Abs(Epsilon(V1))) ||
75 "Convert_CylinderToBSplineSurface");
77 isuperiodic = Standard_False;
78 isvperiodic = Standard_False;
81 // construction du cylindre dans le repere de reference xOy.
83 // Nombre de spans : ouverture maximale = 150 degres ( = PI / 1.2 rds)
85 nbUSpans = (Standard_Integer)IntegerPart( 1.2 * deltaU / PI) + 1;
86 Standard_Real AlfaU = deltaU / ( nbUSpans * 2);
88 nbUPoles = 2 * nbUSpans + 1;
89 nbUKnots = nbUSpans + 1;
94 Standard_Real R = Cyl.Radius();
96 ComputePoles( R, U1, U2, V1, V2, poles);
98 for ( i = 1; i<= nbUKnots; i++) {
99 uknots(i) = U1 + (i-1) * 2 * AlfaU;
102 umults(1)++; umults(nbUKnots)++;
103 vknots(1) = V1; vmults(1) = 2;
104 vknots(2) = V2; vmults(2) = 2;
106 // On replace la bspline dans le repere de la sphere.
107 // et on calcule les poids de la bspline.
110 Trsf.SetTransformation( Cyl.Position(), gp::XOY());
112 for ( i = 1; i <= nbUPoles; i++) {
113 if ( i % 2 == 0) W1 = Cos(AlfaU);
116 for ( j = 1; j <= nbVPoles; j++) {
118 poles( i, j).Transform( Trsf);
124 //=======================================================================
125 //function : Convert_CylinderToBSplineSurface
127 //=======================================================================
129 Convert_CylinderToBSplineSurface::Convert_CylinderToBSplineSurface
130 (const gp_Cylinder& Cyl,
131 const Standard_Real V1 ,
132 const Standard_Real V2 )
133 : Convert_ElementarySurfaceToBSplineSurface (TheNbUPoles, TheNbVPoles,
134 TheNbUKnots, TheNbVKnots,
135 TheUDegree , TheVDegree)
137 Standard_DomainError_Raise_if( Abs(V2-V1) <= Abs(Epsilon(V1)),
138 "Convert_CylinderToBSplineSurface");
140 Standard_Integer i,j;
142 isuperiodic = Standard_True;
143 isvperiodic = Standard_False;
145 // construction du cylindre dans le repere de reference xOy.
147 Standard_Real R = Cyl.Radius();
149 ComputePoles( R, 0., 2.*PI, V1, V2, poles);
156 for ( i = 1; i <= nbUKnots; i++) {
157 uknots(i) = ( i-1) * 2. * PI /3.;
160 vknots(1) = V1; vmults(1) = 2;
161 vknots(2) = V2; vmults(2) = 2;
163 // On replace la bspline dans le repere du cone.
164 // et on calcule les poids de la bspline.
167 Trsf.SetTransformation( Cyl.Position(), gp::XOY());
169 for ( i = 1; i <= nbUPoles; i++) {
170 if ( i % 2 == 0) W = 0.5; // = Cos(pi /3)
173 for ( j = 1; j <= nbVPoles; j++) {
175 poles( i, j).Transform( Trsf);