0028966: Coding Rules - remove Adaptor2d_HCurve2d, Adaptor3d_HCurve and Adaptor3d_HSu...
[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-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <BRepAdaptor_Surface.hxx>
19 #include <BRepClass3d_Intersector3d.hxx>
20 #include <BRepClass_FaceClassifier.hxx>
21 #include <Geom_Line.hxx>
22 #include <GeomAdaptor_Curve.hxx>
23 #include <GeomAdaptor_Curve.hxx>
24 #include <gp_Lin.hxx>
25 #include <gp_Pnt.hxx>
26 #include <gp_Pnt2d.hxx>
27 #include <IntCurveSurface_HInter.hxx>
28 #include <IntCurveSurface_IntersectionPoint.hxx>
29 #include <TopAbs.hxx>
30 #include <TopoDS_Face.hxx>
31
32 //============================================================================
33 BRepClass3d_Intersector3d::BRepClass3d_Intersector3d() 
34 : U(0.0),
35   V(0.0),
36   W(0.0),
37   done(Standard_False),
38   hasapoint(Standard_False),
39   state(TopAbs_UNKNOWN)
40
41 }
42 //============================================================================
43 void BRepClass3d_Intersector3d::Perform(const gp_Lin& L,
44                                         const Standard_Real /*Prm*/,
45                                         const Standard_Real Tol,
46                                         const TopoDS_Face& Face) { 
47
48   IntCurveSurface_HInter   HICS; 
49   BRepAdaptor_Surface      surface;
50   BRepClass_FaceClassifier classifier2d;
51
52   Handle(Geom_Line) geomline = new Geom_Line(L);
53   GeomAdaptor_Curve LL(geomline);
54
55   surface.Initialize(Face,Standard_True);
56
57   const Standard_Boolean IsUPer  = surface.IsUPeriodic();
58   const Standard_Boolean IsVPer  = surface.IsVPeriodic();
59   const Standard_Real    uperiod = IsUPer ? surface.UPeriod() : 0.0;
60   const Standard_Real    vperiod = IsVPer ? surface.VPeriod() : 0.0;
61
62   Standard_Real U1 = surface.FirstUParameter();
63   Standard_Real U2 = surface.LastUParameter();
64   Standard_Real V1 = surface.FirstVParameter();
65   Standard_Real V2 = surface.LastVParameter();
66   
67   //--
68   Handle(GeomAdaptor_Curve) HLL  = new GeomAdaptor_Curve(LL);
69   Handle(BRepAdaptor_Surface) Hsurface = new BRepAdaptor_Surface(surface);
70   //-- 
71   HICS.Perform(HLL,Hsurface);
72   
73   W=RealLast();
74   if(HICS.IsDone()) {
75     for(Standard_Integer index=HICS.NbPoints(); index>=1; index--) {  
76       gp_Pnt2d Puv(HICS.Point(index).U(),HICS.Point(index).V());
77
78       Standard_Integer N1 = 0;
79       Standard_Integer N2 = 0;
80
81       Standard_Real X = Puv.X();
82       Standard_Real Y = Puv.Y();
83
84       if(IsUPer) {
85         if(X > U2) {
86           N1 = RealToInt( (X - U1) / uperiod );
87         }
88         if(X < U1) {
89           N1 = RealToInt( (X - U2) / uperiod );
90         }
91         Puv.SetX(X - uperiod * N1);
92       }
93
94       if(IsVPer) {
95         if(Y > V2) {
96           N2 = RealToInt ( (Y - V1) / vperiod );
97         }
98         if(Y < V1) {
99           N2 = RealToInt ( (Y - V2) / vperiod );
100         }
101         Puv.SetY(Y - vperiod * N2);
102       }
103
104       classifier2d.Perform(Face,Puv,Tol);
105       TopAbs_State currentstate = classifier2d.State();
106       if(currentstate==TopAbs_IN || currentstate==TopAbs_ON) { 
107         const IntCurveSurface_IntersectionPoint& HICSPoint = HICS.Point(index);
108         Standard_Real HICSW = HICSPoint.W();
109 //  Modified by skv - Fri Mar  4 12:07:34 2005 OCC7966 Begin
110         if((W > HICSW) && (HICSW>-Tol)) { 
111 //      if(W > HICSW) { 
112 //  Modified by skv - Fri Mar  4 12:07:34 2005 OCC7966 End
113           hasapoint  = Standard_True;
114           U          = HICSPoint.U();
115           V          = HICSPoint.V();
116           W          = HICSW; 
117           transition = HICSPoint.Transition();
118           pnt        = HICSPoint.Pnt();
119           state      = currentstate;
120           face       = Face;
121           if(Face.Orientation()==TopAbs_REVERSED) { 
122             if(transition == IntCurveSurface_In) 
123               transition = IntCurveSurface_Out;
124             else 
125               transition = IntCurveSurface_In;
126           }
127         } 
128       } //-- classifier state is IN or ON
129       done = Standard_True;
130     } //-- Loop on Intersection points.
131   } //-- HICS.IsDone()
132 }