0024157: Parallelization of assembly part of BO
[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
7 // under the terms of the GNU Lesser General Public 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 <BOPDS_IteratorSI.ixx>
16
17 #include <TopAbs_ShapeEnum.hxx>
18 #include <gp_Pnt.hxx>
19 #include <Bnd_Box.hxx>
20 //
21 #include <TopoDS_Shape.hxx>
22 #include <TopoDS_Vertex.hxx>
23 #include <TopoDS.hxx>
24 #include <BRep_Tool.hxx>
25
26 #include <NCollection_UBTreeFiller.hxx>
27 #include <BOPCol_BoxBndTree.hxx>
28 #include <BOPDS_IndexRange.hxx>
29 #include <BOPDS_PassKeyBoolean.hxx>
30 #include <BOPDS_MapOfPassKeyBoolean.hxx>
31 #include <BOPDS_DS.hxx>
32
33 #include <BOPCol_IndexedDataMapOfShapeBox.hxx>
34 #include <BOPDS_Tools.hxx>
35 #include <BOPCol_DataMapOfShapeInteger.hxx>
36 #include <BOPCol_DataMapOfIntegerInteger.hxx>
37 #include <BOPCol_DataMapOfIntegerListOfInteger.hxx>
38 #include <BOPCol_IndexedMapOfInteger.hxx>
39 #include <BOPDS_ShapeInfo.hxx>
40 #include <BOPCol_ListOfInteger.hxx>
41 #include <BOPCol_IndexedMapOfInteger.hxx>
42
43 //=======================================================================
44 //function : 
45 //purpose  : 
46 //=======================================================================
47 BOPDS_IteratorSI::BOPDS_IteratorSI()
48 :
49   BOPDS_Iterator()
50 {
51 }
52 //=======================================================================
53 //function : 
54 //purpose  : 
55 //=======================================================================
56 BOPDS_IteratorSI::BOPDS_IteratorSI
57   (const Handle(NCollection_BaseAllocator)& theAllocator)
58 :
59   BOPDS_Iterator(theAllocator)
60 {
61 }
62 //=======================================================================
63 //function : ~
64 //purpose  : 
65 //=======================================================================
66 BOPDS_IteratorSI::~BOPDS_IteratorSI()
67 {
68 }
69 //=======================================================================
70 // function: UpdateByLevelOfCheck
71 // purpose: 
72 //=======================================================================
73 void BOPDS_IteratorSI::UpdateByLevelOfCheck(const Standard_Integer theLevel)
74 {
75   Standard_Integer i, aNbInterfTypes;
76   //
77   aNbInterfTypes=BOPDS_DS::NbInterfTypes();
78   for (i=theLevel+1; i<aNbInterfTypes; ++i) {
79     myLists(i).Clear();
80   }
81 }
82 //=======================================================================
83 // function: Intersect
84 // purpose: 
85 //=======================================================================
86 void BOPDS_IteratorSI::Intersect()
87 {
88   Standard_Boolean bFlag;
89   Standard_Integer aNbS, i, aNbB;
90   Standard_Integer aNbSD, iX, j, iDS, jB;
91   TopAbs_ShapeEnum aTi, aTj;
92   Handle(NCollection_IncAllocator) aAllocator;
93   BOPCol_ListIteratorOfListOfInteger aIt;
94   BOPCol_DataMapIteratorOfDataMapOfIntegerListOfInteger aItVSD;
95   //
96   //-----------------------------------------------------scope_1 f
97   aAllocator=new NCollection_IncAllocator();
98   //
99   BOPCol_DataMapOfShapeInteger aMSI(100, aAllocator);
100   BOPCol_DataMapOfIntegerInteger aMII(100, aAllocator);
101   BOPDS_MapOfPassKeyBoolean aMPA(100, aAllocator);
102   BOPDS_MapOfPassKeyBoolean aMPKXB(100, aAllocator);
103   BOPCol_IndexedDataMapOfShapeBox aMSB(100, aAllocator);
104   BOPDS_PassKeyBoolean aPKXB; 
105   //
106   BOPCol_BoxBndTreeSelector aSelector;
107   BOPCol_BoxBndTree aBBTree;
108   NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
109   //
110   // myPairsAvoid, aMSI, aMSB
111   aNbS=myDS->NbSourceShapes();
112   for (i=0; i<aNbS; ++i) {
113     const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
114     //
115     if (!aSI.IsInterfering()) { 
116       continue;
117     }
118     //
119     const TopoDS_Shape& aSi=aSI.Shape();
120     aTi=aSI.ShapeType();
121     if (aTi!=TopAbs_VERTEX) {
122       const BOPCol_ListOfInteger& aLA=aSI.SubShapes();
123       aIt.Initialize(aLA);
124       for (; aIt.More(); aIt.Next()) {
125         iX=aIt.Value();
126         aPKXB.Clear();
127         aPKXB.SetIds(i, iX);
128         aMPA.Add(aPKXB);
129       }
130     }
131     //
132     aPKXB.Clear();
133     aPKXB.SetIds(i, i);
134     aMPA.Add(aPKXB);
135     //
136     const Bnd_Box& aBoxEx=aSI.Box();
137     //
138     aMSI.Bind(aSi, i);
139     aMSB.Add(aSi, aBoxEx);
140   } // for (i=0; i<aNbS; ++i) {
141   // 
142   // aMII
143   aNbB=aMSB.Extent();
144   for (i=1; i<=aNbB; ++i) {
145     const TopoDS_Shape& aS=aMSB.FindKey(i);
146     const Bnd_Box& aBoxEx=aMSB(i);
147     //
148     aTreeFiller.Add(i, aBoxEx);
149     //
150     iDS=aMSI.Find(aS);
151     aMII.Bind(i, iDS);
152   }
153   //
154   aTreeFiller.Fill();
155   //
156   for (i=0; i<aNbS; ++i) {
157     const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
158     aTi=aSI.ShapeType();
159     if (!aSI.IsInterfering()){
160       continue;
161     }
162     //
163     const TopoDS_Shape& aSi=myDS->Shape(i);
164     aTi=aSi.ShapeType();
165     const Bnd_Box& aBoxEx=aMSB.FindFromKey(aSi);
166     aSelector.Clear();
167     aSelector.SetBox(aBoxEx);
168     //
169     aNbSD=aBBTree.Select(aSelector);
170     if (!aNbSD){
171       continue;
172     }
173     //
174     const BOPCol_ListOfInteger& aLI=aSelector.Indices();
175     //
176     aIt.Initialize(aLI);
177     for (; aIt.More(); aIt.Next()) {
178       jB=aIt.Value();  // box index in MII
179       j=aMII.Find(jB); // DS index
180       //
181       aPKXB.SetIds(i, j);
182       if (aMPA.Contains(aPKXB)) {
183         continue;
184       }
185       //
186       if (aMPKXB.Add(aPKXB)) {
187         bFlag=Standard_False;// Bounding boxes are intersected
188         const Bnd_Box& aBoxi=myDS->ShapeInfo(i).Box();
189         const Bnd_Box& aBoxj=myDS->ShapeInfo(j).Box();
190         if (aBoxi.IsOut(aBoxj)) {
191           bFlag=!bFlag; //Bounding boxes of Sub-shapes are intersected
192         }
193         aTj=myDS->ShapeInfo(j).ShapeType();//
194         iX=BOPDS_Tools::TypeToInteger(aTi, aTj);
195         aPKXB.SetFlag(bFlag);
196         myLists(iX).Append(aPKXB);
197       }// if (aMPKXB.Add(aPKXB)) {
198     }// for (; aIt.More(); aIt.Next()) {
199   }//for (i=1; i<=aNbS; ++i) {
200   //
201   aMSI.Clear();
202   aMII.Clear();
203   aMPA.Clear();
204   aMPKXB.Clear();
205   aMSB.Clear();
206   //
207   aAllocator.Nullify();
208   //-----------------------------------------------------scope_1 t
209 }