Integration of OCCT 6.5.0 from SVN
[occt.git] / src / TopOpeBRep / TopOpeBRep_FaceEdgeIntersector.cxx
CommitLineData
7fd59977 1// File: TopOpeBRep_FaceEdgeIntersector.cxx
2// Created: Fri Oct 7 14:16:31 1994
3// Author: Jean Yves LEBEY
4// <jyl@bravox>
5
6
7#include <TopOpeBRep_FaceEdgeIntersector.ixx>
8#include <TopoDS.hxx>
9#include <BRep_Tool.hxx>
10#include <Geom_Curve.hxx>
11#include <TopLoc_Location.hxx>
12#include <IntCurveSurface_IntersectionPoint.hxx>
13#include <IntCurveSurface_TransitionOnCurve.hxx>
14#include <BRepIntCurveSurface_Inter.hxx>
15
16#include <TopExp_Explorer.hxx>
17#include <TopOpeBRepTool_ShapeTool.hxx>
18#include <Precision.hxx>
19#include <Standard_ProgramError.hxx>
20
21#ifdef DEB
22#include <TopAbs.hxx>
23Standard_IMPORT Standard_Boolean TopOpeBRep_GettraceFITOL();
24Standard_IMPORT Standard_Boolean TopOpeBRep_GettraceSAVFF();
25#include <TCollection_AsciiString.hxx>
26#include <Standard_CString.hxx>
27#include <BRepTools.hxx>
28static void SAVFE(const TopoDS_Face& F1,const TopoDS_Edge& E)
29{
30 TCollection_AsciiString aname_1("FE_face"), aname_2("FE_edge");
31 Standard_CString name_1 = aname_1.ToCString(), name_2 = aname_2.ToCString();
32 cout<<"FaceEdgeIntersector : "<<name_1<<","<<name_2<<endl;
33 BRepTools::Write(F1,name_1); BRepTools::Write(E,name_2);
34}
35Standard_IMPORT Standard_Boolean TopOpeBRepTool_GettraceKRO();
36#include <TopOpeBRepTool_KRO.hxx>
37Standard_EXPORT TOPKRO KRO_DSFILLER_INTFE("intersection face/edge");
38#endif
39
40
41//=======================================================================
42//function : TopOpeBRep_FaceEdgeIntersector
43//purpose :
44//=======================================================================
45
46 TopOpeBRep_FaceEdgeIntersector::TopOpeBRep_FaceEdgeIntersector()
47{
48 ResetIntersection();
49}
50
51//=======================================================================
52//function : ResetIntersection
53//purpose :
54//=======================================================================
55
56void TopOpeBRep_FaceEdgeIntersector::ResetIntersection()
57{
58 mySequenceOfPnt.Clear();
59 mySequenceOfState.Clear();
60 myNbPoints = 0;
61 myIntersectionDone = Standard_False;
62}
63
64
65//=======================================================================
66//function : Perform
67//purpose :
68//=======================================================================
69
70void TopOpeBRep_FaceEdgeIntersector::Perform(const TopoDS_Shape& SF,
71 const TopoDS_Shape& SE)
72{
73 ResetIntersection();
74 if (!myForceTolerance) ShapeTolerances(SF,SE);
75 myTol = BRep_Tool::Tolerance(TopoDS::Edge(SE));
76#ifdef DEB
77 if (TopOpeBRep_GettraceFITOL()) cout<<"Perform : myTol = "<<myTol<<endl;
78#endif
79
80 myFace = TopoDS::Face(SF); myFace.Orientation(TopAbs_FORWARD);
81 myEdge = TopoDS::Edge(SE); myEdge.Orientation(TopAbs_FORWARD);
82
83#ifdef DEB
84 if (TopOpeBRep_GettraceSAVFF()) SAVFE(myFace,myEdge);
85#endif
86
87 Standard_Real f,l;
88 TopLoc_Location loc;
89 const Handle(Geom_Curve) C = BRep_Tool::Curve(myEdge,loc,f,l);
90
91#ifdef DEB
92 gp_Trsf Tao1 =
93#endif
94 loc.Transformation();
95 Handle(Geom_Geometry) GGao1 = C->Transformed(loc.Transformation());
96 Handle(Geom_Curve)* PGCao1 = (Handle(Geom_Curve)*)&GGao1;
97 myCurve.Load(*PGCao1,f,l);
98
99
100#ifdef DEB
101 if (TopOpeBRepTool_GettraceKRO()) KRO_DSFILLER_INTFE.Start();
102#endif
103
104 BRepIntCurveSurface_Inter FEINT;
105 FEINT.Init(myFace,myCurve,myTol);
106
107#ifdef DEB
108 if (TopOpeBRepTool_GettraceKRO()) KRO_DSFILLER_INTFE.Stop();
109#endif
110
111 for (FEINT.Init(myFace,myCurve,myTol); FEINT.More(); FEINT.Next()) {
112 mySequenceOfPnt.Append(FEINT.Point());
113 Standard_Integer i = (FEINT.State() == TopAbs_IN) ? 0 : 1;
114 mySequenceOfState.Append(i);
115 }
116
117 myNbPoints = mySequenceOfPnt.Length();
118 myIntersectionDone = Standard_True;
119
120}
121
122
123//=======================================================================
124//function : IsEmpty
125//purpose :
126//=======================================================================
127
128Standard_Boolean TopOpeBRep_FaceEdgeIntersector::IsEmpty ()
129{
130 Standard_Boolean b = myNbPoints == 0;
131 return b;
132}
133
134
135//=======================================================================
136//function : Shape
137//purpose :
138//=======================================================================
139
140const TopoDS_Shape& TopOpeBRep_FaceEdgeIntersector::Shape
141(const Standard_Integer Index) const
142{
143 if ( Index == 1 ) return myFace;
144 else if ( Index == 2 ) return myEdge;
145 else Standard_ProgramError::Raise("TopOpeBRep_FaceEdgeIntersector::Shape");
146
147 return myNullShape;
148}
149
150//=======================================================================
151//function : ForceTolerance
152//purpose :
153//=======================================================================
154
155void TopOpeBRep_FaceEdgeIntersector::ForceTolerance(const Standard_Real Tol)
156{
157 myTol = Tol;
158 myForceTolerance = Standard_True;
159
160#ifdef DEB
161 if (TopOpeBRep_GettraceFITOL())
162 cout<<"ForceTolerance : myTol = "<<myTol<<endl;
163#endif
164}
165
166//=======================================================================
167//function : Tolerance
168//purpose :
169//=======================================================================
170
171Standard_Real TopOpeBRep_FaceEdgeIntersector::Tolerance() const
172{
173 return myTol;
174}
175
176//=======================================================================
177//function : NbPoints
178//purpose :
179//=======================================================================
180
181Standard_Integer TopOpeBRep_FaceEdgeIntersector::NbPoints() const
182{
183 Standard_Integer n = myNbPoints;
184 return n;
185}
186
187
188//=======================================================================
189//function : InitPoint
190//purpose :
191//=======================================================================
192
193void TopOpeBRep_FaceEdgeIntersector::InitPoint()
194{
195 myPointIndex = 1;
196}
197
198//=======================================================================
199//function : MorePoint
200//purpose :
201//=======================================================================
202
203Standard_Boolean TopOpeBRep_FaceEdgeIntersector::MorePoint() const
204{
205 Standard_Boolean b = myPointIndex <= myNbPoints;
206 return b;
207}
208
209//=======================================================================
210//function : NextPoint
211//purpose :
212//=======================================================================
213
214void TopOpeBRep_FaceEdgeIntersector::NextPoint()
215{
216 myPointIndex++;
217}
218
219//=======================================================================
220//function : Value
221//purpose :
222//=======================================================================
223
224gp_Pnt TopOpeBRep_FaceEdgeIntersector::Value() const
225{
226 const IntCurveSurface_IntersectionPoint& IP = mySequenceOfPnt(myPointIndex);
227 const gp_Pnt& P = IP.Pnt();
228 return P;
229}
230
231
232//=======================================================================
233//function : Parameter
234//purpose :
235//=======================================================================
236
237Standard_Real TopOpeBRep_FaceEdgeIntersector::Parameter() const
238{
239 const IntCurveSurface_IntersectionPoint& IP = mySequenceOfPnt(myPointIndex);
240 Standard_Real p = IP.W();
241 return p;
242}
243
244//=======================================================================
245//function : UVPoint
246//purpose :
247//=======================================================================
248
249void TopOpeBRep_FaceEdgeIntersector::UVPoint(gp_Pnt2d& P2d) const
250{
251 const IntCurveSurface_IntersectionPoint& IP = mySequenceOfPnt(myPointIndex);
252 Standard_Real u = IP.U();
253 Standard_Real v = IP.V();
254 P2d.SetCoord(u,v);
255}
256
257//=======================================================================
258//function : State
259//purpose :
260//=======================================================================
261
262TopAbs_State TopOpeBRep_FaceEdgeIntersector::State() const
263{
264 Standard_Integer i = mySequenceOfState(myPointIndex);
265 TopAbs_State s = (i == 0 ) ? TopAbs_IN : TopAbs_ON;
266 return s;
267}
268
269//=======================================================================
270//function : Transition
271//purpose :
272//=======================================================================
273
274TopOpeBRepDS_Transition TopOpeBRep_FaceEdgeIntersector::Transition
275(const Standard_Integer Index,
276 const TopAbs_Orientation FaceOrientation) const
277{
278// TopAbs_ShapeEnum onB = TopAbs_FACE, onA = TopAbs_FACE; // bidon
279// if ((FaceOrientation == TopAbs_INTERNAL) ||
280// (FaceOrientation == TopAbs_EXTERNAL)) {
281// TopOpeBRepDS_Transition TR(TopAbs_IN,TopAbs_IN,onB,onA); // IN bidon
282// TR.Set(FaceOrientation);
283// return TR;
284// }
285
286 TopAbs_State stB, stA;
287
288 const IntCurveSurface_IntersectionPoint& IP = mySequenceOfPnt(myPointIndex);
289
290 if ( Index == 2 ) { //-- Edge In <=> Rentre ds la matiere face
291 switch (IP.Transition()) {
292 case IntCurveSurface_In : stB = TopAbs_OUT; stA = TopAbs_IN; break;
293 case IntCurveSurface_Out : stB = TopAbs_IN; stA = TopAbs_OUT; break;
294 default : stB = TopAbs_IN; stA = TopAbs_IN; break;
295 }
296
297 TopOpeBRepDS_Transition TR;
298 TopAbs_ShapeEnum onB = TopAbs_FACE, onA = TopAbs_FACE;
299 if (FaceOrientation == TopAbs_FORWARD)
300 TR.Set(stB,stA,onB,onA);
301 else if (FaceOrientation == TopAbs_REVERSED)
302 TR.Set(stA,stB,onA,onB);
303 else if (FaceOrientation == TopAbs_EXTERNAL)
304 TR.Set(TopAbs_OUT,TopAbs_OUT,onA,onB);
305 else if (FaceOrientation == TopAbs_INTERNAL)
306 TR.Set(TopAbs_IN,TopAbs_IN,onA,onB);
307 return TR;
308 }
309
310 else if ( Index == 1 ) { //-- Face On est toujours ds la face .
311 switch (IP.Transition()) {
312 case IntCurveSurface_In : stB = stA = TopAbs_IN; break;
313 case IntCurveSurface_Out : stB = stA = TopAbs_IN; break;
314 default : stB = stA = TopAbs_IN; break;
315 }
316 TopAbs_ShapeEnum onB = TopAbs_FACE, onA = TopAbs_FACE;
317 TopOpeBRepDS_Transition TR;
318 TR.Set(stB,stA,onB,onA);
319 return TR;
320 }
321
322 else Standard_ProgramError::Raise("FEINT Transition Index");
323
324// return(TopOpeBRepDS_Transition());
325 TopOpeBRepDS_Transition aValRet ;
326 return (aValRet);
327}
328
329//=======================================================================
330//function : IsVertex
331//purpose :
332//=======================================================================
333
334Standard_Boolean TopOpeBRep_FaceEdgeIntersector::IsVertex
335(const TopoDS_Shape& S, const gp_Pnt& P,
336 const Standard_Real Tol, TopoDS_Vertex& VR)
337{
338 Standard_Boolean isv = Standard_False;
339 VR = myNullVertex;
340
341 Standard_Real Tol2=Tol*Tol;
342 for (myVertexExplorer.Init(S,TopAbs_VERTEX);
343 myVertexExplorer.More();
344 myVertexExplorer.Next()) {
345 const TopoDS_Shape& SS = myVertexExplorer.Current();
346 const TopoDS_Vertex& VV = TopoDS::Vertex(SS);
347 gp_Pnt PV = BRep_Tool::Pnt(VV);
348 isv = P.SquareDistance(PV) < Tol2;
349 if (isv) {
350 VR = VV;
351 }
352 }
353
354 return isv;
355}
356
357//=======================================================================
358//function : IsVertex
359//purpose :
360//=======================================================================
361
362Standard_Boolean TopOpeBRep_FaceEdgeIntersector::IsVertex
363(const Standard_Integer I, TopoDS_Vertex& VR)
364{
365 Standard_Boolean isv = Standard_False;
366 gp_Pnt P = Value();
367 if (I == 1) isv = IsVertex(myFace,P,myTol,VR);
368 else if (I == 2) isv = IsVertex(myEdge,P,myTol,VR);
369 return isv;
370}
371
372//=======================================================================
373//function : Index
374//purpose :
375//=======================================================================
376
377Standard_Integer TopOpeBRep_FaceEdgeIntersector::Index() const
378{
379#ifdef DEB
380 return myPointIndex;
381#else
382 return 0;
383#endif
384}
385
386
387//=======================================================================
388//function : ShapeTolerances
389//purpose : (private)
390//=======================================================================
391
392void TopOpeBRep_FaceEdgeIntersector::ShapeTolerances(const TopoDS_Shape& S1,
393 const TopoDS_Shape& S2)
394{
395 myTol = Max(ToleranceMax(S1,TopAbs_EDGE),ToleranceMax(S2,TopAbs_EDGE));
396 myForceTolerance = Standard_False;
397
398#ifdef DEB
399 if (TopOpeBRep_GettraceFITOL()) {
400 cout<<"ShapeTolerances on S1 = ";TopAbs::Print(S1.ShapeType(),cout);
401 cout<<" S2 = ";TopAbs::Print(S2.ShapeType(),cout);
402 cout<<" : myTol = "<<myTol<<endl;
403 }
404#endif
405}
406
407//=======================================================================
408//function : ToleranceMax
409//purpose : (private)
410//=======================================================================
411
412Standard_Real TopOpeBRep_FaceEdgeIntersector::ToleranceMax
413(const TopoDS_Shape& S,
414 const TopAbs_ShapeEnum T)const
415{
416 TopExp_Explorer e(S,T);
417 if ( ! e.More() ) return Precision::Intersection();
418 else {
419 Standard_Real tol = RealFirst();
420 for (; e.More(); e.Next())
421 tol = Max(tol,TopOpeBRepTool_ShapeTool::Tolerance(e.Current()));
422 return tol;
423 }
424}