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); |
a9dde4a3 |
22 | BSCW = 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 | } |
72523826 |
46 | if(NbUniqueKnots <= 1) |
47 | { |
48 | return 0; |
49 | } |
d15f387a |
50 | TColStd_Array1OfReal Kn(1,NbUniqueKnots); |
51 | TColStd_Array1OfInteger Mult(1,NbUniqueKnots); |
52 | lastKnot = aKnots->Value(1); |
53 | Kn.SetValue(1, aKnots->Value(1)); |
54 | Mult.SetValue(1, aKnotMultiplicities->Value(1)); |
55 | Standard_Integer pos = 1; |
56 | for (i=2; i<=NbKnots; i++) { |
57 | if (aKnots->Value(i) - lastKnot > Epsilon (Abs(lastKnot))) { |
58 | pos++; |
59 | Kn.SetValue(pos, aKnots->Value(i)); |
60 | Mult.SetValue(pos, aKnotMultiplicities->Value(i)); |
61 | lastKnot = aKnots->Value(i); |
62 | } |
63 | else { |
64 | // Knot not unique, increase multiplicity |
65 | Standard_Integer curMult = Mult.Value(pos); |
66 | Mult.SetValue(pos, curMult + aKnotMultiplicities->Value(i)); |
67 | } |
68 | } |
69 | |
70 | Standard_Integer aFMulDiff = 0,aLMulDiff = 0; |
71 | for (i=1; i<=NbUniqueKnots; ++i) { |
72 | Standard_Integer aCurrentVal = Mult.Value(i); |
45521367 |
73 | if (aCurrentVal > Deg + 1) |
74 | { |
75 | if (i == 1) aFMulDiff = aCurrentVal - Deg - 1; |
82314bdf |
76 | if (i == NbUniqueKnots) aLMulDiff = aCurrentVal - Deg - 1; |
0797d9d3 |
77 | #ifdef OCCT_DEBUG |
04232180 |
78 | std::cout << "\nWrong multiplicity " << aCurrentVal << " on " << i |
79 | << " knot!" << "\nChanged to " << Deg + 1 << std::endl; |
45521367 |
80 | #endif |
81 | aCurrentVal = Deg + 1; |
82 | } |
83 | Mult.SetValue(i,aCurrentVal); |
84 | } |
85 | |
86 | //aControlPointsList = new StepGeom_HArray1OfCartesianPoint(1,NbPoles); |
87 | const Handle(StepGeom_HArray1OfCartesianPoint)& aControlPointsList = BSCW->ControlPointsList(); |
88 | Standard_Integer aSumMulDiff = aFMulDiff + aLMulDiff; |
72523826 |
89 | Standard_Integer nbP = NbPoles - aSumMulDiff; |
90 | if( nbP <= 0) |
91 | { |
92 | return 0; |
93 | } |
45521367 |
94 | Array1OfPnt_gen Poles(1,NbPoles - aSumMulDiff); |
45521367 |
95 | |
96 | for (i = 1 + aFMulDiff; i<= NbPoles - aLMulDiff; ++i) |
7fd59977 |
97 | { |
caaeed1b |
98 | CartesianPoint_gen P = MakeCartesianPoint_gen (aControlPointsList->Value(i)); |
99 | if (! P.IsNull()) |
45521367 |
100 | Poles.SetValue(i - aFMulDiff,P->Pnt_fonc()); |
7fd59977 |
101 | else |
caaeed1b |
102 | return 0; |
7fd59977 |
103 | } |
104 | |
7fd59977 |
105 | // --- Does the Curve descriptor LOOKS like a periodic descriptor ? --- |
106 | |
107 | Standard_Integer SumMult = 0; |
d15f387a |
108 | for (i=1; i<=NbUniqueKnots; i++) { |
109 | SumMult += Mult.Value(i); |
7fd59977 |
110 | } |
111 | |
112 | Standard_Boolean shouldBePeriodic; |
113 | if (SumMult == (NbPoles + Deg + 1)) { |
114 | shouldBePeriodic = Standard_False; |
115 | } |
d15f387a |
116 | else if ((Mult.Value(1) == |
117 | Mult.Value(NbUniqueKnots)) && |
118 | ((SumMult - Mult.Value(1)) == NbPoles)) { |
7fd59977 |
119 | shouldBePeriodic = Standard_True; |
120 | } |
121 | else { // --- What is that ??? --- |
122 | shouldBePeriodic = Standard_False; |
123 | //cout << "Strange BSpline Curve Descriptor" << endl; |
124 | } |
caaeed1b |
125 | |
126 | BSplineCurve_retour CC; |
7fd59977 |
127 | if (SC->IsKind(STANDARD_TYPE(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve))) { |
128 | const Handle(TColStd_HArray1OfReal)& aWeight = BSCWR->WeightsData(); |
129 | TColStd_Array1OfReal W(1,NbPoles); |
130 | for (i=1; i<=NbPoles; i++) |
131 | W.SetValue(i,aWeight->Value(i)); |
132 | CC = new BSplineCurve_gen(Poles, W, Kn, Mult, Deg, shouldBePeriodic); |
133 | } |
134 | else |
135 | CC = new BSplineCurve_gen(Poles, Kn, Mult, Deg, shouldBePeriodic); |
136 | |
137 | // abv 04.07.00 CAX-IF TRJ4: trj4_k1_top-md-203.stp #716 (face #581): |
138 | // force periodicity on closed curves |
139 | if ( SC->ClosedCurve() && CC->Degree() >1 && CC->IsClosed() ) { |
140 | CC->SetPeriodic(); |
7fd59977 |
141 | } |
caaeed1b |
142 | return CC; |