Updating test for current state of OCCT
[occt.git] / src / BRepClass / BRepClass_Intersector.cxx
CommitLineData
b311480e 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
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
7fd59977 21
22
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>
28#include <TopExp.hxx>
29#include <IntRes2d_Domain.hxx>
30#include <Geom2dLProp_CLProps2d.hxx>
31#include <Geom2d_Curve.hxx>
32#include <ElCLib.hxx>
33#include <Precision.hxx>
34
35#include <Geom2d_Line.hxx>
36
37#include <Geom2dInt_GInter.hxx>
38
312cd1f5 39#include <Extrema_ExtPC2d.hxx>
40#include <IntRes2d_Transition.hxx>
41#include <IntRes2d_IntersectionPoint.hxx>
42
7fd59977 43//=======================================================================
44//function : BRepClass_Intersector
45//purpose :
46//=======================================================================
47
48BRepClass_Intersector::BRepClass_Intersector()
49{
50}
51
52//=======================================================================
53//function : Perform
54//purpose :
55//=======================================================================
56
57void BRepClass_Intersector::Perform(const gp_Lin2d& L,
58 const Standard_Real P,
59 const Standard_Real Tol,
60 const BRepClass_Edge& E)
61{
62
63 Standard_Real pfbid,plbid;
64 if (BRep_Tool::CurveOnSurface(E.Edge(),E.Face(),pfbid,plbid).IsNull()) {
65 done = Standard_False; // !IsDone()
66 }
67 else {
68 IntRes2d_Domain DL;
69 if(P!=RealLast())
70 DL.SetValues(L.Location(),0.,Tol,ElCLib::Value(P,L),P,Tol);
71 else
72 DL.SetValues(L.Location(),0.,Tol,Standard_True);
73
74 const TopoDS_Edge& EE = E.Edge();
75 const TopoDS_Face& F = E.Face();
76 TopoDS_Vertex Vdeb, Vfin;
77 TopExp::Vertices(EE, Vdeb, Vfin);
78 BRepAdaptor_Curve2d C(EE,F);
79 Standard_Real deb = C.FirstParameter(), fin = C.LastParameter();
312cd1f5 80
81 // Case of "ON": direct check of belonging to edge
82 // taking into account the tolerance
83 Extrema_ExtPC2d theExtPC2d(L.Location(), C);
84 Standard_Real MinDist = RealLast(), aDist;
85 Standard_Integer MinInd = 0, i;
86 if (theExtPC2d.IsDone())
87 {
88 for (i = 1; i <= theExtPC2d.NbExt(); i++)
89 {
90 aDist = theExtPC2d.SquareDistance(i);
91 if (aDist < MinDist)
92 {
93 MinDist = aDist;
94 MinInd = i;
95 }
96 }
97 }
98 if (MinInd)
99 MinDist = sqrt(MinDist);
100 if (MinDist <= Tol)
101 {
102 gp_Pnt2d pnt_exact = (theExtPC2d.Point(MinInd)).Value();
103 Standard_Real par = (theExtPC2d.Point(MinInd)).Parameter();
104 IntRes2d_Transition tr_on_lin(IntRes2d_Head);
105 IntRes2d_Position pos_on_curve = IntRes2d_Middle;
106 if (Abs(par - deb) <= Precision::Confusion())
107 pos_on_curve = IntRes2d_Head;
108 else if (Abs(par - fin) <= Precision::Confusion())
109 pos_on_curve = IntRes2d_End;
110 IntRes2d_Transition tr_on_curve(pos_on_curve);
111 IntRes2d_IntersectionPoint pnt_inter(pnt_exact, 0., par,
112 tr_on_lin, tr_on_curve, Standard_False);
113 this->Append(pnt_inter);
114 done = Standard_True;
115 return;
116 }
117 ///////////////
118
7fd59977 119 gp_Pnt2d pdeb,pfin;
120 C.D0(deb,pdeb);
121 C.D0(fin,pfin);
122 Standard_Real toldeb = 1.e-5, tolfin = 1.e-5;
123#if 0
124 // essai de calcul juste des tolerances du domaine
125 // qui ne couche pas avec les modeles pourris de
126 // styler !!
127 BRepAdaptor_Surface S(F);
128 gp_Vec2d vdeb,vfin;
129 C.D1(deb,pdeb,vdeb);
130 C.D1(fin,pfin,vfin);
131 gp_Pnt P; gp_Vec DU, DV;
132 S.D1(pdeb.X(),pdeb.Y(),P,DU,DV);
133 Standard_Real scaldeb = (vdeb.X()*DU + vdeb.Y()*DV).Magnitude();
134 scaldeb = Max(scaldeb, 1.e-5);
135 toldeb = BRep_Tool::Tolerance(Vdeb)/scaldeb;
136 S.D1(pfin.X(),pfin.Y(),P,DU,DV);
137 Standard_Real scalfin = (vfin.X()*DU + vfin.Y()*DV).Magnitude();
138 scalfin = Max(scalfin, 1.e-5);
139 tolfin = BRep_Tool::Tolerance(Vfin)/scalfin;
140#endif
141
142 IntRes2d_Domain DE(pdeb,deb,toldeb,pfin,fin,tolfin);
143 // temporary periodic domain
144 if (C.Curve()->IsPeriodic()) {
145 DE.SetEquivalentParameters(C.FirstParameter(),
146 C.FirstParameter() +
147 C.Curve()->LastParameter() -
148 C.Curve()->FirstParameter());
149 }
150
151 Handle(Geom2d_Line) GL= new Geom2d_Line(L);
152 Geom2dAdaptor_Curve CGA(GL);
153 Geom2dInt_GInter Inter(CGA,DL,C,DE,
154 Precision::PConfusion(),
155 Precision::PIntersection());
156 this->SetValues(Inter);
157 }
158}
159
160//=======================================================================
161//function : LocalGeometry
162//purpose :
163//=======================================================================
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
184
185