7fd59977 |
1 | // File: Geom2dConvert_BSplineCurveToBezierCurve.cxx |
2 | // Created: Tue Mar 12 15:51:42 1996 |
3 | // Author: Bruno DUMORTIER |
4 | // <dub@fuegox> |
5 | |
6 | |
7 | #include <Geom2dConvert_BSplineCurveToBezierCurve.ixx> |
8 | |
9 | #include <TColgp_Array1OfPnt2d.hxx> |
10 | #include <TColStd_Array1OfReal.hxx> |
11 | |
12 | |
13 | //======================================================================= |
14 | //function : Geom2dConvert_BSplineCurveToBezierCurve |
15 | //purpose : |
16 | //======================================================================= |
17 | |
18 | Geom2dConvert_BSplineCurveToBezierCurve::Geom2dConvert_BSplineCurveToBezierCurve (const Handle(Geom2d_BSplineCurve)& BasisCurve) |
19 | { |
20 | myCurve = Handle(Geom2d_BSplineCurve)::DownCast(BasisCurve->Copy()); |
21 | // periodic curve can't be converted correctly by two main reasons: |
22 | // last pole (equal to first one) is missing; |
23 | // poles recomputation using default boor scheme is fails. |
24 | if(myCurve->IsPeriodic()) myCurve->SetNotPeriodic(); |
25 | Standard_Real Uf = myCurve->FirstParameter(); |
26 | Standard_Real Ul = myCurve->LastParameter(); |
27 | myCurve->Segment(Uf,Ul); |
28 | myCurve->IncreaseMultiplicity(myCurve->FirstUKnotIndex(), |
29 | myCurve->LastUKnotIndex(), |
30 | myCurve->Degree()); |
31 | } |
32 | |
33 | |
34 | //======================================================================= |
35 | //function : Geom2dConvert_BSplineCurveToBezierCurve |
36 | //purpose : |
37 | //======================================================================= |
38 | |
39 | Geom2dConvert_BSplineCurveToBezierCurve::Geom2dConvert_BSplineCurveToBezierCurve |
40 | (const Handle(Geom2d_BSplineCurve)& BasisCurve, |
41 | const Standard_Real U1, |
42 | const Standard_Real U2, |
43 | const Standard_Real ParametricTolerance) |
44 | { |
45 | if (U2 - U1 < ParametricTolerance) |
46 | Standard_DomainError::Raise("GeomConvert_BSplineCurveToBezierSurface"); |
47 | |
48 | Standard_Real Uf = U1, Ul = U2; |
49 | Standard_Real PTol = ParametricTolerance/2 ; |
50 | |
51 | Standard_Integer I1, I2; |
52 | myCurve = Handle(Geom2d_BSplineCurve)::DownCast(BasisCurve->Copy()); |
53 | if(myCurve->IsPeriodic()) myCurve->SetNotPeriodic(); |
54 | |
55 | myCurve->LocateU(U1, PTol, I1, I2); |
56 | if (I1==I2) { // On est sur le noeud |
57 | if ( myCurve->Knot(I1) > U1) Uf = myCurve->Knot(I1); |
58 | } |
59 | |
60 | myCurve->LocateU(U2, PTol, I1, I2); |
61 | if (I1==I2) { // On est sur le noeud |
62 | if ( myCurve->Knot(I1) < U2) Ul = myCurve->Knot(I1); |
63 | } |
64 | |
65 | |
66 | myCurve->Segment(Uf, Ul); |
67 | myCurve->IncreaseMultiplicity(myCurve->FirstUKnotIndex(), |
68 | myCurve->LastUKnotIndex(), |
69 | myCurve->Degree()); |
70 | } |
71 | |
72 | |
73 | //======================================================================= |
74 | //function : Arc |
75 | //purpose : |
76 | //======================================================================= |
77 | |
78 | Handle(Geom2d_BezierCurve) Geom2dConvert_BSplineCurveToBezierCurve::Arc |
79 | (const Standard_Integer Index) |
80 | { |
81 | if ( Index < 1 || Index > myCurve->NbKnots()-1) { |
82 | Standard_OutOfRange::Raise("Geom2dConvert_BSplineCurveToBezierCurve"); |
83 | } |
84 | Standard_Integer Deg = myCurve->Degree(); |
85 | |
86 | TColgp_Array1OfPnt2d Poles(1,Deg+1); |
87 | |
88 | Handle(Geom2d_BezierCurve) C; |
89 | if ( myCurve->IsRational()) { |
90 | TColStd_Array1OfReal Weights(1,Deg+1); |
91 | for ( Standard_Integer i = 1; i <= Deg+1; i++) { |
92 | Poles(i) = myCurve->Pole(i+Deg*(Index-1)); |
93 | Weights(i) = myCurve->Weight(i+Deg*(Index-1)); |
94 | } |
95 | C = new Geom2d_BezierCurve(Poles,Weights); |
96 | } |
97 | else { |
98 | for ( Standard_Integer i = 1; i <= Deg+1; i++) { |
99 | Poles(i) = myCurve->Pole(i+Deg*(Index-1)); |
100 | } |
101 | C = new Geom2d_BezierCurve(Poles); |
102 | } |
103 | return C; |
104 | } |
105 | |
106 | |
107 | //======================================================================= |
108 | //function : Arcs |
109 | //purpose : |
110 | //======================================================================= |
111 | |
112 | void Geom2dConvert_BSplineCurveToBezierCurve::Arcs |
113 | (TColGeom2d_Array1OfBezierCurve& Curves) |
114 | { |
115 | Standard_Integer n = NbArcs(); |
116 | for ( Standard_Integer i = 1; i <= n; i++) { |
117 | Curves(i) = Arc(i); |
118 | } |
119 | } |
120 | |
121 | //======================================================================= |
122 | //function : Knots |
123 | //purpose : |
124 | //======================================================================= |
125 | |
126 | void Geom2dConvert_BSplineCurveToBezierCurve::Knots |
127 | (TColStd_Array1OfReal& TKnots) const |
128 | { |
129 | Standard_Integer ii, kk; |
130 | for (ii = 1, kk = TKnots.Lower(); |
131 | ii <=myCurve->NbKnots(); ii++, kk++) |
132 | TKnots(kk) = myCurve->Knot(ii); |
133 | } |
134 | |
135 | //======================================================================= |
136 | //function : NbArcs |
137 | //purpose : |
138 | //======================================================================= |
139 | |
140 | Standard_Integer Geom2dConvert_BSplineCurveToBezierCurve::NbArcs() const |
141 | { |
142 | return (myCurve->NbKnots()-1); |
143 | } |