0024624: Lost word in license statement in source files
[occt.git] / src / BRepClass / BRepClass_Intersector.cxx
... / ...
CommitLineData
1// Created on: 1992-11-19
2// Created by: Remi LEQUETTE
3// Copyright (c) 1992-1999 Matra Datavision
4// Copyright (c) 1999-2014 OPEN CASCADE SAS
5//
6// This file is part of Open CASCADE Technology software library.
7//
8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
13//
14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
16
17#include <BRepClass_Intersector.ixx>
18#include <BRep_Tool.hxx>
19#include <BRepAdaptor_Curve2d.hxx>
20#include <BRepAdaptor_Surface.hxx>
21#include <TopoDS_Vertex.hxx>
22#include <TopExp.hxx>
23#include <IntRes2d_Domain.hxx>
24#include <Geom2dLProp_CLProps2d.hxx>
25#include <Geom2d_Curve.hxx>
26#include <ElCLib.hxx>
27#include <Precision.hxx>
28
29#include <Geom2d_Line.hxx>
30
31#include <Geom2dInt_GInter.hxx>
32
33#include <Extrema_ExtPC2d.hxx>
34#include <IntRes2d_Transition.hxx>
35#include <IntRes2d_IntersectionPoint.hxx>
36
37static
38void RefineTolerance(const TopoDS_Face& aF,
39 const BRepAdaptor_Curve2d& aC,
40 const Standard_Real aT,
41 Standard_Real& aTolZ);
42
43//=======================================================================
44//function : BRepClass_Intersector
45//purpose :
46//=======================================================================
47
48BRepClass_Intersector::BRepClass_Intersector()
49{
50}
51
52//=======================================================================
53//function : Perform
54//purpose :
55//=======================================================================
56void BRepClass_Intersector::Perform(const gp_Lin2d& L,
57 const Standard_Real P,
58 const Standard_Real Tol,
59 const BRepClass_Edge& E)
60{
61 Standard_Real deb = 0.0, fin = 0.0, aTolZ = Tol;
62 Handle(Geom2d_Curve) aC2D;
63 //
64 const TopoDS_Edge& EE = E.Edge();
65 const TopoDS_Face& F = E.Face();
66
67 //
68 aC2D=BRep_Tool::CurveOnSurface(EE, F, deb, fin);
69 if (aC2D.IsNull()) {
70 done = Standard_False; // !IsDone()
71 return;
72 }
73 //
74 BRepAdaptor_Curve2d C(EE, F);
75 //
76 deb = C.FirstParameter();
77 fin = C.LastParameter();
78 //
79 // Case of "ON": direct check of belonging to edge
80 // taking into account the tolerance
81 Extrema_ExtPC2d anExtPC2d(L.Location(), C);
82 Standard_Real MinDist = RealLast(), aDist;
83 Standard_Integer MinInd = 0, i;
84 if (anExtPC2d.IsDone())
85 {
86 const Standard_Integer aNbPnts = anExtPC2d.NbExt();
87 for (i = 1; i <= aNbPnts; ++i)
88 {
89 aDist = anExtPC2d.SquareDistance(i);
90
91 if (aDist < MinDist)
92 {
93 MinDist = aDist;
94 MinInd = i;
95 }
96 }
97 }
98
99 if (MinInd) {
100 MinDist = sqrt(MinDist);
101 }
102 if (MinDist <= aTolZ) {
103 gp_Pnt2d pnt_exact = (anExtPC2d.Point(MinInd)).Value();
104 Standard_Real par = (anExtPC2d.Point(MinInd)).Parameter();
105 //
106 RefineTolerance(F, C, par, aTolZ);
107 //
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;
113 }
114 else if (Abs(par - fin) <= Precision::Confusion()) {
115 pos_on_curve = IntRes2d_End;
116 }
117 //
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,
121 Standard_False);
122 //
123 Append(pnt_inter);
124 done = Standard_True;
125 return;
126 }
127 }
128 //
129 gp_Pnt2d pdeb,pfin;
130 C.D0(deb,pdeb);
131 C.D0(fin,pfin);
132 Standard_Real toldeb = 1.e-5, tolfin = 1.e-5;
133
134 IntRes2d_Domain DL;
135 //
136 if(P!=RealLast()) {
137 DL.SetValues(L.Location(),0.,aTolZ,ElCLib::Value(P,L),P,aTolZ);
138 }
139 else {
140 DL.SetValues(L.Location(),0.,aTolZ,Standard_True);
141 }
142
143 IntRes2d_Domain DE(pdeb,deb,toldeb,pfin,fin,tolfin);
144 // temporary periodic domain
145 if (C.Curve()->IsPeriodic()) {
146 DE.SetEquivalentParameters(C.FirstParameter(),
147 C.FirstParameter() +
148 C.Curve()->LastParameter() -
149 C.Curve()->FirstParameter());
150 }
151
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());
157 //
158 SetValues(Inter);
159}
160
161//=======================================================================
162//function : LocalGeometry
163//purpose :
164//=======================================================================
165void BRepClass_Intersector::LocalGeometry(const BRepClass_Edge& E,
166 const Standard_Real U,
167 gp_Dir2d& Tang,
168 gp_Dir2d& Norm,
169 Standard_Real& C) const
170{
171 Standard_Real f,l;
172 Geom2dLProp_CLProps2d Prop(BRep_Tool::CurveOnSurface(E.Edge(),E.Face(),f,l),
173 U,2,Precision::PConfusion());
174 Prop.Tangent(Tang);
175 C = Prop.Curvature();
176 if (C > Precision::PConfusion())
177 Prop.Normal(Norm);
178 else
179 Norm.SetCoord(Tang.Y(),-Tang.X());
180}
181
182//=======================================================================
183//function : RefineTolerance
184//purpose :
185//=======================================================================
186void RefineTolerance(const TopoDS_Face& aF,
187 const BRepAdaptor_Curve2d& aC,
188 const Standard_Real aT,
189 Standard_Real& aTolZ)
190{
191 GeomAbs_SurfaceType aTypeS;
192 //
193 BRepAdaptor_Surface aBAS(aF, Standard_False);
194 //
195 aTypeS=aBAS.GetType();
196 if (aTypeS==GeomAbs_Cylinder) {
197 Standard_Real aURes, aVRes, aTolX;
198 gp_Pnt2d aP2D;
199 gp_Vec2d aV2D;
200 //
201 aURes=aBAS.UResolution(aTolZ);
202 aVRes=aBAS.VResolution(aTolZ);
203 //
204 aC.D1(aT, aP2D, aV2D);
205 gp_Dir2d aD2D(aV2D);
206 //
207 aTolX=aURes*aD2D.Y()+aVRes*aD2D.X();
208 if (aTolX<0.) {
209 aTolX=-aTolX;
210 }
211 //
212 if (aTolX < Precision::Confusion()) {
213 aTolX = Precision::Confusion();
214 }
215 //
216 if (aTolX<aTolZ) {
217 aTolZ=aTolX;
218 }
219 }
220}
221
222