1 // Created on: 1993-05-07
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
22 #include <TopOpeBRep_ShapeIntersector2d.ixx>
24 #include <Standard_ProgramError.hxx>
25 #include <Standard_NotImplemented.hxx>
27 #include <Bnd_Box.hxx>
28 #include <TopOpeBRepTool_box.hxx>
31 extern Standard_Boolean TopOpeBRep_GettraceSI();
32 extern Standard_Boolean TopOpeBRep_GetcontextFFOR();
35 //=======================================================================
36 //function : TopOpeBRep_ShapeIntersector2d
38 //=======================================================================
40 TopOpeBRep_ShapeIntersector2d::TopOpeBRep_ShapeIntersector2d()
43 myHBoxTool = FBOX_GetHBoxTool();
44 myFaceScanner.ChangeBoxSort().SetHBoxTool(myHBoxTool);
45 myEdgeScanner.ChangeBoxSort().SetHBoxTool(myHBoxTool);
48 //=======================================================================
51 //=======================================================================
53 void TopOpeBRep_ShapeIntersector2d::Reset()
55 myIntersectionDone = Standard_False;
57 myFFDone = Standard_False;
58 myEEFFDone = Standard_False;
60 myFFInit = Standard_False;
61 myEEFFInit = Standard_False;
64 //=======================================================================
67 //=======================================================================
69 void TopOpeBRep_ShapeIntersector2d::Init
70 (const TopoDS_Shape& S1, const TopoDS_Shape& S2)
78 //=======================================================================
79 //function : SetIntersectionDone
81 //=======================================================================
83 void TopOpeBRep_ShapeIntersector2d::SetIntersectionDone()
85 myIntersectionDone = (myFFDone ||
90 //=======================================================================
91 //function : CurrentGeomShape
93 //=======================================================================
95 const TopoDS_Shape& TopOpeBRep_ShapeIntersector2d::CurrentGeomShape
96 (const Standard_Integer Index) const
98 if ( myIntersectionDone ) {
100 if ( Index == 1 ) return myFaceScanner.Current();
101 else if ( Index == 2 ) return myFaceExplorer.Current();
103 else if (myEEFFDone) {
104 if ( Index == 1 ) return myEdgeScanner.Current();
105 else if ( Index == 2 ) return myEdgeExplorer.Current();
109 Standard_ProgramError::Raise("CurrentGeomShape : no intersection 2d");
110 TopoDS_Shape* bid = new TopoDS_Shape();
115 //=======================================================================
116 //function : InitIntersection
118 //=======================================================================
120 void TopOpeBRep_ShapeIntersector2d::InitIntersection
121 (const TopoDS_Shape& S1, const TopoDS_Shape& S2)
124 InitFFIntersection();
128 //=======================================================================
129 //function : MoreIntersection
131 //=======================================================================
133 Standard_Boolean TopOpeBRep_ShapeIntersector2d::MoreIntersection() const
135 Standard_Boolean res = myIntersectionDone;
138 if (TopOpeBRep_GettraceSI() && res) {
139 if ( myFFDone ) cout<<"FF : ";
140 else if ( myEEFFDone ) cout<<" EE : ";
150 //=======================================================================
151 //function : DumpCurrent
153 //=======================================================================
155 void TopOpeBRep_ShapeIntersector2d::DumpCurrent(const Standard_Integer K) const
159 if ( K == 1 ) myFaceScanner.DumpCurrent(cout);
160 else if ( K == 2 ) myFaceExplorer.DumpCurrent(cout);
162 else if ( myEEFFDone ) {
163 if ( K == 1 ) myEdgeScanner.DumpCurrent(cout);
164 else if ( K == 2 ) myEdgeExplorer.DumpCurrent(cout);
169 //=======================================================================
172 //=======================================================================
174 Standard_Integer TopOpeBRep_ShapeIntersector2d::Index
175 (const Standard_Integer K)const
177 Standard_Integer i = 0;
180 if ( K == 1 ) i = myFaceScanner.Index();
181 else if ( K == 2 ) i = myFaceExplorer.Index();
183 else if ( myEEFFDone ) {
184 if ( K == 1 ) i = myEdgeScanner.Index();
185 else if ( K == 2 ) i = myEdgeExplorer.Index();
192 //=======================================================================
193 //function : NextIntersection
195 //=======================================================================
197 void TopOpeBRep_ShapeIntersector2d::NextIntersection()
199 myIntersectionDone = Standard_False;
202 // precedant etat du More() : 2 faces
203 myFFDone = Standard_False;
204 InitEEFFIntersection();
205 FindEEFFIntersection();
206 if ( !myIntersectionDone ) {
208 FindFFIntersection();
211 else if ( myEEFFDone ) {
213 FindEEFFIntersection();
214 if ( !myIntersectionDone ) {
216 FindFFIntersection();
220 if ( !myIntersectionDone ) {
221 InitFFIntersection();
231 //=======================================================================
232 //function : InitFFIntersection
234 //=======================================================================
236 void TopOpeBRep_ShapeIntersector2d::InitFFIntersection()
239 TopAbs_ShapeEnum tscann = TopAbs_FACE;
240 TopAbs_ShapeEnum texplo = TopAbs_FACE;
241 myFaceScanner.Clear();
242 myFaceScanner.AddBoxesMakeCOB(myShape1,tscann);
243 myFaceExplorer.Init(myShape2,texplo);
244 myFaceScanner.Init(myFaceExplorer);
245 FindFFIntersection();
247 myFFInit = Standard_True;
251 //=======================================================================
252 //function : FindFFIntersection
254 //=======================================================================
256 void TopOpeBRep_ShapeIntersector2d::FindFFIntersection()
258 myFFDone = Standard_False;
259 // myFFSameDomain = Standard_False;
261 if ( MoreFFCouple() ) {
263 // The two candidate intersecting GeomShapes GS1,GS2 and their types t1,t2
264 const TopoDS_Shape& GS1 = myFaceScanner.Current();
265 const TopoDS_Shape& GS2 = myFaceExplorer.Current();
268 if (TopOpeBRep_GettraceSI()) {
270 myFaceScanner.DumpCurrent(cout);
271 myFaceExplorer.DumpCurrent(cout);
276 const TopOpeBRepTool_BoxSort& BS = myFaceScanner.BoxSort();
279 myFFDone = Standard_True;
282 SetIntersectionDone();
286 //=======================================================================
287 //function : MoreFFCouple
289 //=======================================================================
291 Standard_Boolean TopOpeBRep_ShapeIntersector2d::MoreFFCouple() const
293 Standard_Boolean more1 = myFaceScanner.More();
294 Standard_Boolean more2 = myFaceExplorer.More();
295 return (more1 && more2);
299 //=======================================================================
300 //function : NextFFCouple
302 //=======================================================================
304 void TopOpeBRep_ShapeIntersector2d::NextFFCouple()
306 myFaceScanner.Next();
307 Standard_Boolean b1,b2;
309 b1 = (!myFaceScanner.More());
310 b2 = (myFaceExplorer.More());
312 myFaceExplorer.Next();
313 myFaceScanner.Init(myFaceExplorer);
314 b1 = (!myFaceScanner.More());
315 b2 = (myFaceExplorer.More());
326 //=======================================================================
327 //function : InitEEFFIntersection
329 //=======================================================================
331 void TopOpeBRep_ShapeIntersector2d::InitEEFFIntersection()
333 // prepare exploration of the edges of the two current SameDomain faces
334 TopoDS_Shape face1 = myFaceScanner.Current(); // -26-08-96
335 TopoDS_Shape face2 = myFaceExplorer.Current(); // -26-08-96
338 if (TopOpeBRep_GetcontextFFOR()) {
339 face1.Orientation(TopAbs_FORWARD); //-05/07
340 face2.Orientation(TopAbs_FORWARD); //-05/07
341 cout<<"ctx : InitEEFFIntersection : faces FORWARD"<<endl;
345 myEEIntersector.SetFaces(face1,face2);
347 TopAbs_ShapeEnum tscann = TopAbs_EDGE;
348 TopAbs_ShapeEnum texplo = TopAbs_EDGE;
349 myEdgeScanner.Clear();
350 myEdgeScanner.AddBoxesMakeCOB(face1,tscann);
351 myEdgeExplorer.Init(face2,texplo);
352 myEdgeScanner.Init(myEdgeExplorer);
354 myEEFFInit = Standard_True;
358 //=======================================================================
359 //function : FindEEFFIntersection
361 //=======================================================================
363 void TopOpeBRep_ShapeIntersector2d::FindEEFFIntersection()
365 myEEFFDone = Standard_False;
366 while ( MoreEEFFCouple() ) {
367 const TopoDS_Shape& GS1 = myEdgeScanner.Current();
368 const TopoDS_Shape& GS2 = myEdgeExplorer.Current();
369 myEEIntersector.Perform(GS1,GS2);
372 if (TopOpeBRep_GettraceSI() && myEEIntersector.IsEmpty()) {
374 myEdgeScanner.DumpCurrent(cout);
375 myEdgeExplorer.DumpCurrent(cout);
376 cout<<"(EE of FF SameDomain)";
377 cout<<" : EMPTY INTERSECTION";
382 myEEFFDone = ! (myEEIntersector.IsEmpty());
383 if (myEEFFDone) break;
384 else NextEEFFCouple();
386 SetIntersectionDone();
390 //=======================================================================
391 //function : MoreEEFFCouple
393 //=======================================================================
395 Standard_Boolean TopOpeBRep_ShapeIntersector2d::MoreEEFFCouple() const
397 Standard_Boolean more1 = myEdgeScanner.More();
398 Standard_Boolean more2 = myEdgeExplorer.More();
399 return (more1 && more2);
403 //=======================================================================
404 //function : NextEEFFCouple
406 //=======================================================================
408 void TopOpeBRep_ShapeIntersector2d::NextEEFFCouple()
410 myEdgeScanner.Next();
411 while ( ! myEdgeScanner.More() && myEdgeExplorer.More() ) {
412 myEdgeExplorer.Next();
413 myEdgeScanner.Init(myEdgeExplorer);
418 //=======================================================================
421 //=======================================================================
423 const TopoDS_Shape& TopOpeBRep_ShapeIntersector2d::Shape
424 ( const Standard_Integer Index )const
426 if ( Index == 1 ) return myShape1;
427 else if ( Index == 2 ) return myShape2;
429 Standard_ProgramError::Raise("ShapeIntersector : no shape");
430 TopoDS_Shape* bid = new TopoDS_Shape();
434 //=======================================================================
435 //function : ChangeEdgesIntersector
437 //=======================================================================
439 TopOpeBRep_EdgesIntersector&
440 TopOpeBRep_ShapeIntersector2d::ChangeEdgesIntersector()
441 { return myEEIntersector; }