1 // Created on: 1993-10-20
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1993-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 // modified 25/06/1996 PMN : Ajout d'une tolerance Angulaire dans le
18 // constructeur pour le test de continuite G1 (1 Radians c'etait trop
20 //rln 20.06.99 work-around
22 #include <BSplCLib.hxx>
27 #include <Precision.hxx>
28 #include <ShapeConstruct_CompBezierCurvesToBSplineCurve.hxx>
29 #include <Standard_ConstructionError.hxx>
30 #include <TColgp_HArray1OfPnt.hxx>
32 //=======================================================================
33 //function : ShapeConstruct_CompBezierCurvesToBSplineCurve
35 //=======================================================================
36 ShapeConstruct_CompBezierCurvesToBSplineCurve::
37 ShapeConstruct_CompBezierCurvesToBSplineCurve(
38 const Standard_Real AngularTolerance) :
39 myAngular(AngularTolerance),
40 myDone(Standard_False)
46 //=======================================================================
49 //=======================================================================
51 void ShapeConstruct_CompBezierCurvesToBSplineCurve::AddCurve
52 (const TColgp_Array1OfPnt& Poles)
54 if ( !mySequence.IsEmpty()) {
56 P1 = mySequence.Last()->Value(mySequence.Last()->Upper());
57 P2 = Poles(Poles.Lower());
60 // Standard_ConstructionError_Raise_if
61 // ( !P1.IsEqual(P2,Precision::Confusion()),
62 // "ShapeConstruct_CompBezierCurvesToBSplineCurve::Addcurve");
64 myDone = Standard_False;
65 Handle(TColgp_HArray1OfPnt) HPoles =
66 new TColgp_HArray1OfPnt(Poles.Lower(),Poles.Upper());
67 HPoles->ChangeArray1() = Poles;
68 mySequence.Append(HPoles);
72 //=======================================================================
75 //=======================================================================
77 Standard_Integer ShapeConstruct_CompBezierCurvesToBSplineCurve::Degree() const
83 //=======================================================================
86 //=======================================================================
88 Standard_Integer ShapeConstruct_CompBezierCurvesToBSplineCurve::NbPoles() const
90 return CurvePoles.Length();
94 //=======================================================================
97 //=======================================================================
99 void ShapeConstruct_CompBezierCurvesToBSplineCurve::Poles
100 (TColgp_Array1OfPnt& Poles) const
102 Standard_Integer i, Lower = Poles.Lower(), Upper = Poles.Upper();
103 Standard_Integer k = 1;
104 for (i = Lower; i <= Upper; i++) {
105 Poles(i) = CurvePoles(k++);
110 //=======================================================================
113 //=======================================================================
115 Standard_Integer ShapeConstruct_CompBezierCurvesToBSplineCurve::NbKnots() const
117 return CurveKnots.Length();
121 //=======================================================================
122 //function : KnotsAndMults
124 //=======================================================================
126 void ShapeConstruct_CompBezierCurvesToBSplineCurve::KnotsAndMults
127 (TColStd_Array1OfReal& Knots,
128 TColStd_Array1OfInteger& Mults ) const
130 Standard_Integer i, LowerK = Knots.Lower(), UpperK = Knots.Upper();
131 Standard_Integer LowerM = Mults.Lower(), UpperM = Mults.Upper();
132 Standard_Integer k = 1;
133 for (i = LowerK; i <= UpperK; i++) {
134 Knots(i) = CurveKnots(k++);
137 for (i = LowerM; i <= UpperM; i++) {
138 Mults(i) = KnotsMultiplicities(k++);
144 //=======================================================================
147 //=======================================================================
149 void ShapeConstruct_CompBezierCurvesToBSplineCurve::Perform()
151 myDone = Standard_True;
154 KnotsMultiplicities.Clear();
155 Standard_Integer LowerI = 1;
156 Standard_Integer UpperI = mySequence.Length();
157 Standard_Integer NbrCurv = UpperI-LowerI+1;
159 TColStd_Array1OfReal CurveKnVals (1,NbrCurv);
163 for ( i = 1; i <= mySequence.Length(); i++) {
164 myDegree = Max( myDegree, (mySequence(i))->Length() -1);
167 Standard_Real D1, D2, Lambda, Det=0.;
169 Standard_Integer Deg, Inc, MaxDegree = myDegree;
170 TColgp_Array1OfPnt Points(1, myDegree+1);
172 for (i = LowerI ; i <= UpperI ; i++) {
173 // 1- Elever la courbe de Bezier au degre maximum.
174 Deg = mySequence(i)->Length()-1;
175 Inc = myDegree - Deg;
177 BSplCLib::IncreaseDegree(myDegree,
178 mySequence(i)->Array1(), BSplCLib::NoWeights(),
179 Points, BSplCLib::NoWeights());
182 Points = mySequence(i)->Array1();
185 // 2- Traiter le noeud de jonction entre 2 courbes de Bezier.
187 // Traitement du noeud initial de la BSpline.
188 for (Standard_Integer j = 1 ; j <= MaxDegree ; j++) {
189 CurvePoles.Append(Points(j));
191 CurveKnVals(1) = 1.; // Pour amorcer la serie.
192 KnotsMultiplicities.Append(MaxDegree+1);
200 gp_Vec V1(P1, P2), V2(P2, P3);
201 D1 = P1.SquareDistance(P2);
202 D2 = P3.SquareDistance(P2);
203 Lambda = Sqrt(D2/D1);
206 // Traitement de la tangence entre la Bezier et sa precedente.
207 // Ceci permet d''assurer au moins une continuite C1 si
208 // les tangentes sont coherentes.
210 if (V1.Magnitude() > gp::Resolution() &&
211 V2.Magnitude() > gp::Resolution() &&
212 V1.IsParallel(V2, myAngular ) &&
213 MaxDegree > 1) {//rln 20.06.99 work-around
214 KnotsMultiplicities.Append(MaxDegree-1);
215 CurveKnVals(i) = CurveKnVals(i-1) * Lambda;
216 Det += CurveKnVals(i);
220 CurvePoles.Append(Points(1));
221 KnotsMultiplicities.Append(MaxDegree);
222 CurveKnVals(i) = 1.0e0 ;
223 Det += CurveKnVals(i) ;
226 // Stocker les poles.
227 for (Standard_Integer j = 2 ; j <= MaxDegree ; j++) {
228 CurvePoles.Append(Points(j));
235 // Traitement du noeud terminal de la BSpline.
236 CurvePoles.Append(Points(MaxDegree+1));
237 KnotsMultiplicities.Append(MaxDegree+1);
239 P1 = Points(MaxDegree);
242 // Corriger les valeurs nodales pour les faire varier dans [0.,1.].
243 CurveKnots.Append(0.0);
244 for (i = 2 ; i <= NbrCurv ; i++) {
245 CurveKnots.Append(CurveKnots(i-1) + (CurveKnVals(i-1)/Det));
247 CurveKnots.Append(1.0);