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.
18 Handle(StepGeom_BSplineCurveWithKnots) BSCW;
19 Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve) BSCWR;
21 if (SC->IsKind(STANDARD_TYPE(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve))) {
23 Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve)
26 Handle(StepGeom_BSplineCurveWithKnots)
27 ::DownCast(BSCWR->BSplineCurveWithKnots());
30 BSCW = Handle(StepGeom_BSplineCurveWithKnots)::DownCast(SC);
32 const Standard_Integer Deg = BSCW->Degree();
33 const Standard_Integer NbPoles = BSCW->NbControlPointsList();
34 const Standard_Integer NbKnots = BSCW->NbKnotMultiplicities();
36 //aKnotMultiplicities = new TColStd_HArray1OfInteger(1,NbKnots);
37 const Handle(TColStd_HArray1OfInteger)& aKnotMultiplicities = BSCW->KnotMultiplicities();
38 //aKnots = new TColStd_HArray1OfReal(1,NbKnots);
39 const Handle(TColStd_HArray1OfReal)& aKnots = BSCW->Knots();
41 // Count number of unique knots
43 Standard_Integer NbUniqueKnots = 0;
44 Standard_Real lastKnot = RealFirst();
45 for (i=1; i<=NbKnots; ++i) {
46 if (aKnots->Value(i) - lastKnot > Epsilon (Abs(lastKnot))) {
48 lastKnot = aKnots->Value(i);
52 TColStd_Array1OfReal Kn(1,NbUniqueKnots);
53 TColStd_Array1OfInteger Mult(1,NbUniqueKnots);
54 lastKnot = aKnots->Value(1);
55 Kn.SetValue(1, aKnots->Value(1));
56 Mult.SetValue(1, aKnotMultiplicities->Value(1));
57 Standard_Integer pos = 1;
58 for (i=2; i<=NbKnots; i++) {
59 if (aKnots->Value(i) - lastKnot > Epsilon (Abs(lastKnot))) {
61 Kn.SetValue(pos, aKnots->Value(i));
62 Mult.SetValue(pos, aKnotMultiplicities->Value(i));
63 lastKnot = aKnots->Value(i);
66 // Knot not unique, increase multiplicity
67 Standard_Integer curMult = Mult.Value(pos);
68 Mult.SetValue(pos, curMult + aKnotMultiplicities->Value(i));
72 Standard_Integer aFMulDiff = 0,aLMulDiff = 0;
73 for (i=1; i<=NbUniqueKnots; ++i) {
74 Standard_Integer aCurrentVal = Mult.Value(i);
75 if (aCurrentVal > Deg + 1)
77 if (i == 1) aFMulDiff = aCurrentVal - Deg - 1;
78 if (i == NbKnots) aLMulDiff = aCurrentVal - Deg - 1;
80 cout << "\nWrong multiplicity " << aCurrentVal << " on " << i
81 << " knot!" << "\nChanged to " << Deg + 1 << endl;
83 aCurrentVal = Deg + 1;
85 Mult.SetValue(i,aCurrentVal);
88 //aControlPointsList = new StepGeom_HArray1OfCartesianPoint(1,NbPoles);
89 const Handle(StepGeom_HArray1OfCartesianPoint)& aControlPointsList = BSCW->ControlPointsList();
90 Standard_Integer aSumMulDiff = aFMulDiff + aLMulDiff;
91 Array1OfPnt_gen Poles(1,NbPoles - aSumMulDiff);
94 for (i = 1 + aFMulDiff; i<= NbPoles - aLMulDiff; ++i)
96 if (StepToGeom_MakeCartesianPoint_gen::Convert(aControlPointsList->Value(i),P))
97 Poles.SetValue(i - aFMulDiff,P->Pnt_fonc());
99 return Standard_False;
102 // --- Does the Curve descriptor LOOKS like a periodic descriptor ? ---
104 Standard_Integer SumMult = 0;
105 for (i=1; i<=NbUniqueKnots; i++) {
106 SumMult += Mult.Value(i);
109 Standard_Boolean shouldBePeriodic;
110 if (SumMult == (NbPoles + Deg + 1)) {
111 shouldBePeriodic = Standard_False;
113 else if ((Mult.Value(1) ==
114 Mult.Value(NbUniqueKnots)) &&
115 ((SumMult - Mult.Value(1)) == NbPoles)) {
116 shouldBePeriodic = Standard_True;
118 else { // --- What is that ??? ---
119 shouldBePeriodic = Standard_False;
120 //cout << "Strange BSpline Curve Descriptor" << endl;
123 if (SC->IsKind(STANDARD_TYPE(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve))) {
124 const Handle(TColStd_HArray1OfReal)& aWeight = BSCWR->WeightsData();
125 TColStd_Array1OfReal W(1,NbPoles);
126 for (i=1; i<=NbPoles; i++)
127 W.SetValue(i,aWeight->Value(i));
128 CC = new BSplineCurve_gen(Poles, W, Kn, Mult, Deg, shouldBePeriodic);
131 CC = new BSplineCurve_gen(Poles, Kn, Mult, Deg, shouldBePeriodic);
133 // abv 04.07.00 CAX-IF TRJ4: trj4_k1_top-md-203.stp #716 (face #581):
134 // force periodicity on closed curves
135 if ( SC->ClosedCurve() && CC->Degree() >1 && CC->IsClosed() ) {
138 return Standard_True;