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