1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
// File: ShapeUpgrade_SplitSurfaceContinuity.cxx
// Created: Wed Apr 14 15:19:20 1999
// Author: Roman LYGIN
// <rln@kinox.nnov.matra-dtv.fr>
#include <ShapeUpgrade_SplitSurfaceContinuity.ixx>
#include <Geom_BSplineSurface.hxx>
#include <Precision.hxx>
#include <ShapeUpgrade.hxx>
#include <TColGeom_HArray2OfSurface.hxx>
#include <TColStd_HArray1OfInteger.hxx>
#include <Geom_SweptSurface.hxx>
#include <TColStd_HSequenceOfReal.hxx>
#include <Geom_SurfaceOfRevolution.hxx>
#include <ShapeUpgrade_SplitCurve3dContinuity.hxx>
#include <Geom_SurfaceOfLinearExtrusion.hxx>
#include <TColGeom_HArray1OfCurve.hxx>
#include <gp_Ax1.hxx>
#include <Geom_RectangularTrimmedSurface.hxx>
#include <Geom_OffsetSurface.hxx>
#include <ShapeExtend.hxx>
//======================================================================
//function : ShapeUpgrade_SplitSurface
//purpose :
//=======================================================================
ShapeUpgrade_SplitSurfaceContinuity::ShapeUpgrade_SplitSurfaceContinuity()
{
myCriterion = GeomAbs_C1;
myTolerance = Precision::Confusion();
}
//=======================================================================
//function : SetCrierion
//purpose :
//=======================================================================
void ShapeUpgrade_SplitSurfaceContinuity::SetCriterion(const GeomAbs_Shape Criterion)
{
myCriterion = Criterion;
switch (myCriterion) {
default :
case GeomAbs_C1 : myCont = 1; break;
case GeomAbs_C2 : myCont = 2; break;
case GeomAbs_C3 : myCont = 3; break;
case GeomAbs_CN : myCont = 4; break;
}
}
//=======================================================================
//function : SetTolerance
//purpose :
//=======================================================================
void ShapeUpgrade_SplitSurfaceContinuity::SetTolerance(const Standard_Real Tol)
{
myTolerance = Tol;
}
//=======================================================================
//function : Build
//purpose :
//=======================================================================
void ShapeUpgrade_SplitSurfaceContinuity::Compute(const Standard_Boolean Segment)
{
if(!Segment) {
Standard_Real UF,UL,VF,VL;
mySurface->Bounds(UF,UL,VF,VL);
if(!Precision::IsInfinite(UF)) myUSplitValues->SetValue(1,UF);
if(!Precision::IsInfinite(UL)) myUSplitValues->SetValue(myUSplitValues->Length(),UL);
if(!Precision::IsInfinite(VF)) myVSplitValues->SetValue(1,VF);
if(!Precision::IsInfinite(VL)) myVSplitValues->SetValue(myVSplitValues->Length(),VL);
}
Standard_Real UFirst = myUSplitValues->Value(1);
Standard_Real ULast = myUSplitValues->Value(myUSplitValues->Length());
Standard_Real VFirst = myVSplitValues->Value(1);
Standard_Real VLast = myVSplitValues->Value(myVSplitValues->Length());
Standard_Real precision = Precision::Confusion();
// if (ShapeUpgrade::Debug()) cout << "SplitSurfaceContinuity::Build" << endl;
if(mySurface->Continuity() < myCriterion)
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2);
if (myUSplitValues->Length() >2 || myVSplitValues->Length() >2 )
myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
if (mySurface->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))) {
Handle(Geom_SurfaceOfRevolution) Surface = Handle(Geom_SurfaceOfRevolution)::DownCast(mySurface);
if(Surface->Continuity() >= myCriterion && myUSplitValues->Length() ==2 && myVSplitValues->Length() ==2 ) {
return;
}
Handle(Geom_Curve) BasCurve = Surface->BasisCurve();
ShapeUpgrade_SplitCurve3dContinuity spc;
spc.Init(BasCurve,VFirst,VLast);
spc.SetCriterion(myCriterion);
spc.SetTolerance(myTolerance);
spc.SetSplitValues(myVSplitValues);
spc.Compute();
myVSplitValues->Clear();
myVSplitValues->ChangeSequence() = spc.SplitValues()->Sequence();
if ( spc.Status ( ShapeExtend_DONE1 ) )
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 );
if ( spc.Status ( ShapeExtend_DONE2 ) )
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE2 );
if ( spc.Status ( ShapeExtend_DONE3 ) )
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 );
return;
}
if (mySurface->IsKind(STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion))) {
Handle(Geom_SurfaceOfLinearExtrusion) Surface = Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(mySurface);
if(Surface->Continuity() >= myCriterion && myUSplitValues->Length() ==2 && myVSplitValues->Length() == 2) {
return;
}
Handle(Geom_Curve) BasCurve = Surface->BasisCurve();
ShapeUpgrade_SplitCurve3dContinuity spc;
spc.Init(BasCurve,UFirst,ULast);
spc.SetCriterion(myCriterion);
spc.SetTolerance(myTolerance);
spc.SetSplitValues(myUSplitValues);
spc.Compute();
myUSplitValues->Clear();
myUSplitValues->ChangeSequence() = spc.SplitValues()->Sequence();
if ( spc.Status ( ShapeExtend_DONE1 ) )
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 );
if ( spc.Status ( ShapeExtend_DONE2 ) )
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE2 );
if ( spc.Status ( ShapeExtend_DONE3 ) ) {
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 );
Handle(Geom_Curve) aNewBascurve = spc.GetCurve();
Surface->SetBasisCurve(aNewBascurve);
}
return;
}
if (mySurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
Handle(Geom_RectangularTrimmedSurface) tmp = Handle(Geom_RectangularTrimmedSurface)::DownCast (mySurface);
if(tmp->Continuity() >= myCriterion && myUSplitValues->Length() ==2 && myVSplitValues->Length() == 2) {
return;
}
Standard_Real U1,U2,V1,V2;
tmp->Bounds(U1,U2,V1,V2);
Handle(Geom_Surface) theSurf = tmp->BasisSurface();
ShapeUpgrade_SplitSurfaceContinuity sps;
sps.Init(theSurf,Max(U1,UFirst),Min(U2,ULast),Max(V1,VFirst),Min(V2,VLast));
sps.SetUSplitValues(myUSplitValues);
sps.SetVSplitValues(myVSplitValues);
sps.SetTolerance(myTolerance);
sps.SetCriterion(myCriterion);
sps.Compute(Standard_True);
myUSplitValues->Clear();
myUSplitValues->ChangeSequence() = sps.USplitValues()->Sequence();
myVSplitValues->Clear();
myVSplitValues->ChangeSequence() = sps.VSplitValues()->Sequence();
myStatus |= sps.myStatus;
return;
}
else if (mySurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
GeomAbs_Shape BasCriterion;
switch (myCriterion) {
default :
case GeomAbs_C1 : BasCriterion = GeomAbs_C2; break;
case GeomAbs_C2 : BasCriterion = GeomAbs_C3; break;
case GeomAbs_C3 : //if (ShapeUpgrade::Debug()) cout<<". this criterion is not suitable for a Offset Surface"<<endl;;
#ifdef DEB
cout << "Warning: ShapeUpgrade_SplitSurfaceContinuity: criterion C3 for Offset surface" << endl;
#endif
case GeomAbs_CN : BasCriterion = GeomAbs_CN; break;
}
Handle(Geom_OffsetSurface) tmp = Handle(Geom_OffsetSurface)::DownCast (mySurface);
Handle(Geom_Surface) theSurf = tmp->BasisSurface();
if(theSurf->Continuity() >= BasCriterion && myUSplitValues->Length() ==2 && myVSplitValues->Length() == 2) {
return;
}
ShapeUpgrade_SplitSurfaceContinuity sps;
sps.Init(theSurf,UFirst,ULast,VFirst,VLast);
sps.SetUSplitValues(myUSplitValues);
sps.SetVSplitValues(myVSplitValues);
sps.SetTolerance(myTolerance);
sps.SetCriterion(BasCriterion);
sps.Compute(Standard_True);
myUSplitValues->Clear();
myUSplitValues->ChangeSequence() = sps.USplitValues()->Sequence();
myVSplitValues->Clear();
myVSplitValues->ChangeSequence() = sps.VSplitValues()->Sequence();
myStatus |= sps.myStatus;
return;
}
Handle(Geom_BSplineSurface) MyBSpline;
if(mySurface->IsKind(STANDARD_TYPE(Geom_BSplineSurface)))
MyBSpline = Handle(Geom_BSplineSurface)::DownCast(mySurface->Copy());
if (MyBSpline.IsNull()) {
// if (ShapeUpgrade::Debug()) cout<<". "<<" Surface is not a Bspline"<<endl;
return;
}
if(mySurface->Continuity() >= myCriterion) {
return;
}
// it is a BSplineSurface
Standard_Integer UDeg=MyBSpline->UDegree();
Standard_Integer VDeg=MyBSpline->VDegree();
Standard_Integer NbUKnots= MyBSpline->NbUKnots();
Standard_Integer UFirstInd =MyBSpline->FirstUKnotIndex()+1,
ULastInd = MyBSpline->LastUKnotIndex()-1,
VFirstInd =MyBSpline->FirstVKnotIndex()+1,
VLastInd = MyBSpline->LastVKnotIndex()-1;
Standard_Integer NbVKnots= MyBSpline->NbVKnots();
// if (ShapeUpgrade::Debug()) cout<<". NbUKnots="<<NbUKnots<<endl;
if (NbUKnots>2) {
// Only the internal knots are checked.
Standard_Integer iknot= UFirstInd;
for(Standard_Integer j =2; j <= myUSplitValues->Length(); j++) {
ULast = myUSplitValues->Value(j);
for (; iknot <= ULastInd; iknot++) {
Standard_Real valknot = MyBSpline->UKnot(iknot);
if(valknot <= UFirst + precision) continue;
if( valknot >= ULast - precision) break;
Standard_Integer Continuity=UDeg-MyBSpline->UMultiplicity(iknot);
if (Continuity < myCont) {
// At this knot, the Surface is C0; try to remove Knot.
Standard_Integer newMultiplicity=UDeg - myCont;
Standard_Boolean corrected = Standard_False;
if ( newMultiplicity >= 0 )
corrected=MyBSpline->RemoveUKnot(iknot, newMultiplicity, myTolerance);
if (corrected && newMultiplicity > 0) {
Continuity=UDeg-MyBSpline->UMultiplicity(iknot);
corrected = (Continuity >= myCont);
}
if (corrected) {
// at this knot, the continuity is now C1. Nothing else to do.
// if (ShapeUpgrade::Debug()) cout<<". Correction at UKnot "<<iknot<<endl;
// PTV 15.05.2002 decrease iknot and ULastIndex values if knot removed
if (newMultiplicity ==0) { iknot--; ULastInd--; }
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 );
}
else {
// impossible to force C1 within the tolerance:
// this knot will be a splitting value.
Standard_Real u=MyBSpline->UKnot(iknot);
myUSplitValues->InsertBefore(j++,u);
myNbResultingRow++;
// if (ShapeUpgrade::Debug()) cout<<". Splitting at Knot "<<iknot<<endl;
}
}
}
UFirst = ULast;
}
}
// if (ShapeUpgrade::Debug()) cout<<". NbVKnots="<<NbVKnots<<endl;
if (NbVKnots>2) {
// Only the internal knots are checked.
Standard_Integer iknot=VFirstInd;
for(Standard_Integer j1 =2; j1 <= myVSplitValues->Length(); j1++) {
VLast = myVSplitValues->Value(j1);
for (; iknot <= VLastInd; iknot++) {
Standard_Real valknot = MyBSpline->VKnot(iknot);
if(valknot <= VFirst + precision) continue;
if( valknot >= VLast - precision) break;
Standard_Integer Continuity=VDeg-MyBSpline->VMultiplicity(iknot);
if (Continuity < myCont) {
// At this knot, the Surface is C0; try to remove Knot.
Standard_Integer newMultiplicity=VDeg - myCont;
Standard_Boolean corrected = Standard_False;
if( newMultiplicity >= 0 )
corrected=MyBSpline->RemoveVKnot(iknot, newMultiplicity, myTolerance);
if (corrected && newMultiplicity > 0) {
Continuity=VDeg-MyBSpline->VMultiplicity(iknot);
corrected = (Continuity >= myCont);
}
if (corrected ) {
// at this knot, the continuity is now Criterion. Nothing else to do.
// if (ShapeUpgrade::Debug()) cout<<". Correction at VKnot "<<iknot<<endl;
// PTV 15.05.2002 decrease iknot and ULastIndex values if knot removed
if (newMultiplicity ==0) { iknot--; VLastInd--; }
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 );
}
else {
// this knot will be a splitting value.
Standard_Real v=MyBSpline->VKnot(iknot);
myVSplitValues->InsertBefore(j1++,v);
myNbResultingCol++;
// if (ShapeUpgrade::Debug()) cout<<". Splitting at Knot "<<iknot<<endl;
}
}
}
VFirst = VLast;
}
}
if ( Status ( ShapeExtend_DONE3 ) ) {
mySurface = MyBSpline;
}
if (myUSplitValues->Length() >2 || myVSplitValues->Length() >2 )
myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
}
|