1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
21 #include <Convert_ConeToBSplineSurface.ixx>
24 #include <gp_Trsf.hxx>
26 static const Standard_Integer TheUDegree = 2;
27 static const Standard_Integer TheVDegree = 1;
28 static const Standard_Integer TheNbUKnots = 5;
29 static const Standard_Integer TheNbVKnots = 2;
30 static const Standard_Integer TheNbUPoles = 9;
31 static const Standard_Integer TheNbVPoles = 2;
34 static void ComputePoles( const Standard_Real R,
35 const Standard_Real A,
36 const Standard_Real U1,
37 const Standard_Real U2,
38 const Standard_Real V1,
39 const Standard_Real V2,
40 TColgp_Array2OfPnt& Poles)
42 Standard_Real deltaU = U2 - U1;
46 // Number of spans : maximum opening = 150 degrees ( = PI / 1.2 rds)
48 nbUSpans = (Standard_Integer)IntegerPart( 1.2 * deltaU / M_PI) + 1;
49 Standard_Real AlfaU = deltaU / ( nbUSpans * 2);
51 Standard_Real x[TheNbVPoles];
52 Standard_Real z[TheNbVPoles];
54 x[0] = R + V1 * Sin(A);
56 x[1] = R + V2 * Sin(A);
59 Standard_Real UStart = U1;
60 Poles(1,1) = gp_Pnt(x[0]*Cos(UStart),x[0]*Sin(UStart),z[0]);
61 Poles(1,2) = gp_Pnt(x[1]*Cos(UStart),x[1]*Sin(UStart),z[1]);
63 for ( i = 1; i <= nbUSpans; i++) {
64 Poles( 2*i, 1) = gp_Pnt( x[0] * Cos(UStart+AlfaU) / Cos(AlfaU),
65 x[0] * Sin(UStart+AlfaU) / Cos(AlfaU),
67 Poles( 2*i, 2) = gp_Pnt( x[1] * Cos(UStart+AlfaU) / Cos(AlfaU),
68 x[1] * Sin(UStart+AlfaU) / Cos(AlfaU),
70 Poles(2*i+1,1) = gp_Pnt( x[0] * Cos(UStart+2*AlfaU),
71 x[0] * Sin(UStart+2*AlfaU),
73 Poles(2*i+1,2) = gp_Pnt( x[1] * Cos(UStart+2*AlfaU),
74 x[1] * Sin(UStart+2*AlfaU),
81 //=======================================================================
82 //function : Convert_ConeToBSplineSurface
84 //=======================================================================
86 Convert_ConeToBSplineSurface::Convert_ConeToBSplineSurface
88 const Standard_Real U1,
89 const Standard_Real U2,
90 const Standard_Real V1,
91 const Standard_Real V2 )
92 : Convert_ElementarySurfaceToBSplineSurface (TheNbUPoles, TheNbVPoles,
93 TheNbUKnots, TheNbVKnots,
94 TheUDegree , TheVDegree )
96 Standard_Real deltaU = U2 - U1;
97 Standard_DomainError_Raise_if( (Abs(V2-V1) <= Abs(Epsilon(V1))) ||
100 "Convert_ConeToBSplineSurface");
102 isuperiodic = Standard_False;
103 isvperiodic = Standard_False;
105 Standard_Integer i,j;
106 // construction of cone in the reference mark xOy.
108 // Number of spans : maximum opening = 150 degrees ( = PI / 1.2 rds)
110 nbUSpans = (Standard_Integer)IntegerPart( 1.2 * deltaU / M_PI) + 1;
111 Standard_Real AlfaU = deltaU / ( nbUSpans * 2);
113 nbUPoles = 2 * nbUSpans + 1;
114 nbUKnots = nbUSpans + 1;
119 Standard_Real R = C.RefRadius();
120 Standard_Real A = C.SemiAngle();
122 ComputePoles( R, A, U1, U2, V1, V2, poles);
124 for ( i = 1; i<= nbUKnots; i++) {
125 uknots(i) = U1 + (i-1) * 2 * AlfaU;
128 umults(1)++; umults(nbUKnots)++;
129 vknots(1) = V1; vmults(1) = 2;
130 vknots(2) = V2; vmults(2) = 2;
132 // Replace the bspline in the mark of the sphere.
133 // and calculate the weight of the bspline.
136 Trsf.SetTransformation( C.Position(), gp::XOY());
138 for ( i = 1; i <= nbUPoles; i++) {
139 if ( i % 2 == 0) W1 = Cos(AlfaU);
142 for ( j = 1; j <= nbVPoles; j++) {
144 poles( i, j).Transform( Trsf);
150 //=======================================================================
151 //function : Convert_ConeToBSplineSurface
153 //=======================================================================
155 Convert_ConeToBSplineSurface::Convert_ConeToBSplineSurface
157 const Standard_Real V1,
158 const Standard_Real V2 )
159 : Convert_ElementarySurfaceToBSplineSurface (TheNbUPoles, TheNbVPoles,
160 TheNbUKnots, TheNbVKnots,
161 TheUDegree, TheVDegree)
163 Standard_DomainError_Raise_if( Abs(V2-V1) <= Abs(Epsilon(V1)),
164 "Convert_ConeToBSplineSurface");
166 Standard_Integer i,j;
168 isuperiodic = Standard_True;
169 isvperiodic = Standard_False;
171 // construction of the cone in the reference mark xOy.
173 Standard_Real R = C.RefRadius();
174 Standard_Real A = C.SemiAngle();
176 ComputePoles( R, A, 0., 2.*M_PI, V1, V2, poles);
183 for ( i = 1; i <= nbUKnots; i++) {
184 uknots(i) = ( i-1) * 2. * M_PI /3.;
187 vknots(1) = V1; vmults(1) = 2;
188 vknots(2) = V2; vmults(2) = 2;
190 // replace bspline in the mark of the cone.
191 // and calculate the weight of bspline.
194 Trsf.SetTransformation( C.Position(), gp::XOY());
196 for ( i = 1; i <= nbUPoles; i++) {
197 if ( i % 2 == 0) W = 0.5; // = Cos(pi /3)
200 for ( j = 1; j <= nbVPoles; j++) {
202 poles( i, j).Transform( Trsf);