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