0023947: Eliminate trivial compiler warnings in MSVC++ with warning level 4
[occt.git] / src / TopOpeBRep / TopOpeBRep_ProcessGR.cxx
1 // Created on: 1997-02-24
2 // Created by: Prestataire Xuan PHAM PHU
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22 #include <TopOpeBRep_FacesFiller.ixx>
23
24 #ifdef DRAW
25 #include <TopOpeBRep_DRAW.hxx>
26 #endif
27
28 #include <gp_Vec.hxx>
29 #include <Geom2d_Curve.hxx>
30 #include <Geom2d_Line.hxx>
31 #include <Geom_Curve.hxx>
32 #include <Geom_Circle.hxx>
33 #include <Geom_Ellipse.hxx>
34 #include <Geom_Surface.hxx>
35 #include <GeomAPI_ProjectPointOnCurve.hxx>
36 #include <GeomAPI_ProjectPointOnSurf.hxx>
37 #include <BRep_Tool.hxx>
38 #include <BRepAdaptor_Curve.hxx>
39 //#include <BRepAdaptor_Curve2d.hxx>
40 #include <BRepAdaptor_Surface.hxx>
41 #include <TopAbs.hxx>
42 #include <TopExp.hxx>
43 #include <TopoDS.hxx>
44 #include <TopTools_IndexedMapOfShape.hxx>
45 #include <TopOpeBRepTool_ShapeTool.hxx>
46 #include <TopOpeBRepDS_InterferenceTool.hxx>
47 #include <TopOpeBRep_FFTransitionTool.hxx>
48 #include <TopOpeBRep_FacesIntersector.hxx>
49 #include <TopOpeBRep_LineInter.hxx>
50 #include <TopOpeBRep_VPointInter.hxx>
51 #include <TopOpeBRep_Bipoint.hxx>
52 #include <TopOpeBRep_ListOfBipoint.hxx>
53 #include <TopOpeBRep_ListIteratorOfListOfBipoint.hxx>
54 #include <TopOpeBRep_VPointInterIterator.hxx>
55 #include <TopOpeBRep_GeomTool.hxx>
56 #include <Precision.hxx>
57 #include <Standard_CString.hxx>
58 #include <Standard_ProgramError.hxx>
59 #include <TopOpeBRepDS_define.hxx>
60 #include <TopOpeBRep.hxx>
61 #include <TopOpeBRepTool_EXPORT.hxx>
62 #include <TopOpeBRepTool_SC.hxx>
63
64 #ifdef DEB
65 #include <TopOpeBRep_FFDumper.hxx>
66 #include <Geom_TrimmedCurve.hxx>
67 #include <Geom_Line.hxx>
68 extern Standard_Boolean TopOpeBRepDS_GettraceDSF(); 
69 extern Standard_Boolean TopOpeBRepDS_GettraceDSNC(); 
70 extern Standard_Boolean TopOpeBRepDS_GettraceDEGEN();
71 extern Standard_Boolean TopOpeBRep_GettraceBIPS(); 
72 extern Standard_Boolean TopOpeBRep_GettraceDEGEN();
73 extern Standard_Boolean FUN_debnull(const TopoDS_Shape& s){Standard_Boolean isnull = s.IsNull(); if (isnull) cout <<"***"; return isnull;}
74 #endif
75
76 //Standard_EXPORT extern Standard_Real GLOBAL_tolFF;
77 Standard_EXPORTEXTERN Standard_Real GLOBAL_tolFF;
78
79 //=======================================================================
80 //function : StBipVPonF
81 //purpose  : 
82 //=======================================================================
83 TopAbs_State TopOpeBRep_FacesFiller::StBipVPonF
84 (const TopOpeBRep_VPointInter& vpf,const TopOpeBRep_VPointInter& vpl,
85  const TopOpeBRep_LineInter& Lrest,const Standard_Boolean isonedge1) const
86 {
87   
88 #define M_OUT(st) (st == TopAbs_OUT);
89 #define M_IN(st) (st == TopAbs_IN);
90   
91   Standard_Integer sind = isonedge1 ? 2 : 1; 
92   TopAbs_State stf = vpf.State(sind);
93   TopAbs_State stl = vpl.State(sind);
94   Standard_Boolean isout = M_OUT(stf); isout = isout || M_OUT(stl);
95   Standard_Boolean isin = M_IN(stf); isin = isin || M_IN(stl);   
96   if (isout) return TopAbs_OUT;
97   if (isin) return TopAbs_IN;
98
99   Standard_Boolean isperiodic;
100   const TopoDS_Edge& EArc = TopoDS::Edge(Lrest.Arc());
101   BRepAdaptor_Curve BAC(EArc);
102   GeomAbs_CurveType CT = BAC.GetType();
103   isperiodic = (CT == GeomAbs_Circle);
104   isperiodic = isperiodic || (CT == GeomAbs_Ellipse);
105
106   TopOpeBRep_VPointInter vpff = vpf;
107   TopOpeBRep_VPointInter vpll = vpl;
108
109   // xpu200798 : CTS21216, restriction edge 7, f8
110   // purpose : periodic restriction; vpf, vpl describing restriction bounds
111   //      if the Rline is describing the portion on curve (vpl,vpf),
112   //      we have to commutate these bounds.
113   if (isperiodic) { 
114 #ifdef DEB
115 //    TopOpeBRep_FFDumper FFD(*this); 
116 //    cout <<"vpf :"; FFD.DumpVP(vpf,cout);
117 //    cout <<"vpl :"; FFD.DumpVP(vpl,cout);
118 #endif
119
120     Standard_Integer IArc = 0; 
121     if (Lrest.ArcIsEdge(1)) IArc = 1; 
122     if (Lrest.ArcIsEdge(2)) IArc = 2; 
123     if (IArc == 0) {
124 #ifdef DEB
125       Standard_Failure::Raise("StBipVPonF");
126 #endif
127       return TopAbs_UNKNOWN;
128     }
129     Standard_Integer ISI = (IArc == 1) ? 2 : 1; 
130     Standard_Integer sif = vpf.ShapeIndex();
131     Standard_Integer sil = vpl.ShapeIndex();
132     Standard_Boolean act = ((sif == 3)||(sif == ISI)) && ((sil == 3)||(sil == ISI));
133     if (act) {
134       TopOpeBRepDS_Transition Tf = TopOpeBRep_FFTransitionTool::ProcessLineTransition(vpf,ISI,vpf.Edge(ISI).Orientation());
135       TopOpeBRepDS_Transition Tl = TopOpeBRep_FFTransitionTool::ProcessLineTransition(vpl,ISI,vpl.Edge(ISI).Orientation());
136       Standard_Boolean toreverse = (Tf.Orientation(TopAbs_IN) == TopAbs_REVERSED);
137       toreverse = toreverse && (Tl.Orientation(TopAbs_IN) == TopAbs_FORWARD);
138       if (toreverse) {
139         vpff = vpl;
140         vpll = vpf;
141       }
142     } // act
143   } // isperiodic
144
145   TopoDS_Shape F;
146   if (isonedge1) F = myF2;
147   else           F = myF1;
148   Standard_Real uf = TopOpeBRep_FacesFiller::VPParamOnER (vpff,Lrest);
149   Standard_Real ul = TopOpeBRep_FacesFiller::VPParamOnER (vpll,Lrest);
150
151   // NYI XPU: 16-05-97: INTPATCH -> the parametrization of a point on a 
152   // periodized curve is INSUFFICIENT : parVP on line can be either 0. 
153   // or period. 
154   Standard_Boolean badparametrized = (uf > ul);
155   Standard_Real f,l;  f = BAC.FirstParameter(); l = BAC.LastParameter();
156   if (badparametrized) {
157     if (isperiodic) {
158       if (uf == l) uf = f;
159       if (ul == f) ul = l;
160     }
161   }
162
163   const TopoDS_Edge& arc = TopoDS::Edge(Lrest.Arc());
164   BRepAdaptor_Curve BC( arc );     
165   Standard_Real x = 0.789; Standard_Real parmil = (1-x)*uf + x*ul; //xpu170898
166   gp_Pnt pmil = BC.Value(parmil);
167
168 #ifdef DEB
169   Standard_Boolean trc = TopOpeBRep_GettraceBIPS();
170     #ifdef DRAW
171       if (trc) {TCollection_AsciiString aa("pmil"); FUN_brep_draw(aa,pmil);}
172     #endif
173 #endif
174   TopAbs_State st = FSC_StatePonFace (pmil,F,*myPShapeClassifier);
175   return st;
176 }
177
178 //=======================================================================
179 //function : StateVPonFace
180 //purpose  :
181 //=======================================================================
182 TopAbs_State TopOpeBRep_FacesFiller::StateVPonFace(const TopOpeBRep_VPointInter& VP) const
183 {
184   Standard_Integer iVP = VP.ShapeIndex();
185   if (iVP == 3) return TopAbs_ON;
186   
187   Standard_Integer iother =  (iVP == 1) ? 2 : 1;
188   TopoDS_Shape F;
189   if (iother == 1) F = myF1;
190   else             F = myF2;
191   Standard_Real u,v;
192   if (iother == 1) VP.ParametersOnS1(u,v);
193   else VP.ParametersOnS2(u,v);
194   
195   myPShapeClassifier->SetReference(TopoDS::Face(F));
196   myPShapeClassifier->StateP2DReference(gp_Pnt2d(u,v));
197   TopAbs_State state = myPShapeClassifier->State();
198
199   return state;
200 }
201
202 // ----------------------------------------------------------------------
203 //           Class methods
204 // ----------------------------------------------------------------------
205
206 //=======================================================================
207 //function : Lminmax
208 //purpose  : Computes <pmin> and <pmax> the upper and lower bounds of <L>
209 //           enclosing all vpoints.
210 //=======================================================================
211 void TopOpeBRep_FacesFiller::Lminmax(const TopOpeBRep_LineInter& L,
212                                      Standard_Real& pmin,Standard_Real& pmax)
213 {
214   pmin = RealLast();
215   pmax = RealFirst();
216   TopOpeBRep_VPointInterIterator VPI;
217   VPI.Init(L,Standard_False);
218   for (; VPI.More(); VPI.Next()) {
219     const TopOpeBRep_VPointInter& VP = VPI.CurrentVP();
220     Standard_Real p = VP.ParameterOnLine();
221     pmin = Min(pmin,p);
222     pmax = Max(pmax,p);
223   }
224   Standard_Real d = Abs(pmin-pmax);
225   Standard_Boolean id = (d <= Precision::PConfusion());
226   Standard_Boolean isper = L.IsPeriodic();
227   Standard_Integer n = L.NbVPoint();
228   if (id && isper && n >= 2) {
229     Standard_Real per = L.Period();
230     pmax = pmin + per;
231   }
232 }
233
234 //=======================================================================
235 //function : LSameDomainERL
236 //purpose  : Returns <True> if GLine shares a same geometric domain with
237 //           at least one of the restriction edges of <ERL>.    
238 //=======================================================================
239 Standard_Boolean TopOpeBRep_FacesFiller::LSameDomainERL(const TopOpeBRep_LineInter& L,
240                                            const TopTools_ListOfShape& ERL)
241 {
242   Standard_Boolean isone = Standard_False;
243   if(L.TypeLineCurve() == TopOpeBRep_WALKING) return isone;
244
245 #ifdef DRAW
246   Standard_Boolean trc = Standard_False;
247   if (trc) {Handle(Geom_Curve) C = L.Curve(); TCollection_AsciiString aa("line"); FUN_brep_draw(aa,C);}
248 #endif
249
250   Standard_Real f,l; TopOpeBRep_FacesFiller::Lminmax(L,f,l);
251   Standard_Real d = Abs(f-l);
252
253   {
254     Standard_Boolean idINL = (L.INL() && (d == 0)); // null length line, made of VPoints only
255     if (idINL) return Standard_False;
256   } // INL
257
258   Standard_Boolean id = (d <= Precision::PConfusion());
259   if (id) return Standard_False;
260   
261   Handle(Geom_Curve) CL; TopOpeBRep_GeomTool::MakeCurve(f,l,L,CL); 
262   Standard_Real t = 0.417789; Standard_Real p = (1-t)*f + t*l;
263   gp_Pnt Pm = CL->Value(p);
264
265   TopTools_ListIteratorOfListOfShape it; it.Initialize(ERL);
266   for(; it.More(); it.Next()) {
267     const TopoDS_Edge& E = TopoDS::Edge(it.Value());
268     Standard_Real tolE = BRep_Tool::Tolerance(E);
269     Standard_Real maxtol = Max(tolE,GLOBAL_tolFF);
270     BRepAdaptor_Curve BAC(E);
271     f = BAC.FirstParameter(); l = BAC.LastParameter();
272     Standard_Boolean pinc = FUN_tool_PinC(Pm,BAC,f,l,maxtol);
273     if (pinc) {isone = Standard_True; break;}
274   }
275   return isone;
276 }
277
278 //=======================================================================
279 //function : IsVPtransLok
280 //purpose  : Computes the transition <T> of the VPoint <iVP> on the edge
281 //           <SI12>. Returns <False> if the status is unknown.
282 //=======================================================================
283 Standard_Boolean TopOpeBRep_FacesFiller::IsVPtransLok(const TopOpeBRep_LineInter& L,
284                                          const Standard_Integer iVP,const Standard_Integer SI12,
285                                          TopOpeBRepDS_Transition& T)
286 {
287   const TopOpeBRep_VPointInter& VP = L.VPoint(iVP);
288   Standard_Boolean is1 = (SI12 == 1);
289   Standard_Boolean VPonEd = (is1 && VP.IsOnDomS1());
290   VPonEd = VPonEd || (!is1 && VP.IsOnDomS2());
291   if (!VPonEd) return Standard_False;
292
293   const TopoDS_Edge& E = TopoDS::Edge(VP.Edge(SI12)); 
294   TopAbs_Orientation O = E.Orientation(); 
295   T = TopOpeBRep_FFTransitionTool::ProcessLineTransition(VP,SI12,O);
296   Standard_Boolean u = T.IsUnknown();
297   return (!u);
298 }
299
300 Standard_Boolean TopOpeBRep_FacesFiller::TransvpOK(const TopOpeBRep_LineInter& L,
301                                       const Standard_Integer ivp,
302                                       const Standard_Integer SI,
303                                       const Standard_Boolean isINOUT)
304 {
305 #define M_INOUT(stf,stl) ((stf == TopAbs_IN) && (stl == TopAbs_OUT))
306 #define M_OUTIN(stf,stl) ((stf == TopAbs_OUT) && (stl == TopAbs_IN))
307
308   TopOpeBRepDS_Transition T;
309   Standard_Boolean ok = TopOpeBRep_FacesFiller::IsVPtransLok(L,ivp,SI,T);
310   if (ok) {
311     TopAbs_State stb = T.Before();
312     TopAbs_State sta = T.After();
313     if (isINOUT) ok = M_INOUT(stb,sta);
314     else ok = M_OUTIN(stb,sta);
315   }
316   return ok;
317 }
318
319 //=======================================================================
320 //function : VPParamOnER
321 //purpose  :
322 //=======================================================================
323 Standard_Real TopOpeBRep_FacesFiller::VPParamOnER(const TopOpeBRep_VPointInter& vp,
324                                         const TopOpeBRep_LineInter& Lrest)
325 {
326   // If vp(index) is an edge boundary returns the point's parameter.
327
328   const TopoDS_Edge& E = TopoDS::Edge(Lrest.Arc());
329   Standard_Boolean isedge1 =  Lrest.ArcIsEdge(1);
330   Standard_Boolean isedge2 =  Lrest.ArcIsEdge(2);
331   if (isedge1 && vp.IsVertexOnS1()) {
332     const TopoDS_Vertex& v1 = TopoDS::Vertex(vp.VertexOnS1());
333     Standard_Real rr = BRep_Tool::Parameter(v1,E);
334     return rr;
335   }
336   if (isedge2 && vp.IsVertexOnS2())  {
337     const TopoDS_Vertex& v2 = TopoDS::Vertex(vp.VertexOnS2());
338     Standard_Real rr = BRep_Tool::Parameter(v2,E);
339     return rr;
340   }
341   // vp is an intersection point,and we get it's parameter.
342   if (isedge1 && vp.IsOnDomS1()) return vp.ParameterOnArc1();
343   if (isedge2 && vp.IsOnDomS2()) return vp.ParameterOnArc2();
344   
345   // Else,we have to project the point on the edge restriction
346   Standard_Real tolee = BRep_Tool::Tolerance(E);
347   tolee = tolee * 1.e2; //xpu290998 : PRO15369
348   Standard_Real param, dist; Standard_Boolean projok = FUN_tool_projPonE(vp.Value(),tolee,E,param,dist);
349   if (!projok) {
350     Standard_ProgramError::Raise("TopOpeBRep_FacesFiller::VPParamOnER");
351   }
352   return param;
353 }
354
355 //Standard_EXPORT Standard_Boolean FUN_EqualPonR(const TopOpeBRep_LineInter& Lrest,
356 Standard_EXPORT Standard_Boolean FUN_EqualPonR(const TopOpeBRep_LineInter& ,
357                                   const TopOpeBRep_VPointInter& VP1,
358                                   const TopOpeBRep_VPointInter& VP2)
359 {
360   gp_Pnt P1 = VP1.Value(); gp_Pnt P2 = VP2.Value();
361   Standard_Real Ptol1 = VP1.Tolerance(),Ptol2 = VP2.Tolerance();
362   Standard_Real Ptol = (Ptol1 > Ptol2) ? Ptol1 : Ptol2;
363   Standard_Boolean Pequal = P1.IsEqual(P2,Ptol);
364   return Pequal;
365 }
366 Standard_EXPORT Standard_Boolean FUN_EqualponR(const TopOpeBRep_LineInter& Lrest,
367                                   const TopOpeBRep_VPointInter& VP1,
368                                   const TopOpeBRep_VPointInter& VP2)
369 {
370   Standard_Real p1 = TopOpeBRep_FacesFiller::VPParamOnER(VP1,Lrest);
371   Standard_Real p2 = TopOpeBRep_FacesFiller::VPParamOnER(VP2,Lrest);
372   Standard_Boolean pequal = fabs(p1-p2) < Precision::PConfusion();
373   return pequal;
374 }
375
376 //=======================================================================
377 //function : EqualpPOnR
378 //purpose  : 
379 //=======================================================================
380 Standard_Boolean TopOpeBRep_FacesFiller::EqualpPonR(const TopOpeBRep_LineInter& Lrest,
381                                        const TopOpeBRep_VPointInter& VP1,
382                                        const TopOpeBRep_VPointInter& VP2)
383 {
384   Standard_Boolean Pequal = ::FUN_EqualPonR(Lrest,VP1,VP2);
385   Standard_Boolean pequal = ::FUN_EqualponR(Lrest,VP1,VP2);
386   Standard_Boolean pPequal = Pequal && pequal;
387   return pPequal;
388 }