1 // Created on: 1993-07-02
2 // Created by: Martine LANGLOIS
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 Handle(StepGeom_BSplineCurveWithKnots) BSCW;
18 Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve) BSCWR;
20 if (SC->IsKind(STANDARD_TYPE(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve))) {
21 BSCWR = Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve)::DownCast(SC);
22 BSCW = Handle(StepGeom_BSplineCurveWithKnots)::DownCast(BSCWR->BSplineCurveWithKnots());
25 BSCW = Handle(StepGeom_BSplineCurveWithKnots)::DownCast(SC);
27 const Standard_Integer Deg = BSCW->Degree();
28 const Standard_Integer NbPoles = BSCW->NbControlPointsList();
29 const Standard_Integer NbKnots = BSCW->NbKnotMultiplicities();
31 //aKnotMultiplicities = new TColStd_HArray1OfInteger(1,NbKnots);
32 const Handle(TColStd_HArray1OfInteger)& aKnotMultiplicities = BSCW->KnotMultiplicities();
33 //aKnots = new TColStd_HArray1OfReal(1,NbKnots);
34 const Handle(TColStd_HArray1OfReal)& aKnots = BSCW->Knots();
36 // Count number of unique knots
38 Standard_Integer NbUniqueKnots = 0;
39 Standard_Real lastKnot = RealFirst();
40 for (i=1; i<=NbKnots; ++i) {
41 if (aKnots->Value(i) - lastKnot > Epsilon (Abs(lastKnot))) {
43 lastKnot = aKnots->Value(i);
47 TColStd_Array1OfReal Kn(1,NbUniqueKnots);
48 TColStd_Array1OfInteger Mult(1,NbUniqueKnots);
49 lastKnot = aKnots->Value(1);
50 Kn.SetValue(1, aKnots->Value(1));
51 Mult.SetValue(1, aKnotMultiplicities->Value(1));
52 Standard_Integer pos = 1;
53 for (i=2; i<=NbKnots; i++) {
54 if (aKnots->Value(i) - lastKnot > Epsilon (Abs(lastKnot))) {
56 Kn.SetValue(pos, aKnots->Value(i));
57 Mult.SetValue(pos, aKnotMultiplicities->Value(i));
58 lastKnot = aKnots->Value(i);
61 // Knot not unique, increase multiplicity
62 Standard_Integer curMult = Mult.Value(pos);
63 Mult.SetValue(pos, curMult + aKnotMultiplicities->Value(i));
67 Standard_Integer aFMulDiff = 0,aLMulDiff = 0;
68 for (i=1; i<=NbUniqueKnots; ++i) {
69 Standard_Integer aCurrentVal = Mult.Value(i);
70 if (aCurrentVal > Deg + 1)
72 if (i == 1) aFMulDiff = aCurrentVal - Deg - 1;
73 if (i == NbUniqueKnots) aLMulDiff = aCurrentVal - Deg - 1;
75 cout << "\nWrong multiplicity " << aCurrentVal << " on " << i
76 << " knot!" << "\nChanged to " << Deg + 1 << endl;
78 aCurrentVal = Deg + 1;
80 Mult.SetValue(i,aCurrentVal);
83 //aControlPointsList = new StepGeom_HArray1OfCartesianPoint(1,NbPoles);
84 const Handle(StepGeom_HArray1OfCartesianPoint)& aControlPointsList = BSCW->ControlPointsList();
85 Standard_Integer aSumMulDiff = aFMulDiff + aLMulDiff;
86 Array1OfPnt_gen Poles(1,NbPoles - aSumMulDiff);
88 for (i = 1 + aFMulDiff; i<= NbPoles - aLMulDiff; ++i)
90 CartesianPoint_gen P = MakeCartesianPoint_gen (aControlPointsList->Value(i));
92 Poles.SetValue(i - aFMulDiff,P->Pnt_fonc());
97 // --- Does the Curve descriptor LOOKS like a periodic descriptor ? ---
99 Standard_Integer SumMult = 0;
100 for (i=1; i<=NbUniqueKnots; i++) {
101 SumMult += Mult.Value(i);
104 Standard_Boolean shouldBePeriodic;
105 if (SumMult == (NbPoles + Deg + 1)) {
106 shouldBePeriodic = Standard_False;
108 else if ((Mult.Value(1) ==
109 Mult.Value(NbUniqueKnots)) &&
110 ((SumMult - Mult.Value(1)) == NbPoles)) {
111 shouldBePeriodic = Standard_True;
113 else { // --- What is that ??? ---
114 shouldBePeriodic = Standard_False;
115 //cout << "Strange BSpline Curve Descriptor" << endl;
118 BSplineCurve_retour CC;
119 if (SC->IsKind(STANDARD_TYPE(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve))) {
120 const Handle(TColStd_HArray1OfReal)& aWeight = BSCWR->WeightsData();
121 TColStd_Array1OfReal W(1,NbPoles);
122 for (i=1; i<=NbPoles; i++)
123 W.SetValue(i,aWeight->Value(i));
124 CC = new BSplineCurve_gen(Poles, W, Kn, Mult, Deg, shouldBePeriodic);
127 CC = new BSplineCurve_gen(Poles, Kn, Mult, Deg, shouldBePeriodic);
129 // abv 04.07.00 CAX-IF TRJ4: trj4_k1_top-md-203.stp #716 (face #581):
130 // force periodicity on closed curves
131 if ( SC->ClosedCurve() && CC->Degree() >1 && CC->IsClosed() ) {