1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // File: NMTDS_IteratorChecker.cxx
20 // Author: Peter KURNEV
22 #include <NMTDS_IteratorCheckerSI.ixx>
24 #include <TopAbs_ShapeEnum.hxx>
26 #include <Bnd_Box.hxx>
28 #include <TopoDS_Shape.hxx>
29 #include <TopoDS_Vertex.hxx>
31 #include <BRep_Tool.hxx>
33 #include <TColStd_IndexedMapOfInteger.hxx>
34 #include <TColStd_ListOfInteger.hxx>
35 #include <TColStd_DataMapOfIntegerInteger.hxx>
36 #include <TColStd_ListIteratorOfListOfInteger.hxx>
37 #include <TColStd_MapOfInteger.hxx>
38 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
39 #include <TColStd_DataMapOfIntegerListOfInteger.hxx>
40 #include <TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger.hxx>
42 #include <TopTools_DataMapOfShapeInteger.hxx>
44 #include <NCollection_UBTreeFiller.hxx>
45 #include <NMTDS_BoxBndTree.hxx>
46 #include <NMTDS_ShapesDataStructure.hxx>
47 #include <NMTDS_CArray1OfIndexRange.hxx>
48 #include <NMTDS_IndexRange.hxx>
49 #include <NMTDS_PairBoolean.hxx>
50 #include <NMTDS_MapOfPairBoolean.hxx>
51 #include <NMTDS_IndexedDataMapOfShapeBox.hxx>
52 #include <NMTDS_Tools.hxx>
54 //=======================================================================
57 //=======================================================================
58 NMTDS_IteratorCheckerSI::NMTDS_IteratorCheckerSI()
63 //=======================================================================
66 //=======================================================================
67 NMTDS_IteratorCheckerSI::~NMTDS_IteratorCheckerSI()
70 //=======================================================================
71 // function: Intersect
73 //=======================================================================
74 void NMTDS_IteratorCheckerSI::Intersect()
76 Standard_Boolean bFlag;
77 Standard_Integer aNbS, i, aNbA, aNbB, iFlag;
78 Standard_Integer aNbSD, iX, j, iDS, jB, k, aNbLV;
79 TColStd_ListIteratorOfListOfInteger aIt;
80 TColStd_DataMapOfIntegerInteger aMII;
81 TColStd_DataMapOfIntegerListOfInteger aMVSD;
82 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger aItVSD;
83 TopTools_DataMapOfShapeInteger aMSI;
84 TopAbs_ShapeEnum aTi, aTj;
85 NMTDS_PairBoolean aPKXB;
86 NMTDS_MapOfPairBoolean aMPKXB;
87 NMTDS_IndexedDataMapOfShapeBox aMSB;
88 NMTDS_MapOfPairBoolean aMPA;//myPairsAvoid
90 NMTDS_BoxBndTreeSelector aSelector;
91 NMTDS_BoxBndTree aBBTree;
92 NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
94 aNbS=myDS->NumberOfShapesOfTheObject();
96 // myPairsAvoid, aMSI, aMSB
97 for (i=1; i<=aNbS; ++i) {
98 const TopoDS_Shape& aSi=myDS->Shape(i);
100 if (NMTDS_Tools::HasBRep(aTi)) {
101 if (aTi!=TopAbs_VERTEX) {
102 TColStd_IndexedMapOfInteger aMA;
104 myDS->GetAllSuccessors(i, aMA);
107 for (j=1; j<=aNbA; ++j) {
122 myDS->ComputeBoxEx(i, aBoxEx);
124 aMSB.Add(aSi, aBoxEx);
130 for (i=1; i<=aNbB; ++i) {
131 const TopoDS_Shape& aS=aMSB.FindKey(i);
132 const Bnd_Box& aBoxEx=aMSB(i);
134 aTreeFiller.Add(i, aBoxEx);
142 for (i=1; i<=aNbS; ++i) {
143 const TopoDS_Shape& aSi=myDS->Shape(i);
145 if (!NMTDS_Tools::HasBRep(aTi)){
148 const Bnd_Box& aBoxEx=aMSB.FindFromKey(aSi);
150 aSelector.SetBox(aBoxEx);
152 aNbSD=aBBTree.Select(aSelector);
157 const TColStd_ListOfInteger& aLI=aSelector.Indices();
160 TColStd_ListOfInteger aLV;
163 for (; aIt.More(); aIt.Next()) {
164 jB=aIt.Value(); // box index in MII
165 j=aMII.Find(jB); // DS index
168 if (aMPA.Contains(aPKXB)) {
172 if (aMPKXB.Add(aPKXB)) {
173 bFlag=Standard_False;// Bounding boxes are intersected
174 const Bnd_Box& aBoxi=myDS->GetBoundingBox(i);
175 const Bnd_Box& aBoxj=myDS->GetBoundingBox(j);
176 if (aBoxi.IsOut(aBoxj)) {
177 bFlag=!bFlag; //Bounding boxes of Sub-shapes are intersected
179 const TopoDS_Shape& aSj=myDS->Shape(j);
181 iX=NMTDS_Tools::TypeToInteger(aTi, aTj);
182 //bFlag=(iStatus==2);
183 aPKXB.SetFlag(bFlag);
184 myLists[iX].Append(aPKXB);
190 }// if (aMPKXB.Add(aPKXB)) {
191 }// for (; aIt.More(); aIt.Next()) {
196 TColStd_ListOfInteger aLV1;
198 const TopoDS_Vertex& aVi=TopoDS::Vertex(aSi);
200 for (; aIt.More(); aIt.Next()) {
202 const TopoDS_Shape& aSj=myDS->Shape(j);
203 const TopoDS_Vertex& aVj=TopoDS::Vertex(aSj);
204 iFlag=NMTDS_Tools::ComputeVV(aVi, aVj);
210 aMPKXB.Remove(aPKXB);
215 }//for (i=1; i<=aNbS; ++i) {
221 NMTDS_Iterator::FillMVSD(aMVSD, myMVSD);