0026937: Eliminate NO_CXX_EXCEPTION macro support
[occt.git] / src / Convert / Convert_ConeToBSplineSurface.cxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 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
973c2be1 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.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
7fd59977 15//JCV 16/10/91
16
42cf5bc1 17#include <Convert_ConeToBSplineSurface.hxx>
7fd59977 18#include <gp.hxx>
42cf5bc1 19#include <gp_Cone.hxx>
7fd59977 20#include <gp_Trsf.hxx>
42cf5bc1 21#include <Standard_DomainError.hxx>
7fd59977 22
23static const Standard_Integer TheUDegree = 2;
24static const Standard_Integer TheVDegree = 1;
25static const Standard_Integer TheNbUKnots = 5;
26static const Standard_Integer TheNbVKnots = 2;
27static const Standard_Integer TheNbUPoles = 9;
28static const Standard_Integer TheNbVPoles = 2;
29
30
31static void ComputePoles( const Standard_Real R,
32 const Standard_Real A,
33 const Standard_Real U1,
34 const Standard_Real U2,
35 const Standard_Real V1,
36 const Standard_Real V2,
37 TColgp_Array2OfPnt& Poles)
38{
39 Standard_Real deltaU = U2 - U1;
40
41 Standard_Integer i;
42
0d969553 43 // Number of spans : maximum opening = 150 degrees ( = PI / 1.2 rds)
7fd59977 44 Standard_Integer
c6541a0c 45 nbUSpans = (Standard_Integer)IntegerPart( 1.2 * deltaU / M_PI) + 1;
7fd59977 46 Standard_Real AlfaU = deltaU / ( nbUSpans * 2);
47
48 Standard_Real x[TheNbVPoles];
49 Standard_Real z[TheNbVPoles];
50
51 x[0] = R + V1 * Sin(A);
52 z[0] = V1 * Cos(A);
53 x[1] = R + V2 * Sin(A);
54 z[1] = V2 * Cos(A);
55
56 Standard_Real UStart = U1;
57 Poles(1,1) = gp_Pnt(x[0]*Cos(UStart),x[0]*Sin(UStart),z[0]);
58 Poles(1,2) = gp_Pnt(x[1]*Cos(UStart),x[1]*Sin(UStart),z[1]);
59
60 for ( i = 1; i <= nbUSpans; i++) {
61 Poles( 2*i, 1) = gp_Pnt( x[0] * Cos(UStart+AlfaU) / Cos(AlfaU),
62 x[0] * Sin(UStart+AlfaU) / Cos(AlfaU),
63 z[0] );
64 Poles( 2*i, 2) = gp_Pnt( x[1] * Cos(UStart+AlfaU) / Cos(AlfaU),
65 x[1] * Sin(UStart+AlfaU) / Cos(AlfaU),
66 z[1] );
67 Poles(2*i+1,1) = gp_Pnt( x[0] * Cos(UStart+2*AlfaU),
68 x[0] * Sin(UStart+2*AlfaU),
69 z[0] );
70 Poles(2*i+1,2) = gp_Pnt( x[1] * Cos(UStart+2*AlfaU),
71 x[1] * Sin(UStart+2*AlfaU),
72 z[1] );
73 UStart += 2*AlfaU;
74 }
75}
76
77
78//=======================================================================
79//function : Convert_ConeToBSplineSurface
80//purpose :
81//=======================================================================
82
83Convert_ConeToBSplineSurface::Convert_ConeToBSplineSurface
84 (const gp_Cone& C ,
85 const Standard_Real U1,
86 const Standard_Real U2,
87 const Standard_Real V1,
88 const Standard_Real V2 )
89: Convert_ElementarySurfaceToBSplineSurface (TheNbUPoles, TheNbVPoles,
90 TheNbUKnots, TheNbVKnots,
91 TheUDegree , TheVDegree )
92{
93 Standard_Real deltaU = U2 - U1;
94 Standard_DomainError_Raise_if( (Abs(V2-V1) <= Abs(Epsilon(V1))) ||
c6541a0c 95 (deltaU > 2*M_PI) ||
7fd59977 96 (deltaU < 0. ),
97 "Convert_ConeToBSplineSurface");
98
99 isuperiodic = Standard_False;
100 isvperiodic = Standard_False;
101
102 Standard_Integer i,j;
0d969553 103 // construction of cone in the reference mark xOy.
7fd59977 104
0d969553 105 // Number of spans : maximum opening = 150 degrees ( = PI / 1.2 rds)
7fd59977 106 Standard_Integer
c6541a0c 107 nbUSpans = (Standard_Integer)IntegerPart( 1.2 * deltaU / M_PI) + 1;
7fd59977 108 Standard_Real AlfaU = deltaU / ( nbUSpans * 2);
109
110 nbUPoles = 2 * nbUSpans + 1;
111 nbUKnots = nbUSpans + 1;
112
113 nbVPoles = 2;
114 nbVKnots = 2;
115
116 Standard_Real R = C.RefRadius();
117 Standard_Real A = C.SemiAngle();
118
119 ComputePoles( R, A, U1, U2, V1, V2, poles);
120
121 for ( i = 1; i<= nbUKnots; i++) {
122 uknots(i) = U1 + (i-1) * 2 * AlfaU;
123 umults(i) = 2;
124 }
125 umults(1)++; umults(nbUKnots)++;
126 vknots(1) = V1; vmults(1) = 2;
127 vknots(2) = V2; vmults(2) = 2;
128
0d969553
Y
129 // Replace the bspline in the mark of the sphere.
130 // and calculate the weight of the bspline.
7fd59977 131 Standard_Real W1;
132 gp_Trsf Trsf;
133 Trsf.SetTransformation( C.Position(), gp::XOY());
134
135 for ( i = 1; i <= nbUPoles; i++) {
136 if ( i % 2 == 0) W1 = Cos(AlfaU);
137 else W1 = 1.;
138
139 for ( j = 1; j <= nbVPoles; j++) {
140 weights( i, j) = W1;
141 poles( i, j).Transform( Trsf);
142 }
143 }
144}
145
146
147//=======================================================================
148//function : Convert_ConeToBSplineSurface
149//purpose :
150//=======================================================================
151
152Convert_ConeToBSplineSurface::Convert_ConeToBSplineSurface
153 (const gp_Cone& C ,
154 const Standard_Real V1,
155 const Standard_Real V2 )
156: Convert_ElementarySurfaceToBSplineSurface (TheNbUPoles, TheNbVPoles,
157 TheNbUKnots, TheNbVKnots,
158 TheUDegree, TheVDegree)
159{
160 Standard_DomainError_Raise_if( Abs(V2-V1) <= Abs(Epsilon(V1)),
161 "Convert_ConeToBSplineSurface");
162
163 Standard_Integer i,j;
164
165 isuperiodic = Standard_True;
166 isvperiodic = Standard_False;
167
0d969553 168 // construction of the cone in the reference mark xOy.
7fd59977 169
170 Standard_Real R = C.RefRadius();
171 Standard_Real A = C.SemiAngle();
172
c6541a0c 173 ComputePoles( R, A, 0., 2.*M_PI, V1, V2, poles);
7fd59977 174
175 nbUPoles = 6;
176 nbUKnots = 4;
177 nbVPoles = 2;
178 nbVKnots = 2;
179
180 for ( i = 1; i <= nbUKnots; i++) {
c6541a0c 181 uknots(i) = ( i-1) * 2. * M_PI /3.;
7fd59977 182 umults(i) = 2;
183 }
184 vknots(1) = V1; vmults(1) = 2;
185 vknots(2) = V2; vmults(2) = 2;
186
0d969553
Y
187 // replace bspline in the mark of the cone.
188 // and calculate the weight of bspline.
7fd59977 189 Standard_Real W;
190 gp_Trsf Trsf;
191 Trsf.SetTransformation( C.Position(), gp::XOY());
192
193 for ( i = 1; i <= nbUPoles; i++) {
194 if ( i % 2 == 0) W = 0.5; // = Cos(pi /3)
195 else W = 1.;
196
197 for ( j = 1; j <= nbVPoles; j++) {
198 weights( i, j) = W;
199 poles( i, j).Transform( Trsf);
200 }
201 }
202}