1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
17 #include <Convert_CylinderToBSplineSurface.hxx>
19 #include <gp_Cylinder.hxx>
20 #include <gp_Trsf.hxx>
21 #include <Standard_DomainError.hxx>
23 static const Standard_Integer TheUDegree = 2;
24 static const Standard_Integer TheVDegree = 1;
25 static const Standard_Integer TheNbUKnots = 5;
26 static const Standard_Integer TheNbVKnots = 2;
27 static const Standard_Integer TheNbUPoles = 9;
28 static const Standard_Integer TheNbVPoles = 2;
31 static void ComputePoles( const Standard_Real R,
32 const Standard_Real U1,
33 const Standard_Real U2,
34 const Standard_Real V1,
35 const Standard_Real V2,
36 TColgp_Array2OfPnt& Poles)
38 Standard_Real deltaU = U2 - U1;
42 // Number of spans : maximum opening = 150 degrees ( = PI / 1.2 rds)
44 nbUSpans = (Standard_Integer)IntegerPart( 1.2 * deltaU / M_PI) + 1;
45 Standard_Real AlfaU = deltaU / ( nbUSpans * 2);
47 Standard_Real UStart = U1;
48 Poles(1,1) = gp_Pnt(R*Cos(UStart),R*Sin(UStart),V1);
49 Poles(1,2) = gp_Pnt(R*Cos(UStart),R*Sin(UStart),V2);
51 for ( i = 1; i <= nbUSpans; i++) {
52 Poles( 2*i, 1) = gp_Pnt( R * Cos(UStart+AlfaU) / Cos(AlfaU),
53 R * Sin(UStart+AlfaU) / Cos(AlfaU),
55 Poles( 2*i, 2) = gp_Pnt( R * Cos(UStart+AlfaU) / Cos(AlfaU),
56 R * Sin(UStart+AlfaU) / Cos(AlfaU),
58 Poles(2*i+1,1) = gp_Pnt( R * Cos(UStart+2*AlfaU),
59 R * Sin(UStart+2*AlfaU),
61 Poles(2*i+1,2) = gp_Pnt( R * Cos(UStart+2*AlfaU),
62 R * Sin(UStart+2*AlfaU),
69 //=======================================================================
70 //function : Convert_CylinderToBSplineSurface
72 //=======================================================================
74 Convert_CylinderToBSplineSurface::Convert_CylinderToBSplineSurface
75 (const gp_Cylinder& Cyl,
76 const Standard_Real U1 ,
77 const Standard_Real U2 ,
78 const Standard_Real V1 ,
79 const Standard_Real V2 )
80 : Convert_ElementarySurfaceToBSplineSurface (TheNbUPoles, TheNbVPoles,
81 TheNbUKnots, TheNbVKnots,
82 TheUDegree , TheVDegree )
84 Standard_Real deltaU = U2 - U1;
85 Standard_DomainError_Raise_if( (Abs(V2-V1) <= Abs(Epsilon(V1))) ||
88 "Convert_CylinderToBSplineSurface");
90 isuperiodic = Standard_False;
91 isvperiodic = Standard_False;
94 // construction of the cylinder in the reference mark xOy.
96 // Number of spans : maximum opening = 150 degrees ( = PI / 1.2 rds)
98 nbUSpans = (Standard_Integer)IntegerPart( 1.2 * deltaU / M_PI) + 1;
99 Standard_Real AlfaU = deltaU / ( nbUSpans * 2);
101 nbUPoles = 2 * nbUSpans + 1;
102 nbUKnots = nbUSpans + 1;
107 Standard_Real R = Cyl.Radius();
109 ComputePoles( R, U1, U2, V1, V2, poles);
111 for ( i = 1; i<= nbUKnots; i++) {
112 uknots(i) = U1 + (i-1) * 2 * AlfaU;
115 umults(1)++; umults(nbUKnots)++;
116 vknots(1) = V1; vmults(1) = 2;
117 vknots(2) = V2; vmults(2) = 2;
119 // Replace bspline in the mark of the sphere.
120 // and calculate the weight of the bspline.
123 Trsf.SetTransformation( Cyl.Position(), gp::XOY());
125 for ( i = 1; i <= nbUPoles; i++) {
126 if ( i % 2 == 0) W1 = Cos(AlfaU);
129 for ( j = 1; j <= nbVPoles; j++) {
131 poles( i, j).Transform( Trsf);
137 //=======================================================================
138 //function : Convert_CylinderToBSplineSurface
140 //=======================================================================
142 Convert_CylinderToBSplineSurface::Convert_CylinderToBSplineSurface
143 (const gp_Cylinder& Cyl,
144 const Standard_Real V1 ,
145 const Standard_Real V2 )
146 : Convert_ElementarySurfaceToBSplineSurface (TheNbUPoles, TheNbVPoles,
147 TheNbUKnots, TheNbVKnots,
148 TheUDegree , TheVDegree)
150 Standard_DomainError_Raise_if( Abs(V2-V1) <= Abs(Epsilon(V1)),
151 "Convert_CylinderToBSplineSurface");
153 Standard_Integer i,j;
155 isuperiodic = Standard_True;
156 isvperiodic = Standard_False;
158 // construction of the cylinder in the reference mark xOy.
160 Standard_Real R = Cyl.Radius();
162 ComputePoles( R, 0., 2.*M_PI, V1, V2, poles);
169 for ( i = 1; i <= nbUKnots; i++) {
170 uknots(i) = ( i-1) * 2. * M_PI /3.;
173 vknots(1) = V1; vmults(1) = 2;
174 vknots(2) = V2; vmults(2) = 2;
176 // Replace the bspline inn the mark of the cone.
177 // and calculate the weight of the bspline.
180 Trsf.SetTransformation( Cyl.Position(), gp::XOY());
182 for ( i = 1; i <= nbUPoles; i++) {
183 if ( i % 2 == 0) W = 0.5; // = Cos(pi /3)
186 for ( j = 1; j <= nbVPoles; j++) {
188 poles( i, j).Transform( Trsf);