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