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
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.
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.
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.
21 #include <BRepClass3d_Intersector3d.ixx>
23 #include <IntCurveSurface_IntersectionPoint.hxx>
25 #include <TopoDS_Face.hxx>
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>
34 #include <GeomAdaptor_Curve.hxx>
36 #include <GeomAdaptor_HCurve.hxx>
37 #include <BRepAdaptor_HSurface.hxx>
39 //============================================================================
40 BRepClass3d_Intersector3d::BRepClass3d_Intersector3d()
41 : done(Standard_False),hasapoint(Standard_False)
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) {
50 IntCurveSurface_HInter HICS;
51 BRepAdaptor_Surface surface;
52 BRepClass_FaceClassifier classifier2d;
54 Handle(Geom_Line) geomline = new Geom_Line(L);
55 GeomAdaptor_Curve LL(geomline);
57 surface.Initialize(Face,Standard_True);
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;
64 Standard_Real U1 = surface.FirstUParameter();
65 Standard_Real U2 = surface.LastUParameter();
66 Standard_Real V1 = surface.FirstVParameter();
67 Standard_Real V2 = surface.LastVParameter();
70 Handle(GeomAdaptor_HCurve) HLL = new GeomAdaptor_HCurve(LL);
71 Handle(BRepAdaptor_HSurface) Hsurface = new BRepAdaptor_HSurface(surface);
73 HICS.Perform(HLL,Hsurface);
77 for(Standard_Integer index=HICS.NbPoints(); index>=1; index--) {
78 gp_Pnt2d Puv(HICS.Point(index).U(),HICS.Point(index).V());
80 Standard_Integer N1 = 0;
81 Standard_Integer N2 = 0;
83 Standard_Real X = Puv.X();
84 Standard_Real Y = Puv.Y();
88 N1 = RealToInt( (X - U1) / uperiod );
91 N1 = RealToInt( (X - U2) / uperiod );
93 Puv.SetX(X - uperiod * N1);
98 N2 = RealToInt ( (Y - V1) / vperiod );
101 N2 = RealToInt ( (Y - V2) / vperiod );
103 Puv.SetY(Y - vperiod * N2);
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)) {
114 // Modified by skv - Fri Mar 4 12:07:34 2005 OCC7966 End
115 hasapoint = Standard_True;
119 transition = HICSPoint.Transition();
120 pnt = HICSPoint.Pnt();
121 state = currentstate;
123 if(Face.Orientation()==TopAbs_REVERSED) {
124 if(transition == IntCurveSurface_In)
125 transition = IntCurveSurface_Out;
127 transition = IntCurveSurface_In;
130 } //-- classifier state is IN or ON
131 done = Standard_True;
132 } //-- Loop on Intersection points.