1 // Created by: Peter KURNEV
2 // Copyright (c) 2010-2014 OPEN CASCADE SAS
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
7 // This file is part of Open CASCADE Technology software library.
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
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.
15 // Alternatively, this file may be used under the terms of Open CASCADE
16 // commercial license or contractual agreement.
19 #include <Bnd_Box.hxx>
20 #include <BOPAlgo_PaveFiller.hxx>
21 #include <BOPAlgo_Tools.hxx>
22 #include <BOPAlgo_Alerts.hxx>
23 #include <BOPDS_CommonBlock.hxx>
24 #include <BOPDS_CoupleOfPaveBlocks.hxx>
25 #include <BOPDS_DS.hxx>
26 #include <BOPDS_Interf.hxx>
27 #include <BOPDS_Iterator.hxx>
28 #include <BOPDS_MapOfPaveBlock.hxx>
29 #include <BOPDS_Pave.hxx>
30 #include <BOPDS_PaveBlock.hxx>
31 #include <BOPDS_VectorOfInterfEE.hxx>
32 #include <BOPTools_AlgoTools.hxx>
33 #include <BOPTools_Parallel.hxx>
34 #include <BndLib_Add3dCurve.hxx>
35 #include <BRep_Tool.hxx>
36 #include <BRep_Builder.hxx>
37 #include <BRepAdaptor_Curve.hxx>
39 #include <IntTools_CommonPrt.hxx>
40 #include <IntTools_Context.hxx>
41 #include <IntTools_EdgeEdge.hxx>
42 #include <IntTools_Range.hxx>
43 #include <IntTools_SequenceOfCommonPrts.hxx>
44 #include <IntTools_SequenceOfRanges.hxx>
45 #include <IntTools_ShrunkRange.hxx>
46 #include <IntTools_Tools.hxx>
47 #include <NCollection_IncAllocator.hxx>
48 #include <NCollection_Vector.hxx>
49 #include <Precision.hxx>
51 #include <TopoDS_Edge.hxx>
52 #include <TopoDS_Vertex.hxx>
54 /////////////////////////////////////////////////////////////////////////
55 //=======================================================================
56 //class : BOPAlgo_EdgeEdge
58 //=======================================================================
59 class BOPAlgo_EdgeEdge :
60 public IntTools_EdgeEdge,
72 virtual ~BOPAlgo_EdgeEdge(){
75 void SetPaveBlock1(const Handle(BOPDS_PaveBlock)& aPB) {
79 Handle(BOPDS_PaveBlock)& PaveBlock1() {
83 void SetPaveBlock2(const Handle(BOPDS_PaveBlock)& aPB) {
87 Handle(BOPDS_PaveBlock)& PaveBlock2() {
91 void SetFuzzyValue(const Standard_Real theFuzz) {
92 IntTools_EdgeEdge::SetFuzzyValue(theFuzz);
95 virtual void Perform() {
96 BOPAlgo_Algo::UserBreak();
101 IntTools_EdgeEdge::Perform();
103 catch (Standard_Failure)
105 AddError(new BOPAlgo_AlertIntersectionFailed);
110 Handle(BOPDS_PaveBlock) myPB1;
111 Handle(BOPDS_PaveBlock) myPB2;
114 //=======================================================================
115 typedef NCollection_Vector
116 <BOPAlgo_EdgeEdge> BOPAlgo_VectorOfEdgeEdge;
118 typedef BOPTools_Functor
120 BOPAlgo_VectorOfEdgeEdge> BOPAlgo_EdgeEdgeFunctor;
123 <BOPAlgo_EdgeEdgeFunctor,
124 BOPAlgo_VectorOfEdgeEdge> BOPAlgo_EdgeEdgeCnt;
126 /////////////////////////////////////////////////////////////////////////
127 //=======================================================================
128 // function: PerformEE
130 //=======================================================================
131 void BOPAlgo_PaveFiller::PerformEE()
133 FillShrunkData(TopAbs_EDGE, TopAbs_EDGE);
135 myIterator->Initialize(TopAbs_EDGE, TopAbs_EDGE);
136 Standard_Integer iSize = myIterator->ExpectedLength();
141 Standard_Boolean bExpressCompute, bIsPBSplittable1, bIsPBSplittable2;
142 Standard_Integer i, iX, nE1, nE2, aNbCPrts, k, aNbEdgeEdge;
143 Standard_Integer nV11, nV12, nV21, nV22;
144 Standard_Real aTS11, aTS12, aTS21, aTS22, aT11, aT12, aT21, aT22;
145 TopAbs_ShapeEnum aType;
146 BOPDS_ListIteratorOfListOfPaveBlock aIt1, aIt2;
147 Handle(NCollection_BaseAllocator) aAllocator;
148 BOPAlgo_VectorOfEdgeEdge aVEdgeEdge;
149 BOPDS_MapIteratorOfMapOfPaveBlock aItPB;
150 // keep modified edges for further update
151 TColStd_MapOfInteger aMEdges;
153 aAllocator=NCollection_BaseAllocator::CommonBaseAllocator();
154 //-----------------------------------------------------scope f
155 BOPDS_IndexedDataMapOfPaveBlockListOfPaveBlock aMPBLPB(100, aAllocator);
156 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks aMVCPB(100, aAllocator);
157 BOPAlgo_DataMapOfPaveBlockBndBox aDMPBBox(100, aAllocator);
159 BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
160 aEEs.SetIncrement(iSize);
162 for (; myIterator->More(); myIterator->Next()) {
163 myIterator->Value(nE1, nE2);
165 const BOPDS_ShapeInfo& aSIE1=myDS->ShapeInfo(nE1);
166 if (aSIE1.HasFlag()){
169 const BOPDS_ShapeInfo& aSIE2=myDS->ShapeInfo(nE2);
170 if (aSIE2.HasFlag()){
174 BOPDS_ListOfPaveBlock& aLPB1 = myDS->ChangePaveBlocks(nE1);
175 if (aLPB1.IsEmpty()) {
179 BOPDS_ListOfPaveBlock& aLPB2 = myDS->ChangePaveBlocks(nE2);
180 if (aLPB2.IsEmpty()) {
184 const TopoDS_Edge& aE1=(*(TopoDS_Edge *)(&aSIE1.Shape()));
185 const TopoDS_Edge& aE2=(*(TopoDS_Edge *)(&aSIE2.Shape()));
187 aIt1.Initialize(aLPB1);
188 for (; aIt1.More(); aIt1.Next()) {
191 Handle(BOPDS_PaveBlock)& aPB1=aIt1.ChangeValue();
193 if (!GetPBBox(aE1, aPB1, aDMPBBox, aT11, aT12, aTS11, aTS12, aBB1)) {
197 aPB1->Indices(nV11, nV12);
199 aIt2.Initialize(aLPB2);
200 for (; aIt2.More(); aIt2.Next()) {
203 Handle(BOPDS_PaveBlock)& aPB2=aIt2.ChangeValue();
205 if (!GetPBBox(aE2, aPB2, aDMPBBox, aT21, aT22, aTS21, aTS22, aBB2)) {
209 if (aBB1.IsOut(aBB2)) {
213 aPB2->Indices(nV21, nV22);
215 bExpressCompute=((nV11==nV21 && nV12==nV22) ||
216 (nV12==nV21 && nV11==nV22));
218 BOPAlgo_EdgeEdge& anEdgeEdge=aVEdgeEdge.Appended();
220 anEdgeEdge.UseQuickCoincidenceCheck(bExpressCompute);
222 anEdgeEdge.SetPaveBlock1(aPB1);
223 anEdgeEdge.SetPaveBlock2(aPB2);
225 anEdgeEdge.SetEdge1(aE1, aT11, aT12);
226 anEdgeEdge.SetEdge2(aE2, aT21, aT22);
227 anEdgeEdge.SetFuzzyValue(myFuzzyValue);
228 anEdgeEdge.SetProgressIndicator(myProgressIndicator);
229 }//for (; aIt2.More(); aIt2.Next()) {
230 }//for (; aIt1.More(); aIt1.Next()) {
231 }//for (; myIterator->More(); myIterator->Next()) {
233 aNbEdgeEdge=aVEdgeEdge.Length();
234 //======================================================
235 BOPAlgo_EdgeEdgeCnt::Perform(myRunParallel, aVEdgeEdge);
236 //======================================================
238 for (k = 0; k < aNbEdgeEdge; ++k) {
241 BOPAlgo_EdgeEdge& anEdgeEdge=aVEdgeEdge(k);
242 if (!anEdgeEdge.IsDone() || anEdgeEdge.HasErrors()) {
243 // Warn about failed intersection of sub-shapes
244 const TopoDS_Shape& aE1 = myDS->Shape(anEdgeEdge.PaveBlock1()->OriginalEdge());
245 const TopoDS_Shape& aE2 = myDS->Shape(anEdgeEdge.PaveBlock2()->OriginalEdge());
246 AddIntersectionFailedWarning(aE1, aE2);
250 const IntTools_SequenceOfCommonPrts& aCPrts = anEdgeEdge.CommonParts();
251 aNbCPrts = aCPrts.Length();
255 //--------------------------------------------
256 Handle(BOPDS_PaveBlock)& aPB1=anEdgeEdge.PaveBlock1();
257 nE1=aPB1->OriginalEdge();
258 aPB1->Range(aT11, aT12);
259 if (!aPB1->HasShrunkData()) {
262 bIsPBSplittable1 = Standard_False;
265 aPB1->ShrunkData(aTS11, aTS12, aBB1, bIsPBSplittable1);
268 Handle(BOPDS_PaveBlock)& aPB2=anEdgeEdge.PaveBlock2();
269 nE2=aPB2->OriginalEdge();
270 aPB2->Range(aT21, aT22);
271 if (!aPB2->HasShrunkData()) {
274 bIsPBSplittable2 = Standard_False;
277 aPB2->ShrunkData(aTS21, aTS22, aBB2, bIsPBSplittable2);
280 //--------------------------------------------
281 IntTools_Range aR11(aT11, aTS11), aR12(aTS12, aT12),
282 aR21(aT21, aTS21), aR22(aTS22, aT22);
284 Standard_Boolean bAnalytical = Standard_False;
286 const TopoDS_Edge& aOE1 = *(TopoDS_Edge*)&myDS->Shape(nE1);
287 const TopoDS_Edge& aOE2 = *(TopoDS_Edge*)&myDS->Shape(nE2);
289 BRepAdaptor_Curve aBAC1(aOE1), aBAC2(aOE2);
291 GeomAbs_CurveType aType1 = aBAC1.GetType();
292 GeomAbs_CurveType aType2 = aBAC2.GetType();
294 bAnalytical = (((aType1 == GeomAbs_Line) &&
295 (aType2 == GeomAbs_Line ||
296 aType2 == GeomAbs_Circle)) ||
297 ((aType2 == GeomAbs_Line) &&
298 (aType1 == GeomAbs_Line ||
299 aType1 == GeomAbs_Circle)));
302 for (i=1; i<=aNbCPrts; ++i) {
303 const IntTools_CommonPrt& aCPart=aCPrts(i);
305 const TopoDS_Edge& aE1=aCPart.Edge1();
306 const TopoDS_Edge& aE2=aCPart.Edge2();
310 case TopAbs_VERTEX: {
311 if (!bIsPBSplittable1 || !bIsPBSplittable2) {
315 Standard_Boolean bIsOnPave[4], bFlag;
316 Standard_Integer nV[4], j;
317 Standard_Real aT1, aT2, aTol;
319 IntTools_Range aCR1, aCR2;
321 IntTools_Tools::VertexParameters(aCPart, aT1, aT2);
322 aTol = Precision::Confusion();
323 aCR1 = aCPart.Range1();
324 aCR2 = aCPart.Ranges2()(1);
326 //decide to keep the pave or not
327 bIsOnPave[0] = IntTools_Tools::IsOnPave1(aT1, aR11, aTol) ||
328 IntTools_Tools::IsOnPave1(aR11.First(), aCR1, aTol);
329 bIsOnPave[1] = IntTools_Tools::IsOnPave1(aT1, aR12, aTol) ||
330 IntTools_Tools::IsOnPave1(aR12.Last(), aCR1, aTol);
331 bIsOnPave[2] = IntTools_Tools::IsOnPave1(aT2, aR21, aTol) ||
332 IntTools_Tools::IsOnPave1(aR21.First(), aCR2, aTol);
333 bIsOnPave[3] = IntTools_Tools::IsOnPave1(aT2, aR22, aTol) ||
334 IntTools_Tools::IsOnPave1(aR22.Last(), aCR2, aTol);
336 aPB1->Indices(nV[0], nV[1]);
337 aPB2->Indices(nV[2], nV[3]);
339 if((bIsOnPave[0] && bIsOnPave[2]) ||
340 (bIsOnPave[0] && bIsOnPave[3]) ||
341 (bIsOnPave[1] && bIsOnPave[2]) ||
342 (bIsOnPave[1] && bIsOnPave[3])) {
346 bFlag = Standard_False;
347 for (j = 0; j < 4; ++j) {
349 //add interf VE(nV[j], nE)
350 Handle(BOPDS_PaveBlock)& aPB = (j < 2) ? aPB2 : aPB1;
351 bFlag = ForceInterfVE(nV[j], aPB, aMEdges);
356 BOPDS_InterfEE& aEE = aEEs.Appended();
357 aEE.SetIndices(nE1, nE2);
358 aEE.SetCommonPart(aCPart);
362 BOPTools_AlgoTools::MakeNewVertex(aE1, aT1, aE2, aT2, aVnew);
363 Standard_Real aTolVnew = BRep_Tool::Tolerance(aVnew);
365 // increase tolerance for Line/Line intersection, but do not update
366 // the vertex till its intersection with some other shape
367 Standard_Real aTolMin = (BRepAdaptor_Curve(aE1).GetType() == GeomAbs_Line) ?
368 (aCR1.Last() - aCR1.First()) / 2. : (aCR2.Last() - aCR2.First()) / 2.;
369 if (aTolMin > aTolVnew) {
375 Standard_Integer nVS[2], iFound;
376 Standard_Real aTolVx, aD2, aDT2;
377 TColStd_MapOfInteger aMV;
385 if (aMV.Contains(nV[2])) {
389 if (aMV.Contains(nV[3])) {
394 aPnew=BRep_Tool::Pnt(aVnew);
396 for (Standard_Integer k1=0; k1<=j; ++k1) {
397 const TopoDS_Vertex& aVx= *(TopoDS_Vertex*)&(myDS->Shape(nVS[k1]));
398 aTolVx=BRep_Tool::Tolerance(aVx);
399 aPx=BRep_Tool::Pnt(aVx);
400 aD2=aPnew.SquareDistance(aPx);
402 aDT2=100.*(aTolVnew+aTolVx)*(aTolVnew+aTolVx);
416 BOPDS_InterfEE& aEE=aEEs.Appended();
418 aEE.SetIndices(nE1, nE2);
419 aEE.SetCommonPart(aCPart);
421 myDS->AddInterf(nE1, nE2);
423 BOPDS_CoupleOfPaveBlocks aCPB;
425 aCPB.SetPaveBlocks(aPB1, aPB2);
426 aCPB.SetIndexInterf(iX);
427 aCPB.SetTolerance(aTolVnew);
428 aMVCPB.Add(aVnew, aCPB);
429 }//case TopAbs_VERTEX:
437 Standard_Boolean bHasSameBounds;
438 bHasSameBounds=aPB1->HasSameBounds(aPB2);
439 if (!bHasSameBounds) {
443 BOPDS_InterfEE& aEE=aEEs.Appended();
445 aEE.SetIndices(nE1, nE2);
446 aEE.SetCommonPart(aCPart);
448 myDS->AddInterf(nE1, nE2);
450 BOPAlgo_Tools::FillMap<Handle(BOPDS_PaveBlock), TColStd_MapTransientHasher>(aPB1, aPB2, aMPBLPB, aAllocator);
456 }//for (i=1; i<=aNbCPrts; i++) {
457 }//for (k=0; k < aNbFdgeEdge; ++k) {
459 //=========================================
461 //=========================================
462 BOPAlgo_Tools::PerformCommonBlocks(aMPBLPB, aAllocator, myDS);
463 PerformNewVertices(aMVCPB, aAllocator);
465 if (aMEdges.Extent()) {
466 Standard_Integer aNbV = aMVCPB.Extent();
467 for (i = 1; i <= aNbV; ++i) {
468 Handle(BOPDS_PaveBlock) aPB1, aPB2;
469 const BOPDS_CoupleOfPaveBlocks& aCPB = aMVCPB.FindFromIndex(i);
470 aCPB.PaveBlocks(aPB1, aPB2);
472 aMEdges.Remove(aPB1->OriginalEdge());
473 aMEdges.Remove(aPB2->OriginalEdge());
476 SplitPaveBlocks(aMEdges, Standard_False);
479 //-----------------------------------------------------scope t
483 //=======================================================================
484 //function : PerformVerticesEE
486 //=======================================================================
487 void BOPAlgo_PaveFiller::PerformNewVertices
488 (BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& theMVCPB,
489 const Handle(NCollection_BaseAllocator)& theAllocator,
490 const Standard_Boolean bIsEEIntersection)
492 Standard_Integer aNbV = theMVCPB.Extent();
497 Standard_Real aTolAdd = myFuzzyValue / 2.;
499 // 1. Fuse the new vertices
500 TopTools_IndexedDataMapOfShapeListOfShape aImages;
501 TreatNewVertices(theMVCPB, aImages);
503 // 2. Add new vertices to myDS and connect indices to CPB structure
504 BOPDS_VectorOfInterfEE& aEEs = myDS->InterfEE();
505 BOPDS_VectorOfInterfEF& aEFs = myDS->InterfEF();
507 Standard_Integer i, aNb = aImages.Extent();
508 for (i = 1; i <= aNb; ++i) {
509 const TopoDS_Vertex& aV = TopoDS::Vertex(aImages.FindKey(i));
510 const TopTools_ListOfShape& aLVSD = aImages.FindFromIndex(i);
513 aSI.SetShapeType(TopAbs_VERTEX);
515 Standard_Integer iV = myDS->Append(aSI);
517 BOPDS_ShapeInfo& aSIDS = myDS->ChangeShapeInfo(iV);
518 Bnd_Box& aBox = aSIDS.ChangeBox();
519 aBox.Add(BRep_Tool::Pnt(aV));
520 aBox.SetGap(BRep_Tool::Tolerance(aV) + aTolAdd);
522 TopTools_ListIteratorOfListOfShape aItLS(aLVSD);
523 for (; aItLS.More(); aItLS.Next()) {
524 const TopoDS_Shape& aVx = aItLS.Value();
525 BOPDS_CoupleOfPaveBlocks &aCPB = theMVCPB.ChangeFromKey(aVx);
527 // update interference
528 Standard_Integer iX = aCPB.IndexInterf();
529 BOPDS_Interf *aInt = bIsEEIntersection ? (BOPDS_Interf*)(&aEEs(iX)) : (BOPDS_Interf*) (&aEFs(iX));
530 aInt->SetIndexNew(iV);
534 // 3. Map PaveBlock/ListOfVertices to add to this PaveBlock ->aMPBLI
535 BOPDS_IndexedDataMapOfPaveBlockListOfInteger aMPBLI(100, theAllocator);
536 for (i = 1; i <= aNbV; ++i) {
537 const BOPDS_CoupleOfPaveBlocks& aCPB = theMVCPB.FindFromIndex(i);
538 Standard_Integer iV = aCPB.Index();
540 Handle(BOPDS_PaveBlock) aPB[2];
541 aCPB.PaveBlocks(aPB[0], aPB[1]);
542 for (Standard_Integer j = 0; j < 2; ++j) {
543 TColStd_ListOfInteger *pLI = aMPBLI.ChangeSeek(aPB[j]);
545 pLI = &aMPBLI(aMPBLI.Add(aPB[j], TColStd_ListOfInteger(theAllocator)));
549 if (aPB[0] == aPB[1]) {
555 // 4. Compute Extra Paves and split Pave blocks by the Extra paves
556 IntersectVE(aMPBLI, Standard_False);
558 //=======================================================================
559 //function : TreatNewVertices
561 //=======================================================================
562 void BOPAlgo_PaveFiller::TreatNewVertices
563 (const BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& theMVCPB,
564 TopTools_IndexedDataMapOfShapeListOfShape& myImages)
567 // Prepare for intersection
568 TopTools_IndexedDataMapOfShapeReal aVerts;
569 Standard_Integer i, aNbV = theMVCPB.Extent();
570 for (i = 1; i <= aNbV; ++i) {
571 const TopoDS_Shape& aV = theMVCPB.FindKey(i);
572 Standard_Real aTol = theMVCPB.FindFromIndex(i).Tolerance();
573 aVerts.Add(aV, aTol);
576 // Perform intersection
577 TopTools_ListOfListOfShape aChains;
578 BOPAlgo_Tools::IntersectVertices(aVerts, myRunParallel, myFuzzyValue, aChains);
580 // Treat the results - make new vertices for each chain
581 TopTools_ListOfListOfShape::Iterator aItC(aChains);
582 for (; aItC.More(); aItC.Next()) {
583 const TopTools_ListOfShape& aLVSD = aItC.Value();
586 BOPTools_AlgoTools::MakeVertex(aLVSD, aVNew);
587 myImages.Add(aVNew, aLVSD);
590 //=======================================================================
591 //function : FillShrunkData
593 //=======================================================================
594 void BOPAlgo_PaveFiller::FillShrunkData(Handle(BOPDS_PaveBlock)& thePB)
597 Standard_Integer nV1, nV2;
598 thePB->Indices(nV1, nV2);
599 const TopoDS_Vertex& aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1)));
600 const TopoDS_Vertex& aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2)));
602 Standard_Integer nE = thePB->OriginalEdge();
603 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&myDS->Shape(nE)));
605 Standard_Real aT1, aT2;
606 thePB->Range(aT1, aT2);
608 IntTools_ShrunkRange aSR;
609 aSR.SetContext(myContext);
610 aSR.SetData(aE, aT1, aT2, aV1, aV2);
612 // Analyze the results of computations
613 AnalyzeShrunkData(thePB, aSR);
615 //=======================================================================
616 // function: AnalyzeShrunkData
618 //=======================================================================
619 void BOPAlgo_PaveFiller::AnalyzeShrunkData(const Handle(BOPDS_PaveBlock)& thePB,
620 const IntTools_ShrunkRange& theSR)
622 // in case of error treat the warning status
623 Standard_Boolean bWholeEdge = Standard_False;
624 TopoDS_Shape aWarnShape;
626 if (!theSR.IsDone() || !theSR.IsSplittable()) {
627 Standard_Real aEFirst, aELast, aPBFirst, aPBLast;
628 BRep_Tool::Range(theSR.Edge(), aEFirst, aELast);
629 thePB->Range(aPBFirst, aPBLast);
630 bWholeEdge = !(aPBFirst > aEFirst || aPBLast < aELast);
632 aWarnShape = theSR.Edge();
635 const TopoDS_Shape& aV1 = myDS->Shape(thePB->Pave1().Index());
636 const TopoDS_Shape& aV2 = myDS->Shape(thePB->Pave2().Index());
637 BRep_Builder().MakeCompound(TopoDS::Compound(aWarnShape));
638 BRep_Builder().Add(aWarnShape, theSR.Edge());
639 BRep_Builder().Add(aWarnShape, aV1);
640 BRep_Builder().Add(aWarnShape, aV2);
643 if (!theSR.IsDone()) {
645 AddWarning (new BOPAlgo_AlertTooSmallEdge (aWarnShape));
647 AddWarning (new BOPAlgo_AlertBadPositioning (aWarnShape));
648 Standard_Real aTS1, aTS2;
649 theSR.ShrunkRange(aTS1, aTS2);
650 thePB->SetShrunkData(aTS1, aTS2, Bnd_Box(), Standard_False);
655 AddWarning (new BOPAlgo_AlertNotSplittableEdge (aWarnShape));
657 AddWarning (new BOPAlgo_AlertBadPositioning (aWarnShape));
660 Standard_Real aTS1, aTS2;
661 theSR.ShrunkRange(aTS1, aTS2);
662 Bnd_Box aBox = theSR.BndBox();
663 aBox.SetGap(aBox.GetGap() + myFuzzyValue / 2.);
664 thePB->SetShrunkData(aTS1, aTS2, aBox, theSR.IsSplittable());
666 //=======================================================================
667 //function : ForceInterfVE
669 //=======================================================================
670 Standard_Boolean BOPAlgo_PaveFiller::ForceInterfVE(const Standard_Integer nV,
671 Handle(BOPDS_PaveBlock)& aPB,
672 TColStd_MapOfInteger& theMEdges)
674 Standard_Integer nE, nVx, nVSD, iFlag;
675 Standard_Real aT, aTolVNew;
677 nE = aPB->OriginalEdge();
679 const BOPDS_ShapeInfo& aSIE=myDS->ShapeInfo(nE);
680 if (aSIE.HasSubShape(nV)) {
681 return Standard_False;
684 if (myDS->HasInterf(nV, nE)) {
685 return Standard_False;
688 if (myDS->HasInterfShapeSubShapes(nV, nE)) {
689 return Standard_False;
692 if (aPB->Pave1().Index() == nV ||
693 aPB->Pave2().Index() == nV) {
694 return Standard_False;
698 if (myDS->HasShapeSD(nV, nVSD)) {
702 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&myDS->Shape(nVx);
703 const TopoDS_Edge& aE = *(TopoDS_Edge*) &myDS->Shape(nE);
705 iFlag = myContext->ComputeVE(aV, aE, aT, aTolVNew, myFuzzyValue);
706 if (iFlag == 0 || iFlag == -4) {
710 BOPDS_VectorOfInterfVE& aVEs=myDS->InterfVE();
711 aVEs.SetIncrement(10);
713 BOPDS_InterfVE& aVE=aVEs.Appended();
714 aVE.SetIndices(nV, nE);
715 aVE.SetParameter(aT);
717 myDS->AddInterf(nV, nE);
719 // 3 update vertex V/E if necessary
720 nVx=UpdateVertex(nV, aTolVNew);
722 if (myDS->IsNewShape(nVx)) {
723 aVE.SetIndexNew(nVx);
725 // 5 append ext pave to pave block
727 aPave.SetParameter(aT);
728 aPB->AppendExtPave(aPave);
732 // check for self-interference
733 Standard_Integer iRV = myDS->Rank(nV);
734 if (iRV >= 0 && iRV == myDS->Rank(nE)) {
735 // add warning status
737 BRep_Builder().MakeCompound(aWC);
738 BRep_Builder().Add(aWC, aV);
739 BRep_Builder().Add(aWC, aE);
740 AddWarning (new BOPAlgo_AlertSelfInterferingShape (aWC));
742 return Standard_True;
744 return Standard_False;
747 //=======================================================================
748 //function : GetPBBox
750 //=======================================================================
751 Standard_Boolean BOPAlgo_PaveFiller::GetPBBox(const TopoDS_Edge& theE,
752 const Handle(BOPDS_PaveBlock)& thePB,
753 BOPAlgo_DataMapOfPaveBlockBndBox& thePBBox,
754 Standard_Real& theFirst,
755 Standard_Real& theLast,
756 Standard_Real& theSFirst,
757 Standard_Real& theSLast,
760 thePB->Range(theFirst, theLast);
761 // check the validity of PB's range
762 Standard_Boolean bValid = theLast - theFirst > Precision::PConfusion();
768 if (thePB->HasShrunkData()) {
769 Standard_Boolean bIsSplittable;
770 thePB->ShrunkData(theSFirst, theSLast, theBox, bIsSplittable);
774 theSFirst = theFirst;
777 if (thePBBox.IsBound(thePB)) {
778 theBox = thePBBox.Find(thePB);
781 // build bounding box
782 BRepAdaptor_Curve aBAC(theE);
783 Standard_Real aTol = BRep_Tool::Tolerance(theE) + Precision::Confusion();
784 BndLib_Add3dCurve::Add(aBAC, theSFirst, theSLast, aTol, theBox);
785 thePBBox.Bind(thePB, theBox);
790 //=======================================================================
791 //function : ForceInterfEE
793 //=======================================================================
794 void BOPAlgo_PaveFiller::ForceInterfEE()
796 // Now that we have vertices increased and unified, try to find additional
797 // common blocks among the pairs of edges that did not participate in
798 // intersection (PerformEE() method) due to being rejected by bounding boxes.
799 // Here, we are interested in common blocks only, as all real intersections
800 // should have happened already. Thus, we need to look only for the same
801 // vertices in the pairs of pave blocks and check the coincidence of such pave blocks.
803 Handle(NCollection_IncAllocator) anAlloc = new NCollection_IncAllocator;
805 // Initialize pave blocks for all SD vertices
806 Standard_Integer i, aNbS = myDS->NbSourceShapes();
807 for (i = 0; i < aNbS; ++i)
809 const BOPDS_ShapeInfo& aSI = myDS->ShapeInfo(i);
810 if (aSI.ShapeType() == TopAbs_VERTEX)
812 Standard_Integer nVSD;
813 if (myDS->HasShapeSD(i, nVSD))
814 myDS->InitPaveBlocksForVertex(i);
818 // Find all Pave Blocks with both paves being SD vertices.
819 NCollection_IndexedDataMap<BOPDS_Pair,
820 BOPDS_ListOfPaveBlock,
821 BOPDS_PairMapHasher> aPBMap(1, anAlloc);
822 // Fence map of pave blocks
823 BOPDS_MapOfPaveBlock aMPBFence(1, anAlloc);
825 BOPDS_VectorOfListOfPaveBlock& aPBP = myDS->ChangePaveBlocksPool();
826 Standard_Integer aNbPBP = aPBP.Length();
827 for (i = 0; i < aNbPBP; ++i)
829 BOPDS_ListOfPaveBlock& aLPB = aPBP(i);
830 BOPDS_ListIteratorOfListOfPaveBlock aItLPB(aLPB);
831 for (; aItLPB.More(); aItLPB.Next())
833 const Handle(BOPDS_PaveBlock)& aPB = aItLPB.Value();
834 const Handle(BOPDS_PaveBlock)& aPBR = myDS->RealPaveBlock(aPB);
835 if (!aMPBFence.Add(aPBR))
839 Standard_Integer nV1, nV2;
840 aPBR->Indices(nV1, nV2);
842 // Add pave block to a map
843 BOPDS_Pair aPair(nV1, nV2);
844 BOPDS_ListOfPaveBlock *pList = aPBMap.ChangeSeek(aPair);
846 pList = &aPBMap(aPBMap.Add(aPair, BOPDS_ListOfPaveBlock(anAlloc)));
851 Standard_Integer aNbPB = aPBMap.Extent();
855 // Find pairs of Pave Blocks having the same SD vertices,
856 // rejecting the pairs of edges that have already been intersected
858 // Prepare map of pairs of intersected edges
859 BOPDS_MapOfPair aMEEDone(1, anAlloc);
860 myIterator->Initialize(TopAbs_EDGE, TopAbs_EDGE);
861 for (; myIterator->More(); myIterator->Next())
863 Standard_Integer nE1, nE2;
864 myIterator->Value(nE1, nE2);
865 aMEEDone.Add(BOPDS_Pair(nE1, nE2));
868 // Vector of pairs for intersection
869 BOPAlgo_VectorOfEdgeEdge aVEdgeEdge;
871 for (i = 1; i <= aNbPB; ++i)
873 const BOPDS_ListOfPaveBlock& aLPB = aPBMap(i);
874 if (aLPB.Extent() < 2)
877 const BOPDS_Pair& aPair = aPBMap.FindKey(i);
878 Standard_Integer nV1, nV2;
879 aPair.Indices(nV1, nV2);
881 const TopoDS_Vertex& aV1 = TopoDS::Vertex(myDS->Shape(nV1));
882 const TopoDS_Vertex& aV2 = TopoDS::Vertex(myDS->Shape(nV2));
884 // Use the max tolerance of vertices as Fuzzy value for intersection
886 Standard_Real aTolAdd = 2 * Max(BRep_Tool::Tolerance(aV1),
887 BRep_Tool::Tolerance(aV2));
889 // All possible pairs combined from the list <aLPB> should be checked
890 BOPDS_ListIteratorOfListOfPaveBlock aItLPB1(aLPB);
891 for (; aItLPB1.More(); aItLPB1.Next())
893 const Handle(BOPDS_PaveBlock)& aPB1 = aItLPB1.Value();
894 const Standard_Integer nE1 = aPB1->OriginalEdge();
895 const TopoDS_Edge& aE1 = TopoDS::Edge(myDS->Shape(nE1));
896 Standard_Real aT11, aT12;
897 aPB1->Range(aT11, aT12);
899 BOPDS_ListIteratorOfListOfPaveBlock aItLPB2 = aItLPB1;
900 for (aItLPB2.Next(); aItLPB2.More(); aItLPB2.Next())
902 const Handle(BOPDS_PaveBlock)& aPB2 = aItLPB2.Value();
903 const Standard_Integer nE2 = aPB2->OriginalEdge();
905 if (aMEEDone.Contains(BOPDS_Pair(nE1, nE2)))
908 // Make sure that the edges came from different arguments
909 if (myDS->Rank(nE1) == myDS->Rank(nE2))
912 const TopoDS_Edge& aE2 = TopoDS::Edge(myDS->Shape(nE2));
913 Standard_Real aT21, aT22;
914 aPB2->Range(aT21, aT22);
916 // Add pair for intersection
917 BOPAlgo_EdgeEdge& anEdgeEdge = aVEdgeEdge.Appended();
918 anEdgeEdge.UseQuickCoincidenceCheck(Standard_True);
919 anEdgeEdge.SetPaveBlock1(aPB1);
920 anEdgeEdge.SetPaveBlock2(aPB2);
921 anEdgeEdge.SetEdge1(aE1, aT11, aT12);
922 anEdgeEdge.SetEdge2(aE2, aT21, aT22);
923 anEdgeEdge.SetFuzzyValue(myFuzzyValue + aTolAdd);
924 anEdgeEdge.SetProgressIndicator(myProgressIndicator);
929 Standard_Integer aNbPairs = aVEdgeEdge.Length();
938 // Perform intersection of the found pairs
939 BOPAlgo_EdgeEdgeCnt::Perform(myRunParallel, aVEdgeEdge);
941 BOPDS_VectorOfInterfEE& aEEs = myDS->InterfEE();
943 aEEs.SetIncrement(10);
945 // Analyze the results of intersection looking for TopAbs_EDGE
946 // intersection type only.
948 BOPDS_IndexedDataMapOfPaveBlockListOfPaveBlock aMPBLPB(1, anAlloc);
950 for (i = 0; i < aNbPairs; ++i)
952 BOPAlgo_EdgeEdge& anEdgeEdge = aVEdgeEdge(i);
953 if (!anEdgeEdge.IsDone() || anEdgeEdge.HasErrors())
955 // Warn about failed intersection of sub-shapes
956 const TopoDS_Shape& aE1 = myDS->Shape(anEdgeEdge.PaveBlock1()->OriginalEdge());
957 const TopoDS_Shape& aE2 = myDS->Shape(anEdgeEdge.PaveBlock2()->OriginalEdge());
958 AddIntersectionFailedWarning(aE1, aE2);
962 const IntTools_SequenceOfCommonPrts& aCParts = anEdgeEdge.CommonParts();
963 if (aCParts.Length() != 1)
966 const IntTools_CommonPrt& aCP = aCParts(1);
967 if (aCP.Type() != TopAbs_EDGE)
970 Handle(BOPDS_PaveBlock) aPB[] = {anEdgeEdge.PaveBlock1(), anEdgeEdge.PaveBlock2()};
971 const Standard_Integer nE1 = aPB[0]->OriginalEdge();
972 const Standard_Integer nE2 = aPB[1]->OriginalEdge();
974 BOPDS_InterfEE& aEE = aEEs.Appended();
975 aEE.SetIndices(nE1, nE2);
976 aEE.SetCommonPart(aCP);
977 myDS->AddInterf(nE1, nE2);
979 // Fill map for common blocks creation
980 for (Standard_Integer j = 0; j < 2; ++j)
982 if (myDS->IsCommonBlock(aPB[j]))
984 const BOPDS_ListOfPaveBlock& aLPBCB = myDS->CommonBlock(aPB[j])->PaveBlocks();
985 BOPDS_ListIteratorOfListOfPaveBlock aItLPB(aLPBCB);
986 for (; aItLPB.More(); aItLPB.Next())
987 BOPAlgo_Tools::FillMap<Handle(BOPDS_PaveBlock),
988 TColStd_MapTransientHasher>(aPB[j], aItLPB.Value(), aMPBLPB, anAlloc);
991 BOPAlgo_Tools::FillMap<Handle(BOPDS_PaveBlock),
992 TColStd_MapTransientHasher>(aPB[0], aPB[1], aMPBLPB, anAlloc);
995 // Create new common blocks of coinciding pairs.
996 BOPAlgo_Tools::PerformCommonBlocks(aMPBLPB, anAlloc, myDS);