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.
18 #include <BOPAlgo_PaveFiller.ixx>
20 #include <NCollection_IncAllocator.hxx>
22 #include <GeomAPI_ProjectPointOnSurf.hxx>
24 #include <Bnd_Box.hxx>
26 #include <TopoDS_Vertex.hxx>
27 #include <TopoDS_Edge.hxx>
28 #include <TopoDS_Face.hxx>
29 #include <BRep_Tool.hxx>
30 #include <BRepBndLib.hxx>
31 #include <BRepAdaptor_Curve.hxx>
32 #include <BRep_Builder.hxx>
34 #include <IntTools_EdgeFace.hxx>
35 #include <IntTools_Range.hxx>
36 #include <IntTools_SequenceOfCommonPrts.hxx>
37 #include <IntTools_CommonPrt.hxx>
39 #include <BOPCol_MapOfInteger.hxx>
40 #include <BOPCol_NCVector.hxx>
41 #include <BOPCol_TBB.hxx>
43 #include <IntTools_Context.hxx>
44 #include <IntTools_Tools.hxx>
46 #include <BOPDS_Interf.hxx>
47 #include <BOPDS_Iterator.hxx>
48 #include <BOPDS_PaveBlock.hxx>
49 #include <BOPDS_MapOfPaveBlock.hxx>
50 #include <BOPDS_DataMapOfPaveBlockListOfInteger.hxx>
51 #include <BOPDS_CommonBlock.hxx>
52 #include <BOPDS_Pave.hxx>
53 #include <BOPDS_CoupleOfPaveBlocks.hxx>
55 #include <BOPTools_AlgoTools.hxx>
57 #include <BOPAlgo_Tools.hxx>
59 //=======================================================================
60 //class : BOPAlgo_EdgeFace
62 //=======================================================================
63 class BOPAlgo_EdgeFace :
64 public IntTools_EdgeFace,
76 virtual ~BOPAlgo_EdgeFace(){
79 void SetIndices(const Standard_Integer nE,
80 const Standard_Integer nF) {
85 void Indices(Standard_Integer& nE,
86 Standard_Integer& nF) {
91 void SetNewSR(const IntTools_Range& aR){
95 IntTools_Range& NewSR(){
99 void SetPaveBlock(const Handle(BOPDS_PaveBlock)& aPB) {
103 Handle(BOPDS_PaveBlock)& PaveBlock() {
107 virtual void Perform() {
108 BOPAlgo_Algo::UserBreak();
109 IntTools_EdgeFace::Perform();
113 Standard_Integer myIE;
114 Standard_Integer myIF;
115 IntTools_Range myNewSR;
116 Handle(BOPDS_PaveBlock) myPB;
119 //=======================================================================
120 typedef BOPCol_NCVector<BOPAlgo_EdgeFace> BOPAlgo_VectorOfEdgeFace;
122 typedef BOPCol_TBBContextFunctor
124 BOPAlgo_VectorOfEdgeFace,
125 Handle(IntTools_Context),
126 IntTools_Context> BOPAlgo_EdgeFaceFunctor;
128 typedef BOPCol_TBBContextCnt
129 <BOPAlgo_EdgeFaceFunctor,
130 BOPAlgo_VectorOfEdgeFace,
131 Handle(IntTools_Context)> BOPAlgo_EdgeFaceCnt;
133 //=======================================================================
134 //function : PerformEF
136 //=======================================================================
137 void BOPAlgo_PaveFiller::PerformEF()
139 Standard_Integer iSize;
143 FillShrunkData(TopAbs_EDGE, TopAbs_FACE);
145 myIterator->Initialize(TopAbs_EDGE, TopAbs_FACE);
146 iSize=myIterator->ExpectedLength();
151 Standard_Boolean bJustAdd, bV[2];
152 Standard_Integer nE, nF, aDiscretize, i, aNbCPrts, iX, nV[2];
153 Standard_Integer aNbEdgeFace, k;
154 Standard_Real aTolE, aTolF, aTS1, aTS2, aT1, aT2, aDeflection;
155 Handle(NCollection_IncAllocator) aAllocator;
156 TopAbs_ShapeEnum aType;
157 BOPDS_ListIteratorOfListOfPaveBlock aIt;
158 BOPAlgo_VectorOfEdgeFace aVEdgeFace;
160 //-----------------------------------------------------scope f
162 ////aAllocator=new NCollection_IncAllocator();
164 BOPCol_MapOfInteger aMIEFC(100, aAllocator);
165 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks aMVCPB(100, aAllocator);
166 BOPDS_IndexedDataMapOfPaveBlockListOfInteger aMPBLI(100, aAllocator);
171 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
172 aEFs.SetStartSize(iSize);
173 aEFs.SetIncrement(iSize);
176 for (; myIterator->More(); myIterator->Next()) {
177 myIterator->Value(nE, nF, bJustAdd);
182 const BOPDS_ShapeInfo& aSIE=myDS->ShapeInfo(nE);
183 if (aSIE.HasFlag()){//degenerated
187 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&aSIE.Shape()));
188 const TopoDS_Face& aF=(*(TopoDS_Face *)(&myDS->Shape(nF)));
189 const Bnd_Box& aBBF=myDS->ShapeInfo(nF).Box();
191 BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
192 const BOPDS_IndexedMapOfPaveBlock& aMPBF=aFI.PaveBlocksOn();
194 aTolE=BRep_Tool::Tolerance(aE);
195 aTolF=BRep_Tool::Tolerance(aF);
197 BOPDS_ListOfPaveBlock& aLPB=myDS->ChangePaveBlocks(nE);
198 aIt.Initialize(aLPB);
199 for (; aIt.More(); aIt.Next()) {
200 Handle(BOPDS_PaveBlock)& aPB=aIt.ChangeValue();
202 const Handle(BOPDS_PaveBlock) aPBR=myDS->RealPaveBlock(aPB);
203 if (aMPBF.Contains(aPBR)) {
207 if (!aPB->HasShrunkData()) {
212 aPB->ShrunkData(aTS1, aTS2, aBBE);
214 if (aBBF.IsOut (aBBE)) {
218 BOPAlgo_EdgeFace& aEdgeFace=aVEdgeFace.Append1();
220 aEdgeFace.SetIndices(nE, nF);
221 aEdgeFace.SetPaveBlock(aPB);
223 aEdgeFace.SetEdge (aE);
224 aEdgeFace.SetFace (aF);
225 aEdgeFace.SetTolE (aTolE);
226 aEdgeFace.SetTolF (aTolF);
227 aEdgeFace.SetDiscretize (aDiscretize);
228 aEdgeFace.SetDeflection (aDeflection);
230 IntTools_Range aSR(aTS1, aTS2);
231 IntTools_Range anewSR=aSR;
232 BOPTools_AlgoTools::CorrectRange(aE, aF, aSR, anewSR);
233 aEdgeFace.SetNewSR(anewSR);
235 aPB->Range(aT1, aT2);
236 IntTools_Range aPBRange(aT1, aT2);
238 BOPTools_AlgoTools::CorrectRange(aE, aF, aSR, aPBRange);
239 aEdgeFace.SetRange (aPBRange);
240 aEdgeFace.SetProgressIndicator(myProgressIndicator);
242 }//for (; aIt.More(); aIt.Next()) {
243 }//for (; myIterator->More(); myIterator->Next()) {
245 aNbEdgeFace=aVEdgeFace.Extent();
246 //=================================================================
247 BOPAlgo_EdgeFaceCnt::Perform(myRunParallel, aVEdgeFace, myContext);
248 //=================================================================
250 for (k=0; k < aNbEdgeFace; ++k) {
251 BOPAlgo_EdgeFace& aEdgeFace=aVEdgeFace(k);
252 if (!aEdgeFace.IsDone()) {
256 aEdgeFace.Indices(nE, nF);
258 const TopoDS_Edge& aE=aEdgeFace.Edge();
259 const TopoDS_Face& aF=aEdgeFace.Face();
261 aTolE=aEdgeFace.TolE();
262 aTolF=aEdgeFace.TolF();
263 const IntTools_Range& anewSR=aEdgeFace.NewSR();
264 Handle(BOPDS_PaveBlock)& aPB=aEdgeFace.PaveBlock();
266 aPB->Range(aT1, aT2);
267 aPB->Indices(nV[0], nV[1]);
269 BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
270 const BOPCol_MapOfInteger& aMIFOn=aFI.VerticesOn();
271 const BOPCol_MapOfInteger& aMIFIn=aFI.VerticesIn();
273 const IntTools_SequenceOfCommonPrts& aCPrts=aEdgeFace.CommonParts();
274 aNbCPrts=aCPrts.Length();
275 for (i=1; i<=aNbCPrts; ++i) {
276 const IntTools_CommonPrt& aCPart=aCPrts(i);
279 case TopAbs_VERTEX: {
280 Standard_Boolean bIsOnPave[2];
282 Standard_Real aT, aTolToDecide;
285 IntTools_Tools::VertexParameter(aCPart, aT);
286 BOPTools_AlgoTools::MakeNewVertex(aE, aT, aF, aVnew);
288 const IntTools_Range& aR=aCPart.Range1();
291 IntTools_Range aR1(aT1,anewSR.First()),aR2(anewSR.Last(), aT2);
293 bIsOnPave[0]=IntTools_Tools::IsInRange(aR1, aR, aTolToDecide);
294 bIsOnPave[1]=IntTools_Tools::IsInRange(aR2, aR, aTolToDecide);
296 if (bIsOnPave[0] && bIsOnPave[1]) {
297 bV[0]=CheckFacePaves(nV[0], aMIFOn, aMIFIn);
298 bV[1]=CheckFacePaves(nV[1], aMIFOn, aMIFIn);
299 if (bV[0] && bV[1]) {
301 IntTools_CommonPrt aCP = aCPart;
302 aCP.SetType(TopAbs_EDGE);
303 BOPDS_InterfEF& aEF=aEFs(iX);
304 aEF.SetIndices(nE, nF);
305 aEF.SetCommonPart(aCP);
306 myDS->AddInterf(nE, nF);
310 BOPAlgo_Tools::FillMap(aPB, nF, aMPBLI, aAllocator);
314 for (j=0; j<2; ++j) {
316 bV[j]=CheckFacePaves(nV[j], aMIFOn, aMIFIn);
318 const TopoDS_Vertex& aV=
319 (*(TopoDS_Vertex *)(&myDS->Shape(nV[j])));
320 BOPTools_AlgoTools::UpdateVertex(aE, aT, aV);
321 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nV[j]);
322 Bnd_Box& aBoxDS=aSIDS.ChangeBox();
323 BRepBndLib::Add(aV, aBoxDS);
326 bIsOnPave[j] = ForceInterfVF(nV[j], nF);
331 if (!bIsOnPave[0] && !bIsOnPave[1]) {
332 if (CheckFacePaves(aVnew, aMIFOn)) {
336 const gp_Pnt& aPnew = BRep_Tool::Pnt(aVnew);
337 if (!myContext->IsValidPointForFace(aPnew,
343 aBB.UpdateVertex(aVnew, aTolE);
348 BOPDS_InterfEF& aEF=aEFs(iX);
349 aEF.SetIndices(nE, nF);
350 aEF.SetCommonPart(aCPart);
352 myDS->AddInterf(nE, nF);
354 BOPDS_CoupleOfPaveBlocks aCPB;
356 aCPB.SetPaveBlocks(aPB, aPB);
357 aCPB.SetIndexInterf(iX);
358 aMVCPB.Add(aVnew, aCPB);
367 BOPDS_InterfEF& aEF=aEFs(iX);
368 aEF.SetIndices(nE, nF);
370 bV[0]=CheckFacePaves(nV[0], aMIFOn, aMIFIn);
371 bV[1]=CheckFacePaves(nV[1], aMIFOn, aMIFIn);
372 if (!bV[0] || !bV[1]) {
373 myDS->AddInterf(nE, nF);
376 //update tolerance of edge if needed
378 myDS->UpdateEdgeTolerance(nE, aTolF);
381 aEF.SetCommonPart(aCPart);
383 myDS->AddInterf(nE, nF);
385 BOPAlgo_Tools::FillMap(aPB, nF, aMPBLI, aAllocator);
392 }//for (i=1; i<=aNbCPrts; ++i) {
393 }// for (k=0; k < aNbEdgeEdge; ++k) {
395 //=========================================
397 //=========================================
398 BOPAlgo_Tools::PerformCommonBlocks(aMPBLI, aAllocator, myDS);
399 PerformVerticesEF(aMVCPB, aAllocator);
401 // Update FaceInfoIn for all faces having EF common parts
402 BOPCol_MapIteratorOfMapOfInteger aItMI;
403 aItMI.Initialize(aMIEFC);
404 for (; aItMI.More(); aItMI.Next()) {
406 myDS->UpdateFaceInfoIn(nF);
408 // Refine FaceInfoOn to remove all formal pave blocks
409 // made during EF processing
410 //myDS->RefineFaceInfoOn();
411 //-----------------------------------------------------scope t
415 ////aAllocator.Nullify();
417 //=======================================================================
418 //function : PerformVertices1
420 //=======================================================================
421 Standard_Integer BOPAlgo_PaveFiller::PerformVerticesEF
422 (BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& theMVCPB,
423 Handle(NCollection_BaseAllocator)& theAllocator)
425 Standard_Integer aNbV, iRet;
428 aNbV=theMVCPB.Extent();
433 Standard_Integer nVx, nVSD, iV, iErr, nE, iFlag, iX, i, aNbPBLI;
436 BOPCol_ListIteratorOfListOfShape aItLS;
437 BOPCol_ListIteratorOfListOfInteger aItLI;
442 BOPCol_ListOfShape aLS(theAllocator);
443 BOPCol_DataMapOfShapeInteger aMVI(100, theAllocator);
444 BOPDS_IndexedDataMapOfPaveBlockListOfInteger aMPBLI(100, theAllocator);
445 BOPAlgo_PaveFiller aPF(theAllocator);
447 aSI.SetShapeType(TopAbs_VERTEX);
448 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
450 // 1 prepare arguments
451 for (i=1; i<=aNbV; ++i) {
452 const TopoDS_Shape& aS=theMVCPB.FindKey(i);
457 aPF.SetArguments(aLS);
459 iErr=aPF.ErrorStatus();
466 // 3 Add new vertices to theDS;
467 // 4 Map PaveBlock/ListOfVertices to add to this PaveBlock ->aMPBLI
468 aItLS.Initialize(aLS);
469 for (; aItLS.More(); aItLS.Next()) {
470 const TopoDS_Shape& aVx=aItLS.Value();
471 nVx=aPDS->Index(aVx);
473 if (aPDS->HasShapeSD(nVx, nVSD)) {
474 aV=aPDS->Shape(nVSD);
479 // index of new vertex in theDS -> iV
480 if (!aMVI.IsBound(aV)) {
482 iV=myDS->Append(aSI);
484 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(iV);
485 Bnd_Box& aBox=aSIDS.ChangeBox();
486 BRepBndLib::Add(aV, aBox);
494 BOPDS_CoupleOfPaveBlocks &aCPB=theMVCPB.ChangeFromKey(aVx);
496 // update EF interference
497 iX=aCPB.IndexInterf();
498 BOPDS_InterfEF& aEF=aEFs(iX);
501 const Handle(BOPDS_PaveBlock)& aPB=aCPB.PaveBlock1();
502 if (aMPBLI.Contains(aPB)) {
503 BOPCol_ListOfInteger& aLI=aMPBLI.ChangeFromKey(aPB);
507 BOPCol_ListOfInteger aLI(theAllocator);
509 aMPBLI.Add(aPB, aLI);
514 // 5.1 Compute Extra Paves and
515 // 5.2. Add Extra Paves to the PaveBlocks
516 aNbPBLI=aMPBLI.Extent();
517 for (i=1; i<=aNbPBLI; ++i) {
518 Handle(BOPDS_PaveBlock) aPB=aMPBLI.FindKey(i);
519 const BOPCol_ListOfInteger& aLI=aMPBLI.FindFromIndex(i);
520 nE=aPB->OriginalEdge();
521 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&myDS->Shape(nE)));
523 aItLI.Initialize(aLI);
524 for (; aItLI.More(); aItLI.Next()) {
526 const TopoDS_Vertex& aVx=(*(TopoDS_Vertex *)(&myDS->Shape(nVx)));
528 iFlag=myContext->ComputeVE (aVx, aE, aT);
531 aPave.SetParameter(aT);
532 aPB->AppendExtPave(aPave);
536 // 6 Split PaveBlocksa
537 for (i=1; i<=aNbPBLI; ++i) {
538 Handle(BOPDS_PaveBlock) aPB=aMPBLI.FindKey(i);
539 nE=aPB->OriginalEdge();
541 if (!myDS->IsCommonBlock(aPB)) {
542 myDS->UpdatePaveBlock(aPB);
545 const Handle(BOPDS_CommonBlock)& aCB=myDS->CommonBlock(aPB);
546 myDS->UpdateCommonBlock(aCB);
548 }//for (; aItMPBLI.More(); aItMPBLI.Next()) {
552 //=======================================================================
553 // function: CheckFacePaves
555 //=======================================================================
556 Standard_Boolean BOPAlgo_PaveFiller::CheckFacePaves
557 (const Standard_Integer nVx,
558 const BOPCol_MapOfInteger& aMIFOn,
559 const BOPCol_MapOfInteger& aMIFIn)
561 Standard_Boolean bRet;
563 BOPCol_MapIteratorOfMapOfInteger aIt;
567 aIt.Initialize(aMIFOn);
568 for (; aIt.More(); aIt.Next()) {
575 aIt.Initialize(aMIFIn);
576 for (; aIt.More(); aIt.Next()) {
586 //=======================================================================
587 // function: CheckFacePaves
589 //=======================================================================
590 Standard_Boolean BOPAlgo_PaveFiller::CheckFacePaves
591 (const TopoDS_Vertex& aVnew,
592 const BOPCol_MapOfInteger& aMIF)
594 Standard_Boolean bRet;
595 Standard_Integer nV, iFlag;
596 BOPCol_MapIteratorOfMapOfInteger aIt;
600 aIt.Initialize(aMIF);
601 for (; aIt.More(); aIt.Next()) {
603 const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nV)));
604 iFlag=BOPTools_AlgoTools::ComputeVV(aVnew, aV);
612 //=======================================================================
613 //function : ForceInterfVF
615 //=======================================================================
616 Standard_Boolean BOPAlgo_PaveFiller::ForceInterfVF
617 (const Standard_Integer nV,
618 const Standard_Integer nF)
620 Standard_Boolean bRet;
622 bRet = Standard_False;
623 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&myDS->Shape(nV);
624 const TopoDS_Face& aF = *(TopoDS_Face*) &myDS->Shape(nF);
626 GeomAPI_ProjectPointOnSurf& aProj = myContext->ProjPS(aF);
627 const gp_Pnt& aP = BRep_Tool::Pnt(aV);
629 if (!aProj.IsDone()) {
632 Standard_Real aDist, U, V;
634 aDist=aProj.LowerDistance();
635 aProj.LowerDistanceParameters(U, V);
638 bRet = myContext->IsPointInFace (aF, aP2d);
643 BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
644 if (aVFs.Extent() == 0) {
649 BOPDS_InterfVF& aVF=aVFs(i);
650 aVF.SetIndices(nV, nF);
653 myDS->AddInterf(nV, nF);
655 aBB.UpdateVertex(aV, aDist);
656 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nV);
657 Bnd_Box& aBoxDS=aSIDS.ChangeBox();
658 BRepBndLib::Add(aV, aBoxDS);
660 BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
661 BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();