466bb1203f57355ad82992858ec4cf87088ed347
[occt.git] / src / BRepExtrema / BRepExtrema_ExtFF.cxx
1 // File:        BRepExtrema_ExtFF.cxx
2 // Created:     Wed Dec 15 16:48:53 1993
3 // Author:      Christophe MARION
4 //              <cma@sdsun1>
5 // modified by mps (juillet 96 ): on utilise BRepAdaptor a la place de 
6 // GeomAdaptor dans Initialize et Perform.
7 #include <BRepExtrema_ExtFF.ixx>
8 #include <BRepExtrema_ExtCF.hxx>
9 #include <BRep_Tool.hxx>
10 #include <BRepTools.hxx>
11 #include <Geom_Curve.hxx>
12 #include <StdFail_NotDone.hxx>
13 #include <Standard_Failure.hxx>
14 #include <BRepClass_FaceClassifier.hxx>
15 #include <TopoDS.hxx>
16 #include <TopAbs_ShapeEnum.hxx>
17 #include <TopExp_Explorer.hxx>
18 #include <Geom_Surface.hxx>
19 #include <Extrema_POnSurf.hxx>
20 #include <gp_Pnt2d.hxx>
21 #include <Precision.hxx>
22 #include <BRepAdaptor_HSurface.hxx>
23
24 //=======================================================================
25 //function : BRepExtrema_ExtFF
26 //purpose  : 
27 //=======================================================================
28
29 BRepExtrema_ExtFF::BRepExtrema_ExtFF()
30 {
31 }
32
33 //=======================================================================
34 //function : BRepExtrema_ExtFF
35 //purpose  : 
36 //=======================================================================
37
38 BRepExtrema_ExtFF::BRepExtrema_ExtFF
39   (const TopoDS_Face& F1,
40    const TopoDS_Face& F2)
41 {
42  Initialize(F2);
43  Perform(F1,F2);
44 }
45 //=======================================================================
46 //function : Initialize
47 //purpose  : 
48 //=======================================================================
49
50 void BRepExtrema_ExtFF::Initialize(const TopoDS_Face& F2)
51 {
52   BRepAdaptor_Surface Surf(F2);
53   myHS = new BRepAdaptor_HSurface(Surf);
54   Standard_Real Tol = BRep_Tool::Tolerance(F2);
55   Standard_Real U1, U2, V1, V2;
56   BRepTools::UVBounds(F2, U1, U2, V1, V2);
57   myExtrem.Initialize(myHS->Surface(), U1, U2, V1, V2, Tol);
58  
59 }
60
61 //=======================================================================
62 //function : Perform
63 //purpose  : 
64 //=======================================================================
65
66 void BRepExtrema_ExtFF::Perform(const TopoDS_Face& F1,
67                                 const TopoDS_Face& F2)
68
69   Standard_Real U1, U2, V1, V2;
70   Standard_Integer i;   
71   mySqDist.Clear();
72   myPointsOnS1.Clear();
73   myPointsOnS2.Clear();
74   BRepAdaptor_Surface Surf1(F1);
75   Handle(BRepAdaptor_HSurface) HS1 = new BRepAdaptor_HSurface(Surf1);
76   Standard_Real Tol1 = BRep_Tool::Tolerance(F1);
77   BRepTools::UVBounds(F1, U1, U2, V1, V2);
78   myExtrem.Perform(HS1->Surface(), U1, U2, V1, V2, Tol1);
79  
80
81   // exploration des points et classification:
82   BRepClass_FaceClassifier classifier;
83   gp_Pnt2d Puv;
84   TopAbs_State state1, state2;
85   Standard_Real Tol2 = BRep_Tool::Tolerance(F2);
86   Extrema_POnSurf P1, P2;
87   mynbext = 0;
88
89   if (myExtrem.IsParallel()) {
90     mySqDist.Append(myExtrem.SquareDistance(1));
91     mynbext = 1;
92   }
93   else {
94     for (i = 1; i <= myExtrem.NbExt(); i++) {
95       myExtrem.Points(i, P1, P2);
96       P1.Parameter(U1, U2);
97       Puv.SetCoord(U1, U2);
98       classifier.Perform(F1, Puv, Tol1);
99       state1 = classifier.State();
100       P2.Parameter(U1, U2);
101       Puv.SetCoord(U1, U2);
102       classifier.Perform(F2, Puv, Tol2);
103       state2 = classifier.State();
104       if((state1 == TopAbs_ON || state1 == TopAbs_IN) &&
105          (state2 == TopAbs_ON || state2 == TopAbs_IN)) {
106         mynbext++;
107         mySqDist.Append(myExtrem.SquareDistance(i));
108         myPointsOnS1.Append(P1);
109         myPointsOnS2.Append(P2);
110       }
111     }
112   }
113 }
114   
115 //=======================================================================
116 //function : IsDone
117 //purpose  : 
118 //=======================================================================
119
120 Standard_Boolean BRepExtrema_ExtFF::IsDone()const
121 {
122   return myExtrem.IsDone();
123 }
124
125 //=======================================================================
126 //function : IsParallel
127 //purpose  : 
128 //=======================================================================
129
130 Standard_Boolean BRepExtrema_ExtFF::IsParallel()const
131 {
132   return myExtrem.IsParallel();
133 }
134
135
136 //=======================================================================
137 //function : NbExt
138 //purpose  : 
139 //=======================================================================
140
141 Standard_Integer BRepExtrema_ExtFF::NbExt() const
142 {
143   if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
144   return mynbext;
145 }
146
147
148 //=======================================================================
149 //function : SquareDistance
150 //purpose  : 
151 //=======================================================================
152
153 Standard_Real BRepExtrema_ExtFF::SquareDistance
154   (const Standard_Integer N) const
155 {
156   if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
157   if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
158   return mySqDist.Value(N);
159 }
160
161 //=======================================================================
162 //function : ParameterOnFace1
163 //purpose  : 
164 //=======================================================================
165
166 void BRepExtrema_ExtFF::ParameterOnFace1(const Standard_Integer N,
167                                           Standard_Real& U,
168                                           Standard_Real& V) const
169 {
170   if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
171   if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
172   myPointsOnS1.Value(N).Parameter(U, V);
173 }
174
175 //=======================================================================
176 //function : PointOnFace1
177 //purpose  : 
178 //=======================================================================
179
180 gp_Pnt BRepExtrema_ExtFF::PointOnFace1
181   (const Standard_Integer N) const
182 {
183   if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
184   if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
185   gp_Pnt P = myPointsOnS1.Value(N).Value();
186   return P; 
187 }
188
189
190 //=======================================================================
191 //function : ParameterOnFace2
192 //purpose  : 
193 //=======================================================================
194
195 void BRepExtrema_ExtFF::ParameterOnFace2(const Standard_Integer N,
196                                           Standard_Real& U,
197                                           Standard_Real& V) const
198 {
199   if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
200   if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
201   myPointsOnS2.Value(N).Parameter(U, V);
202 }
203
204 //=======================================================================
205 //function : PointOnFace1
206 //purpose  : 
207 //=======================================================================
208
209 gp_Pnt BRepExtrema_ExtFF::PointOnFace2
210   (const Standard_Integer N) const
211 {
212   if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
213   if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
214   gp_Pnt P = myPointsOnS2.Value(N).Value();
215   return P; 
216 }
217
218