1 // Created on: 1999-07-22
2 // Created by: data exchange team
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <ShapeUpgrade_ClosedFaceDivide.ixx>
18 #include <Precision.hxx>
19 #include <ShapeExtend.hxx>
21 #include <TopoDS_Iterator.hxx>
22 #include <TopoDS_Wire.hxx>
23 #include <ShapeExtend_WireData.hxx>
24 #include <TopoDS_Edge.hxx>
25 #include <ShapeAnalysis_Edge.hxx>
26 #include <Geom2d_Curve.hxx>
27 #include <ShapeAnalysis_Curve.hxx>
28 #include <Bnd_Box2d.hxx>
29 #include <TColStd_HSequenceOfReal.hxx>
30 #include <BRep_Tool.hxx>
31 #include <ShapeUpgrade_SplitSurface.hxx>
32 #include <ShapeExtend_CompositeSurface.hxx>
33 #include <ShapeFix_ComposeShell.hxx>
34 #include <TopExp_Explorer.hxx>
35 #include <ShapeAnalysis_Surface.hxx>
36 #include <ShapeAnalysis.hxx>
37 #include <Geom_RectangularTrimmedSurface.hxx>
38 #include <ShapeBuild_ReShape.hxx>
39 #include <ShapeAnalysis.hxx>
41 //=======================================================================
42 //function : ShapeUpgrade_ClosedFaceDivide
44 //=======================================================================
46 ShapeUpgrade_ClosedFaceDivide::ShapeUpgrade_ClosedFaceDivide():
47 ShapeUpgrade_FaceDivide()
52 //=======================================================================
53 //function : ShapeUpgrade_ClosedFaceDivide
55 //=======================================================================
57 ShapeUpgrade_ClosedFaceDivide::ShapeUpgrade_ClosedFaceDivide(const TopoDS_Face& F):
58 ShapeUpgrade_FaceDivide(F)
63 //=======================================================================
64 //function : SplitSurface
66 //=======================================================================
68 Standard_Boolean ShapeUpgrade_ClosedFaceDivide::SplitSurface()
70 Handle(ShapeUpgrade_SplitSurface) SplitSurf = GetSplitSurfaceTool();
71 if ( SplitSurf.IsNull() ) return Standard_False;
73 if ( myResult.IsNull() || myResult.ShapeType() != TopAbs_FACE ) {
74 myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL3 );
75 return Standard_False;
77 TopoDS_Face face = TopoDS::Face ( myResult );
79 Standard_Real Uf,Ul,Vf,Vl;
80 ShapeAnalysis::GetFaceUVBounds ( myFace, Uf, Ul, Vf, Vl );
81 // 01.10.99 pdn Porting on DEC
82 if( ::Precision::IsInfinite(Uf) || ::Precision::IsInfinite(Ul) ||
83 ::Precision::IsInfinite(Vf) || ::Precision::IsInfinite(Vl) )
84 return Standard_False;
87 Handle(Geom_Surface) surf;
88 surf = BRep_Tool::Surface ( face, L );
90 Standard_Boolean isUSplit = Standard_False;
91 Standard_Boolean doSplit = Standard_False;
92 Handle(TColStd_HSequenceOfReal) split = new TColStd_HSequenceOfReal;
94 for(TopoDS_Iterator iter(face); iter.More()&&!doSplit; iter.Next()) {
95 if(iter.Value().ShapeType() != TopAbs_WIRE)
97 TopoDS_Wire wire = TopoDS::Wire(iter.Value());
98 Handle(ShapeExtend_WireData) sewd = new ShapeExtend_WireData(wire);
99 for(Standard_Integer i = 1; i <= sewd->NbEdges()&&!doSplit; i++)
100 if(sewd->IsSeam(i)) {
101 doSplit = Standard_True;
102 TopoDS_Edge edge = sewd->Edge(i);
103 ShapeAnalysis_Edge sae;
104 Handle(Geom2d_Curve) c1, c2;
105 Standard_Real f1,f2,l1,l2;
106 if(!sae.PCurve(edge,face,c1,f1,l1,Standard_False))
109 TopoDS_Shape tmpE = edge.Reversed();
110 if(!sae.PCurve(TopoDS::Edge(tmpE),face,c2,f2,l2,Standard_False))
114 ShapeAnalysis_Curve sac;
116 sac.FillBndBox ( c1, f1, l1, 20, Standard_True, B1 );
117 sac.FillBndBox ( c2, f2, l2, 20, Standard_True, B2 );
118 Standard_Real x1min,y1min,x1max,y1max;
119 Standard_Real x2min,y2min,x2max,y2max;
120 B1.Get(x1min,y1min,x1max,y1max);
121 B2.Get(x2min,y2min,x2max,y2max);
122 Standard_Real xf,xl,yf,yl;
138 Standard_Real dU = xl - xf;
139 Standard_Real dV = yl - yf;
141 Standard_Real step = dU/(myNbSplit+1);
142 Standard_Real val = xf+step;
143 for(Standard_Integer j = 1; j <= myNbSplit; j++, val+=step)
145 isUSplit = Standard_True;
148 Standard_Real step = dV/(myNbSplit+1);
149 Standard_Real val = yf+step;
150 for(Standard_Integer j = 1; j <= myNbSplit; j++, val+=step)
152 isUSplit = Standard_False;
158 //pdn try to define geometric closure.
159 Handle(ShapeAnalysis_Surface) sas = new ShapeAnalysis_Surface( surf );
160 Standard_Boolean uclosed = sas->IsUClosed(Precision());
161 Standard_Boolean vclosed = sas->IsVClosed(Precision());
162 Standard_Real U1, U2, V1, V2;
164 surf -> Bounds(U1, U2, V1, V2);
165 GeomAdaptor_Surface GAS ( surf );
166 Standard_Real toler = GAS.UResolution ( Precision() );
167 if((U2-U1) - (Ul-Uf) < toler ) {
168 Handle(Geom_RectangularTrimmedSurface) rts =
169 new Geom_RectangularTrimmedSurface(surf,U1,(U2+U1)/2,Standard_True);
170 Handle(ShapeAnalysis_Surface) sast = new ShapeAnalysis_Surface( rts );
171 if ( !sast->IsUClosed(Precision())) {
172 doSplit = Standard_True;
173 Standard_Real step = (Ul-Uf)/(myNbSplit+1);
174 Standard_Real val = Uf+step;
175 for(Standard_Integer i = 1; i <= myNbSplit; i++, val+=step)
177 isUSplit = Standard_True;
180 else cout << "Warning: SU_ClosedFaceDivide: Thin face, not splitted" << endl;
184 if( vclosed && !doSplit ) {
185 surf -> Bounds(U1, U2, V1, V2);
186 GeomAdaptor_Surface GAS ( surf );
187 Standard_Real toler = GAS.VResolution ( Precision() );
188 if((V2-V1) - (Vl-Vf) < toler) {
189 Handle(Geom_RectangularTrimmedSurface) rts =
190 new Geom_RectangularTrimmedSurface(surf,V1,(V2+V1)/2,Standard_False);
191 Handle(ShapeAnalysis_Surface) sast = new ShapeAnalysis_Surface( rts );
192 if ( !sast->IsVClosed(Precision())) {
193 doSplit = Standard_True;
194 Standard_Real step = (Vl-Vf)/(myNbSplit+1);
195 Standard_Real val = Vf+step;
196 for(Standard_Integer i = 1; i <= myNbSplit; i++, val+=step)
198 isUSplit = Standard_False;
201 else cout << "Warning: SU_ClosedFaceDivide: Thin face, not splitted" << endl;
208 return Standard_False;
210 SplitSurf->Init ( surf, Uf, Ul, Vf, Vl );
212 SplitSurf->SetUSplitValues(split);
214 SplitSurf->SetVSplitValues(split);
216 SplitSurf->Perform(mySegmentMode);
217 if ( ! SplitSurf->Status ( ShapeExtend_DONE ) ) return Standard_False;
218 Handle(ShapeExtend_CompositeSurface) Grid = SplitSurf->ResSurfaces();
220 ShapeFix_ComposeShell CompShell;
221 CompShell.Init( Grid, L, face, Precision() );
222 CompShell.SetMaxTolerance(MaxTolerance());
223 CompShell.SetContext(Context());
225 if ( CompShell.Status ( ShapeExtend_FAIL ) ||
226 ! CompShell.Status ( ShapeExtend_DONE ) )
227 myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL2 );
229 TopoDS_Shape res = CompShell.Result();
230 myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE2 );
231 for(TopExp_Explorer exp(res, TopAbs_FACE); exp.More(); exp.Next()) {
233 TopoDS_Shape tempf = Context()->Apply(exp.Current());
234 TopoDS_Face f = TopoDS::Face(tempf);
237 Context()->Replace(f,myResult);
239 myResult = Context()->Apply(res);
240 return Standard_True;
244 //=======================================================================
245 //function : SetFaceNumber
247 //=======================================================================
249 void ShapeUpgrade_ClosedFaceDivide::SetNbSplitPoints(const Standard_Integer num)
255 //=======================================================================
256 //function : GetNbSplitPoints
258 //=======================================================================
260 Standard_Integer ShapeUpgrade_ClosedFaceDivide::GetNbSplitPoints() const