1 
2 #include "myBRepExtrema_ExtFF.hxx"
3 #include <BRepExtrema_ExtCF.hxx>
4 #include <BRep_Tool.hxx>
5 #include <BRepTools.hxx>
6 #include <Geom_Curve.hxx>
7 #include <StdFail_NotDone.hxx>
8 #include <Standard_Failure.hxx>
9 #include <BRepClass_FaceClassifier.hxx>
10 #include <TopoDS.hxx>
11 #include <TopAbs_ShapeEnum.hxx>
12 #include <TopExp_Explorer.hxx>
13 #include <Geom_Surface.hxx>
14 #include <Extrema_POnSurf.hxx>
15 #include <gp_Pnt2d.hxx>
16 #include <Precision.hxx>
17 #include <BRepAdaptor_HSurface.hxx>
18 #include "ace.h"
19 #include "CADMBTB_API.hpp"
20 //=======================================================================
21 //function : myBRepExtrema_ExtFF
22 //purpose  :
23 //=======================================================================
24 
myBRepExtrema_ExtFF()25 myBRepExtrema_ExtFF::myBRepExtrema_ExtFF()
26 {
27 }
28 
29 //=======================================================================
30 //function : myBRepExtrema_ExtFF
31 //purpose  :
32 //=======================================================================
myBRepExtrema_ExtFF(const TopoDS_Face & F1,const TopoDS_Face & F2,int id1,int id2)33 myBRepExtrema_ExtFF::myBRepExtrema_ExtFF
34   (const TopoDS_Face& F1,
35    const TopoDS_Face& F2,
36    int id1,
37    int id2)
38 {
39   _id1=id1;
40   _id2=id2;
41   Initialize(F2);
42 
43   Perform(F1,F2);
44 
45 }
myBRepExtrema_ExtFF(const TopoDS_Face & F1,const TopoDS_Face & F2)46 myBRepExtrema_ExtFF::myBRepExtrema_ExtFF
47   (const TopoDS_Face& F1,
48    const TopoDS_Face& F2)
49 {
50   _id1=-1;
51   _id2=-1;
52   Initialize(F2);
53 
54   Perform(F1,F2);
55 
56 }
57 //=======================================================================
58 //function : Initialize
59 //purpose  :
60 //=======================================================================
61 
Initialize(const TopoDS_Face & F2)62 void myBRepExtrema_ExtFF::Initialize(const TopoDS_Face& F2)
63 {
64   BRepAdaptor_Surface Surf(F2);
65   myHS = new BRepAdaptor_HSurface(Surf);;
66   Standard_Real Tol = BRep_Tool::Tolerance(F2);
67   Standard_Real U1, U2, V1, V2;
68   BRepTools::UVBounds(F2, U1, U2, V1, V2);
69   myExtrem.Initialize(myHS->Surface(), U1, U2, V1, V2, Tol);
70 
71 }
72 
73 //=======================================================================
74 //function : Perform
75 //purpose  :
76 //=======================================================================
77 
Perform(const TopoDS_Face & F1,const TopoDS_Face & F2)78 void myBRepExtrema_ExtFF::Perform(const TopoDS_Face& F1,
79 				const TopoDS_Face& F2)
80 { ACE_times[ACE_TIMER_CAD_1].start();
81   ACE_times[ACE_TIMER_CAD_OK].start();
82   Standard_Real U1, U2, V1, V2;
83   Standard_Integer i;
84   mydist.Clear();
85   myPointsOnS1.Clear();
86   myPointsOnS2.Clear();
87   ACE_times[ACE_TIMER_CAD_OK].stop();
88 
89   ACE_times[ACE_TIMER_CAD_14].start();
90 BRepAdaptor_Surface Surf1(F1); /*call UVBounds*/
91   ACE_times[ACE_TIMER_CAD_14].stop();
92 
93   ACE_times[ACE_TIMER_CAD_OK].start();
94   Handle(BRepAdaptor_HSurface) HS1 = new BRepAdaptor_HSurface(Surf1);
95   //ACE_times[ACE_TIMER_CAD_OK].start();
96   Standard_Real Tol1 = BRep_Tool::Tolerance(F1);
97   ACE_times[ACE_TIMER_CAD_OK].stop();
98   ACE_times[ACE_TIMER_CAD_13].start();
99   printf("myBRepExtrema_ExtFF::Perform id1=%d, id2=%d\n",_id1,_id2);
100 if (_id1>=0)
101   CADMBTB_getUVBounds(_id1, U1, U2, V1, V2);
102 else
103   BRepTools::UVBounds(F1, U1, U2, V1, V2);
104   ACE_times[ACE_TIMER_CAD_13].stop();
105   ACE_times[ACE_TIMER_CAD_OK].start();
106   //ACE_times[ACE_TIMER_CAD_2].start();
107   myExtrem.Perform(HS1->Surface(), U1, U2, V1, V2, Tol1);
108   //ACE_times[ACE_TIMER_CAD_2].stop();
109   //ACE_times[ACE_TIMER_CAD_3].stop();
110   // exploration des points et classification:
111   BRepClass_FaceClassifier classifier;
112   gp_Pnt2d Puv;
113   TopAbs_State state1, state2;
114   Standard_Real Tol2 = BRep_Tool::Tolerance(F2);
115   Extrema_POnSurf P1, P2;
116   mynbext = 0;
117   if (myExtrem.IsParallel()) {
118     ACE_times[ACE_TIMER_CAD_OK].stop();
119     mydist.Append(myExtrem.Value(1));
120     mynbext = 1;
121   }
122   else {
123     ACE_times[ACE_TIMER_CAD_OK].stop();
124     for (i = 1; i <= myExtrem.NbExt(); i++) {
125       ACE_times[ACE_TIMER_CAD_OK].start();
126       myExtrem.Points(i, P1, P2);
127       P1.Parameter(U1, U2);
128       Puv.SetCoord(U1, U2);
129       ACE_times[ACE_TIMER_CAD_OK].stop();
130       ACE_times[ACE_TIMER_CAD_15].start();
131 classifier.Perform(F1, Puv, Tol1);/*Call UVBounds*/
132       ACE_times[ACE_TIMER_CAD_15].stop();
133       ACE_times[ACE_TIMER_CAD_OK].start();
134       state1 = classifier.State();
135       P2.Parameter(U1, U2);
136       Puv.SetCoord(U1, U2);
137       classifier.Perform(F2, Puv, Tol2);
138       state2 = classifier.State();
139 //      if(true || (state1 == TopAbs_ON || state1 == TopAbs_IN) &&
140       if
141         (state2 == TopAbs_ON || state2 == TopAbs_IN)
142         //    )
143     {
144 	mynbext++;
145 	mydist.Append(myExtrem.Value(i));
146 	myPointsOnS1.Append(P1);
147 	myPointsOnS2.Append(P2);
148       }else{
149 	cout <<"myBRepExtrema_ExtFF::Perform Point out of Face\n";
150       }
151       ACE_times[ACE_TIMER_CAD_OK].stop();
152       //ACE_times[ACE_TIMER_CAD_16].stop();
153     }
154   }
155   //ACE_times[ACE_TIMER_CAD_3].stop();
156 ACE_times[ACE_TIMER_CAD_1].stop();
157 }
158 
159 //=======================================================================
160 //function : IsDone
161 //purpose  :
162 //=======================================================================
163 
IsDone() const164 Standard_Boolean myBRepExtrema_ExtFF::IsDone()const
165 {
166   return myExtrem.IsDone();
167 }
168 
169 //=======================================================================
170 //function : IsParallel
171 //purpose  :
172 //=======================================================================
173 
IsParallel() const174 Standard_Boolean myBRepExtrema_ExtFF::IsParallel()const
175 {
176   return myExtrem.IsParallel();
177 }
178 
179 
180 //=======================================================================
181 //function : NbExt
182 //purpose  :
183 //=======================================================================
184 
NbExt() const185 Standard_Integer myBRepExtrema_ExtFF::NbExt() const
186 {
187   if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
188   return mynbext;
189 }
190 
191 
192 //=======================================================================
193 //function : Value
194 //purpose  :
195 //=======================================================================
196 
Value(const Standard_Integer N) const197 Standard_Real myBRepExtrema_ExtFF::Value
198   (const Standard_Integer N) const
199 {
200   if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
201   if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
202   return mydist.Value(N);
203 }
204 
205 //=======================================================================
206 //function : ParameterOnFace1
207 //purpose  :
208 //=======================================================================
209 
ParameterOnFace1(const Standard_Integer N,Standard_Real & U,Standard_Real & V) const210 void myBRepExtrema_ExtFF::ParameterOnFace1(const Standard_Integer N,
211 					  Standard_Real& U,
212 					  Standard_Real& V) const
213 {
214   if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
215   if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
216   myPointsOnS1.Value(N).Parameter(U, V);
217 }
218 
219 //=======================================================================
220 //function : PointOnFace1
221 //purpose  :
222 //=======================================================================
223 
PointOnFace1(const Standard_Integer N) const224 gp_Pnt myBRepExtrema_ExtFF::PointOnFace1
225   (const Standard_Integer N) const
226 {
227   if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
228   if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
229   gp_Pnt P = myPointsOnS1.Value(N).Value();
230   return P;
231 }
232 
233 
234 //=======================================================================
235 //function : ParameterOnFace2
236 //purpose  :
237 //=======================================================================
238 
ParameterOnFace2(const Standard_Integer N,Standard_Real & U,Standard_Real & V) const239 void myBRepExtrema_ExtFF::ParameterOnFace2(const Standard_Integer N,
240 					  Standard_Real& U,
241 					  Standard_Real& V) const
242 {
243   if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
244   if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
245   myPointsOnS2.Value(N).Parameter(U, V);
246 }
247 
248 //=======================================================================
249 //function : PointOnFace1
250 //purpose  :
251 //=======================================================================
252 
PointOnFace2(const Standard_Integer N) const253 gp_Pnt myBRepExtrema_ExtFF::PointOnFace2
254   (const Standard_Integer N) const
255 {
256   if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
257   if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
258   gp_Pnt P = myPointsOnS2.Value(N).Value();
259   return P;
260 }
261 
262 
263