0024167: Compiler warnings 'unreacheable code' and 'conditional expression is constan...
[occt.git] / src / BRepClass3d / BRepClass3d_Intersector3d.cxx
1 // Created on: 1994-04-01
2 // Created by: Laurent BUCHARD
3 // Copyright (c) 1994-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 #include <BRepClass3d_Intersector3d.ixx>
22
23 #include <IntCurveSurface_IntersectionPoint.hxx>
24 #include <gp_Lin.hxx>
25 #include <TopoDS_Face.hxx>
26 #include <TopAbs.hxx>
27
28 #include <IntCurveSurface_HInter.hxx>
29 #include <BRepAdaptor_HSurface.hxx>
30 #include <Geom_Line.hxx>
31 #include <gp_Pnt2d.hxx>
32 #include <BRepClass_FaceClassifier.hxx>
33
34 #include <GeomAdaptor_Curve.hxx>
35
36 #include <GeomAdaptor_HCurve.hxx>
37 #include <BRepAdaptor_HSurface.hxx>
38
39 //============================================================================
40 BRepClass3d_Intersector3d::BRepClass3d_Intersector3d() 
41      : done(Standard_False),hasapoint(Standard_False)
42
43 }
44 //============================================================================
45 void BRepClass3d_Intersector3d::Perform(const gp_Lin& L,
46                                         const Standard_Real /*Prm*/,
47                                         const Standard_Real Tol,
48                                         const TopoDS_Face& Face) { 
49
50   IntCurveSurface_HInter   HICS; 
51   BRepAdaptor_Surface      surface;
52   BRepClass_FaceClassifier classifier2d;
53
54   Handle(Geom_Line) geomline = new Geom_Line(L);
55   GeomAdaptor_Curve LL(geomline);
56
57   surface.Initialize(Face,Standard_True);
58
59   const Standard_Boolean IsUPer  = surface.IsUPeriodic();
60   const Standard_Boolean IsVPer  = surface.IsVPeriodic();
61   const Standard_Real    uperiod = IsUPer ? surface.UPeriod() : 0.0;
62   const Standard_Real    vperiod = IsVPer ? surface.VPeriod() : 0.0;
63
64   Standard_Real U1 = surface.FirstUParameter();
65   Standard_Real U2 = surface.LastUParameter();
66   Standard_Real V1 = surface.FirstVParameter();
67   Standard_Real V2 = surface.LastVParameter();
68   
69   //--
70   Handle(GeomAdaptor_HCurve) HLL  = new GeomAdaptor_HCurve(LL);
71   Handle(BRepAdaptor_HSurface) Hsurface = new BRepAdaptor_HSurface(surface);
72   //-- 
73   HICS.Perform(HLL,Hsurface);
74   
75   W=RealLast();
76   if(HICS.IsDone()) {
77     for(Standard_Integer index=HICS.NbPoints(); index>=1; index--) {  
78       gp_Pnt2d Puv(HICS.Point(index).U(),HICS.Point(index).V());
79
80       Standard_Integer N1 = 0;
81       Standard_Integer N2 = 0;
82
83       Standard_Real X = Puv.X();
84       Standard_Real Y = Puv.Y();
85
86       if(IsUPer) {
87         if(X > U2) {
88           N1 = RealToInt( (X - U1) / uperiod );
89         }
90         if(X < U1) {
91           N1 = RealToInt( (X - U2) / uperiod );
92         }
93         Puv.SetX(X - uperiod * N1);
94       }
95
96       if(IsVPer) {
97         if(Y > V2) {
98           N2 = RealToInt ( (Y - V1) / vperiod );
99         }
100         if(Y < V1) {
101           N2 = RealToInt ( (Y - V2) / vperiod );
102         }
103         Puv.SetY(Y - vperiod * N2);
104       }
105
106       classifier2d.Perform(Face,Puv,Tol);
107       TopAbs_State currentstate = classifier2d.State();
108       if(currentstate==TopAbs_IN || currentstate==TopAbs_ON) { 
109         const IntCurveSurface_IntersectionPoint& HICSPoint = HICS.Point(index);
110         Standard_Real HICSW = HICSPoint.W();
111 //  Modified by skv - Fri Mar  4 12:07:34 2005 OCC7966 Begin
112         if((W > HICSW) && (HICSW>-Tol)) { 
113 //      if(W > HICSW) { 
114 //  Modified by skv - Fri Mar  4 12:07:34 2005 OCC7966 End
115           hasapoint  = Standard_True;
116           U          = HICSPoint.U();
117           V          = HICSPoint.V();
118           W          = HICSW; 
119           transition = HICSPoint.Transition();
120           pnt        = HICSPoint.Pnt();
121           state      = currentstate;
122           face       = Face;
123           if(Face.Orientation()==TopAbs_REVERSED) { 
124             if(transition == IntCurveSurface_In) 
125               transition = IntCurveSurface_Out;
126             else 
127               transition = IntCurveSurface_In;
128           }
129         } 
130       } //-- classifier state is IN or ON
131       done = Standard_True;
132     } //-- Loop on Intersection points.
133   } //-- HICS.IsDone()
134 }