b311480e |
1 | // Created on: 2001-11-02 |
2 | // Created by: Peter KURNEV |
3 | // Copyright (c) 2001-2012 OPEN CASCADE SAS |
4 | // |
5 | // The content of this file is subject to the Open CASCADE Technology Public |
6 | // License Version 6.5 (the "License"). You may not use the content of this file |
7 | // except in compliance with the License. Please obtain a copy of the License |
8 | // at http://www.opencascade.org and read it completely before using this file. |
9 | // |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
12 | // |
13 | // The Original Code and all software distributed under the License is |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
15 | // Initial Developer hereby disclaims all such warranties, including without |
16 | // limitation, any warranties of merchantability, fitness for a particular |
17 | // purpose or non-infringement. Please see the License for the specific terms |
18 | // and conditions governing the rights and limitations under the License. |
19 | |
7fd59977 |
20 | |
21 | #include <BOP_BuilderTools.ixx> |
22 | |
23 | #include <TColStd_IndexedMapOfInteger.hxx> |
24 | |
25 | #include <gp_Dir.hxx> |
26 | |
27 | #include <BRepAdaptor_Surface.hxx> |
28 | #include <GeomAbs_SurfaceType.hxx> |
29 | |
30 | #include <TopAbs_State.hxx> |
31 | |
32 | #include <TopoDS_Shape.hxx> |
33 | #include <TopExp.hxx> |
34 | #include <TopExp_Explorer.hxx> |
35 | |
36 | #include <TopTools_ListOfShape.hxx> |
37 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
38 | #include <TopTools_IndexedMapOfOrientedShape.hxx> |
39 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> |
40 | #include <TopTools_IndexedMapOfShape.hxx> |
41 | |
42 | #include <BooleanOperations_StateOfShape.hxx> |
43 | |
44 | #include <BOPTools_Tools3D.hxx> |
45 | #include <BOPTools_SSInterference.hxx> |
46 | |
47 | #include <BOP_ConnexityBlock.hxx> |
48 | #include <BOP_ListOfConnexityBlock.hxx> |
49 | |
50 | //======================================================================= |
51 | // function: StateToCompare |
52 | // purpose: |
53 | //======================================================================= |
b311480e |
54 | BooleanOperations_StateOfShape |
7fd59977 |
55 | BOP_BuilderTools::StateToCompare(const Standard_Integer iRank, |
56 | const BOP_Operation anOp) |
57 | { |
58 | BooleanOperations_StateOfShape aSt=BooleanOperations_UNKNOWN; |
59 | |
60 | if (iRank==1) { |
61 | if (anOp==BOP_COMMON) { |
62 | aSt=BooleanOperations_IN; |
63 | } |
64 | if (anOp==BOP_FUSE) { |
65 | aSt=BooleanOperations_OUT; |
66 | } |
67 | if (anOp==BOP_CUT) { |
68 | aSt=BooleanOperations_OUT; |
69 | } |
70 | if (anOp==BOP_CUT21) { |
71 | aSt=BooleanOperations_IN; |
72 | } |
73 | } |
74 | |
75 | if (iRank==2) { |
76 | if (anOp==BOP_COMMON) { |
77 | aSt=BooleanOperations_IN; |
78 | } |
79 | if (anOp==BOP_FUSE) { |
80 | aSt=BooleanOperations_OUT; |
81 | } |
82 | if (anOp==BOP_CUT) { |
83 | aSt=BooleanOperations_IN; |
84 | } |
85 | if (anOp==BOP_CUT21) { |
86 | aSt=BooleanOperations_OUT; |
87 | } |
88 | } |
89 | return aSt; |
90 | } |
91 | //======================================================================= |
92 | // function: ToReverseSection |
93 | // purpose: |
94 | //======================================================================= |
95 | Standard_Boolean BOP_BuilderTools::ToReverseSection(const Standard_Integer iRank, |
96 | const BOP_Operation anOp) |
97 | { |
98 | Standard_Boolean bFlag=Standard_False; |
99 | |
100 | if (iRank==1) { |
101 | if (anOp==BOP_FUSE || anOp==BOP_CUT) { |
102 | bFlag=Standard_True; |
103 | } |
104 | } |
105 | |
106 | if (iRank==2) { |
107 | if (anOp==BOP_FUSE || anOp==BOP_CUT21) { |
108 | bFlag=Standard_True; |
109 | } |
110 | } |
111 | return bFlag; |
112 | } |
113 | //======================================================================= |
114 | // function: ToReverseFace |
115 | // purpose: |
116 | //======================================================================= |
117 | Standard_Boolean BOP_BuilderTools::ToReverseFace(const Standard_Integer iRank, |
118 | const BOP_Operation anOp) |
119 | { |
120 | Standard_Boolean bFlag=Standard_False; |
121 | |
122 | if (iRank==1) { |
123 | if (anOp==BOP_CUT21) { |
124 | bFlag=Standard_True; |
125 | } |
126 | } |
127 | |
128 | if (iRank==2) { |
129 | if (anOp==BOP_CUT) { |
130 | bFlag=Standard_True; |
131 | } |
132 | } |
133 | return bFlag; |
134 | } |
135 | |
136 | //======================================================================= |
137 | // function: OrientSectionEdgeOnF1 |
138 | // purpose: |
139 | //======================================================================= |
140 | void BOP_BuilderTools::OrientSectionEdgeOnF1(const TopoDS_Face& aF1, |
141 | const TopoDS_Face& aF2, |
142 | const Standard_Integer iRankF1, |
143 | const BOP_Operation anOperation, |
144 | TopoDS_Edge& aE) |
145 | { |
146 | TopAbs_Orientation anOr; |
147 | Standard_Boolean bToReverseSection; |
148 | |
149 | anOr=BOPTools_Tools3D::EdgeOrientation(aE, aF1, aF2); |
150 | aE.Orientation(anOr); |
151 | bToReverseSection=BOP_BuilderTools::ToReverseSection(iRankF1, anOperation); |
152 | if (bToReverseSection) { |
153 | aE.Reverse(); |
154 | } |
155 | } |
156 | |
157 | //======================================================================= |
158 | // function: IsSameDomainFaceWithF1 |
159 | // purpose: |
160 | //======================================================================= |
161 | Standard_Boolean |
162 | BOP_BuilderTools::IsSameDomainFaceWithF1(const Standard_Integer nF1, |
163 | const Standard_Integer nF2, |
164 | const TColStd_IndexedMapOfInteger& aFFIndicesMap, |
165 | BOPTools_CArray1OfSSInterference& aFFs) |
166 | { |
167 | Standard_Boolean bIsSDF, bYes; |
168 | Standard_Integer j, aNbj, iFFx, nFx; |
169 | |
170 | bYes=Standard_False; |
171 | aNbj=aFFIndicesMap.Extent(); |
172 | |
173 | for (j=1; j<=aNbj; j++) { |
174 | iFFx=aFFIndicesMap(j); |
175 | BOPTools_SSInterference& aFFx=aFFs(iFFx); |
176 | bIsSDF=aFFx.IsTangentFaces(); |
177 | if (bIsSDF) { |
178 | nFx=aFFx.OppositeIndex(nF1); |
179 | if (nFx==nF2) { |
180 | return !bYes; |
181 | } |
182 | } |
183 | } |
184 | return bYes; |
185 | } |
186 | |
187 | //======================================================================= |
188 | // function: IsPartIN2DToKeep |
189 | // purpose: |
190 | //======================================================================= |
191 | Standard_Boolean |
192 | BOP_BuilderTools::IsPartIN2DToKeep(const TopAbs_State aST1, |
193 | const Standard_Integer iRankF1, |
194 | const BOP_Operation anOp) |
195 | { |
196 | |
197 | |
198 | Standard_Boolean bRetFlag= (aST1==TopAbs_OUT); |
199 | // |
200 | // Same oriented |
201 | if (bRetFlag) { |
202 | if (anOp==BOP_CUT && iRankF1==2) { |
203 | return !bRetFlag; |
204 | } |
205 | |
206 | if (anOp==BOP_CUT21 && iRankF1==1) { |
207 | return !bRetFlag; |
208 | } |
209 | |
210 | if (anOp==BOP_COMMON && iRankF1==2) { |
211 | return !bRetFlag; |
212 | } |
213 | |
214 | if (anOp==BOP_COMMON && iRankF1==1) { |
215 | return !bRetFlag; |
216 | } |
217 | |
218 | return bRetFlag; |
219 | } |
220 | // |
221 | // Different oriented |
222 | else if (!bRetFlag) { |
223 | if (anOp==BOP_FUSE) { |
224 | return bRetFlag; |
225 | } |
226 | |
227 | if (anOp==BOP_CUT && iRankF1==1) { |
228 | return bRetFlag; |
229 | } |
230 | |
231 | if (anOp==BOP_CUT21 && iRankF1==2) { |
232 | return bRetFlag; |
233 | } |
234 | return !bRetFlag; |
235 | } |
236 | return !bRetFlag; |
237 | } |
238 | //======================================================================= |
239 | // function: IsPartOn2dToKeep |
240 | // purpose: |
241 | //======================================================================= |
242 | Standard_Boolean |
243 | BOP_BuilderTools::IsPartOn2dToKeep(const TopAbs_State aST1, |
244 | const Standard_Integer iRankF1, |
245 | const BOP_Operation anOp) |
246 | { |
247 | Standard_Boolean bRetFlag=Standard_False; |
248 | // |
249 | // 1 OUT |
250 | if (aST1==TopAbs_OUT) { |
251 | if (anOp==BOP_FUSE) { |
252 | bRetFlag=Standard_True; |
253 | } |
254 | if (iRankF1==1) { |
255 | if (anOp==BOP_CUT) { |
256 | bRetFlag=Standard_True; |
257 | } |
258 | } |
259 | if (iRankF1==2) { |
260 | if (anOp==BOP_CUT21) { |
261 | bRetFlag=Standard_True; |
262 | } |
263 | } |
264 | } |
265 | // |
266 | // 2 IN |
267 | if (aST1==TopAbs_IN) { |
268 | if (anOp==BOP_COMMON) { |
269 | bRetFlag=Standard_True; |
270 | } |
271 | if (iRankF1==2) { |
272 | if (anOp==BOP_CUT) { |
273 | bRetFlag=Standard_True; |
274 | } |
275 | } |
276 | if (iRankF1==1) { |
277 | if (anOp==BOP_CUT21) { |
278 | bRetFlag=Standard_True; |
279 | } |
280 | } |
281 | } |
282 | return bRetFlag; |
283 | } |
284 | |
285 | //======================================================================= |
286 | // function: DoMap |
287 | // purpose: |
288 | //======================================================================= |
289 | void BOP_BuilderTools::DoMap |
290 | (BOPTools_CArray1OfSSInterference& aFFs, |
291 | BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aFFMap) |
292 | { |
293 | Standard_Integer i, aNb, nF1, nF2; |
294 | // |
295 | // Intersection Map for Faces |
296 | |
297 | aFFMap.Clear(); |
298 | TColStd_IndexedMapOfInteger aFFIndices; |
299 | |
300 | aNb=aFFs.Extent(); |
301 | for (i=1; i<=aNb; i++) { |
302 | BOPTools_SSInterference& aFF=aFFs(i); |
303 | // Faces |
304 | nF1=aFF.Index1(); |
305 | nF2=aFF.Index2(); |
306 | // nF1 |
307 | if (!aFFMap.Contains(nF1)) { |
308 | aFFIndices.Clear(); |
309 | aFFIndices.Add(i); |
310 | aFFMap.Add(nF1, aFFIndices); |
311 | } |
312 | else { |
313 | TColStd_IndexedMapOfInteger& aMF=aFFMap.ChangeFromKey(nF1); |
314 | aMF.Add(i); |
315 | } |
316 | // nF2 |
317 | if (!aFFMap.Contains(nF2)) { |
318 | aFFIndices.Clear(); |
319 | aFFIndices.Add(i); |
320 | aFFMap.Add(nF2, aFFIndices); |
321 | } |
322 | else { |
323 | TColStd_IndexedMapOfInteger& aMF=aFFMap.ChangeFromKey(nF2); |
324 | aMF.Add(i); |
325 | } |
326 | } |
327 | } |
328 | |
329 | //======================================================================= |
330 | // |
331 | static |
332 | void Pathx(const TopoDS_Shape& aVx, |
333 | const TopoDS_Shape& aEx, |
334 | const TopAbs_ShapeEnum aType2, |
335 | const TopTools_IndexedDataMapOfShapeListOfShape& aVEMap, |
336 | TopTools_IndexedMapOfOrientedShape& aProcessedEdges, |
337 | TopTools_IndexedMapOfOrientedShape& aCBMap); |
338 | |
339 | //======================================================================= |
340 | // function: MakeConnexityBlocks |
341 | // purpose: |
342 | //======================================================================= |
343 | void BOP_BuilderTools::MakeConnexityBlocks(const TopTools_ListOfShape& aLEIn, |
344 | const TopAbs_ShapeEnum aType, |
345 | BOP_ListOfConnexityBlock& aLConBlks) |
346 | { |
347 | Standard_Integer i, aNbV, aNbE; |
348 | TopTools_IndexedDataMapOfShapeListOfShape aVEMap; |
349 | TopTools_IndexedMapOfOrientedShape aProcessedEdges, aCBMap; |
350 | TopAbs_ShapeEnum aType2; |
351 | // |
352 | if (aType==TopAbs_EDGE) { |
353 | aType2=TopAbs_VERTEX; |
354 | } |
355 | else if (aType==TopAbs_FACE) { |
356 | aType2=TopAbs_EDGE; |
357 | } |
358 | else { |
359 | return; |
360 | } |
361 | // |
362 | TopTools_ListIteratorOfListOfShape anIt(aLEIn); |
363 | // |
364 | for (; anIt.More(); anIt.Next()) { |
365 | const TopoDS_Shape& aE=anIt.Value(); |
366 | TopExp::MapShapesAndAncestors(aE, aType2, aType, aVEMap); |
367 | } |
368 | // |
369 | aNbV=aVEMap.Extent(); |
370 | for (i=1; i<=aNbV; i++) { |
371 | aCBMap.Clear(); |
372 | |
373 | const TopoDS_Shape& aV=aVEMap.FindKey(i); |
374 | |
375 | const TopTools_ListOfShape& aLE=aVEMap(i); |
376 | anIt.Initialize(aLE); |
377 | for (; anIt.More(); anIt.Next()) { |
378 | const TopoDS_Shape& aE=anIt.Value(); |
379 | if (!aProcessedEdges.Contains(aE)) { |
380 | aProcessedEdges.Add(aE); |
381 | aCBMap.Add(aE); |
382 | Pathx (aV, aE, aType2, aVEMap, aProcessedEdges, aCBMap); |
383 | } |
384 | } |
385 | aNbE=aCBMap.Extent(); |
386 | if (aNbE) { |
387 | BOP_ConnexityBlock aConnexityBlock; |
388 | aConnexityBlock.SetShapes(aCBMap); |
389 | aLConBlks.Append(aConnexityBlock); |
390 | } |
391 | } |
392 | } |
393 | |
394 | //======================================================================= |
395 | // function: Pathx |
396 | // purpose: |
397 | //======================================================================= |
398 | void Pathx(const TopoDS_Shape& aVx, |
399 | const TopoDS_Shape& aEx, |
400 | const TopAbs_ShapeEnum aType2, |
401 | const TopTools_IndexedDataMapOfShapeListOfShape& aVEMap, |
402 | TopTools_IndexedMapOfOrientedShape& aProcessedEdges, |
403 | TopTools_IndexedMapOfOrientedShape& aCBMap) |
404 | { |
405 | TopExp_Explorer anExp(aEx, aType2); |
406 | for (; anExp.More(); anExp.Next()){ |
407 | const TopoDS_Shape& aV=anExp.Current(); |
408 | |
409 | if (aV.IsSame(aVx)){ |
410 | continue; |
411 | } |
412 | |
413 | const TopTools_ListOfShape& aLE=aVEMap.FindFromKey(aV); |
414 | TopTools_ListIteratorOfListOfShape anIt(aLE); |
415 | for (; anIt.More(); anIt.Next()) { |
416 | const TopoDS_Shape& aE=anIt.Value(); |
417 | if (!aProcessedEdges.Contains(aE)) { |
418 | aProcessedEdges.Add(aE); |
419 | aCBMap.Add(aE); |
420 | |
421 | Pathx (aV, aE, aType2, aVEMap, aProcessedEdges, aCBMap); |
422 | } |
423 | } |
424 | } |
425 | } |
426 | |
427 | |