b311480e |
1 | // Created on: 1993-07-02 |
2 | // Created by: Martine LANGLOIS |
3 | // Copyright (c) 1993-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 | Handle(StepGeom_BSplineCurveWithKnots) BSCW; |
18 | Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve) BSCWR; |
19 | |
20 | if (SC->IsKind(STANDARD_TYPE(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve))) { |
caaeed1b |
21 | BSCWR = Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve)::DownCast(SC); |
22 | BSCW = Handle(StepGeom_BSplineCurveWithKnots)::DownCast(BSCWR->BSplineCurveWithKnots()); |
7fd59977 |
23 | } |
24 | else |
25 | BSCW = Handle(StepGeom_BSplineCurveWithKnots)::DownCast(SC); |
26 | |
27 | const Standard_Integer Deg = BSCW->Degree(); |
28 | const Standard_Integer NbPoles = BSCW->NbControlPointsList(); |
45521367 |
29 | const Standard_Integer NbKnots = BSCW->NbKnotMultiplicities(); |
7fd59977 |
30 | |
45521367 |
31 | //aKnotMultiplicities = new TColStd_HArray1OfInteger(1,NbKnots); |
32 | const Handle(TColStd_HArray1OfInteger)& aKnotMultiplicities = BSCW->KnotMultiplicities(); |
d15f387a |
33 | //aKnots = new TColStd_HArray1OfReal(1,NbKnots); |
34 | const Handle(TColStd_HArray1OfReal)& aKnots = BSCW->Knots(); |
45521367 |
35 | |
d15f387a |
36 | // Count number of unique knots |
7fd59977 |
37 | Standard_Integer i; |
d15f387a |
38 | Standard_Integer NbUniqueKnots = 0; |
39 | Standard_Real lastKnot = RealFirst(); |
45521367 |
40 | for (i=1; i<=NbKnots; ++i) { |
d15f387a |
41 | if (aKnots->Value(i) - lastKnot > Epsilon (Abs(lastKnot))) { |
42 | NbUniqueKnots++; |
43 | lastKnot = aKnots->Value(i); |
44 | } |
45 | } |
46 | |
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))) { |
55 | pos++; |
56 | Kn.SetValue(pos, aKnots->Value(i)); |
57 | Mult.SetValue(pos, aKnotMultiplicities->Value(i)); |
58 | lastKnot = aKnots->Value(i); |
59 | } |
60 | else { |
61 | // Knot not unique, increase multiplicity |
62 | Standard_Integer curMult = Mult.Value(pos); |
63 | Mult.SetValue(pos, curMult + aKnotMultiplicities->Value(i)); |
64 | } |
65 | } |
66 | |
67 | Standard_Integer aFMulDiff = 0,aLMulDiff = 0; |
68 | for (i=1; i<=NbUniqueKnots; ++i) { |
69 | Standard_Integer aCurrentVal = Mult.Value(i); |
45521367 |
70 | if (aCurrentVal > Deg + 1) |
71 | { |
72 | if (i == 1) aFMulDiff = aCurrentVal - Deg - 1; |
73 | if (i == NbKnots) aLMulDiff = aCurrentVal - Deg - 1; |
0797d9d3 |
74 | #ifdef OCCT_DEBUG |
45521367 |
75 | cout << "\nWrong multiplicity " << aCurrentVal << " on " << i |
76 | << " knot!" << "\nChanged to " << Deg + 1 << endl; |
77 | #endif |
78 | aCurrentVal = Deg + 1; |
79 | } |
80 | Mult.SetValue(i,aCurrentVal); |
81 | } |
82 | |
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); |
45521367 |
87 | |
88 | for (i = 1 + aFMulDiff; i<= NbPoles - aLMulDiff; ++i) |
7fd59977 |
89 | { |
caaeed1b |
90 | CartesianPoint_gen P = MakeCartesianPoint_gen (aControlPointsList->Value(i)); |
91 | if (! P.IsNull()) |
45521367 |
92 | Poles.SetValue(i - aFMulDiff,P->Pnt_fonc()); |
7fd59977 |
93 | else |
caaeed1b |
94 | return 0; |
7fd59977 |
95 | } |
96 | |
7fd59977 |
97 | // --- Does the Curve descriptor LOOKS like a periodic descriptor ? --- |
98 | |
99 | Standard_Integer SumMult = 0; |
d15f387a |
100 | for (i=1; i<=NbUniqueKnots; i++) { |
101 | SumMult += Mult.Value(i); |
7fd59977 |
102 | } |
103 | |
104 | Standard_Boolean shouldBePeriodic; |
105 | if (SumMult == (NbPoles + Deg + 1)) { |
106 | shouldBePeriodic = Standard_False; |
107 | } |
d15f387a |
108 | else if ((Mult.Value(1) == |
109 | Mult.Value(NbUniqueKnots)) && |
110 | ((SumMult - Mult.Value(1)) == NbPoles)) { |
7fd59977 |
111 | shouldBePeriodic = Standard_True; |
112 | } |
113 | else { // --- What is that ??? --- |
114 | shouldBePeriodic = Standard_False; |
115 | //cout << "Strange BSpline Curve Descriptor" << endl; |
116 | } |
caaeed1b |
117 | |
118 | BSplineCurve_retour CC; |
7fd59977 |
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); |
125 | } |
126 | else |
127 | CC = new BSplineCurve_gen(Poles, Kn, Mult, Deg, shouldBePeriodic); |
128 | |
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() ) { |
132 | CC->SetPeriodic(); |
7fd59977 |
133 | } |
caaeed1b |
134 | return CC; |