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