| 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 | |
| 16 | #include <Bnd_Box.hxx> |
| 17 | #include <BOPCol_BoxBndTree.hxx> |
| 18 | #include <BOPCol_DataMapOfIntegerInteger.hxx> |
| 19 | #include <BOPCol_DataMapOfIntegerListOfInteger.hxx> |
| 20 | #include <BOPCol_DataMapOfShapeInteger.hxx> |
| 21 | #include <BOPCol_IndexedDataMapOfShapeBox.hxx> |
| 22 | #include <BOPCol_IndexedMapOfInteger.hxx> |
| 23 | #include <BOPCol_ListOfInteger.hxx> |
| 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> |
| 39 | |
| 40 | // |
| 41 | //======================================================================= |
| 42 | //function : |
| 43 | //purpose : |
| 44 | //======================================================================= |
| 45 | BOPDS_IteratorSI::BOPDS_IteratorSI() |
| 46 | : |
| 47 | BOPDS_Iterator() |
| 48 | { |
| 49 | } |
| 50 | //======================================================================= |
| 51 | //function : |
| 52 | //purpose : |
| 53 | //======================================================================= |
| 54 | BOPDS_IteratorSI::BOPDS_IteratorSI |
| 55 | (const Handle(NCollection_BaseAllocator)& theAllocator) |
| 56 | : |
| 57 | BOPDS_Iterator(theAllocator) |
| 58 | { |
| 59 | } |
| 60 | //======================================================================= |
| 61 | //function : ~ |
| 62 | //purpose : |
| 63 | //======================================================================= |
| 64 | BOPDS_IteratorSI::~BOPDS_IteratorSI() |
| 65 | { |
| 66 | } |
| 67 | //======================================================================= |
| 68 | // function: UpdateByLevelOfCheck |
| 69 | // purpose: |
| 70 | //======================================================================= |
| 71 | void 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 | //======================================================================= |
| 81 | // function: Intersect |
| 82 | // purpose: |
| 83 | //======================================================================= |
| 84 | void BOPDS_IteratorSI::Intersect() |
| 85 | { |
| 86 | Standard_Boolean bFlag; |
| 87 | Standard_Integer aNbS, i, aNbB; |
| 88 | Standard_Integer aNbSD, iX, j, iDS, jB; |
| 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 | // |
| 104 | BOPCol_BoxBndTreeSelector aSelector; |
| 105 | BOPCol_BoxBndTree aBBTree; |
| 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 | // |
| 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); |
| 127 | } |
| 128 | } |
| 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); |
| 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(); |
| 157 | if (!aSI.IsInterfering()){ |
| 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(); |
| 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 | } |