7fd59977 |
1 | // File: ShapeUpgrade_SplitCurve2dContinuity.cxx |
2 | // Created: Wed Apr 14 19:18:17 1999 |
3 | // Author: Roman LYGIN |
4 | // <rln@kinox.nnov.matra-dtv.fr> |
5 | |
6 | |
7 | #include <ShapeUpgrade_SplitCurve2dContinuity.ixx> |
8 | #include <Standard_ErrorHandler.hxx> |
9 | #include <Standard_Failure.hxx> |
10 | #include <Geom2d_BSplineCurve.hxx> |
11 | #include <Precision.hxx> |
12 | #include <ShapeUpgrade.hxx> |
13 | #include <Geom2d_TrimmedCurve.hxx> |
14 | #include <Geom2d_OffsetCurve.hxx> |
15 | #include <TColGeom2d_HArray1OfCurve.hxx> |
16 | #include <TColStd_HSequenceOfReal.hxx> |
17 | #include <TColGeom2d_HArray1OfCurve.hxx> |
18 | #include <ShapeExtend.hxx> |
19 | |
20 | |
21 | //======================================================================= |
22 | //function : ShapeUpgrade_SplitCurve2dContinuity |
23 | //purpose : |
24 | //======================================================================= |
25 | |
26 | ShapeUpgrade_SplitCurve2dContinuity::ShapeUpgrade_SplitCurve2dContinuity() |
27 | { |
28 | myCriterion = GeomAbs_C1; |
29 | myTolerance = Precision::PConfusion(); |
30 | myCont =1; |
31 | } |
32 | |
33 | //======================================================================= |
34 | //function : SetCriterion |
35 | //purpose : |
36 | //======================================================================= |
37 | |
38 | void ShapeUpgrade_SplitCurve2dContinuity::SetCriterion(const GeomAbs_Shape Criterion) |
39 | { |
40 | myCriterion = Criterion; |
41 | switch (myCriterion) { |
42 | case GeomAbs_C0 : myCont = 0; break; |
43 | case GeomAbs_C1 : myCont = 1; break; |
44 | case GeomAbs_C2 : myCont = 2; break; |
45 | case GeomAbs_C3 : myCont = 3; break; |
46 | case GeomAbs_CN : myCont = 4; break; |
47 | default : myCont = 1; |
48 | } |
49 | } |
50 | |
51 | //======================================================================= |
52 | //function : SetTolerance |
53 | //purpose : |
54 | //======================================================================= |
55 | |
56 | void ShapeUpgrade_SplitCurve2dContinuity::SetTolerance(const Standard_Real Tol) |
57 | { |
58 | myTolerance = Tol; |
59 | } |
60 | |
61 | //======================================================================= |
62 | //function : Compute |
63 | //purpose : |
64 | //======================================================================= |
65 | |
66 | void ShapeUpgrade_SplitCurve2dContinuity::Compute() |
67 | { |
68 | if(myCurve->Continuity() < myCriterion) |
69 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2); |
70 | if (mySplitValues->Length() > 2) |
71 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1); |
72 | Standard_Real precision = Precision::PConfusion(); |
73 | Standard_Real First = mySplitValues->Value(1); |
74 | Standard_Real Last = mySplitValues->Value(mySplitValues->Length()); |
75 | if (myCurve->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve))) { |
76 | Handle(Geom2d_TrimmedCurve) tmp = Handle(Geom2d_TrimmedCurve)::DownCast (myCurve); |
77 | Handle(Geom2d_Curve) BasCurve = tmp->BasisCurve(); |
78 | ShapeUpgrade_SplitCurve2dContinuity spc; |
79 | // spc.Init(BasCurve,Max(First,tmp->FirstParameter()),Min(Last,tmp->LastParameter())); |
80 | spc.Init(BasCurve,First,Last); |
81 | spc.SetSplitValues(mySplitValues); |
82 | spc.SetTolerance(myTolerance); |
83 | spc.SetCriterion(myCriterion); |
84 | spc.Compute(); |
85 | mySplitValues->Clear(); |
86 | mySplitValues->ChangeSequence() = spc.SplitValues()->Sequence(); |
87 | //mySplitValues = spc.SplitValues(); |
88 | myStatus |= spc.myStatus; |
89 | return; |
90 | } |
91 | else if (myCurve->IsKind(STANDARD_TYPE(Geom2d_OffsetCurve))) { |
92 | GeomAbs_Shape BasCriterion; |
93 | switch (myCriterion) { |
94 | default : |
95 | case GeomAbs_C1 : BasCriterion = GeomAbs_C2; break; |
96 | case GeomAbs_C2 : BasCriterion = GeomAbs_C3; break; |
97 | case GeomAbs_C3 : //if (ShapeUpgrade::Debug()) cout<<". this criterion is not suitable for a Offset curve"<<endl; |
98 | #ifdef DEB |
99 | cout << "Warning: ShapeUpgrade_SplitCurve2dContinuity: criterion C3 for Offset curve" << endl; |
100 | #endif |
101 | case GeomAbs_CN : BasCriterion = GeomAbs_CN; break; |
102 | } |
103 | Handle(Geom2d_OffsetCurve) tmp = Handle(Geom2d_OffsetCurve)::DownCast (myCurve); |
104 | Handle(Geom2d_Curve) BasCurve = tmp->BasisCurve(); |
105 | //Standard_Real Offset = tmp->Offset(); // Offset not used (skl) |
106 | ShapeUpgrade_SplitCurve2dContinuity spc; |
107 | // spc.Init(BasCurve,Max(tmp->FirstParameter(),First),Min(tmp->LastParameter(),Last)); |
108 | spc.Init(BasCurve,First,Last); |
109 | spc.SetSplitValues(mySplitValues); |
110 | spc.SetTolerance(myTolerance); |
111 | spc.SetCriterion(BasCriterion); |
112 | spc.Compute(); |
113 | mySplitValues->Clear(); |
114 | mySplitValues->ChangeSequence() = spc.SplitValues()->Sequence(); |
115 | myStatus |= spc.myStatus; |
116 | return; |
117 | } |
118 | |
119 | Handle(Geom2d_BSplineCurve) MyBSpline = Handle(Geom2d_BSplineCurve)::DownCast (myCurve); |
120 | if (MyBSpline.IsNull()) { |
121 | // if (ShapeUpgrade::Debug()) cout<<". curve is not a Bspline"<<endl; |
122 | return; |
123 | } |
124 | |
125 | myNbCurves=1; |
126 | Standard_Integer Deg=MyBSpline->Degree(); |
127 | Standard_Integer NbKnots= MyBSpline->NbKnots(); |
128 | // if (ShapeUpgrade::Debug()) cout<<". NbKnots="<<NbKnots<<endl; |
129 | if (NbKnots <= 2) { |
130 | return; |
131 | } |
132 | Standard_Integer FirstInd =MyBSpline->FirstUKnotIndex()+1, |
133 | LastInd = MyBSpline->LastUKnotIndex()-1; |
134 | Standard_Integer iknot = FirstInd; |
135 | for(Standard_Integer j =2; j <= mySplitValues->Length(); j++) { |
136 | Last = mySplitValues->Value(j); |
137 | for (; iknot <= LastInd; iknot++) { |
138 | Standard_Real valknot = MyBSpline->Knot(iknot); |
139 | if(valknot <= First + precision) continue; |
140 | if(valknot >= Last - precision) break; |
141 | Standard_Integer Continuity=Deg-MyBSpline->Multiplicity(iknot); |
142 | //Standard_Real tt = MyBSpline->Knot(iknot); // tt not used (skl) |
143 | if (Continuity < myCont) { |
144 | // At this knot, the curve is C0; try to remove Knot. |
145 | Standard_Boolean corrected = Standard_False; |
146 | Standard_Integer newMultiplicity = Deg - myCont; |
147 | if (newMultiplicity < 0) newMultiplicity = 0; |
148 | { |
149 | try { |
150 | OCC_CATCH_SIGNALS |
151 | corrected = MyBSpline->RemoveKnot(iknot, newMultiplicity, myTolerance); |
152 | } |
153 | catch (Standard_Failure) { |
154 | corrected = Standard_False; |
155 | } |
156 | } |
157 | if (corrected && newMultiplicity > 0) { |
158 | Continuity=Deg-MyBSpline->Multiplicity(iknot); |
159 | corrected = (Continuity >= myCont); |
160 | } |
161 | if (corrected) { |
162 | // at this knot, the continuity is now C1. Nothing else to do. |
163 | // if (ShapeUpgrade::Debug()) cout<<". Correction at Knot "<<iknot<<endl; |
164 | myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 ); |
165 | } |
166 | else { |
167 | // impossible to force C1 within the tolerance: |
168 | // this knot will be a splitting value. |
169 | mySplitValues->InsertBefore(j++,MyBSpline->Knot(iknot)); |
170 | myNbCurves++; |
171 | // if (ShapeUpgrade::Debug()) cout<<". Splitting at Knot "<<iknot<<endl; |
172 | } |
173 | } |
174 | } |
175 | |
176 | First = Last; |
177 | } |
178 | |
179 | if (mySplitValues->Length() > 2) |
180 | myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1); |
181 | } |
182 | |