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 | |
4e57c75e |
18 | |
19 | #include <Bnd_Box.hxx> |
42cf5bc1 |
20 | #include <BOPAlgo_PaveFiller.hxx> |
21 | #include <BOPAlgo_SectionAttribute.hxx> |
22 | #include <BOPAlgo_Tools.hxx> |
23 | #include <BOPCol_BoxBndTree.hxx> |
24 | #include <BOPCol_DataMapOfIntegerShape.hxx> |
4e57c75e |
25 | #include <BOPCol_DataMapOfShapeInteger.hxx> |
a2098360 |
26 | #include <BOPCol_DataMapOfShapeListOfShape.hxx> |
4e57c75e |
27 | #include <BOPCol_IndexedDataMapOfShapeBox.hxx> |
a942f2da |
28 | #include <BOPCol_NCVector.hxx> |
c7b59798 |
29 | #include <BOPCol_Parallel.hxx> |
4e57c75e |
30 | #include <BOPDS_CommonBlock.hxx> |
31 | #include <BOPDS_CoupleOfPaveBlocks.hxx> |
42cf5bc1 |
32 | #include <BOPDS_Curve.hxx> |
4e57c75e |
33 | #include <BOPDS_DataMapOfPaveBlockListOfInteger.hxx> |
42cf5bc1 |
34 | #include <BOPDS_DataMapOfPaveBlockListOfPaveBlock.hxx> |
35 | #include <BOPDS_DS.hxx> |
4e57c75e |
36 | #include <BOPDS_Interf.hxx> |
42cf5bc1 |
37 | #include <BOPDS_Iterator.hxx> |
38 | #include <BOPDS_MapOfPaveBlock.hxx> |
4e57c75e |
39 | #include <BOPDS_Pave.hxx> |
42cf5bc1 |
40 | #include <BOPDS_PaveBlock.hxx> |
41 | #include <BOPDS_VectorOfInterfEE.hxx> |
42 | #include <BOPTools_AlgoTools.hxx> |
43 | #include <BRep_Builder.hxx> |
44 | #include <BRep_Tool.hxx> |
45 | #include <BRepBndLib.hxx> |
46 | #include <BRepTools.hxx> |
47 | #include <GeomAPI_ProjectPointOnCurve.hxx> |
48 | #include <gp_Pnt.hxx> |
49 | #include <IntTools_CommonPrt.hxx> |
50 | #include <IntTools_Context.hxx> |
51 | #include <IntTools_EdgeEdge.hxx> |
52 | #include <IntTools_Range.hxx> |
53 | #include <IntTools_SequenceOfCommonPrts.hxx> |
54 | #include <IntTools_SequenceOfRanges.hxx> |
55 | #include <IntTools_ShrunkRange.hxx> |
56 | #include <IntTools_Tools.hxx> |
42cf5bc1 |
57 | #include <NCollection_UBTreeFiller.hxx> |
58 | #include <Precision.hxx> |
59 | #include <TopoDS_Compound.hxx> |
60 | #include <TopoDS_Edge.hxx> |
61 | #include <TopoDS_Face.hxx> |
62 | #include <TopoDS_Vertex.hxx> |
db8e4b9a |
63 | |
42cf5bc1 |
64 | // |
65 | // |
66 | // |
67 | // |
68 | // |
69 | // |
a2098360 |
70 | ///////////////////////////////////////////////////////////////////////// |
a942f2da |
71 | //======================================================================= |
72 | //class : BOPAlgo_EdgeEdge |
73 | //purpose : |
74 | //======================================================================= |
36f4947b |
75 | class BOPAlgo_EdgeEdge : |
76 | public IntTools_EdgeEdge, |
77 | public BOPAlgo_Algo { |
78 | |
a942f2da |
79 | public: |
36f4947b |
80 | |
81 | DEFINE_STANDARD_ALLOC |
82 | // |
83 | BOPAlgo_EdgeEdge(): |
84 | IntTools_EdgeEdge(), |
85 | BOPAlgo_Algo() { |
a942f2da |
86 | }; |
87 | // |
36f4947b |
88 | virtual ~BOPAlgo_EdgeEdge(){ |
a942f2da |
89 | }; |
90 | // |
91 | void SetPaveBlock1(const Handle(BOPDS_PaveBlock)& aPB) { |
92 | myPB1=aPB; |
93 | } |
94 | // |
95 | Handle(BOPDS_PaveBlock)& PaveBlock1() { |
96 | return myPB1; |
97 | } |
98 | // |
99 | void SetPaveBlock2(const Handle(BOPDS_PaveBlock)& aPB) { |
100 | myPB2=aPB; |
101 | } |
102 | // |
103 | Handle(BOPDS_PaveBlock)& PaveBlock2() { |
104 | return myPB2; |
105 | } |
36f4947b |
106 | // |
107 | virtual void Perform() { |
108 | BOPAlgo_Algo::UserBreak(); |
109 | IntTools_EdgeEdge::Perform(); |
110 | } |
a942f2da |
111 | // |
112 | protected: |
113 | Handle(BOPDS_PaveBlock) myPB1; |
114 | Handle(BOPDS_PaveBlock) myPB2; |
115 | }; |
116 | // |
505abfb8 |
117 | //======================================================================= |
118 | typedef BOPCol_NCVector |
119 | <BOPAlgo_EdgeEdge> BOPAlgo_VectorOfEdgeEdge; |
a942f2da |
120 | // |
c7b59798 |
121 | typedef BOPCol_Functor |
505abfb8 |
122 | <BOPAlgo_EdgeEdge, |
123 | BOPAlgo_VectorOfEdgeEdge> BOPAlgo_EdgeEdgeFunctor; |
124 | // |
c7b59798 |
125 | typedef BOPCol_Cnt |
505abfb8 |
126 | <BOPAlgo_EdgeEdgeFunctor, |
127 | BOPAlgo_VectorOfEdgeEdge> BOPAlgo_EdgeEdgeCnt; |
a942f2da |
128 | // |
a2098360 |
129 | ///////////////////////////////////////////////////////////////////////// |
130 | //======================================================================= |
131 | //class : BOPAlgo_TNV |
132 | //purpose : |
133 | //======================================================================= |
134 | class BOPAlgo_TNV : public BOPCol_BoxBndTreeSelector{ |
135 | public: |
136 | BOPAlgo_TNV() |
137 | : BOPCol_BoxBndTreeSelector(), myTree(NULL) { |
138 | }; |
139 | // |
140 | ~BOPAlgo_TNV(){ |
141 | }; |
142 | // |
143 | void SetVertex(const TopoDS_Vertex& aV) { |
144 | myV=aV; |
145 | } |
146 | // |
147 | const TopoDS_Vertex& Vertex()const { |
148 | return myV; |
149 | } |
150 | // |
151 | void SetTree(BOPCol_BoxBndTree& aTree) { |
152 | myTree=&aTree; |
153 | } |
154 | // |
155 | void Perform() { |
156 | myTree->Select(*this); |
157 | } |
158 | // |
159 | protected: |
160 | TopoDS_Vertex myV; |
161 | BOPCol_BoxBndTree *myTree; |
162 | }; |
163 | // |
164 | //======================================================================= |
165 | typedef BOPCol_NCVector |
166 | <BOPAlgo_TNV> BOPAlgo_VectorOfTNV; |
167 | // |
c7b59798 |
168 | typedef BOPCol_Functor |
a2098360 |
169 | <BOPAlgo_TNV, |
170 | BOPAlgo_VectorOfTNV> BOPAlgo_TNVFunctor; |
171 | // |
c7b59798 |
172 | typedef BOPCol_Cnt |
a2098360 |
173 | <BOPAlgo_TNVFunctor, |
174 | BOPAlgo_VectorOfTNV> BOPAlgo_TNVCnt; |
175 | ///////////////////////////////////////////////////////////////////////// |
176 | //======================================================================= |
177 | //class : BOPAlgo_PVE |
178 | //purpose : |
179 | //======================================================================= |
180 | class BOPAlgo_PVE { |
181 | public: |
182 | BOPAlgo_PVE() |
183 | : myIV(-1), myIE(-1), myFlag(-1), myT(-1.) { |
184 | }; |
185 | // |
186 | ~BOPAlgo_PVE(){ |
187 | }; |
188 | // |
189 | void SetIndices(const Standard_Integer nV, |
190 | const Standard_Integer nE){ |
191 | myIV=nV; |
192 | myIE=nE; |
193 | } |
194 | // |
195 | void Indices(Standard_Integer& nV, |
196 | Standard_Integer& nE) const { |
197 | nV=myIV; |
198 | nE=myIE; |
199 | } |
200 | // |
201 | void SetVertex(const TopoDS_Vertex& aV) { |
202 | myV=aV; |
203 | } |
204 | // |
205 | const TopoDS_Vertex& Vertex()const { |
206 | return myV; |
207 | } |
208 | // |
209 | void SetEdge(const TopoDS_Edge& aE) { |
210 | myE=aE; |
211 | } |
212 | // |
213 | const TopoDS_Edge& Edge()const { |
214 | return myE; |
215 | } |
216 | // |
217 | void SetPaveBlock(const Handle(BOPDS_PaveBlock)& aPB) { |
218 | myPB=aPB; |
219 | } |
220 | // |
221 | Handle(BOPDS_PaveBlock)& PaveBlock() { |
222 | return myPB; |
223 | } |
224 | // |
225 | Standard_Integer Flag()const { |
226 | return myFlag; |
227 | } |
228 | // |
229 | Standard_Real Parameter()const { |
230 | return myT; |
231 | } |
232 | // |
1e143abb |
233 | void SetContext(const Handle(IntTools_Context)& aContext) { |
a2098360 |
234 | myContext=aContext; |
235 | } |
236 | // |
1e143abb |
237 | const Handle(IntTools_Context)& Context()const { |
a2098360 |
238 | return myContext; |
239 | } |
240 | // |
241 | void Perform() { |
242 | myFlag=myContext->ComputeVE (myV, myE, myT); |
243 | }; |
244 | // |
245 | protected: |
246 | Standard_Integer myIV; |
247 | Standard_Integer myIE; |
248 | Standard_Integer myFlag; |
249 | Standard_Real myT; |
250 | TopoDS_Vertex myV; |
251 | TopoDS_Edge myE; |
252 | Handle(BOPDS_PaveBlock) myPB; |
1e143abb |
253 | Handle(IntTools_Context) myContext; |
a2098360 |
254 | }; |
255 | //======================================================================= |
256 | typedef BOPCol_NCVector |
257 | <BOPAlgo_PVE> BOPAlgo_VectorOfPVE; |
258 | // |
c7b59798 |
259 | typedef BOPCol_ContextFunctor |
a2098360 |
260 | <BOPAlgo_PVE, |
261 | BOPAlgo_VectorOfPVE, |
1e143abb |
262 | Handle(IntTools_Context), |
263 | IntTools_Context> BOPAlgo_PVEFunctor; |
a2098360 |
264 | // |
c7b59798 |
265 | typedef BOPCol_ContextCnt |
a2098360 |
266 | <BOPAlgo_PVEFunctor, |
267 | BOPAlgo_VectorOfPVE, |
1e143abb |
268 | Handle(IntTools_Context)> BOPAlgo_PVECnt; |
a2098360 |
269 | ///////////////////////////////////////////////////////////////////////// |
4e57c75e |
270 | //======================================================================= |
271 | // function: PerformEE |
272 | // purpose: |
273 | //======================================================================= |
db8e4b9a |
274 | void BOPAlgo_PaveFiller::PerformEE() |
4e57c75e |
275 | { |
a942f2da |
276 | Standard_Integer iSize; |
4e57c75e |
277 | // |
278 | myErrorStatus=0; |
279 | // |
505abfb8 |
280 | FillShrunkData(TopAbs_EDGE, TopAbs_EDGE); |
281 | // |
4e57c75e |
282 | myIterator->Initialize(TopAbs_EDGE, TopAbs_EDGE); |
283 | iSize=myIterator->ExpectedLength(); |
284 | if (!iSize) { |
285 | return; |
286 | } |
287 | // |
a942f2da |
288 | Standard_Boolean bJustAdd; |
289 | Standard_Integer i, iX, nE1, nE2, aNbCPrts, k, aNbFdgeEdge; |
290 | Standard_Real aTS11, aTS12, aTS21, aTS22, aT11, aT12, aT21, aT22; |
291 | TopAbs_ShapeEnum aType; |
292 | BOPDS_ListIteratorOfListOfPaveBlock aIt1, aIt2; |
488e5b9d |
293 | Handle(NCollection_BaseAllocator) aAllocator; |
a942f2da |
294 | BOPDS_MapOfPaveBlock aMPBToUpdate; |
295 | BOPAlgo_VectorOfEdgeEdge aVEdgeEdge; |
296 | BOPDS_MapIteratorOfMapOfPaveBlock aItPB; |
297 | // |
488e5b9d |
298 | aAllocator=NCollection_BaseAllocator::CommonBaseAllocator(); |
4e57c75e |
299 | //-----------------------------------------------------scope f |
4e57c75e |
300 | BOPDS_IndexedDataMapOfPaveBlockListOfPaveBlock aMPBLPB(100, aAllocator); |
301 | BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks aMVCPB(100, aAllocator); |
302 | // |
4e57c75e |
303 | BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE(); |
4e57c75e |
304 | aEEs.SetIncrement(iSize); |
4e57c75e |
305 | // |
306 | for (; myIterator->More(); myIterator->Next()) { |
307 | myIterator->Value(nE1, nE2, bJustAdd); |
308 | if(bJustAdd) { |
309 | continue; |
310 | } |
311 | // |
312 | const BOPDS_ShapeInfo& aSIE1=myDS->ShapeInfo(nE1); |
313 | if (aSIE1.HasFlag()){ |
314 | continue; |
315 | } |
316 | const BOPDS_ShapeInfo& aSIE2=myDS->ShapeInfo(nE2); |
317 | if (aSIE2.HasFlag()){ |
318 | continue; |
319 | } |
320 | // |
321 | const TopoDS_Edge& aE1=(*(TopoDS_Edge *)(&aSIE1.Shape())); |
322 | const TopoDS_Edge& aE2=(*(TopoDS_Edge *)(&aSIE2.Shape())); |
323 | // |
4e57c75e |
324 | BOPDS_ListOfPaveBlock& aLPB1=myDS->ChangePaveBlocks(nE1); |
325 | BOPDS_ListOfPaveBlock& aLPB2=myDS->ChangePaveBlocks(nE2); |
326 | // |
327 | aIt1.Initialize(aLPB1); |
328 | for (; aIt1.More(); aIt1.Next()) { |
329 | Bnd_Box aBB1; |
330 | // |
331 | Handle(BOPDS_PaveBlock)& aPB1=aIt1.ChangeValue(); |
332 | if (!aPB1->HasShrunkData()) { |
505abfb8 |
333 | continue; |
4e57c75e |
334 | } |
335 | aPB1->ShrunkData(aTS11, aTS12, aBB1); |
336 | // |
337 | aIt2.Initialize(aLPB2); |
338 | for (; aIt2.More(); aIt2.Next()) { |
339 | Bnd_Box aBB2; |
340 | // |
341 | Handle(BOPDS_PaveBlock)& aPB2=aIt2.ChangeValue(); |
342 | if (!aPB2->HasShrunkData()) { |
505abfb8 |
343 | continue; |
4e57c75e |
344 | } |
345 | aPB2->ShrunkData(aTS21, aTS22, aBB2); |
346 | // |
347 | if (aBB1.IsOut(aBB2)) { |
348 | continue; |
349 | } |
350 | // |
b4109929 |
351 | aPB1->Range(aT11, aT12); |
352 | aPB2->Range(aT21, aT22); |
b4109929 |
353 | // |
a942f2da |
354 | BOPAlgo_EdgeEdge& anEdgeEdge=aVEdgeEdge.Append1(); |
355 | // |
356 | anEdgeEdge.SetPaveBlock1(aPB1); |
357 | anEdgeEdge.SetPaveBlock2(aPB2); |
358 | // |
ec0cdc0e |
359 | anEdgeEdge.SetEdge1(aE1, aT11, aT12); |
360 | anEdgeEdge.SetEdge2(aE2, aT21, aT22); |
36f4947b |
361 | anEdgeEdge.SetProgressIndicator(myProgressIndicator); |
a942f2da |
362 | }//for (; aIt2.More(); aIt2.Next()) { |
363 | }//for (; aIt1.More(); aIt1.Next()) { |
364 | }//for (; myIterator->More(); myIterator->Next()) { |
365 | // |
366 | aNbFdgeEdge=aVEdgeEdge.Extent(); |
367 | //====================================================== |
368 | BOPAlgo_EdgeEdgeCnt::Perform(myRunParallel, aVEdgeEdge); |
369 | //====================================================== |
370 | // |
371 | for (k=0; k < aNbFdgeEdge; ++k) { |
372 | Bnd_Box aBB1, aBB2; |
373 | // |
374 | BOPAlgo_EdgeEdge& anEdgeEdge=aVEdgeEdge(k); |
375 | if (!anEdgeEdge.IsDone()) { |
376 | continue; |
377 | } |
378 | // |
379 | //-------------------------------------------- |
380 | Handle(BOPDS_PaveBlock)& aPB1=anEdgeEdge.PaveBlock1(); |
381 | nE1=aPB1->OriginalEdge(); |
382 | aPB1->Range(aT11, aT12); |
383 | aPB1->ShrunkData(aTS11, aTS12, aBB1); |
384 | // |
385 | Handle(BOPDS_PaveBlock)& aPB2=anEdgeEdge.PaveBlock2(); |
386 | nE2=aPB2->OriginalEdge(); |
387 | aPB2->Range(aT21, aT22); |
388 | aPB2->ShrunkData(aTS21, aTS22, aBB2); |
389 | // |
390 | //-------------------------------------------- |
391 | IntTools_Range aR11(aT11, aTS11), aR12(aTS12, aT12), |
392 | aR21(aT21, aTS21), aR22(aTS22, aT22); |
393 | // |
394 | const IntTools_SequenceOfCommonPrts& aCPrts = anEdgeEdge.CommonParts(); |
395 | aNbCPrts=aCPrts.Length(); |
396 | for (i=1; i<=aNbCPrts; ++i) { |
397 | const IntTools_CommonPrt& aCPart=aCPrts(i); |
398 | // |
399 | const TopoDS_Edge& aE1=aCPart.Edge1(); |
400 | const TopoDS_Edge& aE2=aCPart.Edge2(); |
401 | // |
402 | aType=aCPart.Type(); |
403 | switch (aType) { |
404 | case TopAbs_VERTEX: { |
405 | Standard_Boolean bIsOnPave[4], bFlag; |
406 | Standard_Integer nV[4], j; |
407 | Standard_Real aT1, aT2, aTol; |
408 | TopoDS_Vertex aVnew; |
409 | IntTools_Range aCR1, aCR2; |
410 | // |
1e143abb |
411 | IntTools_Tools::VertexParameters(aCPart, aT1, aT2); |
a942f2da |
412 | aTol = Precision::Confusion(); |
413 | aCR1 = aCPart.Range1(); |
414 | aCR2 = aCPart.Ranges2()(1); |
415 | // |
416 | //decide to keep the pave or not |
1e143abb |
417 | bIsOnPave[0] = IntTools_Tools::IsOnPave1(aT1, aR11, aTol) || |
418 | IntTools_Tools::IsOnPave1(aR11.First(), aCR1, aTol); |
419 | bIsOnPave[1] = IntTools_Tools::IsOnPave1(aT1, aR12, aTol) || |
420 | IntTools_Tools::IsOnPave1(aR12.Last(), aCR1, aTol); |
421 | bIsOnPave[2] = IntTools_Tools::IsOnPave1(aT2, aR21, aTol) || |
422 | IntTools_Tools::IsOnPave1(aR21.First(), aCR2, aTol); |
423 | bIsOnPave[3] = IntTools_Tools::IsOnPave1(aT2, aR22, aTol) || |
424 | IntTools_Tools::IsOnPave1(aR22.Last(), aCR2, aTol); |
a942f2da |
425 | // |
426 | aPB1->Indices(nV[0], nV[1]); |
427 | aPB2->Indices(nV[2], nV[3]); |
428 | // |
429 | if((bIsOnPave[0] && bIsOnPave[2]) || |
430 | (bIsOnPave[0] && bIsOnPave[3]) || |
431 | (bIsOnPave[1] && bIsOnPave[2]) || |
432 | (bIsOnPave[1] && bIsOnPave[3])) { |
433 | continue; |
434 | } |
435 | // |
436 | bFlag = Standard_False; |
437 | for (j = 0; j < 4; ++j) { |
438 | if (bIsOnPave[j]) { |
439 | //add interf VE(nV[j], nE) |
440 | Handle(BOPDS_PaveBlock)& aPB = (j < 2) ? aPB2 : aPB1; |
441 | ForceInterfVE(nV[j], aPB, aMPBToUpdate); |
442 | bFlag = Standard_True; |
443 | break; |
444 | } |
445 | } |
446 | if (bFlag) { |
447 | continue; |
448 | } |
449 | // |
450 | BOPTools_AlgoTools::MakeNewVertex(aE1, aT1, aE2, aT2, aVnew); |
451 | // <-LXBR |
452 | { |
51740958 |
453 | Standard_Integer nVS[2], iFound; |
a942f2da |
454 | Standard_Real aTolVx, aTolVnew, aD2, aDT2; |
455 | BOPCol_MapOfInteger aMV; |
456 | gp_Pnt aPnew, aPx; |
4e57c75e |
457 | // |
a942f2da |
458 | iFound=0; |
459 | j=-1; |
460 | aMV.Add(nV[0]); |
461 | aMV.Add(nV[1]); |
462 | // |
463 | if (aMV.Contains(nV[2])) { |
464 | ++j; |
465 | nVS[j]=nV[2]; |
466 | } |
467 | if (aMV.Contains(nV[3])) { |
468 | ++j; |
469 | nVS[j]=nV[3]; |
470 | } |
471 | // |
472 | aTolVnew=BRep_Tool::Tolerance(aVnew); |
473 | aPnew=BRep_Tool::Pnt(aVnew); |
474 | // |
51740958 |
475 | for (Standard_Integer k1=0; k1<=j; ++k1) { |
476 | const TopoDS_Vertex& aVx= *(TopoDS_Vertex*)&(myDS->Shape(nVS[k1])); |
a942f2da |
477 | aTolVx=BRep_Tool::Tolerance(aVx); |
478 | aPx=BRep_Tool::Pnt(aVx); |
479 | aD2=aPnew.SquareDistance(aPx); |
480 | // |
481 | aDT2=100.*(aTolVnew+aTolVx)*(aTolVnew+aTolVx); |
7eed5d29 |
482 | // |
a942f2da |
483 | if (aD2<aDT2) { |
484 | iFound=1; |
4e57c75e |
485 | break; |
486 | } |
a942f2da |
487 | } |
488 | // |
489 | if (iFound) { |
490 | continue; |
491 | } |
492 | } |
402bfe81 |
493 | // |
a942f2da |
494 | // 1 |
402bfe81 |
495 | BOPDS_InterfEE& aEE=aEEs.Append1(); |
496 | iX=aEEs.Extent()-1; |
a942f2da |
497 | aEE.SetIndices(nE1, nE2); |
498 | aEE.SetCommonPart(aCPart); |
499 | // 2 |
500 | myDS->AddInterf(nE1, nE2); |
501 | // |
502 | BOPDS_CoupleOfPaveBlocks aCPB; |
503 | // |
504 | aCPB.SetPaveBlocks(aPB1, aPB2); |
505 | aCPB.SetIndexInterf(iX); |
506 | aMVCPB.Add(aVnew, aCPB); |
507 | }//case TopAbs_VERTEX: |
508 | break; |
509 | // |
510 | case TopAbs_EDGE: { |
511 | if (aNbCPrts > 1) { |
4e57c75e |
512 | break; |
a942f2da |
513 | } |
514 | // |
515 | Standard_Boolean bHasSameBounds; |
516 | bHasSameBounds=aPB1->HasSameBounds(aPB2); |
517 | if (!bHasSameBounds) { |
518 | break; |
519 | } |
520 | // 1 |
402bfe81 |
521 | BOPDS_InterfEE& aEE=aEEs.Append1(); |
522 | iX=aEEs.Extent()-1; |
a942f2da |
523 | aEE.SetIndices(nE1, nE2); |
524 | aEE.SetCommonPart(aCPart); |
525 | // 2 |
526 | myDS->AddInterf(nE1, nE2); |
527 | // |
528 | BOPAlgo_Tools::FillMap(aPB1, aPB2, aMPBLPB, aAllocator); |
529 | }//case TopAbs_EDGE |
530 | break; |
531 | default: |
532 | break; |
533 | }//switch (aType) { |
534 | }//for (i=1; i<=aNbCPrts; i++) { |
535 | }//for (k=0; k < aNbFdgeEdge; ++k) { |
4e57c75e |
536 | // |
537 | //========================================= |
538 | // post treatment |
539 | //========================================= |
a3476a9f |
540 | { |
541 | Standard_Integer aNbV; |
542 | Handle(BOPDS_PaveBlock) aPB1, aPB2; |
543 | // |
544 | aNbV=aMVCPB.Extent(); |
545 | for (i=1; i<=aNbV; ++i) { |
546 | const BOPDS_CoupleOfPaveBlocks& aCPB=aMVCPB.FindFromIndex(i); |
547 | aCPB.PaveBlocks(aPB1, aPB2); |
548 | // |
549 | aMPBToUpdate.Remove(aPB1); |
550 | aMPBToUpdate.Remove(aPB2); |
551 | } |
552 | } |
553 | // |
b4109929 |
554 | aItPB.Initialize(aMPBToUpdate); |
555 | for (; aItPB.More(); aItPB.Next()) { |
556 | Handle(BOPDS_PaveBlock) aPB=aItPB.Value(); |
557 | if (!myDS->IsCommonBlock(aPB)) { |
558 | myDS->UpdatePaveBlock(aPB); |
559 | } |
560 | else { |
561 | const Handle(BOPDS_CommonBlock)& aCB=myDS->CommonBlock(aPB); |
562 | myDS->UpdateCommonBlock(aCB); |
563 | } |
564 | } |
565 | // |
5a77460e |
566 | BOPAlgo_Tools::PerformCommonBlocks(aMPBLPB, aAllocator, myDS); |
4e57c75e |
567 | PerformVerticesEE(aMVCPB, aAllocator); |
568 | //-----------------------------------------------------scope t |
569 | aMPBLPB.Clear(); |
570 | aMVCPB.Clear(); |
b4109929 |
571 | aMPBToUpdate.Clear(); |
4e57c75e |
572 | } |
573 | //======================================================================= |
574 | //function : PerformVertices |
575 | //purpose : |
576 | //======================================================================= |
db8e4b9a |
577 | Standard_Integer BOPAlgo_PaveFiller::PerformVerticesEE |
578 | (BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& theMVCPB, |
7f22979e |
579 | const Handle(NCollection_BaseAllocator)& theAllocator) |
4e57c75e |
580 | { |
581 | Standard_Integer aNbV, iRet; |
582 | // |
583 | iRet=0; |
584 | aNbV=theMVCPB.Extent(); |
585 | if (!aNbV) { |
586 | return iRet; |
587 | } |
588 | // |
589 | Standard_Integer nVx, iV, j, nE, iFlag, iX, i, aNb; |
590 | Standard_Real aT; |
4e57c75e |
591 | BOPCol_ListIteratorOfListOfShape aItLS; |
592 | BOPCol_ListIteratorOfListOfInteger aItLI; |
593 | BOPDS_ListIteratorOfListOfPaveBlock aItLPB; |
594 | BOPDS_ShapeInfo aSI; |
595 | BOPDS_Pave aPave; |
596 | // |
597 | BOPDS_IndexedDataMapOfPaveBlockListOfInteger aMPBLI(100, theAllocator); |
598 | BOPCol_ListOfShape aLS(theAllocator); |
599 | BOPCol_IndexedDataMapOfShapeInteger aMVI(100, theAllocator); |
600 | BOPCol_IndexedDataMapOfShapeListOfShape aImages; |
601 | // |
602 | aSI.SetShapeType(TopAbs_VERTEX); |
603 | BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE(); |
604 | // |
605 | // 1 prepare arguments |
606 | // |
607 | // <- DEB |
608 | for (i=1; i<=aNbV; ++i) { |
609 | const TopoDS_Shape& aS=theMVCPB.FindKey(i); |
610 | const BOPDS_CoupleOfPaveBlocks& aCPB=theMVCPB.FindFromIndex(i); |
611 | iV=aCPB.IndexInterf(); |
612 | aMVI.Add(aS, iV); |
613 | } |
614 | // |
615 | // 2 Fuse vertices |
616 | TreatNewVertices(aMVI, aImages); |
617 | // |
618 | // 3 Add new vertices to myDS; |
619 | // connect indices to CPB structure |
620 | aNb = aImages.Extent(); |
621 | for (i=1; i<=aNb; ++i) { |
622 | const TopoDS_Vertex& aV=(*(TopoDS_Vertex*)(&aImages.FindKey(i))); |
623 | const BOPCol_ListOfShape& aLVSD=aImages.FindFromIndex(i); |
624 | // |
625 | aSI.SetShape(aV); |
626 | iV=myDS->Append(aSI); |
627 | // |
628 | BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(iV); |
629 | Bnd_Box& aBox=aSIDS.ChangeBox(); |
630 | BRepBndLib::Add(aV, aBox); |
631 | // |
632 | aItLS.Initialize(aLVSD); |
633 | for (; aItLS.More(); aItLS.Next()) { |
634 | const TopoDS_Shape& aVx = aItLS.Value(); |
635 | BOPDS_CoupleOfPaveBlocks &aCPB=theMVCPB.ChangeFromKey(aVx); |
636 | aCPB.SetIndex(iV); |
637 | // update EE interference |
638 | iX=aCPB.IndexInterf(); |
639 | BOPDS_InterfEE& aEE=aEEs(iX); |
640 | aEE.SetIndexNew(iV); |
641 | } |
642 | } |
643 | // |
644 | // 4 Map PaveBlock/ListOfVertices to add to this PaveBlock ->aMPBLI |
645 | { |
646 | Handle(BOPDS_PaveBlock) aPB[2]; |
647 | // |
648 | for (i=1; i<=aNbV; ++i) { |
649 | const BOPDS_CoupleOfPaveBlocks& aCPB=theMVCPB.FindFromIndex(i); |
650 | iV=aCPB.Index(); |
651 | aCPB.PaveBlocks(aPB[0], aPB[1]); |
652 | for (j=0; j<2; ++j) { |
653 | if (aMPBLI.Contains(aPB[j])) { |
654 | BOPCol_ListOfInteger& aLI=aMPBLI.ChangeFromKey(aPB[j]); |
655 | aLI.Append(iV); |
656 | } |
657 | else { |
658 | BOPCol_ListOfInteger aLI(theAllocator); |
659 | aLI.Append(iV); |
660 | aMPBLI.Add(aPB[j], aLI); |
661 | } |
662 | } |
663 | } |
664 | } |
4e57c75e |
665 | // 5 |
666 | // 5.1 Compute Extra Paves and |
667 | // 5.2. Add Extra Paves to the PaveBlocks |
a2098360 |
668 | //------------------------------------------------------------- |
669 | Standard_Integer k, aNbVPVE; |
670 | BOPAlgo_VectorOfPVE aVPVE; |
671 | // |
4e57c75e |
672 | aNb=aMPBLI.Extent(); |
673 | for(i=1; i<=aNb; ++i) { |
674 | Handle(BOPDS_PaveBlock) aPB=aMPBLI.FindKey(i); |
675 | nE=aPB->OriginalEdge(); |
676 | const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&myDS->Shape(nE))); |
677 | // 1,2 |
678 | const BOPCol_ListOfInteger& aLI=aMPBLI.FindFromIndex(i); |
679 | aItLI.Initialize(aLI); |
680 | for (; aItLI.More(); aItLI.Next()) { |
681 | nVx=aItLI.Value(); |
682 | const TopoDS_Vertex& aVx=(*(TopoDS_Vertex *)(&myDS->Shape(nVx))); |
683 | // |
a2098360 |
684 | BOPAlgo_PVE& aPVE=aVPVE.Append1(); |
685 | aPVE.SetIndices(nVx, nE); |
686 | aPVE.SetVertex(aVx); |
687 | aPVE.SetEdge(aE); |
688 | aPVE.SetPaveBlock(aPB); |
689 | } |
690 | } |
691 | // |
692 | aNbVPVE=aVPVE.Extent(); |
693 | //============================================================= |
694 | BOPAlgo_PVECnt::Perform(myRunParallel, aVPVE, myContext); |
695 | //============================================================= |
696 | // |
697 | for (k=0; k < aNbVPVE; ++k) { |
698 | BOPAlgo_PVE& aPVE=aVPVE(k); |
699 | iFlag=aPVE.Flag(); |
700 | if (!iFlag) { |
701 | aPVE.Indices(nVx, nE); |
702 | aT=aPVE.Parameter(); |
703 | Handle(BOPDS_PaveBlock)& aPB=aPVE.PaveBlock(); |
704 | // |
705 | aPave.SetIndex(nVx); |
706 | aPave.SetParameter(aT); |
707 | aPB->AppendExtPave(aPave); |
4e57c75e |
708 | } |
709 | } |
710 | // 6 Split PaveBlocksa |
711 | aNb=aMPBLI.Extent(); |
712 | for(i=1; i<=aNb; ++i) { |
713 | Handle(BOPDS_PaveBlock) aPB=aMPBLI.FindKey(i); |
714 | nE=aPB->OriginalEdge(); |
715 | // 3 |
5a77460e |
716 | if (!myDS->IsCommonBlock(aPB)) { |
4e57c75e |
717 | myDS->UpdatePaveBlock(aPB); |
718 | } |
719 | else { |
5a77460e |
720 | const Handle(BOPDS_CommonBlock)& aCB=myDS->CommonBlock(aPB); |
4e57c75e |
721 | myDS->UpdateCommonBlock(aCB); |
722 | } |
723 | }//for (; aItMPBLI.More(); aItMPBLI.Next()) { |
724 | // |
725 | return iRet; |
726 | } |
4e57c75e |
727 | //======================================================================= |
728 | //function : TreatNewVertices |
729 | //purpose : |
730 | //======================================================================= |
db8e4b9a |
731 | void BOPAlgo_PaveFiller::TreatNewVertices |
732 | (const BOPCol_IndexedDataMapOfShapeInteger& aMapVI, |
733 | BOPCol_IndexedDataMapOfShapeListOfShape& myImages) |
4e57c75e |
734 | { |
a2098360 |
735 | Standard_Integer i, aNbV;//, aNbVSD; |
4e57c75e |
736 | Standard_Real aTol; |
4e57c75e |
737 | TopoDS_Vertex aVnew; |
a2098360 |
738 | TopoDS_Shape aVF; |
4e57c75e |
739 | BOPCol_IndexedMapOfShape aMVProcessed; |
a2098360 |
740 | BOPCol_MapOfInteger aMFence; |
4e57c75e |
741 | BOPCol_ListIteratorOfListOfInteger aIt; |
319da2e4 |
742 | BOPCol_IndexedDataMapOfShapeListOfShape aDMVLV; |
4e57c75e |
743 | // |
db8e4b9a |
744 | BOPCol_BoxBndTreeSelector aSelector; |
745 | BOPCol_BoxBndTree aBBTree; |
a2098360 |
746 | NCollection_UBTreeFiller <Standard_Integer, |
747 | Bnd_Box> aTreeFiller(aBBTree); |
748 | BOPAlgo_VectorOfTNV aVTNV; |
4e57c75e |
749 | // |
750 | aNbV = aMapVI.Extent(); |
751 | for (i=1; i<=aNbV; ++i) { |
a2098360 |
752 | const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aMapVI.FindKey(i)); |
4e57c75e |
753 | Bnd_Box aBox; |
754 | // |
a2098360 |
755 | aTol=BRep_Tool::Tolerance(aV); |
4e57c75e |
756 | aBox.SetGap(aTol); |
a2098360 |
757 | aBox.Add(BRep_Tool::Pnt(aV)); |
758 | aBox.Enlarge(aTol); |
4e57c75e |
759 | // |
760 | aTreeFiller.Add(i, aBox); |
761 | // |
a2098360 |
762 | BOPAlgo_TNV& aTNV=aVTNV.Append1(); |
763 | aTNV.SetTree(aBBTree); |
764 | aTNV.SetBox(aBox); |
765 | aTNV.SetVertex(aV); |
4e57c75e |
766 | } |
767 | // |
768 | aTreeFiller.Fill(); |
a2098360 |
769 | // |
770 | //=========================================== |
771 | BOPAlgo_TNVCnt::Perform(myRunParallel, aVTNV); |
772 | //=========================================== |
773 | // |
4e57c75e |
774 | // Chains |
775 | for (i=1; i<=aNbV; ++i) { |
a2098360 |
776 | if (!aMFence.Add(i)) { |
4e57c75e |
777 | continue; |
778 | } |
779 | // |
a2098360 |
780 | Standard_Integer aIP, aNbIP1, aIP1; |
4e57c75e |
781 | BOPCol_ListOfShape aLVSD; |
a2098360 |
782 | BOPCol_ListOfInteger aLIP, aLIP1, aLIPC; |
783 | BOPCol_ListIteratorOfListOfInteger aItLIP; |
4e57c75e |
784 | // |
a2098360 |
785 | aLIPC.Append(i); |
786 | aLIP.Append(i); |
302f96fb |
787 | for(;;) { |
a2098360 |
788 | aItLIP.Initialize(aLIP); |
789 | for(; aItLIP.More(); aItLIP.Next()) { |
790 | aIP=aItLIP.Value(); |
4e57c75e |
791 | // |
a2098360 |
792 | BOPAlgo_TNV& aTNV=aVTNV(aIP-1); |
793 | const BOPCol_ListOfInteger& aLI=aTNV.Indices(); |
4e57c75e |
794 | aIt.Initialize(aLI); |
795 | for (; aIt.More(); aIt.Next()) { |
796 | aIP1=aIt.Value(); |
a2098360 |
797 | if (!aMFence.Add(aIP1)) { |
4e57c75e |
798 | continue; |
799 | } |
a2098360 |
800 | aLIP1.Append(aIP1); |
4e57c75e |
801 | } //for (; aIt.More(); aIt.Next()) { |
802 | }//for(; aIt1.More(); aIt1.Next()) { |
803 | // |
a2098360 |
804 | aNbIP1=aLIP1.Extent(); |
4e57c75e |
805 | if (!aNbIP1) { |
a2098360 |
806 | break; // from for(;;) |
4e57c75e |
807 | } |
808 | // |
a2098360 |
809 | aLIP.Clear(); |
810 | aItLIP.Initialize(aLIP1); |
811 | for(; aItLIP.More(); aItLIP.Next()) { |
812 | aIP=aItLIP.Value(); |
813 | aLIP.Append(aIP); |
814 | aLIPC.Append(aIP); |
4e57c75e |
815 | } |
a2098360 |
816 | aLIP1.Clear(); |
817 | }// for(;;) { |
4e57c75e |
818 | // |
a2098360 |
819 | aItLIP.Initialize(aLIPC); |
820 | for(; aItLIP.More(); aItLIP.Next()) { |
821 | aIP=aItLIP.Value(); |
822 | const TopoDS_Vertex& aVP=aVTNV(aIP-1).Vertex(); |
4e57c75e |
823 | aLVSD.Append(aVP); |
4e57c75e |
824 | } |
a2098360 |
825 | aVF=aLVSD.First(); |
319da2e4 |
826 | aDMVLV.Add(aVF, aLVSD); |
4e57c75e |
827 | }// for (i=1; i<=aNbV; ++i) { |
828 | |
829 | // Make new vertices |
319da2e4 |
830 | aNbV = aDMVLV.Extent(); |
831 | for (i = 1; i <= aNbV; ++i) { |
832 | const TopoDS_Shape& aV = aDMVLV.FindKey(i); |
833 | const BOPCol_ListOfShape& aLVSD = aDMVLV(i); |
a2098360 |
834 | if (aLVSD.IsEmpty()) { |
4e57c75e |
835 | myImages.Add(aV, aLVSD); |
836 | } |
a2098360 |
837 | else { |
838 | BOPCol_ListOfShape* pLVSD=(BOPCol_ListOfShape*)&aLVSD; |
839 | BOPTools_AlgoTools::MakeVertex(*pLVSD, aVnew); |
840 | myImages.Add(aVnew, aLVSD); |
841 | } |
4e57c75e |
842 | } |
843 | } |
4e57c75e |
844 | //======================================================================= |
845 | //function : FillShrunkData |
846 | //purpose : |
847 | //======================================================================= |
db8e4b9a |
848 | void BOPAlgo_PaveFiller::FillShrunkData(Handle(BOPDS_PaveBlock)& thePB) |
4e57c75e |
849 | { |
850 | Standard_Integer nE, nV1, nV2, iErr; |
851 | Standard_Real aT1, aT2, aTS1, aTS2; |
1e143abb |
852 | IntTools_ShrunkRange aSR; |
4e57c75e |
853 | // |
854 | myErrorStatus=0; |
855 | myWarningStatus = 0; |
856 | // |
857 | const BOPDS_Pave& aPave1=thePB->Pave1(); |
858 | nV1=aPave1.Index(); |
859 | aT1=aPave1.Parameter(); |
860 | const TopoDS_Vertex& aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1))); |
861 | // |
862 | const BOPDS_Pave& aPave2=thePB->Pave2(); |
863 | nV2=aPave2.Index(); |
864 | aT2=aPave2.Parameter(); |
865 | const TopoDS_Vertex& aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2))); |
866 | // |
867 | nE=thePB->OriginalEdge(); |
868 | const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&myDS->Shape(nE))); |
869 | // |
505abfb8 |
870 | aSR.SetContext(myContext); |
871 | aSR.SetData(aE, aT1, aT2, aV1, aV2); |
4e57c75e |
872 | // |
873 | aSR.Perform(); |
874 | iErr=aSR.ErrorStatus(); |
875 | if (iErr) { |
876 | myWarningStatus = 1; |
877 | //myErrorStatus=40; |
878 | return; |
879 | } |
880 | // |
881 | aSR.ShrunkRange(aTS1, aTS2); |
882 | const Bnd_Box& aBox=aSR.BndBox(); |
883 | // |
884 | thePB->SetShrunkData(aTS1, aTS2, aBox); |
885 | } |
b4109929 |
886 | //======================================================================= |
887 | //function : ForceInterfVE |
888 | //purpose : |
889 | //======================================================================= |
890 | void BOPAlgo_PaveFiller::ForceInterfVE(const Standard_Integer nV, |
891 | Handle(BOPDS_PaveBlock)& aPB, |
892 | BOPDS_MapOfPaveBlock& aMPBToUpdate) |
893 | { |
894 | Standard_Integer aNbPnt, nE; |
895 | gp_Pnt aP; |
896 | // |
897 | nE = aPB->OriginalEdge(); |
898 | // |
899 | const BOPDS_ShapeInfo& aSIE=myDS->ShapeInfo(nE); |
900 | if (aSIE.HasSubShape(nV)) { |
901 | return; |
902 | } |
903 | // |
904 | if (myDS->HasInterf(nV, nE)) { |
905 | return; |
906 | } |
907 | // |
908 | if (myDS->HasInterfShapeSubShapes(nV, nE)) { |
909 | return; |
910 | } |
911 | // |
912 | if (aPB->Pave1().Index() == nV || aPB->Pave2().Index() == nV) { |
913 | return; |
914 | } |
915 | // |
916 | const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&myDS->Shape(nV); |
917 | const TopoDS_Edge& aE = *(TopoDS_Edge*) &myDS->Shape(nE); |
918 | aP=BRep_Tool::Pnt(aV); |
919 | // |
920 | GeomAPI_ProjectPointOnCurve& aProjector=myContext->ProjPC(aE); |
921 | aProjector.Perform(aP); |
922 | // |
923 | aNbPnt = aProjector.NbPoints(); |
924 | if (aNbPnt) { |
925 | Standard_Real aT, aDist; |
402bfe81 |
926 | //Standard_Integer i; |
b4109929 |
927 | BRep_Builder aBB; |
928 | BOPDS_Pave aPave; |
929 | // |
930 | aDist=aProjector.LowerDistance(); |
931 | aT=aProjector.LowerDistanceParameter(); |
932 | // |
933 | BOPDS_VectorOfInterfVE& aVEs=myDS->InterfVE(); |
a3476a9f |
934 | aVEs.SetIncrement(10); |
402bfe81 |
935 | BOPDS_InterfVE& aVE=aVEs.Append1(); |
b4109929 |
936 | aVE.SetIndices(nV, nE); |
937 | aVE.SetParameter(aT); |
938 | // |
939 | myDS->AddInterf(nV, nE); |
940 | // |
941 | aBB.UpdateVertex(aV, aDist); |
942 | BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nV); |
943 | Bnd_Box& aBox=aSIDS.ChangeBox(); |
944 | BRepBndLib::Add(aV, aBox); |
945 | // |
946 | aPave.SetIndex(nV); |
947 | aPave.SetParameter(aT); |
948 | aPB->AppendExtPave(aPave); |
949 | // |
950 | aMPBToUpdate.Add(aPB); |
951 | } |
952 | } |
953 | |
4e57c75e |
954 | /* |
955 | // DEBf |
956 | { |
957 | TopoDS_Compound aCx; |
958 | BRep_Builder aBBx; |
959 | aBBx.MakeCompound(aCx); |
960 | aItMVCPB.Initialize(theMVCPB); |
961 | for (; aItMVCPB.More(); aItMVCPB.Next()) { |
962 | const TopoDS_Shape& aS=aItMVCPB.Key(); |
963 | aBBx.Add(aCx, aS); |
964 | } |
965 | BRepTools::Write(aCx, "cx"); |
966 | } |
967 | // DEBt |
968 | */ |