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.
18 #include <Geom2d_BezierCurve.hxx>
19 #include <Geom2d_BSplineCurve.hxx>
20 #include <Geom2dConvert_BSplineCurveToBezierCurve.hxx>
21 #include <Standard_DomainError.hxx>
22 #include <Standard_OutOfRange.hxx>
23 #include <TColgp_Array1OfPnt2d.hxx>
24 #include <TColStd_Array1OfReal.hxx>
26 //=======================================================================
27 //function : Geom2dConvert_BSplineCurveToBezierCurve
29 //=======================================================================
30 Geom2dConvert_BSplineCurveToBezierCurve::Geom2dConvert_BSplineCurveToBezierCurve (const Handle(Geom2d_BSplineCurve)& BasisCurve)
32 myCurve = Handle(Geom2d_BSplineCurve)::DownCast(BasisCurve->Copy());
33 // periodic curve can't be converted correctly by two main reasons:
34 // last pole (equal to first one) is missing;
35 // poles recomputation using default boor scheme is fails.
36 if(myCurve->IsPeriodic()) myCurve->SetNotPeriodic();
37 Standard_Real Uf = myCurve->FirstParameter();
38 Standard_Real Ul = myCurve->LastParameter();
39 myCurve->Segment(Uf,Ul);
40 myCurve->IncreaseMultiplicity(myCurve->FirstUKnotIndex(),
41 myCurve->LastUKnotIndex(),
46 //=======================================================================
47 //function : Geom2dConvert_BSplineCurveToBezierCurve
49 //=======================================================================
51 Geom2dConvert_BSplineCurveToBezierCurve::Geom2dConvert_BSplineCurveToBezierCurve
52 (const Handle(Geom2d_BSplineCurve)& BasisCurve,
53 const Standard_Real U1,
54 const Standard_Real U2,
55 const Standard_Real ParametricTolerance)
57 if (U2 - U1 < ParametricTolerance)
58 throw Standard_DomainError("GeomConvert_BSplineCurveToBezierSurface");
60 Standard_Real Uf = U1, Ul = U2;
61 Standard_Real PTol = ParametricTolerance/2 ;
63 Standard_Integer I1, I2;
64 myCurve = Handle(Geom2d_BSplineCurve)::DownCast(BasisCurve->Copy());
65 if(myCurve->IsPeriodic()) myCurve->SetNotPeriodic();
67 myCurve->LocateU(U1, PTol, I1, I2);
68 if (I1==I2) { // On est sur le noeud
69 if ( myCurve->Knot(I1) > U1) Uf = myCurve->Knot(I1);
72 myCurve->LocateU(U2, PTol, I1, I2);
73 if (I1==I2) { // On est sur le noeud
74 if ( myCurve->Knot(I1) < U2) Ul = myCurve->Knot(I1);
78 myCurve->Segment(Uf, Ul);
79 myCurve->IncreaseMultiplicity(myCurve->FirstUKnotIndex(),
80 myCurve->LastUKnotIndex(),
85 //=======================================================================
88 //=======================================================================
90 Handle(Geom2d_BezierCurve) Geom2dConvert_BSplineCurveToBezierCurve::Arc
91 (const Standard_Integer Index)
93 if ( Index < 1 || Index > myCurve->NbKnots()-1) {
94 throw Standard_OutOfRange("Geom2dConvert_BSplineCurveToBezierCurve");
96 Standard_Integer Deg = myCurve->Degree();
98 TColgp_Array1OfPnt2d Poles(1,Deg+1);
100 Handle(Geom2d_BezierCurve) C;
101 if ( myCurve->IsRational()) {
102 TColStd_Array1OfReal Weights(1,Deg+1);
103 for ( Standard_Integer i = 1; i <= Deg+1; i++) {
104 Poles(i) = myCurve->Pole(i+Deg*(Index-1));
105 Weights(i) = myCurve->Weight(i+Deg*(Index-1));
107 C = new Geom2d_BezierCurve(Poles,Weights);
110 for ( Standard_Integer i = 1; i <= Deg+1; i++) {
111 Poles(i) = myCurve->Pole(i+Deg*(Index-1));
113 C = new Geom2d_BezierCurve(Poles);
119 //=======================================================================
122 //=======================================================================
124 void Geom2dConvert_BSplineCurveToBezierCurve::Arcs
125 (TColGeom2d_Array1OfBezierCurve& Curves)
127 Standard_Integer n = NbArcs();
128 for ( Standard_Integer i = 1; i <= n; i++) {
133 //=======================================================================
136 //=======================================================================
138 void Geom2dConvert_BSplineCurveToBezierCurve::Knots
139 (TColStd_Array1OfReal& TKnots) const
141 Standard_Integer ii, kk;
142 for (ii = 1, kk = TKnots.Lower();
143 ii <=myCurve->NbKnots(); ii++, kk++)
144 TKnots(kk) = myCurve->Knot(ii);
147 //=======================================================================
150 //=======================================================================
152 Standard_Integer Geom2dConvert_BSplineCurveToBezierCurve::NbArcs() const
154 return (myCurve->NbKnots()-1);