b311480e |
1 | // Created by: Peter KURNEV |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
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. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
7fd59977 |
14 | |
42cf5bc1 |
15 | |
42cf5bc1 |
16 | #include <BOPTools_Set.hxx> |
17 | #include <BRep_Tool.hxx> |
98730279 |
18 | #include <TopExp_Explorer.hxx> |
19 | #include <TopoDS_Edge.hxx> |
42cf5bc1 |
20 | #include <TopoDS_Shape.hxx> |
1155d05a |
21 | #include <TopTools_MapOfShape.hxx> |
98730279 |
22 | |
23 | static |
24 | Standard_Integer NormalizedIds(const Standard_Integer aId, |
25 | const Standard_Integer aDiv); |
26 | |
27 | //======================================================================= |
28 | //function : |
29 | //purpose : |
30 | //======================================================================= |
31 | BOPTools_Set::BOPTools_Set() |
32 | : |
33 | myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()), |
34 | myShapes(myAllocator) |
35 | { |
36 | myNbShapes=0; |
37 | mySum=0; |
38 | myUpper=432123; |
39 | } |
40 | //======================================================================= |
41 | //function : |
42 | //purpose : |
43 | //======================================================================= |
44 | BOPTools_Set::BOPTools_Set |
45 | (const Handle(NCollection_BaseAllocator)& theAllocator) |
46 | : |
47 | myAllocator(theAllocator), |
48 | myShapes(myAllocator) |
49 | { |
50 | myNbShapes=0; |
51 | mySum=0; |
52 | myUpper=432123; |
53 | } |
158f2931 |
54 | |
55 | //======================================================================= |
56 | //function : BOPTools_Set |
57 | //purpose : |
58 | //======================================================================= |
59 | BOPTools_Set::BOPTools_Set (const BOPTools_Set& theOther) |
60 | : myAllocator(theOther.myAllocator), |
61 | myShape (theOther.myShape), |
62 | myNbShapes (theOther.myNbShapes), |
63 | mySum (theOther.mySum), |
64 | myUpper (theOther.myUpper) |
65 | { |
66 | for (TopTools_ListIteratorOfListOfShape aIt (theOther.myShapes); aIt.More(); aIt.Next()) |
67 | { |
68 | const TopoDS_Shape& aShape = aIt.Value(); |
69 | myShapes.Append (aShape); |
70 | } |
71 | } |
72 | |
98730279 |
73 | //======================================================================= |
74 | //function :~ |
75 | //purpose : |
76 | //======================================================================= |
77 | BOPTools_Set::~BOPTools_Set() |
78 | { |
79 | Clear(); |
80 | } |
81 | //======================================================================= |
82 | //function : Clear |
83 | //purpose : |
84 | //======================================================================= |
85 | void BOPTools_Set::Clear() |
86 | { |
87 | myNbShapes=0; |
88 | mySum=0; |
89 | myShapes.Clear(); |
90 | } |
91 | //======================================================================= |
92 | //function : NbShapes |
93 | //purpose : |
94 | //======================================================================= |
95 | Standard_Integer BOPTools_Set::NbShapes()const |
96 | { |
97 | return myNbShapes; |
98 | } |
99 | //======================================================================= |
100 | //function :Assign |
101 | //purpose : |
102 | //======================================================================= |
103 | BOPTools_Set& BOPTools_Set::Assign(const BOPTools_Set& theOther) |
104 | { |
1155d05a |
105 | TopTools_ListIteratorOfListOfShape aIt; |
98730279 |
106 | // |
107 | myShape=theOther.myShape; |
108 | myNbShapes=theOther.myNbShapes; |
109 | mySum=theOther.mySum; |
110 | myUpper=theOther.myUpper; |
111 | myAllocator=theOther.myAllocator; |
112 | // |
113 | myShapes.Clear(); |
114 | aIt.Initialize(theOther.myShapes); |
115 | for (; aIt.More(); aIt.Next()) { |
116 | const TopoDS_Shape& aSx=aIt.Value(); |
117 | myShapes.Append(aSx); |
118 | } |
119 | return *this; |
120 | } |
121 | //======================================================================= |
122 | //function : Shape |
123 | //purpose : |
124 | //======================================================================= |
125 | const TopoDS_Shape& BOPTools_Set::Shape()const |
126 | { |
127 | return myShape; |
128 | } |
2b2be3fb |
129 | |
98730279 |
130 | //======================================================================= |
2b2be3fb |
131 | // function : HashCode |
132 | // purpose : |
98730279 |
133 | //======================================================================= |
2b2be3fb |
134 | Standard_Integer BOPTools_Set::HashCode (const Standard_Integer theUpperBound) const |
98730279 |
135 | { |
2b2be3fb |
136 | return ::HashCode (mySum, theUpperBound); |
98730279 |
137 | } |
2b2be3fb |
138 | |
98730279 |
139 | //======================================================================= |
140 | //function : IsEqual |
141 | //purpose : |
142 | //======================================================================= |
143 | Standard_Boolean BOPTools_Set::IsEqual |
144 | (const BOPTools_Set& theOther)const |
145 | { |
146 | Standard_Boolean bRet; |
147 | // |
148 | bRet=Standard_False; |
149 | // |
150 | if (theOther.myNbShapes!=myNbShapes) { |
151 | return bRet; |
152 | } |
153 | // |
1155d05a |
154 | TopTools_MapOfShape aM1; |
155 | TopTools_ListIteratorOfListOfShape aIt; |
98730279 |
156 | // |
157 | aIt.Initialize(myShapes); |
158 | for (; aIt.More(); aIt.Next()) { |
159 | const TopoDS_Shape& aSx1=aIt.Value(); |
160 | aM1.Add(aSx1); |
161 | } |
162 | // |
163 | aIt.Initialize(theOther.myShapes); |
164 | for (; aIt.More(); aIt.Next()) { |
165 | const TopoDS_Shape& aSx2=aIt.Value(); |
166 | if (!aM1.Contains(aSx2)) { |
167 | return bRet; |
168 | } |
169 | } |
170 | // |
171 | return !bRet; |
172 | } |
173 | //======================================================================= |
174 | //function : Add |
175 | //purpose : |
176 | //======================================================================= |
177 | void BOPTools_Set::Add(const TopoDS_Shape& theS, |
178 | const TopAbs_ShapeEnum theType) |
179 | { |
180 | Standard_Integer aId, aIdN; |
19dcfc1b |
181 | TopAbs_Orientation aOr; |
98730279 |
182 | TopExp_Explorer aExp; |
183 | // |
184 | myShape=theS; |
185 | myShapes.Clear(); |
186 | myNbShapes=0; |
187 | mySum=0; |
188 | // |
189 | aExp.Init(theS, theType); |
190 | for (; aExp.More(); aExp.Next()) { |
191 | const TopoDS_Shape& aSx=aExp.Current(); |
192 | if (theType==TopAbs_EDGE) { |
193 | const TopoDS_Edge& aEx=*((TopoDS_Edge*)&aSx); |
194 | if (BRep_Tool::Degenerated(aEx)) { |
195 | continue; |
196 | } |
197 | } |
19dcfc1b |
198 | // |
199 | aOr=aSx.Orientation(); |
200 | if (aOr==TopAbs_INTERNAL) { |
201 | TopoDS_Shape aSy; |
202 | // |
203 | aSy=aSx; |
204 | // |
205 | aSy.Orientation(TopAbs_FORWARD); |
206 | myShapes.Append(aSy); |
207 | // |
208 | aSy.Orientation(TopAbs_REVERSED); |
209 | myShapes.Append(aSy); |
210 | } |
211 | else { |
212 | myShapes.Append(aSx); |
213 | } |
98730279 |
214 | } |
215 | // |
216 | myNbShapes=myShapes.Extent(); |
217 | if (!myNbShapes) { |
218 | return; |
219 | } |
220 | // |
1155d05a |
221 | TopTools_ListIteratorOfListOfShape aIt; |
98730279 |
222 | // |
223 | aIt.Initialize(myShapes); |
224 | for (; aIt.More(); aIt.Next()) { |
225 | const TopoDS_Shape& aSx=aIt.Value(); |
226 | aId=aSx.HashCode(myUpper); |
227 | aIdN=NormalizedIds(aId, myNbShapes); |
228 | mySum+=aIdN; |
229 | } |
230 | } |
231 | //======================================================================= |
232 | // function: NormalizedIds |
233 | // purpose : |
234 | //======================================================================= |
235 | Standard_Integer NormalizedIds(const Standard_Integer aId, |
236 | const Standard_Integer aDiv) |
237 | { |
238 | Standard_Integer aMax, aTresh, aIdRet; |
239 | // |
240 | aIdRet=aId; |
241 | aMax=::IntegerLast(); |
242 | aTresh=aMax/aDiv; |
243 | if (aId>aTresh) { |
244 | aIdRet=aId%aTresh; |
245 | } |
246 | return aIdRet; |
247 | } |