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.
23 // Modified by skv - Fri Mar 4 12:07:34 2005 OCC7966
25 #include <BRepClass3d_Intersector3d.ixx>
27 #include <IntCurveSurface_IntersectionPoint.hxx>
29 #include <TopoDS_Face.hxx>
33 #include <IntCurveSurface_HInter.hxx>
34 #include <BRepAdaptor_HSurface.hxx>
35 #include <Geom_Line.hxx>
36 #include <gp_Pnt2d.hxx>
37 #include <BRepClass_FaceClassifier.hxx>
39 #include <GeomAdaptor_Curve.hxx>
41 #include <GeomAdaptor_HCurve.hxx>
42 #include <BRepAdaptor_HSurface.hxx>
44 //============================================================================
45 BRepClass3d_Intersector3d::BRepClass3d_Intersector3d()
46 : done(Standard_False),hasapoint(Standard_False)
49 //============================================================================
50 void BRepClass3d_Intersector3d::Perform(const gp_Lin& L,
51 const Standard_Real /*Prm*/,
52 const Standard_Real Tol,
53 const TopoDS_Face& Face) {
55 IntCurveSurface_HInter HICS;
56 BRepAdaptor_Surface surface;
57 BRepClass_FaceClassifier classifier2d;
59 Handle(Geom_Line) geomline = new Geom_Line(L);
60 GeomAdaptor_Curve LL(geomline);
62 surface.Initialize(Face,Standard_True);
64 Standard_Boolean IsUPer, IsVPer;
65 Standard_Real uperiod=0, vperiod=0;
66 if ((IsUPer = surface.IsUPeriodic()))
67 uperiod = surface.UPeriod();
68 if ((IsVPer = surface.IsVPeriodic()))
69 vperiod = surface.VPeriod();
71 Standard_Real U1, U2, V1, V2;
72 U1 = surface.FirstUParameter();
73 U2 = surface.LastUParameter();
74 V1 = surface.FirstVParameter();
75 V2 = surface.LastVParameter();
78 Handle(GeomAdaptor_HCurve) HLL = new GeomAdaptor_HCurve(LL);
79 Handle(BRepAdaptor_HSurface) Hsurface = new BRepAdaptor_HSurface(surface);
81 HICS.Perform(HLL,Hsurface);
85 for(Standard_Integer index=HICS.NbPoints(); index>=1; index--) {
86 gp_Pnt2d Puv(HICS.Point(index).U(),HICS.Point(index).V());
88 Standard_Integer N1 = 0;
89 Standard_Integer N2 = 0;
91 Standard_Real X = Puv.X();
92 Standard_Real Y = Puv.Y();
96 N1 = RealToInt( (X - U1) / uperiod );
99 N1 = RealToInt( (X - U2) / uperiod );
101 Puv.SetX(X - uperiod * N1);
106 N2 = RealToInt ( (Y - V1) / vperiod );
109 N2 = RealToInt ( (Y - V2) / vperiod );
111 Puv.SetY(Y - vperiod * N2);
114 classifier2d.Perform(Face,Puv,Tol);
115 TopAbs_State currentstate = classifier2d.State();
116 if(currentstate==TopAbs_IN || currentstate==TopAbs_ON) {
117 const IntCurveSurface_IntersectionPoint& HICSPoint = HICS.Point(index);
118 Standard_Real HICSW = HICSPoint.W();
119 // Modified by skv - Fri Mar 4 12:07:34 2005 OCC7966 Begin
120 if((W > HICSW) && (HICSW>-Tol)) {
122 // Modified by skv - Fri Mar 4 12:07:34 2005 OCC7966 End
123 hasapoint = Standard_True;
127 transition = HICSPoint.Transition();
128 pnt = HICSPoint.Pnt();
129 state = currentstate;
131 if(Face.Orientation()==TopAbs_REVERSED) {
132 if(transition == IntCurveSurface_In)
133 transition = IntCurveSurface_Out;
135 transition = IntCurveSurface_In;
138 } //-- classifier state is IN or ON
139 done = Standard_True;
140 } //-- Loop on Intersection points.