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