Warnings on vc14 were eliminated
[occt.git] / src / GeomConvert / GeomConvert_BSplineCurveToBezierCurve.cxx
CommitLineData
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
7fd59977 17
42cf5bc1 18#include <Geom_BezierCurve.hxx>
19#include <Geom_BSplineCurve.hxx>
20#include <GeomConvert_BSplineCurveToBezierCurve.hxx>
21#include <Standard_DimensionError.hxx>
22#include <Standard_DomainError.hxx>
23#include <Standard_OutOfRange.hxx>
7fd59977 24#include <TColgp_Array1OfPnt.hxx>
25#include <TColStd_Array1OfReal.hxx>
7fd59977 26
27//=======================================================================
28//function : GeomConvert_BSplineCurveToBezierCurve
29//purpose :
30//=======================================================================
7fd59977 31GeomConvert_BSplineCurveToBezierCurve::GeomConvert_BSplineCurveToBezierCurve (const Handle(Geom_BSplineCurve)& BasisCurve)
32{
33 myCurve = Handle(Geom_BSplineCurve)::DownCast(BasisCurve->Copy());
34 Standard_Real Uf = myCurve->FirstParameter();
35 Standard_Real Ul = myCurve->LastParameter();
36 myCurve->Segment(Uf,Ul);
37 myCurve->IncreaseMultiplicity(myCurve->FirstUKnotIndex(),
38 myCurve->LastUKnotIndex(),
39 myCurve->Degree());
40}
41
42
43//=======================================================================
44//function : GeomConvert_BSplineCurveToBezierCurve
45//purpose :
46// 01/12/1997 PMN: On elimine d'eventuelles micro-courbe PRO11516
47//=======================================================================Real I
48
49GeomConvert_BSplineCurveToBezierCurve::GeomConvert_BSplineCurveToBezierCurve
50(const Handle(Geom_BSplineCurve)& BasisCurve,
51 const Standard_Real U1,
52 const Standard_Real U2,
53 const Standard_Real ParametricTolerance)
54{
55 if (U2 - U1 < ParametricTolerance)
9775fa61 56 throw Standard_DomainError("GeomConvert_BSplineCurveToBezierSurface");
7fd59977 57
58 Standard_Real Uf = U1, Ul = U2;
59 Standard_Real PTol = ParametricTolerance/2 ;
60
61 Standard_Integer I1, I2;
62 myCurve = Handle(Geom_BSplineCurve)::DownCast(BasisCurve->Copy());
63
64 myCurve->LocateU(U1, PTol, I1, I2);
65 if (I1==I2) { // On est sur le noeud
66 if ( myCurve->Knot(I1) > U1) Uf = myCurve->Knot(I1);
67 }
68
69 myCurve->LocateU(U2, PTol, I1, I2);
70 if (I1==I2) { // On est sur le noeud
71 if ( myCurve->Knot(I1) < U2) Ul = myCurve->Knot(I1);
72 }
73
74 myCurve->Segment(Uf,Ul);
75 myCurve->IncreaseMultiplicity(myCurve->FirstUKnotIndex(),
76 myCurve->LastUKnotIndex(),
77 myCurve->Degree());
78}
79
80
81//=======================================================================
82//function : Arc
83//purpose :
84//=======================================================================
85
86Handle(Geom_BezierCurve) GeomConvert_BSplineCurveToBezierCurve::Arc
87(const Standard_Integer Index)
88{
89 if ( Index < 1 || Index > myCurve->NbKnots()-1) {
9775fa61 90 throw Standard_OutOfRange("GeomConvert_BSplineCurveToBezierCurve");
7fd59977 91 }
92 Standard_Integer Deg = myCurve->Degree();
93
94 TColgp_Array1OfPnt Poles(1,Deg+1);
95
96 Handle(Geom_BezierCurve) C;
97 if ( myCurve->IsRational()) {
98 TColStd_Array1OfReal Weights(1,Deg+1);
99 for ( Standard_Integer i = 1; i <= Deg+1; i++) {
100 Poles(i) = myCurve->Pole(i+Deg*(Index-1));
101 Weights(i) = myCurve->Weight(i+Deg*(Index-1));
102 }
103 C = new Geom_BezierCurve(Poles,Weights);
104 }
105 else {
106 for ( Standard_Integer i = 1; i <= Deg+1; i++) {
107 Poles(i) = myCurve->Pole(i+Deg*(Index-1));
108 }
109 C = new Geom_BezierCurve(Poles);
110 }
111 return C;
112}
113
114
115//=======================================================================
116//function : Arcs
117//purpose :
118//=======================================================================
119
120void GeomConvert_BSplineCurveToBezierCurve::Arcs
121(TColGeom_Array1OfBezierCurve& Curves)
122{
123 Standard_Integer n = NbArcs();
124 for ( Standard_Integer i = 1; i <= n; i++) {
125 Curves(i) = Arc(i);
126 }
127}
128
129//=======================================================================
130//function : Knots
131//purpose :
132//=======================================================================
133
134void GeomConvert_BSplineCurveToBezierCurve::Knots
135 (TColStd_Array1OfReal& TKnots) const
136{
137 Standard_Integer ii, kk;
138 for (ii = 1, kk = TKnots.Lower();
139 ii <=myCurve->NbKnots(); ii++, kk++)
140 TKnots(kk) = myCurve->Knot(ii);
141}
142
143//=======================================================================
144//function : NbArcs
145//purpose :
146//=======================================================================
147
148Standard_Integer GeomConvert_BSplineCurveToBezierCurve::NbArcs() const
149{
150 return (myCurve->NbKnots()-1);
151}