1 // Created on: 1996-03-12
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <Geom2dConvert_BSplineCurveToBezierCurve.ixx>
19 #include <TColgp_Array1OfPnt2d.hxx>
20 #include <TColStd_Array1OfReal.hxx>
23 //=======================================================================
24 //function : Geom2dConvert_BSplineCurveToBezierCurve
26 //=======================================================================
28 Geom2dConvert_BSplineCurveToBezierCurve::Geom2dConvert_BSplineCurveToBezierCurve (const Handle(Geom2d_BSplineCurve)& BasisCurve)
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(),
44 //=======================================================================
45 //function : Geom2dConvert_BSplineCurveToBezierCurve
47 //=======================================================================
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)
55 if (U2 - U1 < ParametricTolerance)
56 Standard_DomainError::Raise("GeomConvert_BSplineCurveToBezierSurface");
58 Standard_Real Uf = U1, Ul = U2;
59 Standard_Real PTol = ParametricTolerance/2 ;
61 Standard_Integer I1, I2;
62 myCurve = Handle(Geom2d_BSplineCurve)::DownCast(BasisCurve->Copy());
63 if(myCurve->IsPeriodic()) myCurve->SetNotPeriodic();
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);
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);
76 myCurve->Segment(Uf, Ul);
77 myCurve->IncreaseMultiplicity(myCurve->FirstUKnotIndex(),
78 myCurve->LastUKnotIndex(),
83 //=======================================================================
86 //=======================================================================
88 Handle(Geom2d_BezierCurve) Geom2dConvert_BSplineCurveToBezierCurve::Arc
89 (const Standard_Integer Index)
91 if ( Index < 1 || Index > myCurve->NbKnots()-1) {
92 Standard_OutOfRange::Raise("Geom2dConvert_BSplineCurveToBezierCurve");
94 Standard_Integer Deg = myCurve->Degree();
96 TColgp_Array1OfPnt2d Poles(1,Deg+1);
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));
105 C = new Geom2d_BezierCurve(Poles,Weights);
108 for ( Standard_Integer i = 1; i <= Deg+1; i++) {
109 Poles(i) = myCurve->Pole(i+Deg*(Index-1));
111 C = new Geom2d_BezierCurve(Poles);
117 //=======================================================================
120 //=======================================================================
122 void Geom2dConvert_BSplineCurveToBezierCurve::Arcs
123 (TColGeom2d_Array1OfBezierCurve& Curves)
125 Standard_Integer n = NbArcs();
126 for ( Standard_Integer i = 1; i <= n; i++) {
131 //=======================================================================
134 //=======================================================================
136 void Geom2dConvert_BSplineCurveToBezierCurve::Knots
137 (TColStd_Array1OfReal& TKnots) const
139 Standard_Integer ii, kk;
140 for (ii = 1, kk = TKnots.Lower();
141 ii <=myCurve->NbKnots(); ii++, kk++)
142 TKnots(kk) = myCurve->Knot(ii);
145 //=======================================================================
148 //=======================================================================
150 Standard_Integer Geom2dConvert_BSplineCurveToBezierCurve::NbArcs() const
152 return (myCurve->NbKnots()-1);