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 <Geom_RectangularTrimmedSurface.hxx>
23 #include <Geom_Plane.hxx>
24 #include <Geom_Surface.hxx>
25 #include <Geom_RectangularTrimmedSurface.hxx>
27 #include <TopoDS_Vertex.hxx>
28 #include <TopoDS_Edge.hxx>
29 #include <TopoDS_Face.hxx>
31 #include <BRepBndLib.hxx>
33 #include <BRep_Tool.hxx>
34 #include <BRep_Builder.hxx>
37 #include <TopExp_Explorer.hxx>
39 #include <Geom_Curve.hxx>
40 #include <Geom_Surface.hxx>
41 #include <Geom2d_Curve.hxx>
43 #include <BOPCol_NCVector.hxx>
44 #include <BOPCol_TBB.hxx>
45 #include <BOPCol_MapOfShape.hxx>
47 #include <BOPDS_VectorOfListOfPaveBlock.hxx>
48 #include <BOPDS_ListOfPaveBlock.hxx>
49 #include <BOPDS_PaveBlock.hxx>
50 #include <BOPDS_CommonBlock.hxx>
51 #include <BOPDS_Pave.hxx>
52 #include <BOPDS_ShapeInfo.hxx>
53 #include <BOPDS_MapOfPaveBlock.hxx>
54 #include <BOPDS_VectorOfInterfFF.hxx>
55 #include <BOPDS_Interf.hxx>
56 #include <BOPDS_VectorOfCurve.hxx>
57 #include <BOPDS_VectorOfFaceInfo.hxx>
58 #include <BOPDS_FaceInfo.hxx>
59 #include <BOPDS_MapOfPaveBlock.hxx>
60 #include <BOPDS_Curve.hxx>
61 #include <BOPDS_Iterator.hxx>
63 #include <BOPTools_AlgoTools.hxx>
64 #include <BOPTools_AlgoTools2D.hxx>
67 Standard_Boolean IsBasedOnPlane(const TopoDS_Face& aF);
70 static void UpdateVertices(const TopoDS_Edge& aE,
71 const TopoDS_Face& aF);
73 //=======================================================================
74 //class : BOPAlgo_SplitEdge
76 //=======================================================================
77 class BOPAlgo_SplitEdge {
84 ~BOPAlgo_SplitEdge() {
87 void SetData(const TopoDS_Edge& aE,
88 const TopoDS_Vertex& aV1,
89 const Standard_Real aT1,
90 const TopoDS_Vertex& aV2,
91 const Standard_Real aT2) {
100 void SetPaveBlock(const Handle(BOPDS_PaveBlock)& aPB) {
104 Handle(BOPDS_PaveBlock)& PaveBlock() {
108 void SetCommonBlock(const Handle(BOPDS_CommonBlock)& aCB) {
112 Handle(BOPDS_CommonBlock)& CommonBlock() {
116 const TopoDS_Edge& SplitEdge() const {
120 const Bnd_Box Box() {
125 BOPTools_AlgoTools::MakeSplitEdge(myE,
129 BRepBndLib::Add(myESp, myBox);
140 Handle(BOPDS_PaveBlock) myPB;
141 Handle(BOPDS_CommonBlock) myCB;
147 //=======================================================================
148 typedef BOPCol_NCVector
149 <BOPAlgo_SplitEdge> BOPAlgo_VectorOfSplitEdge;
151 typedef BOPCol_TBBFunctor
153 BOPAlgo_VectorOfSplitEdge> BOPAlgo_SplitEdgeFunctor;
155 typedef BOPCol_TBBCnt
156 <BOPAlgo_SplitEdgeFunctor,
157 BOPAlgo_VectorOfSplitEdge> BOPAlgo_SplitEdgeCnt;
159 //=======================================================================
160 //class : BOPAlgo_MPC
162 //=======================================================================
166 : myFlag(Standard_False) {
172 void SetEdge(const TopoDS_Edge& aE) {
176 const TopoDS_Edge& Edge() const {
180 void SetFace(const TopoDS_Face& aF) {
184 const TopoDS_Face& Face() const {
188 void SetFlag(const Standard_Boolean bFlag) {
192 Standard_Boolean Flag() const {
197 BOPTools_AlgoTools2D::BuildPCurveForEdgeOnFace(myE, myF);
199 UpdateVertices(myE, myF);
204 Standard_Boolean myFlag;
209 //=======================================================================
210 typedef BOPCol_NCVector
211 <BOPAlgo_MPC> BOPAlgo_VectorOfMPC;
213 typedef BOPCol_TBBFunctor
215 BOPAlgo_VectorOfMPC> BOPAlgo_MPCFunctor;
217 typedef BOPCol_TBBCnt
219 BOPAlgo_VectorOfMPC> BOPAlgo_MPCCnt;
221 //=======================================================================
222 //class : BOPAlgo_BPC
224 //=======================================================================
233 void SetFace(const TopoDS_Face& aF) {
237 void SetEdge(const TopoDS_Edge& aE) {
242 BOPTools_AlgoTools2D::BuildPCurveForEdgeOnPlane (myE, myF);
249 //=======================================================================
250 typedef BOPCol_NCVector
251 <BOPAlgo_BPC> BOPAlgo_VectorOfBPC;
253 typedef BOPCol_TBBFunctor
255 BOPAlgo_VectorOfBPC> BOPAlgo_BPCFunctor;
257 typedef BOPCol_TBBCnt
259 BOPAlgo_VectorOfBPC> BOPAlgo_BPCCnt;
262 //=======================================================================
263 // function: MakeSplitEdges
265 //=======================================================================
266 void BOPAlgo_PaveFiller::MakeSplitEdges()
268 Standard_Integer aNbPBP;
272 BOPDS_VectorOfListOfPaveBlock& aPBP=myDS->ChangePaveBlocksPool();
273 aNbPBP=aPBP.Extent();
278 Standard_Boolean bCB, bV1, bV2;
279 Standard_Integer i, nE, nV1, nV2, nSp, aNbPB, aNbVBSE, k;
280 Standard_Real aT1, aT2;
281 BOPDS_ListIteratorOfListOfPaveBlock aItPB, aItPBCB;
282 Handle(BOPDS_PaveBlock) aPB;
283 BOPDS_MapOfPaveBlock aMPB(100);
284 TopoDS_Vertex aV1, aV2;
286 BOPAlgo_VectorOfSplitEdge aVBSE;
289 for (i=0; i<aNbPBP; ++i) {
290 BOPDS_ListOfPaveBlock& aLPB=aPBP(i);
295 aPB->Indices(nV1, nV2);
296 bV1=myDS->IsNewShape(nV1);
297 bV2=myDS->IsNewShape(nV2);
300 nE=aPB->OriginalEdge();
306 aItPB.Initialize(aLPB);
307 for (; aItPB.More(); aItPB.Next()) {
309 const Handle(BOPDS_CommonBlock)& aCB=myDS->CommonBlock(aPB);
312 myDS->SortPaveBlocks(aCB);
313 aPB=aCB->PaveBlock1();
317 nE=aPB->OriginalEdge();
318 aPB->Indices(nV1, nV2);
319 aPB->Range(aT1, aT2);
321 aE=(*(TopoDS_Edge *)(&myDS->Shape(nE)));
322 aE.Orientation(TopAbs_FORWARD);
324 aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1)));
325 aV1.Orientation(TopAbs_FORWARD);
327 aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2)));
328 aV2.Orientation(TopAbs_REVERSED);
330 BOPAlgo_SplitEdge& aBSE=aVBSE.Append1();
332 aBSE.SetData(aE, aV1, aT1, aV2, aT2);
333 aBSE.SetPaveBlock(aPB);
335 aBSE.SetCommonBlock(aCB);
338 } // for (; aItPB.More(); aItPB.Next()) {
339 } // for (i=0; i<aNbPBP; ++i) {
341 aNbVBSE=aVBSE.Extent();
342 //======================================================
343 BOPAlgo_SplitEdgeCnt::Perform(myRunParallel, aVBSE);
344 //======================================================
348 aSI.SetShapeType(TopAbs_EDGE);
350 for (k=0; k < aNbVBSE; ++k) {
351 BOPAlgo_SplitEdge& aBSE=aVBSE(k);
353 const TopoDS_Edge& aSp=aBSE.SplitEdge();
354 const Bnd_Box& aBox=aBSE.Box();
356 Handle(BOPDS_PaveBlock) aPBk=aBSE.PaveBlock();
357 Handle(BOPDS_CommonBlock)& aCBk=aBSE.CommonBlock();
360 aSI.ChangeBox()=aBox;
362 nSp=myDS->Append(aSI);
364 if (!aCBk.IsNull()) {
372 //=======================================================================
373 // function: SplitEdge
375 //=======================================================================
376 Standard_Integer BOPAlgo_PaveFiller::SplitEdge(const Standard_Integer nE,
377 const Standard_Integer nV1,
378 const Standard_Real aT1,
379 const Standard_Integer nV2,
380 const Standard_Real aT2)
382 Standard_Integer nSp;
383 TopoDS_Vertex aV1, aV2;
387 aSI.SetShapeType(TopAbs_EDGE);
389 aE=(*(TopoDS_Edge *)(&myDS->Shape(nE)));
390 aE.Orientation(TopAbs_FORWARD);
392 aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1)));
393 aV1.Orientation(TopAbs_FORWARD);
395 aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2)));
396 aV2.Orientation(TopAbs_REVERSED);
398 BOPTools_AlgoTools::MakeSplitEdge(aE, aV1, aT1, aV2, aT2, aSp);
402 Bnd_Box& aBox=aSI.ChangeBox();
403 BRepBndLib::Add(aSp, aBox);
405 nSp=myDS->Append(aSI);
408 //=======================================================================
409 // function: MakePCurves
411 //=======================================================================
412 void BOPAlgo_PaveFiller::MakePCurves()
415 Standard_Integer i, nF1, nF2, aNbC, k, nE, aNbFF, aNbFI;
416 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
417 BOPDS_MapIteratorOfMapOfPaveBlock aItMPB;
418 TopoDS_Face aF1F, aF2F;
419 BOPAlgo_VectorOfMPC aVMPC;
423 // 1. Process Common Blocks
424 const BOPDS_VectorOfFaceInfo& aFIP=myDS->FaceInfoPool();
427 for (i=0; i<aNbFI; ++i) {
428 const BOPDS_FaceInfo& aFI=aFIP(i);
431 aF1F=(*(TopoDS_Face *)(&myDS->Shape(nF1)));
432 aF1F.Orientation(TopAbs_FORWARD);
434 const BOPDS_IndexedMapOfPaveBlock& aMPBIn=aFI.PaveBlocksIn();
435 aItMPB.Initialize(aMPBIn);
436 for(; aItMPB.More(); aItMPB.Next()) {
437 const Handle(BOPDS_PaveBlock)& aPB=aItMPB.Value();
439 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&myDS->Shape(nE)));
441 BOPAlgo_MPC& aMPC=aVMPC.Append1();
447 const BOPDS_IndexedMapOfPaveBlock& aMPBOn=aFI.PaveBlocksOn();
448 aItMPB.Initialize(aMPBOn);
449 for(; aItMPB.More(); aItMPB.Next()) {
450 const Handle(BOPDS_PaveBlock)& aPB=aItMPB.Value();
451 if (myDS->IsCommonBlockOnEdge(aPB)) {
453 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&myDS->Shape(nE)));
455 BOPAlgo_MPC& aMPC=aVMPC.Append1();
460 }// for (i=0; i<aNbFI; ++i) {
462 // 2. Process section edges
463 Standard_Boolean bPCurveOnS[2];
467 bPCurveOnS[0]=mySectionAttribute.PCurveOnS1();
468 bPCurveOnS[1]=mySectionAttribute.PCurveOnS2();
470 if (bPCurveOnS[0] || bPCurveOnS[1]) {
471 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
473 for (i=0; i<aNbFF; ++i) {
474 const BOPDS_InterfFF& aFF=aFFs(i);
475 aFF.Indices(nF1, nF2);
477 aFf[0]=(*(TopoDS_Face *)(&myDS->Shape(nF1)));
478 aFf[0].Orientation(TopAbs_FORWARD);
480 aFf[1]=(*(TopoDS_Face *)(&myDS->Shape(nF2)));
481 aFf[1].Orientation(TopAbs_FORWARD);
483 const BOPDS_VectorOfCurve& aVNC=aFF.Curves();
485 for (k=0; k<aNbC; ++k) {
486 const BOPDS_Curve& aNC=aVNC(k);
487 const BOPDS_ListOfPaveBlock& aLPB=aNC.PaveBlocks();
488 aItLPB.Initialize(aLPB);
489 for(; aItLPB.More(); aItLPB.Next()) {
490 const Handle(BOPDS_PaveBlock)& aPB=aItLPB.Value();
492 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&myDS->Shape(nE)));
494 for (m=0; m<2; ++m) {
496 BOPAlgo_MPC& aMPC=aVMPC.Append1();
498 aMPC.SetFace(aFf[m]);
499 aMPC.SetFlag(bPCurveOnS[m]);
504 }// for (i=0; i<aNbFF; ++i) {
505 }//if (bPCurveOnS1 || bPCurveOnS2 ) {
507 //======================================================
508 BOPAlgo_MPCCnt::Perform(myRunParallel, aVMPC);
509 //======================================================
511 //=======================================================================
512 // function: RefineFaceInfoOn
514 //=======================================================================
515 void BOPAlgo_PaveFiller::RefineFaceInfoOn()
517 Standard_Integer aNbPBP;
521 BOPDS_VectorOfListOfPaveBlock& aPBP=myDS->ChangePaveBlocksPool();
522 aNbPBP=aPBP.Extent();
527 Standard_Boolean bV1, bV2;
528 Standard_Integer i, nV1, nV2, aNbPB;
529 Handle(BOPDS_PaveBlock) aPB;
531 for (i=0; i<aNbPBP; ++i) {
532 BOPDS_ListOfPaveBlock& aLPB=aPBP(i);
537 aPB->Indices(nV1, nV2);
538 bV1=myDS->IsNewShape(nV1);
539 bV2=myDS->IsNewShape(nV2);
542 if (!myDS->IsCommonBlock(aPB)) {
543 // the PB seems to be untouced
547 }//if (!(bV1 || bV2)) {
549 }//for (i=0; i<aNbPBP; ++i) {
550 myDS->RefineFaceInfoOn();
552 //=======================================================================
553 //function : UpdateVertices
554 //purpose : update tolerances of vertices comparing extremities of
556 //=======================================================================
557 void UpdateVertices(const TopoDS_Edge& aE,
558 const TopoDS_Face& aF)
561 Standard_Real aT[2], aUx, aVx, aTolV2, aD2, aD;
564 Handle(Geom_Surface) aS;
565 Handle(Geom_Curve) aC3D;
566 Handle(Geom2d_Curve) aC2D;
572 aEf.Orientation(TopAbs_FORWARD);
574 TopExp::Vertices(aEf, aV[0], aV[1]);
576 aS=BRep_Tool::Surface(aF);
577 aC3D=BRep_Tool::Curve(aEf, aT[0], aT[1]);
578 aC2D=BRep_Tool::CurveOnSurface(aEf, aF, aT[0], aT[1]);
580 for (j=0; j<2; ++j) {
581 aTolV2=BRep_Tool::Tolerance(aV[j]);
582 aTolV2=aTolV2*aTolV2;
584 aC3D->D0(aT[j], aP3D);
585 aC2D->D0(aT[j], aP2Dx);
586 aP2Dx.Coord(aUx, aVx);
587 aS->D0(aUx, aVx, aP3Dx);
588 aD2=aP3D.SquareDistance(aP3Dx);
591 aBB.UpdateVertex(aV[j], aD);
595 //=======================================================================
598 //=======================================================================
599 void BOPAlgo_PaveFiller::Prepare()
601 TopAbs_ShapeEnum aType[] = {
606 Standard_Boolean bJustAdd, bIsBasedOnPlane;
607 Standard_Integer i, aNb, n1, nF;
608 TopExp_Explorer aExp;
609 BOPCol_MapOfShape aMF;
610 BOPCol_MapIteratorOfMapOfShape aItMF;
615 for(i=0; i<aNb; ++i) {
616 myIterator->Initialize(aType[i], aType[2]);
617 for (; myIterator->More(); myIterator->Next()) {
618 myIterator->Value(n1, nF, bJustAdd);
619 const TopoDS_Face& aF=(*(TopoDS_Face *)(&myDS->Shape(nF)));
621 bIsBasedOnPlane=IsBasedOnPlane(aF);
622 if (bIsBasedOnPlane) {
632 BOPAlgo_VectorOfBPC aVBPC;
634 aItMF.Initialize(aMF);
635 for (; aItMF.More(); aItMF.Next()) {
636 const TopoDS_Face& aF=*((TopoDS_Face *)&aItMF.Key());
637 aExp.Init(aF, aType[1]);
638 for (; aExp.More(); aExp.Next()) {
639 const TopoDS_Edge& aE=*((TopoDS_Edge *)&aExp.Current());
640 BOPAlgo_BPC& aBPC=aVBPC.Append1();
646 //======================================================
647 BOPAlgo_BPCCnt::Perform(myRunParallel, aVBPC);
648 //======================================================
650 //=======================================================================
651 //function : IsBasedOnPlane
653 //=======================================================================
654 Standard_Boolean IsBasedOnPlane(const TopoDS_Face& aF)
656 TopLoc_Location aLoc;
657 Handle(Geom_RectangularTrimmedSurface) aGRTS;
658 Handle(Geom_Plane) aGP;
660 const Handle(Geom_Surface)& aS = BRep_Tool::Surface(aF, aLoc);
661 aGRTS = Handle(Geom_RectangularTrimmedSurface)::DownCast(aS);
662 if(!aGRTS.IsNull()) {
663 aGP = Handle(Geom_Plane)::DownCast(aGRTS->BasisSurface());
666 aGP = Handle(Geom_Plane)::DownCast(aS);
669 return (!aGP.IsNull());