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.SetIncrement(iSize);
174 for (; myIterator->More(); myIterator->Next()) {
175 myIterator->Value(nE, nF, bJustAdd);
180 const BOPDS_ShapeInfo& aSIE=myDS->ShapeInfo(nE);
181 if (aSIE.HasFlag()){//degenerated
185 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&aSIE.Shape()));
186 const TopoDS_Face& aF=(*(TopoDS_Face *)(&myDS->Shape(nF)));
187 const Bnd_Box& aBBF=myDS->ShapeInfo(nF).Box();
189 BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
190 const BOPDS_IndexedMapOfPaveBlock& aMPBF=aFI.PaveBlocksOn();
192 aTolE=BRep_Tool::Tolerance(aE);
193 aTolF=BRep_Tool::Tolerance(aF);
195 BOPDS_ListOfPaveBlock& aLPB=myDS->ChangePaveBlocks(nE);
196 aIt.Initialize(aLPB);
197 for (; aIt.More(); aIt.Next()) {
198 Handle(BOPDS_PaveBlock)& aPB=aIt.ChangeValue();
200 const Handle(BOPDS_PaveBlock) aPBR=myDS->RealPaveBlock(aPB);
201 if (aMPBF.Contains(aPBR)) {
205 if (!aPB->HasShrunkData()) {
210 aPB->ShrunkData(aTS1, aTS2, aBBE);
212 if (aBBF.IsOut (aBBE)) {
216 BOPAlgo_EdgeFace& aEdgeFace=aVEdgeFace.Append1();
218 aEdgeFace.SetIndices(nE, nF);
219 aEdgeFace.SetPaveBlock(aPB);
221 aEdgeFace.SetEdge (aE);
222 aEdgeFace.SetFace (aF);
223 aEdgeFace.SetTolE (aTolE);
224 aEdgeFace.SetTolF (aTolF);
225 aEdgeFace.SetDiscretize (aDiscretize);
226 aEdgeFace.SetDeflection (aDeflection);
228 IntTools_Range aSR(aTS1, aTS2);
229 IntTools_Range anewSR=aSR;
230 BOPTools_AlgoTools::CorrectRange(aE, aF, aSR, anewSR);
231 aEdgeFace.SetNewSR(anewSR);
233 aPB->Range(aT1, aT2);
234 IntTools_Range aPBRange(aT1, aT2);
236 BOPTools_AlgoTools::CorrectRange(aE, aF, aSR, aPBRange);
237 aEdgeFace.SetRange (aPBRange);
238 aEdgeFace.SetProgressIndicator(myProgressIndicator);
240 }//for (; aIt.More(); aIt.Next()) {
241 }//for (; myIterator->More(); myIterator->Next()) {
243 aNbEdgeFace=aVEdgeFace.Extent();
244 //=================================================================
245 BOPAlgo_EdgeFaceCnt::Perform(myRunParallel, aVEdgeFace, myContext);
246 //=================================================================
248 for (k=0; k < aNbEdgeFace; ++k) {
249 BOPAlgo_EdgeFace& aEdgeFace=aVEdgeFace(k);
250 if (!aEdgeFace.IsDone()) {
254 aEdgeFace.Indices(nE, nF);
256 const TopoDS_Edge& aE=aEdgeFace.Edge();
257 const TopoDS_Face& aF=aEdgeFace.Face();
259 aTolE=aEdgeFace.TolE();
260 aTolF=aEdgeFace.TolF();
261 const IntTools_Range& anewSR=aEdgeFace.NewSR();
262 Handle(BOPDS_PaveBlock)& aPB=aEdgeFace.PaveBlock();
264 aPB->Range(aT1, aT2);
265 aPB->Indices(nV[0], nV[1]);
267 BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
268 const BOPCol_MapOfInteger& aMIFOn=aFI.VerticesOn();
269 const BOPCol_MapOfInteger& aMIFIn=aFI.VerticesIn();
271 const IntTools_SequenceOfCommonPrts& aCPrts=aEdgeFace.CommonParts();
272 aNbCPrts=aCPrts.Length();
273 for (i=1; i<=aNbCPrts; ++i) {
274 const IntTools_CommonPrt& aCPart=aCPrts(i);
277 case TopAbs_VERTEX: {
278 Standard_Boolean bIsOnPave[2];
280 Standard_Real aT, aTolToDecide;
283 IntTools_Tools::VertexParameter(aCPart, aT);
284 BOPTools_AlgoTools::MakeNewVertex(aE, aT, aF, aVnew);
286 const IntTools_Range& aR=aCPart.Range1();
289 IntTools_Range aR1(aT1,anewSR.First()),aR2(anewSR.Last(), aT2);
291 bIsOnPave[0]=IntTools_Tools::IsInRange(aR1, aR, aTolToDecide);
292 bIsOnPave[1]=IntTools_Tools::IsInRange(aR2, aR, aTolToDecide);
294 if (bIsOnPave[0] && bIsOnPave[1]) {
295 bV[0]=CheckFacePaves(nV[0], aMIFOn, aMIFIn);
296 bV[1]=CheckFacePaves(nV[1], aMIFOn, aMIFIn);
297 if (bV[0] && bV[1]) {
298 IntTools_CommonPrt aCP = aCPart;
299 aCP.SetType(TopAbs_EDGE);
300 BOPDS_InterfEF& aEF=aEFs.Append1();
302 aEF.SetIndices(nE, nF);
303 aEF.SetCommonPart(aCP);
304 myDS->AddInterf(nE, nF);
308 BOPAlgo_Tools::FillMap(aPB, nF, aMPBLI, aAllocator);
312 for (j=0; j<2; ++j) {
314 bV[j]=CheckFacePaves(nV[j], aMIFOn, aMIFIn);
316 const TopoDS_Vertex& aV=
317 (*(TopoDS_Vertex *)(&myDS->Shape(nV[j])));
318 BOPTools_AlgoTools::UpdateVertex(aE, aT, aV);
319 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nV[j]);
320 Bnd_Box& aBoxDS=aSIDS.ChangeBox();
321 BRepBndLib::Add(aV, aBoxDS);
324 bIsOnPave[j] = ForceInterfVF(nV[j], nF);
329 if (!bIsOnPave[0] && !bIsOnPave[1]) {
330 if (CheckFacePaves(aVnew, aMIFOn)) {
334 const gp_Pnt& aPnew = BRep_Tool::Pnt(aVnew);
335 if (!myContext->IsValidPointForFace(aPnew,
341 aBB.UpdateVertex(aVnew, aTolE);
345 BOPDS_InterfEF& aEF=aEFs.Append1();
347 aEF.SetIndices(nE, nF);
348 aEF.SetCommonPart(aCPart);
350 myDS->AddInterf(nE, nF);
352 BOPDS_CoupleOfPaveBlocks aCPB;
354 aCPB.SetPaveBlocks(aPB, aPB);
355 aCPB.SetIndexInterf(iX);
356 aMVCPB.Add(aVnew, aCPB);
364 BOPDS_InterfEF& aEF=aEFs.Append1();
366 aEF.SetIndices(nE, nF);
368 bV[0]=CheckFacePaves(nV[0], aMIFOn, aMIFIn);
369 bV[1]=CheckFacePaves(nV[1], aMIFOn, aMIFIn);
370 if (!bV[0] || !bV[1]) {
371 myDS->AddInterf(nE, nF);
374 //update tolerance of edge if needed
376 myDS->UpdateEdgeTolerance(nE, aTolF);
379 aEF.SetCommonPart(aCPart);
381 myDS->AddInterf(nE, nF);
383 BOPAlgo_Tools::FillMap(aPB, nF, aMPBLI, aAllocator);
390 }//for (i=1; i<=aNbCPrts; ++i) {
391 }// for (k=0; k < aNbEdgeEdge; ++k) {
393 //=========================================
395 //=========================================
396 BOPAlgo_Tools::PerformCommonBlocks(aMPBLI, aAllocator, myDS);
397 PerformVerticesEF(aMVCPB, aAllocator);
399 // Update FaceInfoIn for all faces having EF common parts
400 BOPCol_MapIteratorOfMapOfInteger aItMI;
401 aItMI.Initialize(aMIEFC);
402 for (; aItMI.More(); aItMI.Next()) {
404 myDS->UpdateFaceInfoIn(nF);
406 // Refine FaceInfoOn to remove all formal pave blocks
407 // made during EF processing
408 //myDS->RefineFaceInfoOn();
409 //-----------------------------------------------------scope t
413 ////aAllocator.Nullify();
415 //=======================================================================
416 //function : PerformVertices1
418 //=======================================================================
419 Standard_Integer BOPAlgo_PaveFiller::PerformVerticesEF
420 (BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& theMVCPB,
421 Handle(NCollection_BaseAllocator)& theAllocator)
423 Standard_Integer aNbV, iRet;
426 aNbV=theMVCPB.Extent();
431 Standard_Integer nVx, nVSD, iV, iErr, nE, iFlag, iX, i, aNbPBLI;
434 BOPCol_ListIteratorOfListOfShape aItLS;
435 BOPCol_ListIteratorOfListOfInteger aItLI;
440 BOPCol_ListOfShape aLS(theAllocator);
441 BOPCol_DataMapOfShapeInteger aMVI(100, theAllocator);
442 BOPDS_IndexedDataMapOfPaveBlockListOfInteger aMPBLI(100, theAllocator);
443 BOPAlgo_PaveFiller aPF(theAllocator);
445 aSI.SetShapeType(TopAbs_VERTEX);
446 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
448 // 1 prepare arguments
449 for (i=1; i<=aNbV; ++i) {
450 const TopoDS_Shape& aS=theMVCPB.FindKey(i);
455 aPF.SetArguments(aLS);
457 iErr=aPF.ErrorStatus();
464 // 3 Add new vertices to theDS;
465 // 4 Map PaveBlock/ListOfVertices to add to this PaveBlock ->aMPBLI
466 aItLS.Initialize(aLS);
467 for (; aItLS.More(); aItLS.Next()) {
468 const TopoDS_Shape& aVx=aItLS.Value();
469 nVx=aPDS->Index(aVx);
471 if (aPDS->HasShapeSD(nVx, nVSD)) {
472 aV=aPDS->Shape(nVSD);
477 // index of new vertex in theDS -> iV
478 if (!aMVI.IsBound(aV)) {
480 iV=myDS->Append(aSI);
482 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(iV);
483 Bnd_Box& aBox=aSIDS.ChangeBox();
484 BRepBndLib::Add(aV, aBox);
492 BOPDS_CoupleOfPaveBlocks &aCPB=theMVCPB.ChangeFromKey(aVx);
494 // update EF interference
495 iX=aCPB.IndexInterf();
496 BOPDS_InterfEF& aEF=aEFs(iX);
499 const Handle(BOPDS_PaveBlock)& aPB=aCPB.PaveBlock1();
500 if (aMPBLI.Contains(aPB)) {
501 BOPCol_ListOfInteger& aLI=aMPBLI.ChangeFromKey(aPB);
505 BOPCol_ListOfInteger aLI(theAllocator);
507 aMPBLI.Add(aPB, aLI);
512 // 5.1 Compute Extra Paves and
513 // 5.2. Add Extra Paves to the PaveBlocks
514 aNbPBLI=aMPBLI.Extent();
515 for (i=1; i<=aNbPBLI; ++i) {
516 Handle(BOPDS_PaveBlock) aPB=aMPBLI.FindKey(i);
517 const BOPCol_ListOfInteger& aLI=aMPBLI.FindFromIndex(i);
518 nE=aPB->OriginalEdge();
519 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&myDS->Shape(nE)));
521 aItLI.Initialize(aLI);
522 for (; aItLI.More(); aItLI.Next()) {
524 const TopoDS_Vertex& aVx=(*(TopoDS_Vertex *)(&myDS->Shape(nVx)));
526 iFlag=myContext->ComputeVE (aVx, aE, aT);
529 aPave.SetParameter(aT);
530 aPB->AppendExtPave(aPave);
534 // 6 Split PaveBlocksa
535 for (i=1; i<=aNbPBLI; ++i) {
536 Handle(BOPDS_PaveBlock) aPB=aMPBLI.FindKey(i);
537 nE=aPB->OriginalEdge();
539 if (!myDS->IsCommonBlock(aPB)) {
540 myDS->UpdatePaveBlock(aPB);
543 const Handle(BOPDS_CommonBlock)& aCB=myDS->CommonBlock(aPB);
544 myDS->UpdateCommonBlock(aCB);
546 }//for (; aItMPBLI.More(); aItMPBLI.Next()) {
550 //=======================================================================
551 // function: CheckFacePaves
553 //=======================================================================
554 Standard_Boolean BOPAlgo_PaveFiller::CheckFacePaves
555 (const Standard_Integer nVx,
556 const BOPCol_MapOfInteger& aMIFOn,
557 const BOPCol_MapOfInteger& aMIFIn)
559 Standard_Boolean bRet;
561 BOPCol_MapIteratorOfMapOfInteger aIt;
565 aIt.Initialize(aMIFOn);
566 for (; aIt.More(); aIt.Next()) {
573 aIt.Initialize(aMIFIn);
574 for (; aIt.More(); aIt.Next()) {
584 //=======================================================================
585 // function: CheckFacePaves
587 //=======================================================================
588 Standard_Boolean BOPAlgo_PaveFiller::CheckFacePaves
589 (const TopoDS_Vertex& aVnew,
590 const BOPCol_MapOfInteger& aMIF)
592 Standard_Boolean bRet;
593 Standard_Integer nV, iFlag;
594 BOPCol_MapIteratorOfMapOfInteger aIt;
598 aIt.Initialize(aMIF);
599 for (; aIt.More(); aIt.Next()) {
601 const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nV)));
602 iFlag=BOPTools_AlgoTools::ComputeVV(aVnew, aV);
610 //=======================================================================
611 //function : ForceInterfVF
613 //=======================================================================
614 Standard_Boolean BOPAlgo_PaveFiller::ForceInterfVF
615 (const Standard_Integer nV,
616 const Standard_Integer nF)
618 Standard_Boolean bRet;
620 bRet = Standard_False;
621 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&myDS->Shape(nV);
622 const TopoDS_Face& aF = *(TopoDS_Face*) &myDS->Shape(nF);
624 GeomAPI_ProjectPointOnSurf& aProj = myContext->ProjPS(aF);
625 const gp_Pnt& aP = BRep_Tool::Pnt(aV);
627 if (!aProj.IsDone()) {
630 Standard_Real aDist, U, V;
632 aDist=aProj.LowerDistance();
633 aProj.LowerDistanceParameters(U, V);
636 bRet = myContext->IsPointInFace (aF, aP2d);
638 //Standard_Integer i;
641 BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
642 BOPDS_InterfVF& aVF=aVFs.Append1();
643 aVF.SetIndices(nV, nF);
646 myDS->AddInterf(nV, nF);
648 aBB.UpdateVertex(aV, aDist);
649 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nV);
650 Bnd_Box& aBoxDS=aSIDS.ChangeBox();
651 BRepBndLib::Add(aV, aBoxDS);
653 BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
654 BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();