b311480e |
1 | // Created on: 1996-03-12 |
2 | // Created by: Bruno DUMORTIER |
3 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | #include <Geom2dConvert_BSplineCurveToBezierCurve.ixx> |
18 | |
19 | #include <TColgp_Array1OfPnt2d.hxx> |
20 | #include <TColStd_Array1OfReal.hxx> |
21 | |
22 | |
23 | //======================================================================= |
24 | //function : Geom2dConvert_BSplineCurveToBezierCurve |
25 | //purpose : |
26 | //======================================================================= |
27 | |
28 | Geom2dConvert_BSplineCurveToBezierCurve::Geom2dConvert_BSplineCurveToBezierCurve (const Handle(Geom2d_BSplineCurve)& BasisCurve) |
29 | { |
30 | myCurve = Handle(Geom2d_BSplineCurve)::DownCast(BasisCurve->Copy()); |
31 | // periodic curve can't be converted correctly by two main reasons: |
32 | // last pole (equal to first one) is missing; |
33 | // poles recomputation using default boor scheme is fails. |
34 | if(myCurve->IsPeriodic()) myCurve->SetNotPeriodic(); |
35 | Standard_Real Uf = myCurve->FirstParameter(); |
36 | Standard_Real Ul = myCurve->LastParameter(); |
37 | myCurve->Segment(Uf,Ul); |
38 | myCurve->IncreaseMultiplicity(myCurve->FirstUKnotIndex(), |
39 | myCurve->LastUKnotIndex(), |
40 | myCurve->Degree()); |
41 | } |
42 | |
43 | |
44 | //======================================================================= |
45 | //function : Geom2dConvert_BSplineCurveToBezierCurve |
46 | //purpose : |
47 | //======================================================================= |
48 | |
49 | Geom2dConvert_BSplineCurveToBezierCurve::Geom2dConvert_BSplineCurveToBezierCurve |
50 | (const Handle(Geom2d_BSplineCurve)& BasisCurve, |
51 | const Standard_Real U1, |
52 | const Standard_Real U2, |
53 | const Standard_Real ParametricTolerance) |
54 | { |
55 | if (U2 - U1 < ParametricTolerance) |
56 | Standard_DomainError::Raise("GeomConvert_BSplineCurveToBezierSurface"); |
57 | |
58 | Standard_Real Uf = U1, Ul = U2; |
59 | Standard_Real PTol = ParametricTolerance/2 ; |
60 | |
61 | Standard_Integer I1, I2; |
62 | myCurve = Handle(Geom2d_BSplineCurve)::DownCast(BasisCurve->Copy()); |
63 | if(myCurve->IsPeriodic()) myCurve->SetNotPeriodic(); |
64 | |
65 | myCurve->LocateU(U1, PTol, I1, I2); |
66 | if (I1==I2) { // On est sur le noeud |
67 | if ( myCurve->Knot(I1) > U1) Uf = myCurve->Knot(I1); |
68 | } |
69 | |
70 | myCurve->LocateU(U2, PTol, I1, I2); |
71 | if (I1==I2) { // On est sur le noeud |
72 | if ( myCurve->Knot(I1) < U2) Ul = myCurve->Knot(I1); |
73 | } |
74 | |
75 | |
76 | myCurve->Segment(Uf, Ul); |
77 | myCurve->IncreaseMultiplicity(myCurve->FirstUKnotIndex(), |
78 | myCurve->LastUKnotIndex(), |
79 | myCurve->Degree()); |
80 | } |
81 | |
82 | |
83 | //======================================================================= |
84 | //function : Arc |
85 | //purpose : |
86 | //======================================================================= |
87 | |
88 | Handle(Geom2d_BezierCurve) Geom2dConvert_BSplineCurveToBezierCurve::Arc |
89 | (const Standard_Integer Index) |
90 | { |
91 | if ( Index < 1 || Index > myCurve->NbKnots()-1) { |
92 | Standard_OutOfRange::Raise("Geom2dConvert_BSplineCurveToBezierCurve"); |
93 | } |
94 | Standard_Integer Deg = myCurve->Degree(); |
95 | |
96 | TColgp_Array1OfPnt2d Poles(1,Deg+1); |
97 | |
98 | Handle(Geom2d_BezierCurve) C; |
99 | if ( myCurve->IsRational()) { |
100 | TColStd_Array1OfReal Weights(1,Deg+1); |
101 | for ( Standard_Integer i = 1; i <= Deg+1; i++) { |
102 | Poles(i) = myCurve->Pole(i+Deg*(Index-1)); |
103 | Weights(i) = myCurve->Weight(i+Deg*(Index-1)); |
104 | } |
105 | C = new Geom2d_BezierCurve(Poles,Weights); |
106 | } |
107 | else { |
108 | for ( Standard_Integer i = 1; i <= Deg+1; i++) { |
109 | Poles(i) = myCurve->Pole(i+Deg*(Index-1)); |
110 | } |
111 | C = new Geom2d_BezierCurve(Poles); |
112 | } |
113 | return C; |
114 | } |
115 | |
116 | |
117 | //======================================================================= |
118 | //function : Arcs |
119 | //purpose : |
120 | //======================================================================= |
121 | |
122 | void Geom2dConvert_BSplineCurveToBezierCurve::Arcs |
123 | (TColGeom2d_Array1OfBezierCurve& Curves) |
124 | { |
125 | Standard_Integer n = NbArcs(); |
126 | for ( Standard_Integer i = 1; i <= n; i++) { |
127 | Curves(i) = Arc(i); |
128 | } |
129 | } |
130 | |
131 | //======================================================================= |
132 | //function : Knots |
133 | //purpose : |
134 | //======================================================================= |
135 | |
136 | void Geom2dConvert_BSplineCurveToBezierCurve::Knots |
137 | (TColStd_Array1OfReal& TKnots) const |
138 | { |
139 | Standard_Integer ii, kk; |
140 | for (ii = 1, kk = TKnots.Lower(); |
141 | ii <=myCurve->NbKnots(); ii++, kk++) |
142 | TKnots(kk) = myCurve->Knot(ii); |
143 | } |
144 | |
145 | //======================================================================= |
146 | //function : NbArcs |
147 | //purpose : |
148 | //======================================================================= |
149 | |
150 | Standard_Integer Geom2dConvert_BSplineCurveToBezierCurve::NbArcs() const |
151 | { |
152 | return (myCurve->NbKnots()-1); |
153 | } |