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_SectionAttribute.hxx>
22 #include <BOPAlgo_Tools.hxx>
23 #include <BOPCol_MapOfInteger.hxx>
24 #include <BOPCol_NCVector.hxx>
25 #include <BOPCol_Parallel.hxx>
26 #include <BOPDS_CommonBlock.hxx>
27 #include <BOPDS_CoupleOfPaveBlocks.hxx>
28 #include <BOPDS_Curve.hxx>
29 #include <BOPDS_DataMapOfPaveBlockListOfInteger.hxx>
30 #include <BOPDS_DS.hxx>
31 #include <BOPDS_Interf.hxx>
32 #include <BOPDS_Iterator.hxx>
33 #include <BOPDS_MapOfPaveBlock.hxx>
34 #include <BOPDS_Pave.hxx>
35 #include <BOPDS_PaveBlock.hxx>
36 #include <BOPTools_AlgoTools.hxx>
37 #include <BRep_Builder.hxx>
38 #include <BRep_Tool.hxx>
39 #include <BRepAdaptor_Curve.hxx>
40 #include <BRepBndLib.hxx>
41 #include <GeomAPI_ProjectPointOnSurf.hxx>
43 #include <IntTools_CommonPrt.hxx>
44 #include <IntTools_Context.hxx>
45 #include <IntTools_EdgeFace.hxx>
46 #include <IntTools_Range.hxx>
47 #include <IntTools_SequenceOfCommonPrts.hxx>
48 #include <IntTools_Tools.hxx>
49 #include <TopoDS_Edge.hxx>
50 #include <TopoDS_Face.hxx>
51 #include <TopoDS_Vertex.hxx>
62 //=======================================================================
63 //class : BOPAlgo_EdgeFace
65 //=======================================================================
66 class BOPAlgo_EdgeFace :
67 public IntTools_EdgeFace,
79 virtual ~BOPAlgo_EdgeFace(){
82 void SetIndices(const Standard_Integer nE,
83 const Standard_Integer nF) {
88 void Indices(Standard_Integer& nE,
89 Standard_Integer& nF) {
94 void SetNewSR(const IntTools_Range& aR){
98 IntTools_Range& NewSR(){
102 void SetPaveBlock(const Handle(BOPDS_PaveBlock)& aPB) {
106 Handle(BOPDS_PaveBlock)& PaveBlock() {
110 virtual void Perform() {
111 BOPAlgo_Algo::UserBreak();
112 IntTools_EdgeFace::Perform();
116 Standard_Integer myIE;
117 Standard_Integer myIF;
118 IntTools_Range myNewSR;
119 Handle(BOPDS_PaveBlock) myPB;
122 //=======================================================================
123 typedef BOPCol_NCVector<BOPAlgo_EdgeFace> BOPAlgo_VectorOfEdgeFace;
125 typedef BOPCol_ContextFunctor
127 BOPAlgo_VectorOfEdgeFace,
128 Handle(IntTools_Context),
129 IntTools_Context> BOPAlgo_EdgeFaceFunctor;
131 typedef BOPCol_ContextCnt
132 <BOPAlgo_EdgeFaceFunctor,
133 BOPAlgo_VectorOfEdgeFace,
134 Handle(IntTools_Context)> BOPAlgo_EdgeFaceCnt;
136 //=======================================================================
137 //function : PerformEF
139 //=======================================================================
140 void BOPAlgo_PaveFiller::PerformEF()
142 Standard_Integer iSize;
146 FillShrunkData(TopAbs_EDGE, TopAbs_FACE);
148 myIterator->Initialize(TopAbs_EDGE, TopAbs_FACE);
149 iSize=myIterator->ExpectedLength();
154 Standard_Boolean bJustAdd, bV[2];
155 Standard_Integer nE, nF, aDiscretize, i, aNbCPrts, iX, nV[2];
156 Standard_Integer aNbEdgeFace, k;
157 Standard_Real aTolE, aTolF, aTS1, aTS2, aT1, aT2, aDeflection;
158 Handle(NCollection_BaseAllocator) aAllocator;
159 TopAbs_ShapeEnum aType;
160 BOPDS_ListIteratorOfListOfPaveBlock aIt;
161 BOPAlgo_VectorOfEdgeFace aVEdgeFace;
163 //-----------------------------------------------------scope f
165 aAllocator=NCollection_BaseAllocator::CommonBaseAllocator();
167 BOPCol_MapOfInteger aMIEFC(100, aAllocator);
168 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks aMVCPB(100, aAllocator);
169 BOPDS_IndexedDataMapOfPaveBlockListOfInteger aMPBLI(100, aAllocator);
174 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
175 aEFs.SetIncrement(iSize);
177 for (; myIterator->More(); myIterator->Next()) {
178 myIterator->Value(nE, nF, bJustAdd);
183 const BOPDS_ShapeInfo& aSIE=myDS->ShapeInfo(nE);
184 if (aSIE.HasFlag()){//degenerated
188 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&aSIE.Shape()));
189 const TopoDS_Face& aF=(*(TopoDS_Face *)(&myDS->Shape(nF)));
190 const Bnd_Box& aBBF=myDS->ShapeInfo(nF).Box();
192 BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
193 const BOPDS_IndexedMapOfPaveBlock& aMPBF=aFI.PaveBlocksOn();
195 aTolE=BRep_Tool::Tolerance(aE);
196 aTolF=BRep_Tool::Tolerance(aF);
198 BOPDS_ListOfPaveBlock& aLPB=myDS->ChangePaveBlocks(nE);
199 aIt.Initialize(aLPB);
200 for (; aIt.More(); aIt.Next()) {
201 Handle(BOPDS_PaveBlock)& aPB=aIt.ChangeValue();
203 const Handle(BOPDS_PaveBlock) aPBR=myDS->RealPaveBlock(aPB);
204 if (aMPBF.Contains(aPBR)) {
208 if (!aPB->HasShrunkData()) {
213 aPB->ShrunkData(aTS1, aTS2, aBBE);
215 if (aBBF.IsOut (aBBE)) {
219 BOPAlgo_EdgeFace& aEdgeFace=aVEdgeFace.Append1();
221 aEdgeFace.SetIndices(nE, nF);
222 aEdgeFace.SetPaveBlock(aPB);
224 aEdgeFace.SetEdge (aE);
225 aEdgeFace.SetFace (aF);
226 aEdgeFace.SetTolE (aTolE);
227 aEdgeFace.SetTolF (aTolF);
228 aEdgeFace.SetDiscretize (aDiscretize);
229 aEdgeFace.SetDeflection (aDeflection);
231 IntTools_Range aSR(aTS1, aTS2);
232 IntTools_Range anewSR=aSR;
233 BOPTools_AlgoTools::CorrectRange(aE, aF, aSR, anewSR);
234 aEdgeFace.SetNewSR(anewSR);
236 aPB->Range(aT1, aT2);
237 IntTools_Range aPBRange(aT1, aT2);
239 BOPTools_AlgoTools::CorrectRange(aE, aF, aSR, aPBRange);
240 aEdgeFace.SetRange (aPBRange);
241 aEdgeFace.SetProgressIndicator(myProgressIndicator);
243 }//for (; aIt.More(); aIt.Next()) {
244 }//for (; myIterator->More(); myIterator->Next()) {
246 aNbEdgeFace=aVEdgeFace.Extent();
247 //=================================================================
248 BOPAlgo_EdgeFaceCnt::Perform(myRunParallel, aVEdgeFace, myContext);
249 //=================================================================
251 for (k=0; k < aNbEdgeFace; ++k) {
252 BOPAlgo_EdgeFace& aEdgeFace=aVEdgeFace(k);
253 if (!aEdgeFace.IsDone()) {
257 aEdgeFace.Indices(nE, nF);
259 const TopoDS_Edge& aE=aEdgeFace.Edge();
260 const TopoDS_Face& aF=aEdgeFace.Face();
262 aTolE=aEdgeFace.TolE();
263 aTolF=aEdgeFace.TolF();
264 const IntTools_Range& anewSR=aEdgeFace.NewSR();
265 Handle(BOPDS_PaveBlock)& aPB=aEdgeFace.PaveBlock();
267 aPB->Range(aT1, aT2);
268 aPB->Indices(nV[0], nV[1]);
270 BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
271 const BOPCol_MapOfInteger& aMIFOn=aFI.VerticesOn();
272 const BOPCol_MapOfInteger& aMIFIn=aFI.VerticesIn();
274 const IntTools_SequenceOfCommonPrts& aCPrts=aEdgeFace.CommonParts();
275 aNbCPrts=aCPrts.Length();
276 for (i=1; i<=aNbCPrts; ++i) {
277 const IntTools_CommonPrt& aCPart=aCPrts(i);
280 case TopAbs_VERTEX: {
281 Standard_Boolean bIsOnPave[2];
283 Standard_Real aT, aTolToDecide;
286 IntTools_Tools::VertexParameter(aCPart, aT);
287 BOPTools_AlgoTools::MakeNewVertex(aE, aT, aF, aVnew);
289 const IntTools_Range& aR=aCPart.Range1();
292 IntTools_Range aR1(aT1,anewSR.First()),aR2(anewSR.Last(), aT2);
294 bIsOnPave[0]=IntTools_Tools::IsInRange(aR1, aR, aTolToDecide);
295 bIsOnPave[1]=IntTools_Tools::IsInRange(aR2, aR, aTolToDecide);
297 if (bIsOnPave[0] && bIsOnPave[1]) {
298 bV[0]=CheckFacePaves(nV[0], aMIFOn, aMIFIn);
299 bV[1]=CheckFacePaves(nV[1], aMIFOn, aMIFIn);
300 if (bV[0] && bV[1]) {
301 IntTools_CommonPrt aCP = aCPart;
302 aCP.SetType(TopAbs_EDGE);
303 BOPDS_InterfEF& aEF=aEFs.Append1();
305 aEF.SetIndices(nE, nF);
306 aEF.SetCommonPart(aCP);
307 myDS->AddInterf(nE, nF);
311 BOPAlgo_Tools::FillMap(aPB, nF, aMPBLI, aAllocator);
315 for (j=0; j<2; ++j) {
317 bV[j]=CheckFacePaves(nV[j], aMIFOn, aMIFIn);
319 const TopoDS_Vertex& aV=
320 (*(TopoDS_Vertex *)(&myDS->Shape(nV[j])));
321 BOPTools_AlgoTools::UpdateVertex(aE, aT, aV);
322 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nV[j]);
323 Bnd_Box& aBoxDS=aSIDS.ChangeBox();
324 BRepBndLib::Add(aV, aBoxDS);
327 bIsOnPave[j] = ForceInterfVF(nV[j], nF);
332 if (!bIsOnPave[0] && !bIsOnPave[1]) {
333 if (CheckFacePaves(aVnew, aMIFOn)) {
337 const gp_Pnt& aPnew = BRep_Tool::Pnt(aVnew);
338 Standard_Real aTolV = BRep_Tool::Tolerance(aVnew);
339 aTolV = Max(aTolV, Max(aTolE, aTolF));
341 if (!myContext->IsPointInFace(aPnew, aF, aTolV)) {
345 aBB.UpdateVertex(aVnew, aTolV);
349 BOPDS_InterfEF& aEF=aEFs.Append1();
351 aEF.SetIndices(nE, nF);
352 aEF.SetCommonPart(aCPart);
354 myDS->AddInterf(nE, nF);
356 BOPDS_CoupleOfPaveBlocks aCPB;
358 aCPB.SetPaveBlocks(aPB, aPB);
359 aCPB.SetIndexInterf(iX);
360 aMVCPB.Add(aVnew, aCPB);
368 BOPDS_InterfEF& aEF=aEFs.Append1();
370 aEF.SetIndices(nE, nF);
372 bV[0]=CheckFacePaves(nV[0], aMIFOn, aMIFIn);
373 bV[1]=CheckFacePaves(nV[1], aMIFOn, aMIFIn);
374 if (!bV[0] || !bV[1]) {
375 myDS->AddInterf(nE, nF);
378 //update tolerance of edge if needed
380 myDS->UpdateEdgeTolerance(nE, aTolF);
383 aEF.SetCommonPart(aCPart);
385 myDS->AddInterf(nE, nF);
387 BOPAlgo_Tools::FillMap(aPB, nF, aMPBLI, aAllocator);
394 }//for (i=1; i<=aNbCPrts; ++i) {
395 }// for (k=0; k < aNbEdgeEdge; ++k) {
397 //=========================================
399 //=========================================
400 BOPAlgo_Tools::PerformCommonBlocks(aMPBLI, aAllocator, myDS);
401 PerformVerticesEF(aMVCPB, aAllocator);
403 // Update FaceInfoIn for all faces having EF common parts
404 BOPCol_MapIteratorOfMapOfInteger aItMI;
405 aItMI.Initialize(aMIEFC);
406 for (; aItMI.More(); aItMI.Next()) {
408 myDS->UpdateFaceInfoIn(nF);
410 // Refine FaceInfoOn to remove all formal pave blocks
411 // made during EF processing
412 //myDS->RefineFaceInfoOn();
413 //-----------------------------------------------------scope t
417 ////aAllocator.Nullify();
419 //=======================================================================
420 //function : PerformVertices1
422 //=======================================================================
423 Standard_Integer BOPAlgo_PaveFiller::PerformVerticesEF
424 (BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& theMVCPB,
425 const Handle(NCollection_BaseAllocator)& theAllocator)
427 Standard_Integer aNbV, iRet;
430 aNbV=theMVCPB.Extent();
435 Standard_Integer nVx, nVSD, iV, iErr, nE, iFlag, iX, i, aNbPBLI;
438 BOPCol_ListIteratorOfListOfShape aItLS;
439 BOPCol_ListIteratorOfListOfInteger aItLI;
444 BOPCol_ListOfShape aLS(theAllocator);
445 BOPCol_DataMapOfShapeInteger aMVI(100, theAllocator);
446 BOPDS_IndexedDataMapOfPaveBlockListOfInteger aMPBLI(100, theAllocator);
447 BOPAlgo_PaveFiller aPF(theAllocator);
449 aSI.SetShapeType(TopAbs_VERTEX);
450 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
452 // 1 prepare arguments
453 for (i=1; i<=aNbV; ++i) {
454 const TopoDS_Shape& aS=theMVCPB.FindKey(i);
459 aPF.SetArguments(aLS);
461 iErr=aPF.ErrorStatus();
468 // 3 Add new vertices to theDS;
469 // 4 Map PaveBlock/ListOfVertices to add to this PaveBlock ->aMPBLI
470 aItLS.Initialize(aLS);
471 for (; aItLS.More(); aItLS.Next()) {
472 const TopoDS_Shape& aVx=aItLS.Value();
473 nVx=aPDS->Index(aVx);
475 if (aPDS->HasShapeSD(nVx, nVSD)) {
476 aV=aPDS->Shape(nVSD);
481 // index of new vertex in theDS -> iV
482 if (!aMVI.IsBound(aV)) {
484 iV=myDS->Append(aSI);
486 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(iV);
487 Bnd_Box& aBox=aSIDS.ChangeBox();
488 BRepBndLib::Add(aV, aBox);
496 BOPDS_CoupleOfPaveBlocks &aCPB=theMVCPB.ChangeFromKey(aVx);
498 // update EF interference
499 iX=aCPB.IndexInterf();
500 BOPDS_InterfEF& aEF=aEFs(iX);
503 const Handle(BOPDS_PaveBlock)& aPB=aCPB.PaveBlock1();
504 if (aMPBLI.Contains(aPB)) {
505 BOPCol_ListOfInteger& aLI=aMPBLI.ChangeFromKey(aPB);
509 BOPCol_ListOfInteger aLI(theAllocator);
511 aMPBLI.Add(aPB, aLI);
516 // 5.1 Compute Extra Paves and
517 // 5.2. Add Extra Paves to the PaveBlocks
518 aNbPBLI=aMPBLI.Extent();
519 for (i=1; i<=aNbPBLI; ++i) {
520 Handle(BOPDS_PaveBlock) aPB=aMPBLI.FindKey(i);
521 const BOPCol_ListOfInteger& aLI=aMPBLI.FindFromIndex(i);
522 nE=aPB->OriginalEdge();
523 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&myDS->Shape(nE)));
525 aItLI.Initialize(aLI);
526 for (; aItLI.More(); aItLI.Next()) {
528 const TopoDS_Vertex& aVx=(*(TopoDS_Vertex *)(&myDS->Shape(nVx)));
530 iFlag=myContext->ComputeVE (aVx, aE, aT);
533 aPave.SetParameter(aT);
534 aPB->AppendExtPave(aPave);
538 // 6 Split PaveBlocksa
539 for (i=1; i<=aNbPBLI; ++i) {
540 Handle(BOPDS_PaveBlock) aPB=aMPBLI.FindKey(i);
541 nE=aPB->OriginalEdge();
543 if (!myDS->IsCommonBlock(aPB)) {
544 myDS->UpdatePaveBlock(aPB);
547 const Handle(BOPDS_CommonBlock)& aCB=myDS->CommonBlock(aPB);
548 myDS->UpdateCommonBlock(aCB);
550 }//for (; aItMPBLI.More(); aItMPBLI.Next()) {
554 //=======================================================================
555 // function: CheckFacePaves
557 //=======================================================================
558 Standard_Boolean BOPAlgo_PaveFiller::CheckFacePaves
559 (const Standard_Integer nVx,
560 const BOPCol_MapOfInteger& aMIFOn,
561 const BOPCol_MapOfInteger& aMIFIn)
563 Standard_Boolean bRet;
565 BOPCol_MapIteratorOfMapOfInteger aIt;
569 aIt.Initialize(aMIFOn);
570 for (; aIt.More(); aIt.Next()) {
577 aIt.Initialize(aMIFIn);
578 for (; aIt.More(); aIt.Next()) {
588 //=======================================================================
589 // function: CheckFacePaves
591 //=======================================================================
592 Standard_Boolean BOPAlgo_PaveFiller::CheckFacePaves
593 (const TopoDS_Vertex& aVnew,
594 const BOPCol_MapOfInteger& aMIF)
596 Standard_Boolean bRet;
597 Standard_Integer nV, iFlag;
598 BOPCol_MapIteratorOfMapOfInteger aIt;
602 aIt.Initialize(aMIF);
603 for (; aIt.More(); aIt.Next()) {
605 const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nV)));
606 iFlag=BOPTools_AlgoTools::ComputeVV(aVnew, aV);
614 //=======================================================================
615 //function : ForceInterfVF
617 //=======================================================================
618 Standard_Boolean BOPAlgo_PaveFiller::ForceInterfVF
619 (const Standard_Integer nV,
620 const Standard_Integer nF)
622 Standard_Boolean bRet;
624 bRet = Standard_False;
625 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&myDS->Shape(nV);
626 const TopoDS_Face& aF = *(TopoDS_Face*) &myDS->Shape(nF);
628 GeomAPI_ProjectPointOnSurf& aProj = myContext->ProjPS(aF);
629 const gp_Pnt& aP = BRep_Tool::Pnt(aV);
631 if (!aProj.IsDone()) {
634 Standard_Real aDist, U, V;
636 aDist=aProj.LowerDistance();
637 aProj.LowerDistanceParameters(U, V);
640 bRet = myContext->IsPointInFace (aF, aP2d);
642 //Standard_Integer i;
645 BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
646 aVFs.SetIncrement(10);
647 BOPDS_InterfVF& aVF=aVFs.Append1();
648 aVF.SetIndices(nV, nF);
651 myDS->AddInterf(nV, nF);
653 aBB.UpdateVertex(aV, aDist);
654 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nV);
655 Bnd_Box& aBoxDS=aSIDS.ChangeBox();
656 BRepBndLib::Add(aV, aBoxDS);
658 BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
659 BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();