summaryrefslogtreecommitdiff
path: root/src/BRepClass/BRepClass_Intersector.cxx
blob: d3f2f1bc0cb40d5ce4b79b3cf807dd92046f69ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// File:	BRepClass_Intersector.cxx
// Created:	Thu Nov 19 15:04:21 1992
// Author:	Remi LEQUETTE
//		<rle@phylox>


#include <BRepClass_Intersector.ixx>
#include <BRep_Tool.hxx>
#include <BRepAdaptor_Curve2d.hxx>
#include <BRepAdaptor_Surface.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopExp.hxx>
#include <IntRes2d_Domain.hxx>
#include <Geom2dLProp_CLProps2d.hxx>
#include <Geom2d_Curve.hxx>
#include <ElCLib.hxx>
#include <Precision.hxx>

#include <Geom2d_Line.hxx>

#include <Geom2dInt_GInter.hxx>

//=======================================================================
//function : BRepClass_Intersector
//purpose  : 
//=======================================================================

BRepClass_Intersector::BRepClass_Intersector()
{
}

//=======================================================================
//function : Perform
//purpose  : 
//=======================================================================

void  BRepClass_Intersector::Perform(const gp_Lin2d& L, 
				     const Standard_Real P, 
				     const Standard_Real Tol, 
				     const BRepClass_Edge& E)
{
  
  Standard_Real pfbid,plbid;
  if (BRep_Tool::CurveOnSurface(E.Edge(),E.Face(),pfbid,plbid).IsNull()) {
    done = Standard_False; // !IsDone()
  }
  else {
    IntRes2d_Domain DL;
    if(P!=RealLast()) 
      DL.SetValues(L.Location(),0.,Tol,ElCLib::Value(P,L),P,Tol);
    else 
      DL.SetValues(L.Location(),0.,Tol,Standard_True);
    
    const TopoDS_Edge& EE = E.Edge();
    const TopoDS_Face& F = E.Face();
    TopoDS_Vertex Vdeb, Vfin;
    TopExp::Vertices(EE, Vdeb, Vfin);
    BRepAdaptor_Curve2d C(EE,F);
    Standard_Real deb = C.FirstParameter(), fin = C.LastParameter();
    gp_Pnt2d pdeb,pfin;
    C.D0(deb,pdeb);
    C.D0(fin,pfin);
    Standard_Real toldeb = 1.e-5, tolfin = 1.e-5;
#if 0 
    // essai de calcul juste des tolerances du domaine
    // qui ne couche pas avec les modeles pourris de 
    // styler !!
    BRepAdaptor_Surface S(F);
    gp_Vec2d vdeb,vfin;
    C.D1(deb,pdeb,vdeb);
    C.D1(fin,pfin,vfin);
    gp_Pnt P; gp_Vec DU, DV;
    S.D1(pdeb.X(),pdeb.Y(),P,DU,DV);
    Standard_Real scaldeb = (vdeb.X()*DU + vdeb.Y()*DV).Magnitude();
    scaldeb = Max(scaldeb, 1.e-5);
    toldeb = BRep_Tool::Tolerance(Vdeb)/scaldeb;
    S.D1(pfin.X(),pfin.Y(),P,DU,DV);
    Standard_Real scalfin = (vfin.X()*DU + vfin.Y()*DV).Magnitude();
    scalfin = Max(scalfin, 1.e-5);
    tolfin = BRep_Tool::Tolerance(Vfin)/scalfin;
#endif
    
    IntRes2d_Domain DE(pdeb,deb,toldeb,pfin,fin,tolfin);
    // temporary periodic domain
    if (C.Curve()->IsPeriodic()) {
      DE.SetEquivalentParameters(C.FirstParameter(),
				 C.FirstParameter() + 
				 C.Curve()->LastParameter() -
				 C.Curve()->FirstParameter());
    }
    
    Handle(Geom2d_Line) GL= new Geom2d_Line(L);
    Geom2dAdaptor_Curve CGA(GL);
    Geom2dInt_GInter Inter(CGA,DL,C,DE,
			   Precision::PConfusion(),
			   Precision::PIntersection());
    this->SetValues(Inter);
  }
}

//=======================================================================
//function : LocalGeometry
//purpose  : 
//=======================================================================

void  BRepClass_Intersector::LocalGeometry(const BRepClass_Edge& E, 
					   const Standard_Real U, 
					   gp_Dir2d& Tang, 
					   gp_Dir2d& Norm, 
					   Standard_Real& C) const 
{
  Standard_Real f,l;
  Geom2dLProp_CLProps2d Prop(BRep_Tool::CurveOnSurface(E.Edge(),E.Face(),f,l),
			     U,2,Precision::PConfusion());
  Prop.Tangent(Tang);
  C = Prop.Curvature();
  if (C > Precision::PConfusion())
    Prop.Normal(Norm);
  else
    Norm.SetCoord(Tang.Y(),-Tang.X());
}