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