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