| 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 | |
| 22 | |
| 23 | // Modified by skv - Fri Mar 4 12:07:34 2005 OCC7966 |
| 24 | |
| 25 | #include <BRepClass3d_Intersector3d.ixx> |
| 26 | |
| 27 | #include <IntCurveSurface_IntersectionPoint.hxx> |
| 28 | #include <gp_Lin.hxx> |
| 29 | #include <TopoDS_Face.hxx> |
| 30 | #include <TopAbs.hxx> |
| 31 | |
| 32 | |
| 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> |
| 38 | |
| 39 | #include <GeomAdaptor_Curve.hxx> |
| 40 | |
| 41 | #include <GeomAdaptor_HCurve.hxx> |
| 42 | #include <BRepAdaptor_HSurface.hxx> |
| 43 | |
| 44 | //============================================================================ |
| 45 | BRepClass3d_Intersector3d::BRepClass3d_Intersector3d() |
| 46 | : done(Standard_False),hasapoint(Standard_False) |
| 47 | { |
| 48 | } |
| 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) { |
| 54 | |
| 55 | IntCurveSurface_HInter HICS; |
| 56 | BRepAdaptor_Surface surface; |
| 57 | BRepClass_FaceClassifier classifier2d; |
| 58 | |
| 59 | Handle(Geom_Line) geomline = new Geom_Line(L); |
| 60 | GeomAdaptor_Curve LL(geomline); |
| 61 | |
| 62 | surface.Initialize(Face,Standard_True); |
| 63 | |
| 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(); |
| 70 | |
| 71 | Standard_Real U1, U2, V1, V2; |
| 72 | U1 = surface.FirstUParameter(); |
| 73 | U2 = surface.LastUParameter(); |
| 74 | V1 = surface.FirstVParameter(); |
| 75 | V2 = surface.LastVParameter(); |
| 76 | |
| 77 | //-- |
| 78 | Handle(GeomAdaptor_HCurve) HLL = new GeomAdaptor_HCurve(LL); |
| 79 | Handle(BRepAdaptor_HSurface) Hsurface = new BRepAdaptor_HSurface(surface); |
| 80 | //-- |
| 81 | HICS.Perform(HLL,Hsurface); |
| 82 | |
| 83 | W=RealLast(); |
| 84 | if(HICS.IsDone()) { |
| 85 | for(Standard_Integer index=HICS.NbPoints(); index>=1; index--) { |
| 86 | gp_Pnt2d Puv(HICS.Point(index).U(),HICS.Point(index).V()); |
| 87 | |
| 88 | Standard_Integer N1 = 0; |
| 89 | Standard_Integer N2 = 0; |
| 90 | |
| 91 | Standard_Real X = Puv.X(); |
| 92 | Standard_Real Y = Puv.Y(); |
| 93 | |
| 94 | if(IsUPer) { |
| 95 | if(X > U2) { |
| 96 | N1 = RealToInt( (X - U1) / uperiod ); |
| 97 | } |
| 98 | if(X < U1) { |
| 99 | N1 = RealToInt( (X - U2) / uperiod ); |
| 100 | } |
| 101 | Puv.SetX(X - uperiod * N1); |
| 102 | } |
| 103 | |
| 104 | if(IsVPer) { |
| 105 | if(Y > V2) { |
| 106 | N2 = RealToInt ( (Y - V1) / vperiod ); |
| 107 | } |
| 108 | if(Y < V1) { |
| 109 | N2 = RealToInt ( (Y - V2) / vperiod ); |
| 110 | } |
| 111 | Puv.SetY(Y - vperiod * N2); |
| 112 | } |
| 113 | |
| 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)) { |
| 121 | // if(W > HICSW) { |
| 122 | // Modified by skv - Fri Mar 4 12:07:34 2005 OCC7966 End |
| 123 | hasapoint = Standard_True; |
| 124 | U = HICSPoint.U(); |
| 125 | V = HICSPoint.V(); |
| 126 | W = HICSW; |
| 127 | transition = HICSPoint.Transition(); |
| 128 | pnt = HICSPoint.Pnt(); |
| 129 | state = currentstate; |
| 130 | face = Face; |
| 131 | if(Face.Orientation()==TopAbs_REVERSED) { |
| 132 | if(transition == IntCurveSurface_In) |
| 133 | transition = IntCurveSurface_Out; |
| 134 | else |
| 135 | transition = IntCurveSurface_In; |
| 136 | } |
| 137 | } |
| 138 | } //-- classifier state is IN or ON |
| 139 | done = Standard_True; |
| 140 | } //-- Loop on Intersection points. |
| 141 | } //-- HICS.IsDone() |
| 142 | } |
| 143 | |
| 144 | |
| 145 | |