1 // Created on: 1996-03-12
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 #include <GeomConvert_BSplineCurveToBezierCurve.ixx>
25 #include <TColgp_Array1OfPnt.hxx>
26 #include <TColStd_Array1OfReal.hxx>
29 //=======================================================================
30 //function : GeomConvert_BSplineCurveToBezierCurve
32 //=======================================================================
34 GeomConvert_BSplineCurveToBezierCurve::GeomConvert_BSplineCurveToBezierCurve (const Handle(Geom_BSplineCurve)& BasisCurve)
36 myCurve = Handle(Geom_BSplineCurve)::DownCast(BasisCurve->Copy());
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 : GeomConvert_BSplineCurveToBezierCurve
49 // 01/12/1997 PMN: On elimine d'eventuelles micro-courbe PRO11516
50 //=======================================================================Real I
52 GeomConvert_BSplineCurveToBezierCurve::GeomConvert_BSplineCurveToBezierCurve
53 (const Handle(Geom_BSplineCurve)& BasisCurve,
54 const Standard_Real U1,
55 const Standard_Real U2,
56 const Standard_Real ParametricTolerance)
58 if (U2 - U1 < ParametricTolerance)
59 Standard_DomainError::Raise("GeomConvert_BSplineCurveToBezierSurface");
61 Standard_Real Uf = U1, Ul = U2;
62 Standard_Real PTol = ParametricTolerance/2 ;
64 Standard_Integer I1, I2;
65 myCurve = Handle(Geom_BSplineCurve)::DownCast(BasisCurve->Copy());
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);
77 myCurve->Segment(Uf,Ul);
78 myCurve->IncreaseMultiplicity(myCurve->FirstUKnotIndex(),
79 myCurve->LastUKnotIndex(),
84 //=======================================================================
87 //=======================================================================
89 Handle(Geom_BezierCurve) GeomConvert_BSplineCurveToBezierCurve::Arc
90 (const Standard_Integer Index)
92 if ( Index < 1 || Index > myCurve->NbKnots()-1) {
93 Standard_OutOfRange::Raise("GeomConvert_BSplineCurveToBezierCurve");
95 Standard_Integer Deg = myCurve->Degree();
97 TColgp_Array1OfPnt Poles(1,Deg+1);
99 Handle(Geom_BezierCurve) C;
100 if ( myCurve->IsRational()) {
101 TColStd_Array1OfReal Weights(1,Deg+1);
102 for ( Standard_Integer i = 1; i <= Deg+1; i++) {
103 Poles(i) = myCurve->Pole(i+Deg*(Index-1));
104 Weights(i) = myCurve->Weight(i+Deg*(Index-1));
106 C = new Geom_BezierCurve(Poles,Weights);
109 for ( Standard_Integer i = 1; i <= Deg+1; i++) {
110 Poles(i) = myCurve->Pole(i+Deg*(Index-1));
112 C = new Geom_BezierCurve(Poles);
118 //=======================================================================
121 //=======================================================================
123 void GeomConvert_BSplineCurveToBezierCurve::Arcs
124 (TColGeom_Array1OfBezierCurve& Curves)
126 Standard_Integer n = NbArcs();
127 for ( Standard_Integer i = 1; i <= n; i++) {
132 //=======================================================================
135 //=======================================================================
137 void GeomConvert_BSplineCurveToBezierCurve::Knots
138 (TColStd_Array1OfReal& TKnots) const
140 Standard_Integer ii, kk;
141 for (ii = 1, kk = TKnots.Lower();
142 ii <=myCurve->NbKnots(); ii++, kk++)
143 TKnots(kk) = myCurve->Knot(ii);
146 //=======================================================================
149 //=======================================================================
151 Standard_Integer GeomConvert_BSplineCurveToBezierCurve::NbArcs() const
153 return (myCurve->NbKnots()-1);