Integration of OCCT 6.5.0 from SVN
[occt.git] / src / Convert / Convert_CylinderToBSplineSurface.cxx
1 //File Convert_CylinderToBSplineSurface.cxx
2 //JCV 16/10/91
3
4
5 #include <Convert_CylinderToBSplineSurface.ixx>
6
7 #include <gp.hxx>
8 #include <gp_Trsf.hxx>
9
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;
16
17
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)
24 {
25   Standard_Real deltaU = U2 - U1;
26   
27   Standard_Integer i;
28
29   // Nombre de spans : ouverture maximale = 150 degres ( = PI / 1.2 rds)
30   Standard_Integer 
31     nbUSpans = (Standard_Integer)IntegerPart( 1.2 * deltaU / PI) + 1;
32   Standard_Real AlfaU = deltaU / ( nbUSpans * 2);
33
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);
37   
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),
41                              V1 );
42     Poles( 2*i, 2) = gp_Pnt( R * Cos(UStart+AlfaU) / Cos(AlfaU),
43                              R * Sin(UStart+AlfaU) / Cos(AlfaU),
44                              V2 );
45     Poles(2*i+1,1) = gp_Pnt( R * Cos(UStart+2*AlfaU),
46                              R * Sin(UStart+2*AlfaU),
47                              V1 );
48     Poles(2*i+1,2) = gp_Pnt( R * Cos(UStart+2*AlfaU),
49                              R * Sin(UStart+2*AlfaU),
50                              V2 );
51     UStart += 2*AlfaU;
52   }
53 }
54
55
56 //=======================================================================
57 //function : Convert_CylinderToBSplineSurface
58 //purpose  : 
59 //=======================================================================
60
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  ) 
70 {
71   Standard_Real deltaU = U2 - U1;
72   Standard_DomainError_Raise_if( (Abs(V2-V1) <= Abs(Epsilon(V1))) ||
73                                  (deltaU  >  2*PI)                || 
74                                  (deltaU  <  0.  ),
75                                  "Convert_CylinderToBSplineSurface");
76
77   isuperiodic = Standard_False;
78   isvperiodic = Standard_False;
79
80   Standard_Integer i,j;
81   // construction du cylindre dans le repere de reference xOy.
82
83   // Nombre de spans : ouverture maximale = 150 degres ( = PI / 1.2 rds)
84   Standard_Integer 
85     nbUSpans = (Standard_Integer)IntegerPart( 1.2 * deltaU / PI) + 1;
86   Standard_Real AlfaU = deltaU / ( nbUSpans * 2);
87
88   nbUPoles = 2 * nbUSpans + 1;
89   nbUKnots = nbUSpans + 1;
90
91   nbVPoles = 2;
92   nbVKnots = 2;
93
94   Standard_Real R = Cyl.Radius();
95   
96   ComputePoles( R, U1, U2, V1, V2, poles);
97
98   for ( i = 1; i<= nbUKnots; i++) {
99     uknots(i) = U1 + (i-1) * 2 * AlfaU;
100     umults(i) = 2;
101   }
102   umults(1)++; umults(nbUKnots)++;
103   vknots(1) = V1; vmults(1) = 2;
104   vknots(2) = V2; vmults(2) = 2;
105
106   // On replace la bspline dans le repere de la sphere.
107   // et on calcule les poids de la bspline.
108   Standard_Real W1;
109   gp_Trsf Trsf;
110   Trsf.SetTransformation( Cyl.Position(), gp::XOY());
111
112   for ( i = 1; i <= nbUPoles; i++) {
113     if ( i % 2 == 0)  W1 = Cos(AlfaU);
114     else              W1 = 1.;
115
116     for ( j = 1; j <= nbVPoles; j++) {
117       weights( i, j) = W1;
118       poles( i, j).Transform( Trsf);
119     }
120   }
121 }
122
123
124 //=======================================================================
125 //function : Convert_CylinderToBSplineSurface
126 //purpose  : 
127 //=======================================================================
128
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)
136 {
137   Standard_DomainError_Raise_if( Abs(V2-V1) <= Abs(Epsilon(V1)),
138                                  "Convert_CylinderToBSplineSurface");
139
140   Standard_Integer i,j;
141
142   isuperiodic = Standard_True;
143   isvperiodic = Standard_False;
144
145   // construction du cylindre dans le repere de reference xOy.
146
147   Standard_Real R = Cyl.Radius();
148   
149   ComputePoles( R, 0., 2.*PI, V1, V2, poles); 
150
151   nbUPoles = 6;
152   nbUKnots = 4;
153   nbVPoles = 2;
154   nbVKnots = 2;
155   
156   for ( i = 1; i <= nbUKnots; i++) {
157     uknots(i) = ( i-1) * 2. * PI /3.;
158     umults(i) = 2;
159   }
160   vknots(1) = V1;  vmults(1) = 2;
161   vknots(2) = V2;  vmults(2) = 2;
162
163   // On replace la bspline dans le repere du cone.
164   // et on calcule les poids de la bspline.
165   Standard_Real W;
166   gp_Trsf Trsf;
167   Trsf.SetTransformation( Cyl.Position(), gp::XOY());
168
169   for ( i = 1; i <= nbUPoles; i++) {
170     if ( i % 2 == 0)  W = 0.5;    // = Cos(pi /3)
171     else              W = 1.;
172
173     for ( j = 1; j <= nbVPoles; j++) {
174       weights( i, j) = W;
175       poles( i, j).Transform( Trsf);
176     }
177   }
178 }
179