0026019: Unstable behavior of test cases with operation mkvolume
[occt.git] / src / BOPDS / BOPDS_IteratorSI.cxx
1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #include <Bnd_Box.hxx>
16 #include <BOPCol_BoxBndTree.hxx>
17 #include <BOPCol_DataMapOfIntegerInteger.hxx>
18 #include <BOPCol_DataMapOfIntegerListOfInteger.hxx>
19 #include <BOPCol_DataMapOfShapeInteger.hxx>
20 #include <BOPCol_IndexedDataMapOfShapeBox.hxx>
21 #include <BOPCol_ListOfInteger.hxx>
22 #include <BOPDS_DS.hxx>
23 #include <BOPDS_IndexRange.hxx>
24 #include <BOPDS_IteratorSI.hxx>
25 #include <BOPDS_MapOfPassKeyBoolean.hxx>
26 #include <BOPDS_PassKeyBoolean.hxx>
27 #include <BOPDS_ShapeInfo.hxx>
28 #include <BOPDS_Tools.hxx>
29 #include <BRep_Tool.hxx>
30 #include <gp_Pnt.hxx>
31 #include <NCollection_IncAllocator.hxx>
32 #include <NCollection_UBTreeFiller.hxx>
33 #include <TopAbs_ShapeEnum.hxx>
34 #include <TopoDS.hxx>
35 #include <TopoDS_Shape.hxx>
36 #include <TopoDS_Vertex.hxx>
37
38 //
39 //=======================================================================
40 //function : 
41 //purpose  : 
42 //=======================================================================
43 BOPDS_IteratorSI::BOPDS_IteratorSI()
44 :
45   BOPDS_Iterator()
46 {
47 }
48 //=======================================================================
49 //function : 
50 //purpose  : 
51 //=======================================================================
52 BOPDS_IteratorSI::BOPDS_IteratorSI
53   (const Handle(NCollection_BaseAllocator)& theAllocator)
54 :
55   BOPDS_Iterator(theAllocator)
56 {
57 }
58 //=======================================================================
59 //function : ~
60 //purpose  : 
61 //=======================================================================
62 BOPDS_IteratorSI::~BOPDS_IteratorSI()
63 {
64 }
65 //=======================================================================
66 // function: UpdateByLevelOfCheck
67 // purpose: 
68 //=======================================================================
69 void BOPDS_IteratorSI::UpdateByLevelOfCheck(const Standard_Integer theLevel)
70 {
71   Standard_Integer i, aNbInterfTypes;
72   //
73   aNbInterfTypes=BOPDS_DS::NbInterfTypes();
74   for (i=theLevel+1; i<aNbInterfTypes; ++i) {
75     myLists(i).Clear();
76   }
77 }
78 //=======================================================================
79 // function: Intersect
80 // purpose: 
81 //=======================================================================
82 void BOPDS_IteratorSI::Intersect()
83 {
84   Standard_Boolean bFlag;
85   Standard_Integer aNbS, i, aNbB;
86   Standard_Integer aNbSD, iX, j, iDS, jB;
87   TopAbs_ShapeEnum aTi, aTj;
88   Handle(NCollection_IncAllocator) aAllocator;
89   BOPCol_ListIteratorOfListOfInteger aIt;
90   //
91   //-----------------------------------------------------scope_1 f
92   aAllocator=new NCollection_IncAllocator();
93   //
94   BOPCol_DataMapOfShapeInteger aMSI(100, aAllocator);
95   BOPCol_DataMapOfIntegerInteger aMII(100, aAllocator);
96   BOPDS_MapOfPassKeyBoolean aMPA(100, aAllocator);
97   BOPDS_MapOfPassKeyBoolean aMPKXB(100, aAllocator);
98   BOPCol_IndexedDataMapOfShapeBox aMSB(100, aAllocator);
99   BOPDS_PassKeyBoolean aPKXB; 
100   //
101   BOPCol_BoxBndTreeSelector aSelector;
102   BOPCol_BoxBndTree aBBTree;
103   NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
104   //
105   // myPairsAvoid, aMSI, aMSB
106   aNbS=myDS->NbSourceShapes();
107   for (i=0; i<aNbS; ++i) {
108     const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
109     //
110     if (!aSI.IsInterfering()) { 
111       continue;
112     }
113     //
114     const TopoDS_Shape& aSi=aSI.Shape();
115     aTi=aSI.ShapeType();
116     if (aTi!=TopAbs_VERTEX) {
117       const BOPCol_ListOfInteger& aLA=aSI.SubShapes();
118       aIt.Initialize(aLA);
119       for (; aIt.More(); aIt.Next()) {
120         iX=aIt.Value();
121         aPKXB.Clear();
122         aPKXB.SetIds(i, iX);
123         aMPA.Add(aPKXB);
124       }
125     }
126     //
127     aPKXB.Clear();
128     aPKXB.SetIds(i, i);
129     aMPA.Add(aPKXB);
130     //
131     const Bnd_Box& aBoxEx=aSI.Box();
132     //
133     aMSI.Bind(aSi, i);
134     aMSB.Add(aSi, aBoxEx);
135   } // for (i=0; i<aNbS; ++i) {
136   // 
137   // aMII
138   aNbB=aMSB.Extent();
139   for (i=1; i<=aNbB; ++i) {
140     const TopoDS_Shape& aS=aMSB.FindKey(i);
141     const Bnd_Box& aBoxEx=aMSB(i);
142     //
143     aTreeFiller.Add(i, aBoxEx);
144     //
145     iDS=aMSI.Find(aS);
146     aMII.Bind(i, iDS);
147   }
148   //
149   aTreeFiller.Fill();
150   //
151   for (i=0; i<aNbS; ++i) {
152     const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
153     aTi=aSI.ShapeType();
154     if (!aSI.IsInterfering()){
155       continue;
156     }
157     //
158     const TopoDS_Shape& aSi=myDS->Shape(i);
159     aTi=aSi.ShapeType();
160     const Bnd_Box& aBoxEx=aMSB.FindFromKey(aSi);
161     aSelector.Clear();
162     aSelector.SetBox(aBoxEx);
163     //
164     aNbSD=aBBTree.Select(aSelector);
165     if (!aNbSD){
166       continue;
167     }
168     //
169     const BOPCol_ListOfInteger& aLI=aSelector.Indices();
170     //
171     aIt.Initialize(aLI);
172     for (; aIt.More(); aIt.Next()) {
173       jB=aIt.Value();  // box index in MII
174       j=aMII.Find(jB); // DS index
175       //
176       aPKXB.SetIds(i, j);
177       if (aMPA.Contains(aPKXB)) {
178         continue;
179       }
180       //
181       if (aMPKXB.Add(aPKXB)) {
182         bFlag=Standard_False;// Bounding boxes are intersected
183         const Bnd_Box& aBoxi=myDS->ShapeInfo(i).Box();
184         const Bnd_Box& aBoxj=myDS->ShapeInfo(j).Box();
185         if (aBoxi.IsOut(aBoxj)) {
186           bFlag=!bFlag; //Bounding boxes of Sub-shapes are intersected
187         }
188         aTj=myDS->ShapeInfo(j).ShapeType();//
189         iX=BOPDS_Tools::TypeToInteger(aTi, aTj);
190         aPKXB.SetFlag(bFlag);
191         myLists(iX).Append(aPKXB);
192       }// if (aMPKXB.Add(aPKXB)) {
193     }// for (; aIt.More(); aIt.Next()) {
194   }//for (i=1; i<=aNbS; ++i) {
195   //
196   aMSI.Clear();
197   aMII.Clear();
198   aMPA.Clear();
199   aMPKXB.Clear();
200   aMSB.Clear();
201   //
202   aAllocator.Nullify();
203   //-----------------------------------------------------scope_1 t
204 }