Commit | Line | Data |
---|---|---|
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_CircleToBSplineCurve.hxx> |
7fd59977 | 18 | #include <gp.hxx> |
19 | #include <gp_Ax2d.hxx> | |
42cf5bc1 | 20 | #include <gp_Circ2d.hxx> |
7fd59977 | 21 | #include <gp_Dir2d.hxx> |
22 | #include <gp_Trsf2d.hxx> | |
42cf5bc1 | 23 | #include <Precision.hxx> |
24 | #include <Standard_DomainError.hxx> | |
25 | #include <TColgp_Array1OfPnt2d.hxx> | |
26 | #include <TColgp_HArray1OfPnt2d.hxx> | |
27 | #include <TColStd_Array1OfReal.hxx> | |
28 | #include <TColStd_HArray1OfInteger.hxx> | |
29 | #include <TColStd_HArray1OfReal.hxx> | |
7fd59977 | 30 | |
31 | //Attention : | |
0d969553 Y |
32 | //To avoid use of persistent tables in the fields |
33 | //the tables are dimensioned to the maximum (TheNbKnots and TheNbPoles) | |
34 | //that correspond to the full circle. For an arc of circle there is a | |
35 | //need of less poles and nodes, that is why the fields | |
36 | //nbKnots and nbPoles are present and updated in the | |
37 | //constructor of an arc of B-spline circle to take into account | |
38 | //the real number of poles and nodes. | |
7fd59977 | 39 | // parametrization : |
40 | // Reference : Rational B-spline for Curve and Surface Representation | |
41 | // Wayne Tiller CADG September 1983 | |
7fd59977 | 42 | // x(t) = (1 - t^2) / (1 + t^2) |
43 | // y(t) = 2 t / (1 + t^2) | |
7fd59977 | 44 | // then t = Sqrt(2) u / ((Sqrt(2) - 2) u + 2) |
7fd59977 | 45 | // => u = 2 t / (Sqrt(2) + (2 - Sqrt(2)) t) |
7fd59977 | 46 | //======================================================================= |
47 | //function : Convert_CircleToBSplineCurve | |
48 | //purpose : this constructs a periodic circle | |
49 | //======================================================================= | |
7fd59977 | 50 | Convert_CircleToBSplineCurve::Convert_CircleToBSplineCurve |
51 | (const gp_Circ2d& C, const Convert_ParameterisationType Parameterisation) | |
52 | :Convert_ConicToBSplineCurve(0,0,0){ | |
53 | ||
54 | Standard_Integer ii ; | |
55 | ||
56 | Standard_Real R, | |
57 | value ; | |
58 | Handle(TColStd_HArray1OfReal) CosNumeratorPtr, | |
59 | SinNumeratorPtr ; | |
60 | ||
61 | ||
62 | R = C.Radius() ; | |
63 | if (Parameterisation != Convert_TgtThetaOver2 && | |
64 | Parameterisation != Convert_RationalC1) { | |
0d969553 Y |
65 | // In case if BuildCosAndSin does not know how to manage the periodicity |
66 | // => trim on 0,2*PI | |
7fd59977 | 67 | isperiodic = Standard_False; |
68 | Convert_ConicToBSplineCurve:: | |
69 | BuildCosAndSin(Parameterisation, | |
c6541a0c | 70 | 0, 2*M_PI, |
7fd59977 | 71 | CosNumeratorPtr, |
72 | SinNumeratorPtr, | |
73 | weights, | |
74 | degree, | |
75 | knots, | |
76 | mults); | |
77 | } | |
78 | else { | |
79 | isperiodic = Standard_True; | |
80 | Convert_ConicToBSplineCurve:: | |
81 | BuildCosAndSin(Parameterisation, | |
82 | CosNumeratorPtr, | |
83 | SinNumeratorPtr, | |
84 | weights, | |
85 | degree, | |
86 | knots, | |
87 | mults); | |
88 | } | |
89 | ||
90 | ||
91 | nbPoles = CosNumeratorPtr->Length(); | |
92 | nbKnots = knots->Length(); | |
93 | ||
94 | poles = | |
95 | new TColgp_HArray1OfPnt2d(1,nbPoles); | |
96 | ||
97 | ||
98 | gp_Dir2d Ox = C.XAxis().Direction(); | |
99 | gp_Dir2d Oy = C.YAxis().Direction(); | |
100 | gp_Trsf2d Trsf; | |
101 | Trsf.SetTransformation( C.XAxis(), gp::OX2d()); | |
102 | if ( Ox.X() * Oy.Y() - Ox.Y() * Oy.X() > 0.0e0) { | |
103 | value = R ; | |
104 | } | |
105 | else { | |
106 | value = -R ; | |
107 | } | |
108 | ||
0d969553 Y |
109 | // Replace the bspline in the reference of the circle. |
110 | // and calculate the weight of the bspline. | |
7fd59977 | 111 | |
112 | for (ii = 1; ii <= nbPoles ; ii++) { | |
113 | poles->ChangeArray1()(ii).SetCoord(1, R * CosNumeratorPtr->Value(ii)) ; | |
114 | poles->ChangeArray1()(ii).SetCoord(2, value * SinNumeratorPtr->Value(ii)) ; | |
115 | poles->ChangeArray1()(ii).Transform( Trsf); | |
116 | } | |
117 | ||
118 | } | |
119 | //======================================================================= | |
120 | //function : Convert_CircleToBSplineCurve | |
121 | //purpose : this constructs a non periodic circle | |
122 | //======================================================================= | |
123 | ||
124 | Convert_CircleToBSplineCurve::Convert_CircleToBSplineCurve | |
125 | (const gp_Circ2d& C, | |
126 | const Standard_Real UFirst, | |
127 | const Standard_Real ULast, | |
128 | const Convert_ParameterisationType Parameterisation) | |
129 | :Convert_ConicToBSplineCurve(0,0,0) | |
130 | { | |
131 | Standard_Real delta = ULast - UFirst ; | |
132 | Standard_Real Eps = Precision::PConfusion(); | |
133 | ||
c6541a0c | 134 | if ( (delta > (2*M_PI + Eps)) || (delta <= 0.0e0) ) { |
9775fa61 | 135 | throw Standard_DomainError( "Convert_CircleToBSplineCurve"); |
7fd59977 | 136 | } |
137 | ||
138 | Standard_Integer ii; | |
139 | Standard_Real R, value ; | |
140 | Handle(TColStd_HArray1OfReal) CosNumeratorPtr,SinNumeratorPtr ; | |
141 | ||
142 | ||
143 | R = C.Radius() ; | |
144 | isperiodic = Standard_False; | |
145 | Convert_ConicToBSplineCurve::BuildCosAndSin(Parameterisation, | |
146 | UFirst, | |
147 | ULast, | |
148 | CosNumeratorPtr, | |
149 | SinNumeratorPtr, | |
150 | weights, | |
151 | degree, | |
152 | knots, | |
153 | mults) ; | |
154 | ||
155 | ||
156 | ||
157 | nbPoles = CosNumeratorPtr->Length(); | |
158 | nbKnots = knots->Length(); | |
159 | ||
160 | poles = | |
161 | new TColgp_HArray1OfPnt2d(1,nbPoles) ; | |
162 | ||
163 | gp_Dir2d Ox = C.XAxis().Direction(); | |
164 | gp_Dir2d Oy = C.YAxis().Direction(); | |
165 | gp_Trsf2d Trsf; | |
166 | Trsf.SetTransformation( C.XAxis(), gp::OX2d()); | |
167 | if ( Ox.X() * Oy.Y() - Ox.Y() * Oy.X() > 0.0e0) { | |
168 | value = R ; | |
169 | } | |
170 | else { | |
171 | value = -R ; | |
172 | } | |
173 | ||
0d969553 Y |
174 | // Replace the bspline in the reference of the circle. |
175 | // and calculate the weight of the bspline. | |
7fd59977 | 176 | |
177 | for (ii = 1; ii <= nbPoles ; ii++) { | |
178 | poles->ChangeArray1()(ii).SetCoord(1, R * CosNumeratorPtr->Value(ii)) ; | |
179 | poles->ChangeArray1()(ii).SetCoord(2, value * SinNumeratorPtr->Value(ii)) ; | |
180 | poles->ChangeArray1()(ii).Transform( Trsf); | |
181 | } | |
182 | ||
183 | } | |
184 |