4e57c75e |
1 | // Created by: Peter KURNEV |
973c2be1 |
2 | // Copyright (c) 2010-2014 OPEN CASCADE SAS |
4e57c75e |
3 | // Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE |
4 | // Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, |
5 | // EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS |
6 | // |
973c2be1 |
7 | // This file is part of Open CASCADE Technology software library. |
4e57c75e |
8 | // |
d5f74e42 |
9 | // This library is free software; you can redistribute it and/or modify it under |
10 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
11 | // by the Free Software Foundation, with special exception defined in the file |
12 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
13 | // distribution for complete text of the license and disclaimer of any warranty. |
4e57c75e |
14 | // |
973c2be1 |
15 | // Alternatively, this file may be used under the terms of Open CASCADE |
16 | // commercial license or contractual agreement. |
4e57c75e |
17 | |
42cf5bc1 |
18 | |
19 | #include <BOPAlgo_Builder.hxx> |
20 | #include <BOPAlgo_BuilderFace.hxx> |
21 | #include <BOPAlgo_PaveFiller.hxx> |
4e57c75e |
22 | #include <BOPCol_DataMapOfIntegerListOfShape.hxx> |
23 | #include <BOPCol_DataMapOfShapeShape.hxx> |
42cf5bc1 |
24 | #include <BOPCol_ListOfInteger.hxx> |
25 | #include <BOPCol_ListOfShape.hxx> |
26 | #include <BOPCol_MapOfInteger.hxx> |
a0a3f6ac |
27 | #include <BOPCol_NCVector.hxx> |
c7b59798 |
28 | #include <BOPCol_Parallel.hxx> |
4e57c75e |
29 | #include <BOPDS_DS.hxx> |
30 | #include <BOPDS_FaceInfo.hxx> |
4e57c75e |
31 | #include <BOPDS_Interf.hxx> |
42cf5bc1 |
32 | #include <BOPDS_MapOfPaveBlock.hxx> |
33 | #include <BOPDS_PaveBlock.hxx> |
34 | #include <BOPDS_ShapeInfo.hxx> |
4e57c75e |
35 | #include <BOPDS_VectorOfCurve.hxx> |
42cf5bc1 |
36 | #include <BOPDS_VectorOfInterfFF.hxx> |
4e57c75e |
37 | #include <BOPDS_VectorOfPoint.hxx> |
4e57c75e |
38 | #include <BOPTools.hxx> |
39 | #include <BOPTools_AlgoTools.hxx> |
acccace3 |
40 | #include <BOPTools_AlgoTools2D.hxx> |
4e57c75e |
41 | #include <BOPTools_AlgoTools3D.hxx> |
4e57c75e |
42 | #include <BOPTools_CoupleOfShape.hxx> |
42cf5bc1 |
43 | #include <BOPTools_DataMapOfShapeSet.hxx> |
4e57c75e |
44 | #include <BOPTools_ListOfCoupleOfShape.hxx> |
45 | #include <BOPTools_MapOfSet.hxx> |
42cf5bc1 |
46 | #include <BRep_Builder.hxx> |
47 | #include <BRep_Tool.hxx> |
48 | #include <IntTools_Context.hxx> |
42cf5bc1 |
49 | #include <TopExp_Explorer.hxx> |
50 | #include <TopoDS_Compound.hxx> |
51 | #include <TopoDS_Edge.hxx> |
52 | #include <TopoDS_Face.hxx> |
53 | #include <TopoDS_Shape.hxx> |
54 | #include <TopoDS_Vertex.hxx> |
4e57c75e |
55 | |
42cf5bc1 |
56 | // |
57 | // |
58 | // |
59 | // |
60 | // |
61 | // |
62 | // |
63 | // |
4e57c75e |
64 | static |
65 | Standard_Boolean HasPaveBlocksOnIn(const BOPDS_FaceInfo& aFI1, |
66 | const BOPDS_FaceInfo& aFI2); |
67 | static |
68 | void FillMap(const TopoDS_Shape& aS1, |
69 | const TopoDS_Shape& aS2, |
70 | BOPCol_IndexedDataMapOfShapeListOfShape& aDMSLS, |
488e5b9d |
71 | Handle(NCollection_BaseAllocator)& aAllocator); |
4e57c75e |
72 | static |
73 | void MakeBlocksCnx(const BOPCol_IndexedDataMapOfShapeListOfShape& aMILI, |
74 | BOPCol_DataMapOfIntegerListOfShape& aMBlocks, |
488e5b9d |
75 | Handle(NCollection_BaseAllocator)& aAllocator); |
a0a3f6ac |
76 | // |
77 | typedef BOPCol_NCVector<TopoDS_Shape> BOPAlgo_VectorOfShape; |
78 | // |
79 | typedef BOPCol_NCVector<BOPAlgo_VectorOfShape> \ |
80 | BOPAlgo_VectorOfVectorOfShape; |
81 | // |
82 | typedef NCollection_IndexedDataMap\ |
83 | <BOPTools_Set, Standard_Integer, BOPTools_SetMapHasher> \ |
84 | BOPAlgo_IndexedDataMapOfSetInteger; |
85 | // |
86 | //======================================================================= |
87 | //class : BOPAlgo_PairOfShapeBoolean |
88 | //purpose : |
89 | //======================================================================= |
36f4947b |
90 | class BOPAlgo_PairOfShapeBoolean : public BOPAlgo_Algo { |
91 | |
a0a3f6ac |
92 | public: |
36f4947b |
93 | DEFINE_STANDARD_ALLOC |
94 | |
95 | BOPAlgo_PairOfShapeBoolean() : |
96 | BOPAlgo_Algo(), |
97 | myFlag(Standard_False) { |
98 | } |
99 | // |
100 | virtual ~BOPAlgo_PairOfShapeBoolean() { |
a0a3f6ac |
101 | } |
102 | // |
103 | TopoDS_Shape& Shape1() { |
104 | return myShape1; |
105 | } |
106 | // |
107 | TopoDS_Shape& Shape2() { |
108 | return myShape2; |
109 | } |
110 | // |
111 | Standard_Boolean& Flag() { |
112 | return myFlag; |
113 | } |
114 | // |
36f4947b |
115 | void SetContext(const Handle(IntTools_Context)& aContext) { |
116 | myContext=aContext; |
117 | } |
118 | // |
119 | const Handle(IntTools_Context)& Context()const { |
120 | return myContext; |
121 | } |
122 | // |
123 | virtual void Perform() { |
124 | BOPAlgo_Algo::UserBreak(); |
125 | // |
126 | const TopoDS_Face& aFj=*((TopoDS_Face*)&myShape1); |
127 | const TopoDS_Face& aFk=*((TopoDS_Face*)&myShape2); |
128 | myFlag=BOPTools_AlgoTools::AreFacesSameDomain(aFj, aFk, myContext); |
129 | } |
130 | // |
a0a3f6ac |
131 | protected: |
132 | Standard_Boolean myFlag; |
133 | TopoDS_Shape myShape1; |
134 | TopoDS_Shape myShape2; |
36f4947b |
135 | Handle(IntTools_Context) myContext; |
a0a3f6ac |
136 | }; |
137 | // |
138 | typedef BOPCol_NCVector<BOPAlgo_PairOfShapeBoolean> \ |
139 | BOPAlgo_VectorOfPairOfShapeBoolean; |
140 | // |
c7b59798 |
141 | typedef BOPCol_ContextFunctor |
36f4947b |
142 | <BOPAlgo_PairOfShapeBoolean, |
143 | BOPAlgo_VectorOfPairOfShapeBoolean, |
144 | Handle(IntTools_Context), |
145 | IntTools_Context> BOPCol_BuilderSDFaceFunctor; |
146 | // |
c7b59798 |
147 | typedef BOPCol_ContextCnt |
36f4947b |
148 | <BOPCol_BuilderSDFaceFunctor, |
149 | BOPAlgo_VectorOfPairOfShapeBoolean, |
150 | Handle(IntTools_Context)> BOPAlgo_BuilderSDFaceCnt; |
a0a3f6ac |
151 | // |
a0a3f6ac |
152 | //======================================================================= |
153 | // BuilderFace |
154 | // |
155 | typedef BOPCol_NCVector<BOPAlgo_BuilderFace> BOPAlgo_VectorOfBuilderFace; |
156 | // |
c7b59798 |
157 | typedef BOPCol_Functor |
a0a3f6ac |
158 | <BOPAlgo_BuilderFace, |
159 | BOPAlgo_VectorOfBuilderFace> BOPAlgo_BuilderFaceFunctor; |
160 | // |
c7b59798 |
161 | typedef BOPCol_Cnt |
a0a3f6ac |
162 | <BOPAlgo_BuilderFaceFunctor, |
163 | BOPAlgo_VectorOfBuilderFace> BOPAlgo_BuilderFaceCnt; |
164 | // |
165 | //======================================================================= |
166 | //class : BOPAlgo_VFI |
167 | //purpose : |
168 | //======================================================================= |
36f4947b |
169 | class BOPAlgo_VFI : public BOPAlgo_Algo { |
170 | |
a0a3f6ac |
171 | public: |
36f4947b |
172 | DEFINE_STANDARD_ALLOC |
173 | |
174 | BOPAlgo_VFI() : |
175 | BOPAlgo_Algo(), |
176 | myFlag(-1) { |
a0a3f6ac |
177 | } |
178 | // |
36f4947b |
179 | virtual ~BOPAlgo_VFI(){ |
a0a3f6ac |
180 | } |
181 | // |
182 | void SetVertex(const TopoDS_Vertex& aV) { |
183 | myV=aV; |
184 | } |
185 | // |
186 | TopoDS_Vertex& Vertex() { |
187 | return myV; |
188 | } |
189 | // |
190 | void SetFace(const TopoDS_Face& aF) { |
191 | myF=aF; |
192 | } |
193 | // |
194 | TopoDS_Face& Face() { |
195 | return myF; |
196 | } |
197 | // |
198 | Standard_Integer Flag()const { |
199 | return myFlag; |
200 | } |
201 | // |
1e143abb |
202 | void SetContext(const Handle(IntTools_Context)& aContext) { |
a0a3f6ac |
203 | myContext=aContext; |
204 | } |
205 | // |
1e143abb |
206 | const Handle(IntTools_Context)& Context()const { |
a0a3f6ac |
207 | return myContext; |
208 | } |
209 | // |
36f4947b |
210 | virtual void Perform() { |
a0a3f6ac |
211 | Standard_Real aT1, aT2; |
212 | // |
36f4947b |
213 | BOPAlgo_Algo::UserBreak(); |
a0a3f6ac |
214 | myFlag=myContext->ComputeVF(myV, myF, aT1, aT2); |
215 | } |
216 | // |
217 | protected: |
218 | Standard_Integer myFlag; |
219 | TopoDS_Vertex myV; |
220 | TopoDS_Face myF; |
1e143abb |
221 | Handle(IntTools_Context) myContext; |
a0a3f6ac |
222 | }; |
223 | // |
224 | typedef BOPCol_NCVector<BOPAlgo_VFI> BOPAlgo_VectorOfVFI; |
225 | // |
c7b59798 |
226 | typedef BOPCol_ContextFunctor |
a0a3f6ac |
227 | <BOPAlgo_VFI, |
228 | BOPAlgo_VectorOfVFI, |
1e143abb |
229 | Handle(IntTools_Context), |
230 | IntTools_Context> BOPAlgo_VFIFunctor; |
a0a3f6ac |
231 | // |
c7b59798 |
232 | typedef BOPCol_ContextCnt |
a0a3f6ac |
233 | <BOPAlgo_VFIFunctor, |
234 | BOPAlgo_VectorOfVFI, |
1e143abb |
235 | Handle(IntTools_Context)> BOPAlgo_VFICnt; |
a0a3f6ac |
236 | // |
4e57c75e |
237 | //======================================================================= |
238 | //function : FillImagesFaces |
239 | //purpose : |
240 | //======================================================================= |
acccace3 |
241 | void BOPAlgo_Builder::FillImagesFaces() |
4e57c75e |
242 | { |
243 | myErrorStatus=0; |
244 | // |
245 | BuildSplitFaces(); |
246 | FillSameDomainFaces(); |
247 | FillImagesFaces1(); |
248 | } |
249 | //======================================================================= |
250 | //function : BuildSplitFaces |
251 | //purpose : |
252 | //======================================================================= |
acccace3 |
253 | void BOPAlgo_Builder::BuildSplitFaces() |
4e57c75e |
254 | { |
255 | Standard_Boolean bHasFaceInfo, bIsClosed, bIsDegenerated, bToReverse; |
37e640d5 |
256 | Standard_Integer i, j, k, aNbS, aNbPBIn, aNbPBOn, aNbPBSc, aNbAV, nSp; |
37e640d5 |
257 | Standard_Size aNbBF; |
4e57c75e |
258 | TopoDS_Face aFF, aFSD; |
259 | TopoDS_Edge aSp, aEE; |
260 | TopAbs_Orientation anOriF, anOriE; |
261 | TopExp_Explorer aExp; |
262 | BOPCol_ListIteratorOfListOfShape aIt; |
263 | BOPCol_ListOfInteger aLIAV; |
264 | BOPCol_MapOfShape aMFence; |
acccace3 |
265 | Handle(NCollection_BaseAllocator) aAllocator; |
4e57c75e |
266 | BOPCol_ListOfShape aLFIm(myAllocator); |
acccace3 |
267 | BOPAlgo_VectorOfBuilderFace aVBF; |
4e57c75e |
268 | // |
269 | myErrorStatus=0; |
270 | // |
271 | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~scope f |
488e5b9d |
272 | aAllocator= |
273 | NCollection_BaseAllocator::CommonBaseAllocator(); |
4e57c75e |
274 | // |
275 | BOPCol_ListOfShape aLE(aAllocator); |
276 | BOPCol_MapOfShape aMDE(100, aAllocator); |
277 | // |
278 | aNbS=myDS->NbSourceShapes(); |
acccace3 |
279 | // |
4e57c75e |
280 | for (i=0; i<aNbS; ++i) { |
281 | const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i); |
282 | if (aSI.ShapeType()!=TopAbs_FACE) { |
283 | continue; |
284 | } |
285 | // |
286 | const TopoDS_Face& aF=(*(TopoDS_Face*)(&aSI.Shape())); |
287 | // |
288 | bHasFaceInfo=myDS->HasFaceInfo(i); |
289 | if(!bHasFaceInfo) { |
290 | continue; |
291 | } |
292 | // |
4e57c75e |
293 | const BOPDS_FaceInfo& aFI=myDS->FaceInfo(i); |
294 | // |
295 | const BOPDS_IndexedMapOfPaveBlock& aMPBIn=aFI.PaveBlocksIn(); |
296 | const BOPDS_IndexedMapOfPaveBlock& aMPBOn=aFI.PaveBlocksOn(); |
297 | const BOPDS_IndexedMapOfPaveBlock& aMPBSc=aFI.PaveBlocksSc(); |
298 | aLIAV.Clear(); |
299 | myDS->AloneVertices(i, aLIAV); |
300 | |
301 | aNbPBIn=aMPBIn.Extent(); |
302 | aNbPBOn=aMPBOn.Extent(); |
303 | aNbPBSc=aMPBSc.Extent(); |
304 | aNbAV=aLIAV.Extent(); |
305 | if (!aNbPBIn && !aNbPBOn && !aNbPBSc && !aNbAV) { // not compete |
306 | continue; |
307 | } |
308 | // |
309 | aMFence.Clear(); |
310 | // |
311 | anOriF=aF.Orientation(); |
312 | aFF=aF; |
313 | aFF.Orientation(TopAbs_FORWARD); |
4e57c75e |
314 | // |
315 | // 1. Fill the egdes set for the face aFF -> LE |
316 | aLE.Clear(); |
317 | // |
318 | // |
319 | // 1.1 Bounding edges |
320 | aExp.Init(aFF, TopAbs_EDGE); |
321 | for (; aExp.More(); aExp.Next()) { |
322 | const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&aExp.Current())); |
323 | anOriE=aE.Orientation(); |
324 | bIsDegenerated=BRep_Tool::Degenerated(aE); |
325 | bIsClosed=BRep_Tool::IsClosed(aE, aF); |
326 | // |
327 | if (!myImages.IsBound(aE)) { |
328 | if (anOriE==TopAbs_INTERNAL) { |
329 | aEE=aE; |
330 | aEE.Orientation(TopAbs_FORWARD); |
331 | aLE.Append(aEE); |
332 | aEE.Orientation(TopAbs_REVERSED); |
333 | aLE.Append(aEE); |
334 | } |
335 | else { |
336 | aLE.Append(aE); |
337 | } |
338 | } |
339 | else {//else 1 |
340 | const BOPCol_ListOfShape& aLIE=myImages.Find(aE); |
341 | aIt.Initialize(aLIE); |
342 | for (; aIt.More(); aIt.Next()) { |
343 | aSp=(*(TopoDS_Edge*)(&aIt.Value())); |
344 | if (bIsDegenerated) { |
345 | aSp.Orientation(anOriE); |
346 | aLE.Append(aSp); |
347 | continue; |
348 | } |
349 | // |
350 | if (anOriE==TopAbs_INTERNAL) { |
351 | aSp.Orientation(TopAbs_FORWARD); |
352 | aLE.Append(aSp); |
353 | aSp.Orientation(TopAbs_REVERSED); |
354 | aLE.Append(aSp); |
355 | continue; |
356 | } |
357 | // |
358 | if (bIsClosed) { |
359 | if (aMFence.Add(aSp)) { |
360 | if (!BRep_Tool::IsClosed(aSp, aF)){ |
361 | BOPTools_AlgoTools3D::DoSplitSEAMOnFace(aSp, aF); |
362 | } |
363 | // |
364 | aSp.Orientation(TopAbs_FORWARD); |
365 | aLE.Append(aSp); |
366 | aSp.Orientation(TopAbs_REVERSED); |
367 | aLE.Append(aSp); |
368 | }// if (aMFence.Add(aSp)) |
369 | continue; |
370 | }// if (bIsClosed){ |
371 | // |
372 | aSp.Orientation(anOriE); |
373 | bToReverse=BOPTools_AlgoTools::IsSplitToReverse(aSp, aE, myContext); |
374 | if (bToReverse) { |
375 | aSp.Reverse(); |
376 | } |
377 | aLE.Append(aSp); |
378 | }// for (; aIt.More(); aIt.Next()) { |
379 | }// else 1 |
380 | }// for (; aExp.More(); aExp.Next()) { |
381 | // |
382 | // |
383 | // 1.2 In edges |
384 | for (j=1; j<=aNbPBIn; ++j) { |
385 | const Handle(BOPDS_PaveBlock)& aPB=aMPBIn(j); |
386 | nSp=aPB->Edge(); |
387 | aSp=(*(TopoDS_Edge*)(&myDS->Shape(nSp))); |
388 | // |
389 | aSp.Orientation(TopAbs_FORWARD); |
390 | aLE.Append(aSp); |
391 | aSp.Orientation(TopAbs_REVERSED); |
392 | aLE.Append(aSp); |
393 | } |
394 | // |
395 | // |
396 | // 1.3 Section edges |
397 | for (j=1; j<=aNbPBSc; ++j) { |
398 | const Handle(BOPDS_PaveBlock)& aPB=aMPBSc(j); |
399 | nSp=aPB->Edge(); |
400 | aSp=(*(TopoDS_Edge*)(&myDS->Shape(nSp))); |
401 | // |
402 | aSp.Orientation(TopAbs_FORWARD); |
403 | aLE.Append(aSp); |
404 | aSp.Orientation(TopAbs_REVERSED); |
405 | aLE.Append(aSp); |
406 | } |
407 | // |
acccace3 |
408 | BOPTools_AlgoTools2D::BuildPCurveForEdgesOnPlane (aLE, aFF); |
4e57c75e |
409 | // |
acccace3 |
410 | // 3 Build split faces |
411 | BOPAlgo_BuilderFace& aBF=aVBF.Append1(); |
412 | aBF.SetFace(aF); |
4e57c75e |
413 | aBF.SetShapes(aLE); |
db8e4b9a |
414 | aBF.SetRunParallel(myRunParallel); |
36f4947b |
415 | aBF.SetProgressIndicator(myProgressIndicator); |
4e57c75e |
416 | // |
acccace3 |
417 | }// for (i=0; i<aNbS; ++i) { |
418 | // |
419 | aNbBF=aVBF.Extent(); |
420 | // |
421 | //=================================================== |
796a784d |
422 | BOPAlgo_BuilderFaceCnt::Perform(myRunParallel, aVBF); |
acccace3 |
423 | //=================================================== |
424 | // |
37e640d5 |
425 | for (k=0; k<(Standard_Integer)aNbBF; ++k) { |
acccace3 |
426 | aLFIm.Clear(); |
427 | // |
428 | BOPAlgo_BuilderFace& aBF=aVBF(k); |
429 | TopoDS_Face aF=aBF.Face(); |
430 | anOriF=aBF.Orientation(); |
431 | aF.Orientation(anOriF); |
4e57c75e |
432 | // |
433 | const BOPCol_ListOfShape& aLFR=aBF.Areas(); |
434 | aIt.Initialize(aLFR); |
435 | for (; aIt.More(); aIt.Next()) { |
436 | TopoDS_Shape& aFR=aIt.ChangeValue(); |
437 | if (anOriF==TopAbs_REVERSED) { |
438 | aFR.Orientation(TopAbs_REVERSED); |
439 | } |
440 | //aFR.Orientation(anOriF); |
441 | aLFIm.Append(aFR); |
4e57c75e |
442 | } |
443 | // |
444 | mySplits.Bind(aF, aLFIm); |
acccace3 |
445 | }// for (k=0; k<aNbBF; ++k) { |
4e57c75e |
446 | // |
4e57c75e |
447 | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~scope t |
448 | } |
449 | //======================================================================= |
450 | //function : FillSameDomainFaces |
451 | //purpose : |
452 | //======================================================================= |
acccace3 |
453 | void BOPAlgo_Builder::FillSameDomainFaces() |
4e57c75e |
454 | { |
455 | Standard_Boolean bFlag; |
19941687 |
456 | Standard_Integer i, j, k, aNbFFs, aNbCurves, aNbPoints, nF1, nF2, aNbS; |
488e5b9d |
457 | Handle(NCollection_BaseAllocator) aAllocator; |
19941687 |
458 | BOPCol_ListIteratorOfListOfShape aItF; |
459 | BOPCol_MapOfShape aMFence; |
460 | BOPAlgo_IndexedDataMapOfSetInteger aIDMSS; |
461 | BOPAlgo_VectorOfVectorOfShape aVVS; |
98730279 |
462 | // |
4e57c75e |
463 | myErrorStatus=0; |
464 | // |
465 | const BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF(); |
466 | // |
467 | aNbFFs=aFFs.Extent(); |
468 | if (!aNbFFs) { |
469 | return; |
470 | } |
4e57c75e |
471 | // |
472 | for (i=0; i<aNbFFs; ++i) { |
473 | const BOPDS_InterfFF& aFF=aFFs(i); |
474 | aFF.Indices(nF1, nF2); |
475 | // |
476 | const BOPDS_VectorOfCurve& aCurves=aFF.Curves(); |
477 | aNbCurves=aCurves.Extent(); |
478 | if (aNbCurves) { |
479 | // |
480 | bFlag=Standard_False; |
481 | for (j=0; j<aNbCurves; ++j) { |
482 | const BOPDS_Curve& aNC=aCurves.Value(j); |
483 | bFlag=aNC.HasEdge(); |
484 | if (bFlag) { |
485 | break; |
486 | } |
487 | } |
488 | if (bFlag) { |
489 | continue; |
490 | } |
491 | //continue; |
492 | } |
493 | // |
494 | const BOPDS_VectorOfPoint& aPoints=aFF.Points(); |
495 | aNbPoints=aPoints.Extent(); |
496 | if (aNbPoints) { |
497 | continue; |
498 | } |
499 | // |
500 | if (!myDS->HasFaceInfo(nF1) || !myDS->HasFaceInfo(nF2) ) { |
501 | continue; |
502 | } |
503 | // |
504 | const BOPDS_FaceInfo& aFI1=myDS->FaceInfo(nF1); |
505 | const BOPDS_FaceInfo& aFI2=myDS->FaceInfo(nF2); |
4e57c75e |
506 | // |
19941687 |
507 | const TopoDS_Shape& aF1=myDS->Shape(nF1); |
508 | const TopoDS_Shape& aF2=myDS->Shape(nF2); |
509 | // |
510 | bFlag=HasPaveBlocksOnIn(aFI1, aFI2); |
c209782c |
511 | bFlag=bFlag && (mySplits.IsBound(aF1) && mySplits.IsBound(aF2)); |
512 | // |
19941687 |
513 | if (bFlag) { |
514 | for (k=0; k<2; ++k) { |
98730279 |
515 | const TopoDS_Shape& aF=(!k) ? aF1 : aF2; |
516 | const BOPCol_ListOfShape& aLF=mySplits.Find(aF); |
517 | // |
518 | aItF.Initialize(aLF); |
519 | for (; aItF.More(); aItF.Next()) { |
520 | const TopoDS_Shape& aFx=aItF.Value(); |
521 | // |
522 | if (aMFence.Add(aFx)) { |
523 | BOPTools_Set aSTx; |
524 | // |
525 | aSTx.Add(aFx, TopAbs_EDGE); |
526 | // |
527 | if (!aIDMSS.Contains(aSTx)) { |
528 | BOPAlgo_VectorOfShape& aVS=aVVS.Append1(); |
529 | aVS.Append(aFx); |
530 | // |
531 | j=aVVS.Extent()-1; |
532 | aIDMSS.Add (aSTx, j); |
533 | } |
534 | else { |
535 | j=aIDMSS.ChangeFromKey(aSTx); |
536 | BOPAlgo_VectorOfShape& aVS=aVVS(j); |
537 | aVS.Append(aFx); |
538 | } |
539 | } |
540 | } |
c209782c |
541 | } |
19941687 |
542 | }// if (bFlag) { |
543 | else {// if (!bFlag) |
544 | BOPTools_Set aST1, aST2; |
c209782c |
545 | // |
98730279 |
546 | aST1.Add(aF1, TopAbs_EDGE); |
547 | aST2.Add(aF2, TopAbs_EDGE); |
c209782c |
548 | // |
c209782c |
549 | if (aST1.IsEqual(aST2)) { |
98730279 |
550 | if (!aIDMSS.Contains(aST1)) { |
551 | BOPAlgo_VectorOfShape& aVS=aVVS.Append1(); |
552 | if (aMFence.Add(aF1)) { |
553 | aVS.Append(aF1); |
554 | } |
555 | if (aMFence.Add(aF2)) { |
556 | aVS.Append(aF2); |
557 | } |
558 | // |
559 | k=aVVS.Extent()-1; |
560 | aIDMSS.Add (aST1, k); |
561 | } |
562 | else { |
563 | k=aIDMSS.ChangeFromKey(aST1); |
564 | BOPAlgo_VectorOfShape& aVS=aVVS(k); |
565 | if (aMFence.Add(aF1)) { |
566 | aVS.Append(aF1); |
567 | } |
568 | if (aMFence.Add(aF2)) { |
569 | aVS.Append(aF2); |
570 | } |
571 | } |
19941687 |
572 | }//if (aST1.IsEqual(aST2)) { |
573 | }// else {// if (!bFlag) |
574 | // |
575 | }// for (i=0; i<aNbFFs; ++i) { |
576 | // |
577 | aIDMSS.Clear(); |
578 | // |
796a784d |
579 | Standard_Boolean bFlagSD; |
19941687 |
580 | Standard_Integer aNbVPSB, aNbVVS, aNbF, aNbF1; |
581 | BOPAlgo_VectorOfPairOfShapeBoolean aVPSB; |
582 | // |
583 | aNbVVS=aVVS.Extent(); |
584 | for (i=0; i<aNbVVS; ++i) { |
585 | const BOPAlgo_VectorOfShape& aVS=aVVS(i); |
586 | aNbF=aVS.Extent(); |
587 | if (aNbF<2) { |
4e57c75e |
588 | continue; |
589 | } |
590 | // |
19941687 |
591 | aNbF1=aNbF-1; |
592 | for (j=0; j<aNbF1; ++j) { |
593 | const TopoDS_Shape& aFj=aVS(j); |
594 | for (k=j+1; k<aNbF; ++k) { |
98730279 |
595 | const TopoDS_Shape& aFk=aVS(k); |
596 | BOPAlgo_PairOfShapeBoolean& aPSB=aVPSB.Append1(); |
597 | aPSB.Shape1()=aFj; |
598 | aPSB.Shape2()=aFk; |
36f4947b |
599 | aPSB.SetProgressIndicator(myProgressIndicator); |
4e57c75e |
600 | } |
19941687 |
601 | } |
602 | } |
36f4947b |
603 | //================================================================ |
604 | BOPAlgo_BuilderSDFaceCnt::Perform(myRunParallel, aVPSB, myContext); |
605 | //================================================================ |
488e5b9d |
606 | aAllocator= |
607 | NCollection_BaseAllocator::CommonBaseAllocator(); |
19941687 |
608 | BOPCol_IndexedDataMapOfShapeListOfShape aDMSLS(100, aAllocator); |
609 | BOPCol_DataMapOfIntegerListOfShape aMBlocks(100, aAllocator); |
610 | // |
611 | aNbVPSB=aVPSB.Extent(); |
612 | for (i=0; i<aNbVPSB; ++i) { |
613 | BOPAlgo_PairOfShapeBoolean& aPSB=aVPSB(i); |
614 | bFlagSD=aPSB.Flag(); |
615 | if (bFlagSD) { |
616 | const TopoDS_Shape& aFj=aPSB.Shape1(); |
617 | const TopoDS_Shape& aFk=aPSB.Shape2(); |
618 | FillMap(aFj, aFk, aDMSLS, aAllocator); |
619 | } |
620 | } |
621 | aVPSB.Clear(); |
4e57c75e |
622 | // |
623 | // 2. Make blocks |
624 | MakeBlocksCnx(aDMSLS, aMBlocks, aAllocator); |
625 | // |
626 | // 3. Fill same domain faces map -> aMSDF |
627 | aNbS = aMBlocks.Extent(); |
628 | for (i=0; i<aNbS; ++i) { |
629 | const BOPCol_ListOfShape& aLSD=aMBlocks.Find(i); |
19941687 |
630 | if (aLSD.IsEmpty()) { |
631 | continue; |
4e57c75e |
632 | } |
c209782c |
633 | // |
19941687 |
634 | const TopoDS_Shape& aFSD1=aLSD.First(); |
635 | aItF.Initialize(aLSD); |
636 | for (; aItF.More(); aItF.Next()) { |
637 | const TopoDS_Shape& aFSD=aItF.Value(); |
638 | myShapesSD.Bind(aFSD, aFSD1); |
639 | // |
640 | // If the face has no splits but are SD face, |
641 | // it is considered as splitted face |
642 | if (!mySplits.IsBound(aFSD)) { |
98730279 |
643 | BOPCol_ListOfShape aLS; |
644 | aLS.Append(aFSD); |
645 | mySplits.Bind(aFSD, aLS); |
19941687 |
646 | } |
647 | } |
c209782c |
648 | } |
4e57c75e |
649 | aMBlocks.Clear(); |
650 | aDMSLS.Clear(); |
4e57c75e |
651 | } |
652 | //======================================================================= |
653 | // function: FillImagesFaces1 |
654 | // purpose: |
655 | //======================================================================= |
acccace3 |
656 | void BOPAlgo_Builder::FillImagesFaces1() |
4e57c75e |
657 | { |
a0a3f6ac |
658 | Standard_Integer i, aNbS, iSense, nVx, aNbVFI, iFlag; |
4e57c75e |
659 | TopoDS_Face aFSD; |
a0a3f6ac |
660 | TopoDS_Vertex aVx; |
661 | BRep_Builder aBB; |
4e57c75e |
662 | BOPCol_ListOfInteger aLIAV; |
663 | BOPCol_ListOfShape aLFIm; |
a0a3f6ac |
664 | BOPCol_ListIteratorOfListOfInteger aItV; |
665 | BOPCol_ListIteratorOfListOfShape aItLS, aItF; |
666 | BOPAlgo_VectorOfVFI aVVFI; |
4e57c75e |
667 | // |
668 | aNbS=myDS->NbSourceShapes(); |
669 | for (i=0; i<aNbS; ++i) { |
670 | const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i); |
671 | if (aSI.ShapeType()!=TopAbs_FACE) { |
672 | continue; |
673 | } |
674 | // |
675 | const TopoDS_Face& aF=(*(TopoDS_Face*)(&aSI.Shape())); |
676 | // |
677 | if (!mySplits.IsBound(aF)) { |
678 | continue; |
679 | } |
a0a3f6ac |
680 | // |
681 | // 1. |
4e57c75e |
682 | aLIAV.Clear(); |
683 | myDS->AloneVertices(i, aLIAV); |
684 | aLFIm.Clear(); |
685 | // |
686 | const BOPCol_ListOfShape& aLSp=mySplits.Find(aF); |
687 | aItLS.Initialize(aLSp); |
688 | for (; aItLS.More(); aItLS.Next()) { |
689 | const TopoDS_Face& aFSp=(*(TopoDS_Face*)(&aItLS.Value())); |
690 | if (!myShapesSD.IsBound(aFSp)) { |
691 | aLFIm.Append(aFSp); |
692 | } |
693 | else { |
694 | aFSD=(*(TopoDS_Face*)(&myShapesSD.Find(aFSp))); |
695 | iSense=BOPTools_AlgoTools::Sense(aFSp, aFSD); |
696 | if (iSense<0) { |
697 | aFSD.Reverse(); |
698 | } |
699 | aLFIm.Append(aFSD); |
700 | } |
701 | } |
702 | // |
a0a3f6ac |
703 | //FillInternalVertices(aLFIm, aLIAV); |
4e57c75e |
704 | // |
705 | myImages.Bind(aF, aLFIm); |
c209782c |
706 | // |
a0a3f6ac |
707 | // 2. fill myOrigins |
c209782c |
708 | aItLS.Initialize(aLFIm); |
709 | for (; aItLS.More(); aItLS.Next()) { |
710 | const TopoDS_Face& aFSp=(*(TopoDS_Face*)(&aItLS.Value())); |
711 | myOrigins.Bind(aFSp, aF); |
712 | } |
4e57c75e |
713 | // |
a0a3f6ac |
714 | // 3. |
715 | aItV.Initialize(aLIAV); |
716 | for (; aItV.More(); aItV.Next()) { |
717 | nVx=aItV.Value(); |
718 | aVx=(*(TopoDS_Vertex*)(&myDS->Shape(nVx))); |
719 | aVx.Orientation(TopAbs_INTERNAL); |
720 | // |
721 | aItF.Initialize(aLFIm); |
722 | for (; aItF.More(); aItF.Next()) { |
723 | TopoDS_Face& aFy=(*(TopoDS_Face*)(&aItF.Value())); |
724 | // |
725 | BOPAlgo_VFI& aVFI=aVVFI.Append1(); |
726 | aVFI.SetVertex(aVx); |
727 | aVFI.SetFace(aFy); |
36f4947b |
728 | aVFI.SetProgressIndicator(myProgressIndicator); |
4e57c75e |
729 | } |
730 | } |
a0a3f6ac |
731 | }// for (i=0; i<aNbS; ++i) { |
732 | // |
733 | // 4. |
734 | aNbVFI=aVVFI.Extent(); |
735 | //================================================================ |
736 | BOPAlgo_VFICnt::Perform(myRunParallel, aVVFI, myContext); |
737 | //================================================================ |
738 | // |
739 | for (i=0; i < aNbVFI; ++i) { |
740 | BOPAlgo_VFI& aVFI=aVVFI(i); |
741 | // |
742 | iFlag=aVFI.Flag(); |
743 | if (!iFlag) { |
51740958 |
744 | TopoDS_Vertex& aVertex=aVFI.Vertex(); |
a0a3f6ac |
745 | TopoDS_Face& aFy=aVFI.Face(); |
51740958 |
746 | aBB.Add(aFy, aVertex); |
a0a3f6ac |
747 | } |
4e57c75e |
748 | } |
749 | } |
750 | //======================================================================= |
751 | //function : MakeBlocksCnx |
752 | //purpose : |
753 | //======================================================================= |
754 | void MakeBlocksCnx(const BOPCol_IndexedDataMapOfShapeListOfShape& aMILI, |
755 | BOPCol_DataMapOfIntegerListOfShape& aMBlocks, |
488e5b9d |
756 | Handle(NCollection_BaseAllocator)& aAllocator) |
4e57c75e |
757 | { |
758 | Standard_Integer aNbV, aNbVS, aNbVP, aNbEC, k, i, j; |
759 | BOPCol_ListIteratorOfListOfShape aItLI; |
760 | // |
761 | BOPCol_MapOfShape aMVS(100, aAllocator); |
762 | BOPCol_IndexedMapOfShape aMEC(100, aAllocator); |
763 | BOPCol_IndexedMapOfShape aMVP(100, aAllocator); |
764 | BOPCol_IndexedMapOfShape aMVAdd(100, aAllocator); |
765 | // |
766 | aNbV=aMILI.Extent(); |
767 | // |
768 | for (k=0,i=1; i<=aNbV; ++i) { |
769 | aNbVS=aMVS.Extent(); |
770 | if (aNbVS==aNbV) { |
771 | break; |
772 | } |
773 | // |
774 | const TopoDS_Shape& nV=aMILI.FindKey(i); |
775 | if (aMVS.Contains(nV)){ |
776 | continue; |
777 | } |
778 | aMVS.Add(nV); |
779 | // |
780 | aMEC.Clear(); |
781 | aMVP.Clear(); |
782 | aMVAdd.Clear(); |
783 | // |
784 | aMVP.Add(nV); |
302f96fb |
785 | for(;;) { |
4e57c75e |
786 | aNbVP=aMVP.Extent(); |
787 | for (j=1; j<=aNbVP; ++j) { |
788 | const TopoDS_Shape& nVP=aMVP(j); |
789 | const BOPCol_ListOfShape& aLV=aMILI.FindFromKey(nVP); |
790 | aItLI.Initialize(aLV); |
791 | for (; aItLI.More(); aItLI.Next()) { |
792 | const TopoDS_Shape& nVx=aItLI.Value(); |
793 | if (aMEC.Contains(nVx)) { |
794 | continue; |
795 | } |
796 | // |
797 | aMVS.Add(nVx); |
798 | aMEC.Add(nVx); |
799 | aMVAdd.Add(nVx); |
800 | } |
801 | } |
802 | // |
803 | aNbVP=aMVAdd.Extent(); |
804 | if (!aNbVP) { |
805 | break; // from while(1) |
806 | } |
807 | // |
808 | aMVP.Clear(); |
809 | for (j=1; j<=aNbVP; ++j) { |
810 | aMVP.Add(aMVAdd(j)); |
811 | } |
812 | aMVAdd.Clear(); |
813 | }//while(1) { |
814 | // |
815 | BOPCol_ListOfShape aLIx(aAllocator); |
816 | // |
817 | aNbEC = aMEC.Extent(); |
818 | for (j=1; j<=aNbEC; ++j) { |
819 | const TopoDS_Shape& nVx=aMEC(j); |
820 | aLIx.Append(nVx); |
821 | } |
822 | // |
823 | aMBlocks.Bind(k, aLIx); |
824 | ++k; |
825 | }//for (k=0,i=1; i<=aNbV; ++i) |
826 | aMVAdd.Clear(); |
827 | aMVP.Clear(); |
828 | aMEC.Clear(); |
829 | aMVS.Clear(); |
830 | } |
4e57c75e |
831 | //======================================================================= |
832 | //function : FillMap |
833 | //purpose : |
834 | //======================================================================= |
835 | void FillMap(const TopoDS_Shape& aS1, |
836 | const TopoDS_Shape& aS2, |
837 | BOPCol_IndexedDataMapOfShapeListOfShape& aDMSLS, |
488e5b9d |
838 | Handle(NCollection_BaseAllocator)& aAllocator) |
4e57c75e |
839 | { |
840 | if (aDMSLS.Contains(aS1)) { |
841 | BOPCol_ListOfShape& aLS=aDMSLS.ChangeFromKey(aS1); |
842 | aLS.Append(aS2); |
843 | } |
844 | else { |
845 | BOPCol_ListOfShape aLS(aAllocator); |
846 | aLS.Append(aS2); |
847 | aDMSLS.Add(aS1, aLS); |
848 | } |
849 | // |
850 | if (aDMSLS.Contains(aS2)) { |
851 | BOPCol_ListOfShape& aLS=aDMSLS.ChangeFromKey(aS2); |
852 | aLS.Append(aS1); |
853 | } |
854 | else { |
855 | BOPCol_ListOfShape aLS(aAllocator); |
856 | aLS.Append(aS1); |
857 | aDMSLS.Add(aS2, aLS); |
858 | } |
859 | } |
860 | //======================================================================= |
861 | //function :HasPaveBlocksOnIn |
862 | //purpose : |
863 | //======================================================================= |
864 | Standard_Boolean HasPaveBlocksOnIn(const BOPDS_FaceInfo& aFI1, |
865 | const BOPDS_FaceInfo& aFI2) |
866 | { |
867 | Standard_Boolean bRet; |
319da2e4 |
868 | Standard_Integer i, aNbPB; |
4e57c75e |
869 | // |
870 | bRet=Standard_False; |
319da2e4 |
871 | const BOPDS_IndexedMapOfPaveBlock& aMPBOn1 = aFI1.PaveBlocksOn(); |
872 | const BOPDS_IndexedMapOfPaveBlock& aMPBIn1 = aFI1.PaveBlocksIn(); |
873 | // |
874 | const BOPDS_IndexedMapOfPaveBlock& aMPBOn2 = aFI2.PaveBlocksOn(); |
875 | aNbPB = aMPBOn2.Extent(); |
876 | for (i = 1; i <= aNbPB; ++i) { |
877 | const Handle(BOPDS_PaveBlock)& aPB = aMPBOn2(i); |
878 | bRet = aMPBOn1.Contains(aPB) || aMPBIn1.Contains(aPB); |
4e57c75e |
879 | if (bRet) { |
880 | return bRet; |
881 | } |
882 | } |
883 | // |
319da2e4 |
884 | const BOPDS_IndexedMapOfPaveBlock& aMPBIn2 = aFI2.PaveBlocksIn(); |
885 | aNbPB = aMPBIn2.Extent(); |
886 | for (i = 1; i <= aNbPB; ++i) { |
887 | const Handle(BOPDS_PaveBlock)& aPB = aMPBIn2(i); |
888 | bRet = aMPBOn1.Contains(aPB) || aMPBIn1.Contains(aPB); |
4e57c75e |
889 | if (bRet) { |
890 | return bRet; |
891 | } |
892 | } |
893 | return bRet; |
894 | } |
a0a3f6ac |
895 | |
4e57c75e |
896 | /* |
897 | //DEBf |
898 | { |
899 | TopoDS_Compound aCx; |
900 | BRep_Builder aBBx; |
901 | BOPCol_ListIteratorOfListOfShape aItx; |
902 | // |
903 | aBBx.MakeCompound(aCx); |
904 | aBBx.Add(aCx, aFF); |
905 | aItx.Initialize(aLE); |
906 | for (; aItx.More(); aItx.Next()) { |
907 | const TopoDS_Shape& aEx=aItx.Value(); |
908 | aBBx.Add(aCx, aEx); |
909 | } |
910 | int a=0; |
911 | } |
912 | //DEBt |
913 | */ |