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 | #include <Bnd_Box.hxx> |
944768d2 |
16 | #include <Bnd_OBB.hxx> |
9324aa2d |
17 | #include <Bnd_Tools.hxx> |
42cf5bc1 |
18 | #include <BOPDS_DS.hxx> |
19 | #include <BOPDS_IndexRange.hxx> |
20 | #include <BOPDS_IteratorSI.hxx> |
25dfc507 |
21 | #include <BOPDS_MapOfPair.hxx> |
22 | #include <BOPDS_Pair.hxx> |
42cf5bc1 |
23 | #include <BOPDS_ShapeInfo.hxx> |
24 | #include <BOPDS_Tools.hxx> |
9324aa2d |
25 | #include <BOPTools_BoxTree.hxx> |
42cf5bc1 |
26 | #include <BRep_Tool.hxx> |
27 | #include <gp_Pnt.hxx> |
944768d2 |
28 | #include <IntTools_Context.hxx> |
42cf5bc1 |
29 | #include <TopAbs_ShapeEnum.hxx> |
1155d05a |
30 | #include <TColStd_DataMapOfIntegerInteger.hxx> |
31 | #include <TColStd_DataMapOfIntegerListOfInteger.hxx> |
32 | #include <TColStd_ListOfInteger.hxx> |
42cf5bc1 |
33 | #include <TopoDS.hxx> |
34 | #include <TopoDS_Shape.hxx> |
35 | #include <TopoDS_Vertex.hxx> |
1155d05a |
36 | #include <TopTools_DataMapOfShapeInteger.hxx> |
4e57c75e |
37 | |
42cf5bc1 |
38 | // |
4e57c75e |
39 | //======================================================================= |
40 | //function : |
41 | //purpose : |
42 | //======================================================================= |
ceaa5e27 |
43 | BOPDS_IteratorSI::BOPDS_IteratorSI() |
4e57c75e |
44 | : |
45 | BOPDS_Iterator() |
46 | { |
47 | } |
48 | //======================================================================= |
49 | //function : |
50 | //purpose : |
51 | //======================================================================= |
ceaa5e27 |
52 | BOPDS_IteratorSI::BOPDS_IteratorSI |
53 | (const Handle(NCollection_BaseAllocator)& theAllocator) |
4e57c75e |
54 | : |
55 | BOPDS_Iterator(theAllocator) |
56 | { |
57 | } |
58 | //======================================================================= |
59 | //function : ~ |
60 | //purpose : |
61 | //======================================================================= |
ceaa5e27 |
62 | BOPDS_IteratorSI::~BOPDS_IteratorSI() |
4e57c75e |
63 | { |
64 | } |
65 | //======================================================================= |
ceaa5e27 |
66 | // function: UpdateByLevelOfCheck |
67 | // purpose: |
68 | //======================================================================= |
69 | void BOPDS_IteratorSI::UpdateByLevelOfCheck(const Standard_Integer theLevel) |
70 | { |
71 | Standard_Integer i, aNbInterfTypes; |
72 | // |
73 | aNbInterfTypes=BOPDS_DS::NbInterfTypes(); |
74 | for (i=theLevel+1; i<aNbInterfTypes; ++i) { |
75 | myLists(i).Clear(); |
76 | } |
77 | } |
78 | //======================================================================= |
4e57c75e |
79 | // function: Intersect |
80 | // purpose: |
81 | //======================================================================= |
9324aa2d |
82 | void BOPDS_IteratorSI::Intersect (const Handle(IntTools_Context)& theCtx, |
83 | const Standard_Boolean theCheckOBB, |
84 | const Standard_Real theFuzzyValue) |
4e57c75e |
85 | { |
9324aa2d |
86 | const Standard_Integer aNbS = myDS->NbSourceShapes(); |
87 | |
88 | BOPTools_BoxTree aBBTree; |
89 | aBBTree.SetSize (aNbS); |
90 | |
91 | for (Standard_Integer i = 0; i < aNbS; ++i) |
92 | { |
93 | const BOPDS_ShapeInfo& aSI = myDS->ShapeInfo (i); |
94 | if (!aSI.IsInterfering()) |
ceaa5e27 |
95 | continue; |
9324aa2d |
96 | |
25dfc507 |
97 | const Bnd_Box& aBoxEx = aSI.Box(); |
9324aa2d |
98 | aBBTree.Add (i, Bnd_Tools::Bnd2BVH (aBoxEx)); |
4e57c75e |
99 | } |
9324aa2d |
100 | |
101 | aBBTree.Build(); |
102 | |
103 | // Select pairs of shapes with interfering bounding boxes |
104 | BOPTools_BoxPairSelector aPairSelector; |
105 | aPairSelector.SetBVHSets (&aBBTree, &aBBTree); |
106 | aPairSelector.SetSame (Standard_True); |
107 | aPairSelector.Select(); |
108 | aPairSelector.Sort(); |
109 | |
110 | // Treat the selected pairs |
111 | const std::vector<BOPTools_BoxPairSelector::PairIDs>& aPairs = aPairSelector.Pairs(); |
112 | const Standard_Integer aNbPairs = static_cast<Standard_Integer> (aPairs.size()); |
113 | |
114 | for (Standard_Integer iPair = 0; iPair < aNbPairs; ++iPair) |
115 | { |
116 | const BOPTools_BoxPairSelector::PairIDs& aPair = aPairs[iPair]; |
117 | |
118 | const BOPDS_ShapeInfo& aSI1 = myDS->ShapeInfo (aPair.ID1); |
119 | const BOPDS_ShapeInfo& aSI2 = myDS->ShapeInfo (aPair.ID2); |
120 | |
121 | const TopAbs_ShapeEnum aType1 = aSI1.ShapeType(); |
122 | const TopAbs_ShapeEnum aType2 = aSI2.ShapeType(); |
123 | |
124 | Standard_Integer iType1 = BOPDS_Tools::TypeToInteger (aType1); |
125 | Standard_Integer iType2 = BOPDS_Tools::TypeToInteger (aType2); |
126 | |
127 | // avoid interfering of the shape with its sub-shapes |
128 | if (((iType1 < iType2) && aSI1.HasSubShape (aPair.ID2)) || |
129 | ((iType1 > iType2) && aSI2.HasSubShape (aPair.ID1))) |
4e57c75e |
130 | continue; |
9324aa2d |
131 | |
132 | if (theCheckOBB) |
133 | { |
134 | // Check intersection of Oriented bounding boxes of the shapes |
135 | const Bnd_OBB& anOBB1 = theCtx->OBB (aSI1.Shape (), theFuzzyValue); |
136 | const Bnd_OBB& anOBB2 = theCtx->OBB (aSI2.Shape (), theFuzzyValue); |
137 | |
138 | if (anOBB1.IsOut (anOBB2)) |
4e57c75e |
139 | continue; |
9324aa2d |
140 | } |
141 | |
142 | Standard_Integer iX = BOPDS_Tools::TypeToInteger (aType1, aType2); |
143 | myLists(iX).Append (BOPDS_Pair (Min (aPair.ID1, aPair.ID2), |
144 | Max (aPair.ID1, aPair.ID2))); |
145 | } |
4e57c75e |
146 | } |