2c3b2e0983673762ce1350e2f6b7c2b0ad471ca2
[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 <BOPDS_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(const Handle(NCollection_BaseAllocator)& theAllocator)
57 :
58   BOPDS_Iterator(theAllocator)
59 {
60 }
61 //=======================================================================
62 //function : ~
63 //purpose  : 
64 //=======================================================================
65   BOPDS_IteratorSI::~BOPDS_IteratorSI()
66 {
67 }
68 //=======================================================================
69 // function: Intersect
70 // purpose: 
71 //=======================================================================
72   void BOPDS_IteratorSI::Intersect()
73 {
74   Standard_Boolean bFlag;
75   Standard_Integer aNbS, i, aNbB;//, iFlag, aNbLV, aNbA
76   Standard_Integer aNbSD, iX, j, iDS, jB, k;;
77   TopAbs_ShapeEnum aTi, aTj;
78   Handle(NCollection_IncAllocator) aAllocator;
79   BOPCol_ListIteratorOfListOfInteger aIt;
80   BOPCol_DataMapIteratorOfDataMapOfIntegerListOfInteger aItVSD;
81   //
82   //-----------------------------------------------------scope_1 f
83   aAllocator=new NCollection_IncAllocator();
84   //
85   BOPCol_DataMapOfShapeInteger aMSI(100, aAllocator);
86   BOPCol_DataMapOfIntegerInteger aMII(100, aAllocator);
87   BOPDS_MapOfPassKeyBoolean aMPA(100, aAllocator);
88   BOPDS_MapOfPassKeyBoolean aMPKXB(100, aAllocator);
89   BOPCol_IndexedDataMapOfShapeBox aMSB(100, aAllocator);
90   BOPDS_PassKeyBoolean aPKXB; 
91   //
92   BOPDS_BoxBndTreeSelector aSelector;
93   BOPDS_BoxBndTree aBBTree;
94   NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
95   //
96   // myPairsAvoid, aMSI, aMSB
97   aNbS=myDS->NbSourceShapes();
98   for (i=0; i<aNbS; ++i) {
99     const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
100     //
101     if (aSI.HasBRep()) {
102       const TopoDS_Shape& aSi=aSI.Shape();
103       aTi=aSI.ShapeType();
104       if (aTi!=TopAbs_VERTEX) {
105         const BOPCol_ListOfInteger& aLA=aSI.SubShapes();
106         aIt.Initialize(aLA);
107         for (; aIt.More(); aIt.Next()) {
108           iX=aIt.Value();
109           aPKXB.Clear();
110           aPKXB.SetIds(i, iX);
111           aMPA.Add(aPKXB);
112         }
113       }
114       //
115       aPKXB.Clear();
116       aPKXB.SetIds(i, i);
117       aMPA.Add(aPKXB);
118       //
119       const Bnd_Box& aBoxEx=aSI.Box();
120       //
121       aMSI.Bind(aSi, i);
122       aMSB.Add(aSi, aBoxEx);
123     }
124   } // for (i=0; i<aNbS; ++i) {
125   // 
126   // aMII
127   aNbB=aMSB.Extent();
128   for (i=1; i<=aNbB; ++i) {
129     const TopoDS_Shape& aS=aMSB.FindKey(i);
130     const Bnd_Box& aBoxEx=aMSB(i);
131     //
132     aTreeFiller.Add(i, aBoxEx);
133     //
134     iDS=aMSI.Find(aS);
135     aMII.Bind(i, iDS);
136   }
137   //
138   aTreeFiller.Fill();
139   //
140   for (i=0; i<aNbS; ++i) {
141     const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
142     aTi=aSI.ShapeType();
143     if (!aSI.HasBRep()){
144       continue;
145     }
146     //
147     const TopoDS_Shape& aSi=myDS->Shape(i);
148     aTi=aSi.ShapeType();
149     const Bnd_Box& aBoxEx=aMSB.FindFromKey(aSi);
150     aSelector.Clear();
151     aSelector.SetBox(aBoxEx);
152     //
153     aNbSD=aBBTree.Select(aSelector);
154     if (!aNbSD){
155       continue;
156     }
157     //
158     const BOPCol_ListOfInteger& aLI=aSelector.Indices();
159     //
160     k=0;
161     //
162     aIt.Initialize(aLI);
163     for (; aIt.More(); aIt.Next()) {
164       jB=aIt.Value();  // box index in MII
165       j=aMII.Find(jB); // DS index
166       //
167       aPKXB.SetIds(i, j);
168       if (aMPA.Contains(aPKXB)) {
169         continue;
170       }
171       //
172       if (aMPKXB.Add(aPKXB)) {
173         bFlag=Standard_False;// Bounding boxes are intersected
174         const Bnd_Box& aBoxi=myDS->ShapeInfo(i).Box();
175         const Bnd_Box& aBoxj=myDS->ShapeInfo(j).Box();
176         if (aBoxi.IsOut(aBoxj)) {
177           bFlag=!bFlag; //Bounding boxes of Sub-shapes are intersected
178         }
179         aTj=myDS->ShapeInfo(j).ShapeType();//
180         iX=BOPDS_Tools::TypeToInteger(aTi, aTj);
181         aPKXB.SetFlag(bFlag);
182         myLists(iX).Append(aPKXB);
183       }// if (aMPKXB.Add(aPKXB)) {
184     }// for (; aIt.More(); aIt.Next()) {
185   }//for (i=1; i<=aNbS; ++i) {
186   //
187   aMSI.Clear();
188   aMII.Clear();
189   aMPA.Clear();
190   aMPKXB.Clear();
191   aMSB.Clear();
192   //
193   aAllocator.Nullify();
194   //-----------------------------------------------------scope_1 t
195 }
196
197 //=======================================================================
198 // function: UpdateByLevelOfCheck
199 // purpose: 
200 //=======================================================================
201   void BOPDS_IteratorSI::UpdateByLevelOfCheck(const Standard_Integer theLevel)
202 {
203   Standard_Integer i;
204   //
205   for (i=theLevel+1; i<6; ++i) {
206     myLists(i).Clear();
207   }
208 }