1 // Created on: 1992-11-19
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1992-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 #include <BRepClass_Intersector.ixx>
24 #include <BRep_Tool.hxx>
25 #include <BRepAdaptor_Curve2d.hxx>
26 #include <BRepAdaptor_Surface.hxx>
27 #include <TopoDS_Vertex.hxx>
29 #include <IntRes2d_Domain.hxx>
30 #include <Geom2dLProp_CLProps2d.hxx>
31 #include <Geom2d_Curve.hxx>
33 #include <Precision.hxx>
35 #include <Geom2d_Line.hxx>
37 #include <Geom2dInt_GInter.hxx>
39 #include <Extrema_ExtPC2d.hxx>
40 #include <IntRes2d_Transition.hxx>
41 #include <IntRes2d_IntersectionPoint.hxx>
44 void RefineTolerance(const TopoDS_Face& aF,
45 const BRepAdaptor_Curve2d& aC,
46 const Standard_Real aT,
47 Standard_Real& aTolZ);
49 //=======================================================================
50 //function : BRepClass_Intersector
52 //=======================================================================
54 BRepClass_Intersector::BRepClass_Intersector()
58 //=======================================================================
61 //=======================================================================
62 void BRepClass_Intersector::Perform(const gp_Lin2d& L,
63 const Standard_Real P,
64 const Standard_Real Tol,
65 const BRepClass_Edge& E)
67 Standard_Real deb, fin, aTolZ;
68 Handle(Geom2d_Curve) aC2D;
71 const TopoDS_Edge& EE = E.Edge();
72 const TopoDS_Face& F = E.Face();
74 aC2D=BRep_Tool::CurveOnSurface(EE, F, deb, fin);
76 done = Standard_False; // !IsDone()
80 BRepAdaptor_Curve2d C(EE, F);
82 deb = C.FirstParameter();
83 fin = C.LastParameter();
85 // Case of "ON": direct check of belonging to edge
86 // taking into account the tolerance
87 Extrema_ExtPC2d theExtPC2d(L.Location(), C);
88 Standard_Real MinDist = RealLast(), aDist;
89 Standard_Integer MinInd = 0, i;
90 if (theExtPC2d.IsDone()) {
91 for (i = 1; i <= theExtPC2d.NbExt(); ++i) {
92 aDist = theExtPC2d.SquareDistance(i);
93 if (aDist < MinDist) {
100 MinDist = sqrt(MinDist);
102 if (MinDist <= aTolZ) {
103 gp_Pnt2d pnt_exact = (theExtPC2d.Point(MinInd)).Value();
104 Standard_Real par = (theExtPC2d.Point(MinInd)).Parameter();
106 RefineTolerance(F, C, par, aTolZ);
108 if (MinDist <= aTolZ) {
109 IntRes2d_Transition tr_on_lin(IntRes2d_Head);
110 IntRes2d_Position pos_on_curve = IntRes2d_Middle;
111 if (Abs(par - deb) <= Precision::Confusion()) {
112 pos_on_curve = IntRes2d_Head;
114 else if (Abs(par - fin) <= Precision::Confusion()) {
115 pos_on_curve = IntRes2d_End;
118 IntRes2d_Transition tr_on_curve(pos_on_curve);
119 IntRes2d_IntersectionPoint pnt_inter(pnt_exact, 0., par,
120 tr_on_lin, tr_on_curve,
124 done = Standard_True;
132 Standard_Real toldeb = 1.e-5, tolfin = 1.e-5;
137 DL.SetValues(L.Location(),0.,aTolZ,ElCLib::Value(P,L),P,aTolZ);
140 DL.SetValues(L.Location(),0.,aTolZ,Standard_True);
143 IntRes2d_Domain DE(pdeb,deb,toldeb,pfin,fin,tolfin);
144 // temporary periodic domain
145 if (C.Curve()->IsPeriodic()) {
146 DE.SetEquivalentParameters(C.FirstParameter(),
148 C.Curve()->LastParameter() -
149 C.Curve()->FirstParameter());
152 Handle(Geom2d_Line) GL= new Geom2d_Line(L);
153 Geom2dAdaptor_Curve CGA(GL);
154 Geom2dInt_GInter Inter(CGA,DL,C,DE,
155 Precision::PConfusion(),
156 Precision::PIntersection());
161 //=======================================================================
162 //function : LocalGeometry
164 //=======================================================================
165 void BRepClass_Intersector::LocalGeometry(const BRepClass_Edge& E,
166 const Standard_Real U,
169 Standard_Real& C) const
172 Geom2dLProp_CLProps2d Prop(BRep_Tool::CurveOnSurface(E.Edge(),E.Face(),f,l),
173 U,2,Precision::PConfusion());
175 C = Prop.Curvature();
176 if (C > Precision::PConfusion())
179 Norm.SetCoord(Tang.Y(),-Tang.X());
182 //=======================================================================
183 //function : RefineTolerance
185 //=======================================================================
186 void RefineTolerance(const TopoDS_Face& aF,
187 const BRepAdaptor_Curve2d& aC,
188 const Standard_Real aT,
189 Standard_Real& aTolZ)
191 GeomAbs_SurfaceType aTypeS;
193 BRepAdaptor_Surface aBAS(aF, Standard_False);
195 aTypeS=aBAS.GetType();
196 if (aTypeS==GeomAbs_Cylinder) {
197 Standard_Real aURes, aVRes, aTolX;
201 aURes=aBAS.UResolution(aTolZ);
202 aVRes=aBAS.VResolution(aTolZ);
204 aC.D1(aT, aP2D, aV2D);
207 aTolX=aURes*aD2D.Y()+aVRes*aD2D.X();