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
|
// File: ShapeUpgrade_ClosedFaceDivide.cxx
// Created: Thu Jul 22 16:11:23 1999
// Author: data exchange team
// <det@friendox>
#include <ShapeUpgrade_ClosedFaceDivide.ixx>
#include <Precision.hxx>
#include <ShapeExtend.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopoDS_Wire.hxx>
#include <ShapeExtend_WireData.hxx>
#include <TopoDS_Edge.hxx>
#include <ShapeAnalysis_Edge.hxx>
#include <Geom2d_Curve.hxx>
#include <ShapeAnalysis_Curve.hxx>
#include <Bnd_Box2d.hxx>
#include <TColStd_HSequenceOfReal.hxx>
#include <BRep_Tool.hxx>
#include <ShapeUpgrade_SplitSurface.hxx>
#include <ShapeExtend_CompositeSurface.hxx>
#include <ShapeFix_ComposeShell.hxx>
#include <TopExp_Explorer.hxx>
#include <ShapeAnalysis_Surface.hxx>
#include <ShapeAnalysis.hxx>
#include <Geom_RectangularTrimmedSurface.hxx>
#include <ShapeBuild_ReShape.hxx>
#include <ShapeAnalysis.hxx>
//=======================================================================
//function : ShapeUpgrade_ClosedFaceDivide
//purpose :
//=======================================================================
ShapeUpgrade_ClosedFaceDivide::ShapeUpgrade_ClosedFaceDivide():
ShapeUpgrade_FaceDivide()
{
myNbSplit = 1;
}
//=======================================================================
//function : ShapeUpgrade_ClosedFaceDivide
//purpose :
//=======================================================================
ShapeUpgrade_ClosedFaceDivide::ShapeUpgrade_ClosedFaceDivide(const TopoDS_Face& F):
ShapeUpgrade_FaceDivide(F)
{
myNbSplit = 1;
}
//=======================================================================
//function : SplitSurface
//purpose :
//=======================================================================
Standard_Boolean ShapeUpgrade_ClosedFaceDivide::SplitSurface()
{
Handle(ShapeUpgrade_SplitSurface) SplitSurf = GetSplitSurfaceTool();
if ( SplitSurf.IsNull() ) return Standard_False;
if ( myResult.IsNull() || myResult.ShapeType() != TopAbs_FACE ) {
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL3 );
return Standard_False;
}
TopoDS_Face face = TopoDS::Face ( myResult );
Standard_Real Uf,Ul,Vf,Vl;
ShapeAnalysis::GetFaceUVBounds ( myFace, Uf, Ul, Vf, Vl );
// 01.10.99 pdn Porting on DEC
if( ::Precision::IsInfinite(Uf) || ::Precision::IsInfinite(Ul) ||
::Precision::IsInfinite(Vf) || ::Precision::IsInfinite(Vl) )
return Standard_False;
TopLoc_Location L;
Handle(Geom_Surface) surf;
surf = BRep_Tool::Surface ( face, L );
Standard_Boolean isUSplit = Standard_False;
Standard_Boolean doSplit = Standard_False;
Handle(TColStd_HSequenceOfReal) split = new TColStd_HSequenceOfReal;
for(TopoDS_Iterator iter(face); iter.More()&&!doSplit; iter.Next()) {
if(iter.Value().ShapeType() != TopAbs_WIRE)
continue;
TopoDS_Wire wire = TopoDS::Wire(iter.Value());
Handle(ShapeExtend_WireData) sewd = new ShapeExtend_WireData(wire);
for(Standard_Integer i = 1; i <= sewd->NbEdges()&&!doSplit; i++)
if(sewd->IsSeam(i)) {
doSplit = Standard_True;
TopoDS_Edge edge = sewd->Edge(i);
ShapeAnalysis_Edge sae;
Handle(Geom2d_Curve) c1, c2;
Standard_Real f1,f2,l1,l2;
if(!sae.PCurve(edge,face,c1,f1,l1,Standard_False))
continue;
//smh#8
TopoDS_Shape tmpE = edge.Reversed();
if(!sae.PCurve(TopoDS::Edge(tmpE),face,c2,f2,l2,Standard_False))
continue;
if(c2==c1) continue;
// splitting
ShapeAnalysis_Curve sac;
Bnd_Box2d B1, B2;
sac.FillBndBox ( c1, f1, l1, 20, Standard_True, B1 );
sac.FillBndBox ( c2, f2, l2, 20, Standard_True, B2 );
Standard_Real x1min,y1min,x1max,y1max;
Standard_Real x2min,y2min,x2max,y2max;
B1.Get(x1min,y1min,x1max,y1max);
B2.Get(x2min,y2min,x2max,y2max);
Standard_Real xf,xl,yf,yl;
if(x1min < x2min) {
xf = x1max;
xl = x2min;
} else {
xf = x2max;
xl = x1min;
}
if(y1min < y2min) {
yf = y1max;
yl = y2min;
} else {
yf = y2max;
yl = y1min;
}
Standard_Real dU = xl - xf;
Standard_Real dV = yl - yf;
if(dU > dV) {
Standard_Real step = dU/(myNbSplit+1);
Standard_Real val = xf+step;
for(Standard_Integer j = 1; j <= myNbSplit; j++, val+=step)
split->Append(val);
isUSplit = Standard_True;
}
else {
Standard_Real step = dV/(myNbSplit+1);
Standard_Real val = yf+step;
for(Standard_Integer j = 1; j <= myNbSplit; j++, val+=step)
split->Append(val);
isUSplit = Standard_False;
}
}
}
if(!doSplit) {
//pdn try to define geometric closure.
Handle(ShapeAnalysis_Surface) sas = new ShapeAnalysis_Surface( surf );
Standard_Boolean uclosed = sas->IsUClosed(Precision());
Standard_Boolean vclosed = sas->IsVClosed(Precision());
Standard_Real U1, U2, V1, V2;
if(uclosed) {
surf -> Bounds(U1, U2, V1, V2);
GeomAdaptor_Surface GAS ( surf );
Standard_Real toler = GAS.UResolution ( Precision() );
if((U2-U1) - (Ul-Uf) < toler ) {
Handle(Geom_RectangularTrimmedSurface) rts =
new Geom_RectangularTrimmedSurface(surf,U1,(U2+U1)/2,Standard_True);
Handle(ShapeAnalysis_Surface) sast = new ShapeAnalysis_Surface( rts );
if ( !sast->IsUClosed(Precision())) {
doSplit = Standard_True;
Standard_Real step = (Ul-Uf)/(myNbSplit+1);
Standard_Real val = Uf+step;
for(Standard_Integer i = 1; i <= myNbSplit; i++, val+=step)
split->Append(val);
isUSplit = Standard_True;
}
#ifdef DEB
else cout << "Warning: SU_ClosedFaceDivide: Thin face, not splitted" << endl;
#endif
}
}
if( vclosed && !doSplit ) {
surf -> Bounds(U1, U2, V1, V2);
GeomAdaptor_Surface GAS ( surf );
Standard_Real toler = GAS.VResolution ( Precision() );
if((V2-V1) - (Vl-Vf) < toler) {
Handle(Geom_RectangularTrimmedSurface) rts =
new Geom_RectangularTrimmedSurface(surf,V1,(V2+V1)/2,Standard_False);
Handle(ShapeAnalysis_Surface) sast = new ShapeAnalysis_Surface( rts );
if ( !sast->IsVClosed(Precision())) {
doSplit = Standard_True;
Standard_Real step = (Vl-Vf)/(myNbSplit+1);
Standard_Real val = Vf+step;
for(Standard_Integer i = 1; i <= myNbSplit; i++, val+=step)
split->Append(val);
isUSplit = Standard_False;
}
#ifdef DEB
else cout << "Warning: SU_ClosedFaceDivide: Thin face, not splitted" << endl;
#endif
}
}
}
if(!doSplit)
return Standard_False;
SplitSurf->Init ( surf, Uf, Ul, Vf, Vl );
if(isUSplit)
SplitSurf->SetUSplitValues(split);
else
SplitSurf->SetVSplitValues(split);
SplitSurf->Perform(mySegmentMode);
if ( ! SplitSurf->Status ( ShapeExtend_DONE ) ) return Standard_False;
Handle(ShapeExtend_CompositeSurface) Grid = SplitSurf->ResSurfaces();
ShapeFix_ComposeShell CompShell;
CompShell.Init( Grid, L, face, Precision() );
CompShell.SetMaxTolerance(MaxTolerance());
CompShell.SetContext(Context());
CompShell.Perform();
if ( CompShell.Status ( ShapeExtend_FAIL ) ||
! CompShell.Status ( ShapeExtend_DONE ) )
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL2 );
TopoDS_Shape res = CompShell.Result();
myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE2 );
for(TopExp_Explorer exp(res, TopAbs_FACE); exp.More(); exp.Next()) {
//smh#8
TopoDS_Shape tempf = Context()->Apply(exp.Current());
TopoDS_Face f = TopoDS::Face(tempf);
myResult = f;
if(SplitSurface())
Context()->Replace(f,myResult);
}
myResult = Context()->Apply(res);
return Standard_True;
}
//=======================================================================
//function : SetFaceNumber
//purpose :
//=======================================================================
void ShapeUpgrade_ClosedFaceDivide::SetNbSplitPoints(const Standard_Integer num)
{
if(num > 0)
myNbSplit = num;
}
//=======================================================================
//function : GetNbSplitPoints
//purpose :
//=======================================================================
Standard_Integer ShapeUpgrade_ClosedFaceDivide::GetNbSplitPoints() const
{
return myNbSplit;
}
|