From: pkv Date: Tue, 15 Apr 2014 03:19:00 +0000 (+0400) Subject: 0024639: Parallelization FillDS part of BO X-Git-Tag: V6_8_0_beta~397 X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=a20983607caa0795183bdb6863fea3617ac8d767;p=occt-copy.git 0024639: Parallelization FillDS part of BO The contents dealing with: Parallel computation of Face/Face interferences; Parallel computation of Edge/Edge interferences (Post-Treatment Level); Parallel intersection of bounding boxes (BOPDS_Iterator Level). --- diff --git a/src/BOPAlgo/BOPAlgo_PaveFiller.cxx b/src/BOPAlgo/BOPAlgo_PaveFiller.cxx index c2788ce233..37f58c5661 100644 --- a/src/BOPAlgo/BOPAlgo_PaveFiller.cxx +++ b/src/BOPAlgo/BOPAlgo_PaveFiller.cxx @@ -145,6 +145,7 @@ void BOPAlgo_PaveFiller::Init() // // 2.myIterator myIterator=new BOPDS_Iterator(myAllocator); + myIterator->SetRunParallel(myRunParallel); myIterator->SetDS(myDS); myIterator->Prepare(); // diff --git a/src/BOPAlgo/BOPAlgo_PaveFiller_3.cxx b/src/BOPAlgo/BOPAlgo_PaveFiller_3.cxx index e5929af764..44ecfd7415 100644 --- a/src/BOPAlgo/BOPAlgo_PaveFiller_3.cxx +++ b/src/BOPAlgo/BOPAlgo_PaveFiller_3.cxx @@ -42,6 +42,7 @@ #include // #include +#include #include #include #include @@ -64,6 +65,7 @@ // #include +///////////////////////////////////////////////////////////////////////// //======================================================================= //class : BOPAlgo_EdgeEdge //purpose : @@ -110,6 +112,147 @@ typedef BOPCol_TBBCnt BOPAlgo_EdgeEdgeCnt; // +///////////////////////////////////////////////////////////////////////// +//======================================================================= +//class : BOPAlgo_TNV +//purpose : +//======================================================================= +class BOPAlgo_TNV : public BOPCol_BoxBndTreeSelector{ + public: + BOPAlgo_TNV() + : BOPCol_BoxBndTreeSelector(), myTree(NULL) { + }; + // + ~BOPAlgo_TNV(){ + }; + // + void SetVertex(const TopoDS_Vertex& aV) { + myV=aV; + } + // + const TopoDS_Vertex& Vertex()const { + return myV; + } + // + void SetTree(BOPCol_BoxBndTree& aTree) { + myTree=&aTree; + } + // + void Perform() { + myTree->Select(*this); + } + // + protected: + TopoDS_Vertex myV; + BOPCol_BoxBndTree *myTree; +}; +// +//======================================================================= +typedef BOPCol_NCVector + BOPAlgo_VectorOfTNV; +// +typedef BOPCol_TBBFunctor + BOPAlgo_TNVFunctor; +// +typedef BOPCol_TBBCnt + BOPAlgo_TNVCnt; +///////////////////////////////////////////////////////////////////////// +//======================================================================= +//class : BOPAlgo_PVE +//purpose : +//======================================================================= +class BOPAlgo_PVE { + public: + BOPAlgo_PVE() + : myIV(-1), myIE(-1), myFlag(-1), myT(-1.) { + }; + // + ~BOPAlgo_PVE(){ + }; + // + void SetIndices(const Standard_Integer nV, + const Standard_Integer nE){ + myIV=nV; + myIE=nE; + } + // + void Indices(Standard_Integer& nV, + Standard_Integer& nE) const { + nV=myIV; + nE=myIE; + } + // + void SetVertex(const TopoDS_Vertex& aV) { + myV=aV; + } + // + const TopoDS_Vertex& Vertex()const { + return myV; + } + // + void SetEdge(const TopoDS_Edge& aE) { + myE=aE; + } + // + const TopoDS_Edge& Edge()const { + return myE; + } + // + void SetPaveBlock(const Handle(BOPDS_PaveBlock)& aPB) { + myPB=aPB; + } + // + Handle(BOPDS_PaveBlock)& PaveBlock() { + return myPB; + } + // + Standard_Integer Flag()const { + return myFlag; + } + // + Standard_Real Parameter()const { + return myT; + } + // + void SetContext(const Handle(BOPInt_Context)& aContext) { + myContext=aContext; + } + // + const Handle(BOPInt_Context)& Context()const { + return myContext; + } + // + void Perform() { + myFlag=myContext->ComputeVE (myV, myE, myT); + }; + // + protected: + Standard_Integer myIV; + Standard_Integer myIE; + Standard_Integer myFlag; + Standard_Real myT; + TopoDS_Vertex myV; + TopoDS_Edge myE; + Handle(BOPDS_PaveBlock) myPB; + Handle(BOPInt_Context) myContext; +}; +//======================================================================= +typedef BOPCol_NCVector + BOPAlgo_VectorOfPVE; +// +typedef BOPCol_TBBContextFunctor + BOPAlgo_PVEFunctor; +// +typedef BOPCol_TBBContextCnt + BOPAlgo_PVECnt; +///////////////////////////////////////////////////////////////////////// //======================================================================= // function: PerformEE // purpose: @@ -492,10 +635,13 @@ Standard_Integer BOPAlgo_PaveFiller::PerformVerticesEE } } } - // // 5 // 5.1 Compute Extra Paves and // 5.2. Add Extra Paves to the PaveBlocks + //------------------------------------------------------------- + Standard_Integer k, aNbVPVE; + BOPAlgo_VectorOfPVE aVPVE; + // aNb=aMPBLI.Extent(); for(i=1; i<=aNb; ++i) { Handle(BOPDS_PaveBlock) aPB=aMPBLI.FindKey(i); @@ -508,12 +654,30 @@ Standard_Integer BOPAlgo_PaveFiller::PerformVerticesEE nVx=aItLI.Value(); const TopoDS_Vertex& aVx=(*(TopoDS_Vertex *)(&myDS->Shape(nVx))); // - iFlag=myContext->ComputeVE (aVx, aE, aT); - if (!iFlag) { - aPave.SetIndex(nVx); - aPave.SetParameter(aT); - aPB->AppendExtPave(aPave); - } + BOPAlgo_PVE& aPVE=aVPVE.Append1(); + aPVE.SetIndices(nVx, nE); + aPVE.SetVertex(aVx); + aPVE.SetEdge(aE); + aPVE.SetPaveBlock(aPB); + } + } + // + aNbVPVE=aVPVE.Extent(); + //============================================================= + BOPAlgo_PVECnt::Perform(myRunParallel, aVPVE, myContext); + //============================================================= + // + for (k=0; k < aNbVPVE; ++k) { + BOPAlgo_PVE& aPVE=aVPVE(k); + iFlag=aPVE.Flag(); + if (!iFlag) { + aPVE.Indices(nVx, nE); + aT=aPVE.Parameter(); + Handle(BOPDS_PaveBlock)& aPB=aPVE.PaveBlock(); + // + aPave.SetIndex(nVx); + aPave.SetParameter(aT); + aPB->AppendExtPave(aPave); } } // 6 Split PaveBlocksa @@ -533,7 +697,6 @@ Standard_Integer BOPAlgo_PaveFiller::PerformVerticesEE // return iRet; } - //======================================================================= //function : TreatNewVertices //purpose : @@ -542,136 +705,117 @@ void BOPAlgo_PaveFiller::TreatNewVertices (const BOPCol_IndexedDataMapOfShapeInteger& aMapVI, BOPCol_IndexedDataMapOfShapeListOfShape& myImages) { - Standard_Integer j, i, aNbV, aNbVSD; + Standard_Integer i, aNbV;//, aNbVSD; Standard_Real aTol; - TopoDS_Shape aVF; TopoDS_Vertex aVnew; + TopoDS_Shape aVF; BOPCol_IndexedMapOfShape aMVProcessed; - + BOPCol_MapOfInteger aMFence; BOPCol_ListIteratorOfListOfInteger aIt; - BOPCol_IndexedDataMapOfShapeListOfShape aMVLV; - BOPCol_DataMapOfIntegerShape aMIS; - BOPCol_IndexedDataMapOfShapeBox aMSB; + BOPCol_DataMapOfShapeListOfShape aDMVLV; + BOPCol_DataMapIteratorOfDataMapOfShapeListOfShape aItDMVLV; // BOPCol_BoxBndTreeSelector aSelector; BOPCol_BoxBndTree aBBTree; - NCollection_UBTreeFiller aTreeFiller(aBBTree); + NCollection_UBTreeFiller aTreeFiller(aBBTree); + BOPAlgo_VectorOfTNV aVTNV; // aNbV = aMapVI.Extent(); for (i=1; i<=aNbV; ++i) { - const TopoDS_Shape& aV=aMapVI.FindKey(i); + const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aMapVI.FindKey(i)); Bnd_Box aBox; // - aTol=BRep_Tool::Tolerance(*(TopoDS_Vertex*)(&aV)); + aTol=BRep_Tool::Tolerance(aV); aBox.SetGap(aTol); - BRepBndLib::Add(aV, aBox); + aBox.Add(BRep_Tool::Pnt(aV)); + aBox.Enlarge(aTol); // aTreeFiller.Add(i, aBox); // - aMIS.Bind(i, aV); - aMSB.Add(aV, aBox); + BOPAlgo_TNV& aTNV=aVTNV.Append1(); + aTNV.SetTree(aBBTree); + aTNV.SetBox(aBox); + aTNV.SetVertex(aV); } // aTreeFiller.Fill(); - + // + //=========================================== + BOPAlgo_TNVCnt::Perform(myRunParallel, aVTNV); + //=========================================== + // // Chains for (i=1; i<=aNbV; ++i) { - const TopoDS_Shape& aV=aMapVI.FindKey(i); - // - if (aMVProcessed.Contains(aV)) { + if (!aMFence.Add(i)) { continue; } // - Standard_Integer aNbIP, aIP, aNbIP1, aIP1; + Standard_Integer aIP, aNbIP1, aIP1; BOPCol_ListOfShape aLVSD; - BOPCol_MapOfInteger aMIP, aMIP1, aMIPC; - BOPCol_MapIteratorOfMapOfInteger aIt1; + BOPCol_MapIteratorOfMapOfInteger aItMI; + BOPCol_ListOfInteger aLIP, aLIP1, aLIPC; + BOPCol_ListIteratorOfListOfInteger aItLIP; // - aMIP.Add(i); + aLIPC.Append(i); + aLIP.Append(i); for(;;) { - aNbIP=aMIP.Extent(); - aIt1.Initialize(aMIP); - for(; aIt1.More(); aIt1.Next()) { - aIP=aIt1.Key(); - if (aMIPC.Contains(aIP)) { - continue; - } - // - const TopoDS_Shape& aVP=aMIS.Find(aIP); - const Bnd_Box& aBoxVP=aMSB.FindFromKey(aVP); + aItLIP.Initialize(aLIP); + for(; aItLIP.More(); aItLIP.Next()) { + aIP=aItLIP.Value(); // - aSelector.Clear(); - aSelector.SetBox(aBoxVP); - // - aNbVSD=aBBTree.Select(aSelector); - if (!aNbVSD) { - continue; // it must not be - } - // - const BOPCol_ListOfInteger& aLI=aSelector.Indices(); + BOPAlgo_TNV& aTNV=aVTNV(aIP-1); + const BOPCol_ListOfInteger& aLI=aTNV.Indices(); aIt.Initialize(aLI); for (; aIt.More(); aIt.Next()) { aIP1=aIt.Value(); - if (aMIP.Contains(aIP1)) { + if (!aMFence.Add(aIP1)) { continue; } - aMIP1.Add(aIP1); + aLIP1.Append(aIP1); } //for (; aIt.More(); aIt.Next()) { }//for(; aIt1.More(); aIt1.Next()) { // - aNbIP1=aMIP1.Extent(); + aNbIP1=aLIP1.Extent(); if (!aNbIP1) { - break; // from while(1) + break; // from for(;;) } // - aIt1.Initialize(aMIP); - for(; aIt1.More(); aIt1.Next()) { - aIP=aIt1.Key(); - aMIPC.Add(aIP); + aLIP.Clear(); + aItLIP.Initialize(aLIP1); + for(; aItLIP.More(); aItLIP.Next()) { + aIP=aItLIP.Value(); + aLIP.Append(aIP); + aLIPC.Append(aIP); } - // - aMIP.Clear(); - aIt1.Initialize(aMIP1); - for(; aIt1.More(); aIt1.Next()) { - aIP=aIt1.Key(); - aMIP.Add(aIP); - } - aMIP1.Clear(); - }// while(1) - //... - aNbIP=aMIPC.Extent(); - if (!aNbIP) { - aMIPC.Add(i); - } + aLIP1.Clear(); + }// for(;;) { // - aIt1.Initialize(aMIPC); - for(j=0; aIt1.More(); aIt1.Next(), ++j) { - aIP=aIt1.Key(); - const TopoDS_Shape& aVP=aMIS.Find(aIP); - if (!j) { - aVF=aVP; - } + aItLIP.Initialize(aLIPC); + for(; aItLIP.More(); aItLIP.Next()) { + aIP=aItLIP.Value(); + const TopoDS_Vertex& aVP=aVTNV(aIP-1).Vertex(); aLVSD.Append(aVP); - aMVProcessed.Add(aVP); } - aMVLV.Add(aVF, aLVSD); + aVF=aLVSD.First(); + aDMVLV.Bind(aVF, aLVSD); }// for (i=1; i<=aNbV; ++i) { // Make new vertices - aNbV=aMVLV.Extent(); - for (i=1; i<=aNbV; ++i) { - const TopoDS_Shape& aV=aMVLV.FindKey(i); - BOPCol_ListOfShape& aLVSD=aMVLV.ChangeFromIndex(i); - aNbVSD=aLVSD.Extent(); - if (aNbVSD>1) { - BOPTools_AlgoTools::MakeVertex(aLVSD, aVnew); - myImages.Add(aVnew, aLVSD); - } else { + aItDMVLV.Initialize(aDMVLV); + for(; aItDMVLV.More(); aItDMVLV.Next()) { + const TopoDS_Shape& aV=aItDMVLV.Key(); + const BOPCol_ListOfShape& aLVSD=aItDMVLV.Value(); + if (aLVSD.IsEmpty()) { myImages.Add(aV, aLVSD); } + else { + BOPCol_ListOfShape* pLVSD=(BOPCol_ListOfShape*)&aLVSD; + BOPTools_AlgoTools::MakeVertex(*pLVSD, aVnew); + myImages.Add(aVnew, aLVSD); + } } } - //======================================================================= //function : FillShrunkData //purpose : diff --git a/src/BOPAlgo/BOPAlgo_PaveFiller_6.cxx b/src/BOPAlgo/BOPAlgo_PaveFiller_6.cxx index 4c090a3a87..3c131fa931 100644 --- a/src/BOPAlgo/BOPAlgo_PaveFiller_6.cxx +++ b/src/BOPAlgo/BOPAlgo_PaveFiller_6.cxx @@ -62,6 +62,8 @@ #include #include #include +#include +#include #include #include @@ -94,6 +96,78 @@ static void ToleranceFF(const BRepAdaptor_Surface& aBAS1, const BRepAdaptor_Surface& aBAS2, Standard_Real& aTolFF); +///////////////////////////////////////////////////////////////////////// +//======================================================================= +//class : BOPAlgo_FaceFace +//purpose : +//======================================================================= +class BOPAlgo_FaceFace : public IntTools_FaceFace { + public: + BOPAlgo_FaceFace() + : IntTools_FaceFace(), myIF1(-1), myIF2(-1), myTolFF(1.e-7) { + } + // + ~BOPAlgo_FaceFace() { + } + // + void SetIndices(const Standard_Integer nF1, + const Standard_Integer nF2) { + myIF1=nF1; + myIF2=nF2; + } + // + void Indices(Standard_Integer& nF1, + Standard_Integer& nF2) const { + nF1=myIF1; + nF2=myIF2; + } + // + void SetFaces(const TopoDS_Face& aF1, + const TopoDS_Face& aF2) { + myF1=aF1; + myF2=aF2; + } + // + const TopoDS_Face& Face1()const { + return myF1; + } + // + const TopoDS_Face& Face2()const { + return myF2; + } + // + void SetTolFF(const Standard_Real aTolFF) { + myTolFF=aTolFF; + } + // + Standard_Real TolFF() const{ + return myTolFF; + } + // + void Perform() { + IntTools_FaceFace::Perform(myF1, myF2); + } + // + protected: + Standard_Integer myIF1; + Standard_Integer myIF2; + Standard_Real myTolFF; + TopoDS_Face myF1; + TopoDS_Face myF2; +}; +// +//======================================================================= +typedef BOPCol_NCVector + BOPAlgo_VectorOfFaceFace; +// +typedef BOPCol_TBBFunctor + BOPAlgo_FaceFaceFunctor; +// +typedef BOPCol_TBBCnt + BOPAlgo_FaceFaceCnt; +///////////////////////////////////////////////////////////////////////// //======================================================================= //function : PerformFF //purpose : @@ -114,9 +188,11 @@ void BOPAlgo_PaveFiller::PerformFF() Standard_Boolean bJustAdd, bApp, bCompC2D1, bCompC2D2, bIsDone; Standard_Boolean bToSplit, bTangentFaces; Standard_Integer nF1, nF2, aNbCurves, aNbPoints, iX, i, iP, iC, aNbLP; + Standard_Integer aNbFaceFace, k; Standard_Real aApproxTol, aTolR3D, aTolR2D, aTolFF; BRepAdaptor_Surface aBAS1, aBAS2; BOPCol_MapOfInteger aMI; + BOPAlgo_VectorOfFaceFace aVFaceFace; // BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF(); aFFs.SetStartSize(iSize); @@ -165,7 +241,13 @@ void BOPAlgo_PaveFiller::PerformFF() } } // - IntTools_FaceFace aFaceFace; + ToleranceFF(aBAS1, aBAS2, aTolFF); + // + BOPAlgo_FaceFace& aFaceFace=aVFaceFace.Append1(); + // + aFaceFace.SetIndices(nF1, nF2); + aFaceFace.SetFaces(aF1, aF2); + aFaceFace.SetTolFF(aTolFF); // IntSurf_ListOfPntOn2S aListOfPnts; GetEFPnts(nF1, nF2, aListOfPnts); @@ -173,10 +255,22 @@ void BOPAlgo_PaveFiller::PerformFF() if (aNbLP) { aFaceFace.SetList(aListOfPnts); } - + // aFaceFace.SetParameters(bApp, bCompC2D1, bCompC2D2, aApproxTol); // - aFaceFace.Perform(aF1, aF2); + //aFaceFace.Perform(aF1, aF2); + }//for (; myIterator->More(); myIterator->Next()) { + // + aNbFaceFace=aVFaceFace.Extent(); + //====================================================== + BOPAlgo_FaceFaceCnt::Perform(myRunParallel, aVFaceFace); + //====================================================== + // + for (k=0; k < aNbFaceFace; ++k) { + BOPAlgo_FaceFace& aFaceFace=aVFaceFace(k); + // + aFaceFace.Indices(nF1, nF2); + aTolFF=aFaceFace.TolFF(); // bIsDone=aFaceFace.IsDone(); if (bIsDone) { @@ -184,8 +278,6 @@ void BOPAlgo_PaveFiller::PerformFF() aTolR2D=aFaceFace.TolReached2d(); bTangentFaces=aFaceFace.TangentFaces(); // - ToleranceFF(aBAS1, aBAS2, aTolFF); - // if (aTolR3D < aTolFF){ aTolR3D=aTolFF; } @@ -250,7 +342,7 @@ void BOPAlgo_PaveFiller::PerformFF() aNbPoints=0; aFF.Init(aNbCurves, aNbPoints); } - }// for (; myIterator->More(); myIterator->Next()) { + }// for (k=0; k < aNbFaceFace; ++k) { } //======================================================================= //function : MakeBlocks diff --git a/src/BOPDS/BOPDS_Iterator.cdl b/src/BOPDS/BOPDS_Iterator.cdl index aa25bb0dc8..6b15c0bfd5 100644 --- a/src/BOPDS/BOPDS_Iterator.cdl +++ b/src/BOPDS/BOPDS_Iterator.cdl @@ -17,13 +17,13 @@ class Iterator from BOPDS - ---Purpose: - -- The class BOPDS_Iterator is - -- 1.to compute intersections between BRep sub-shapes - -- of arguments of an operation (see the class BOPDS_DS) - -- in terms of theirs bounding boxes - -- 2.provides interface to iterare the pairs of - -- intersected sub-shapes of given type + ---Purpose: + -- The class BOPDS_Iterator is + -- 1.to compute intersections between BRep sub-shapes + -- of arguments of an operation (see the class BOPDS_DS) + -- in terms of theirs bounding boxes + -- 2.provides interface to iterare the pairs of + -- intersected sub-shapes of given type uses BaseAllocator from BOPCol, @@ -35,89 +35,99 @@ uses ListIteratorOfListOfPassKeyBoolean from BOPDS, VectorOfListOfPassKeyBoolean from BOPDS ---raises is Create - returns Iterator from BOPDS; + returns Iterator from BOPDS; ---C++: alias "Standard_EXPORT virtual ~BOPDS_Iterator();" - ---Purpose: - --- Empty contructor - --- - + ---Purpose: + --- Empty contructor + --- + Create (theAllocator: BaseAllocator from BOPCol) - returns Iterator from BOPDS; - ---Purpose: - --- Contructor - --- theAllocator - the allocator to manage the memory - --- - + returns Iterator from BOPDS; + ---Purpose: + --- Contructor + --- theAllocator - the allocator to manage the memory + --- + SetDS(me:out; - pDS:PDS from BOPDS); - ---Purpose: - --- Modifier - --- Sets the data structure to process - + pDS:PDS from BOPDS); + ---Purpose: + --- Modifier + --- Sets the data structure to process + DS(me) returns DS from BOPDS; ---C++:return const & - ---Purpose: - --- Selector - --- Returns the data structure + ---Purpose: + --- Selector + --- Returns the data structure Initialize(me: out; - theType1: ShapeEnum from TopAbs; - theType2: ShapeEnum from TopAbs); - ---Purpose: - --- Initializes the iterator - --- theType1 - the first type of shape - --- theType2 - the second type of shape + theType1: ShapeEnum from TopAbs; + theType2: ShapeEnum from TopAbs); + ---Purpose: + --- Initializes the iterator + --- theType1 - the first type of shape + --- theType2 - the second type of shape More(me) - returns Boolean from Standard; - ---Purpose: - --- Returns true if still there are pairs + returns Boolean from Standard; + ---Purpose: + --- Returns true if still there are pairs -- of intersected shapes Next(me:out); - ---Purpose: - --- Moves iterations ahead + ---Purpose: + --- Moves iterations ahead Value(me; - theIndex1:out Integer from Standard; - theIndex2:out Integer from Standard; - theWithSubShape: out Boolean from Standard); - ---Purpose: - --- Returns indices (DS) of intersected shapes - --- theIndex1 - the index of the first shape - --- theIndex2 - the index of the second shape - --- theWithSubShape - flag. True if the sub-shapes of - --- shapes are intersected - + theIndex1:out Integer from Standard; + theIndex2:out Integer from Standard; + theWithSubShape: out Boolean from Standard); + ---Purpose: + --- Returns indices (DS) of intersected shapes + --- theIndex1 - the index of the first shape + --- theIndex2 - the index of the second shape + --- theWithSubShape - flag. True if the sub-shapes of + --- shapes are intersected + Prepare(me:out) - is virtual; - ---Purpose: - --- Perform the intersection algorithm and prepare - --- the results to be used + is virtual; + ---Purpose: + --- Perform the intersection algorithm and prepare + --- the results to be used ExpectedLength(me) - returns Integer from Standard; - ---Purpose: - --- Returns the number of intersections founded - + returns Integer from Standard; + ---Purpose: + --- Returns the number of intersections founded + BlockLength(me) - returns Integer from Standard; - ---Purpose: - --- Returns the block length + returns Integer from Standard; + ---Purpose: + --- Returns the block length Intersect(me:out) - is virtual protected; - + is virtual protected; + + SetRunParallel(me:out; + theFlag:Boolean from Standard); + ---Purpose: Set the flag of parallel processing + -- if is true the parallel processing is switched on + -- if is false the parallel processing is switched off + -- + RunParallel(me) + returns Boolean from Standard; + ---Purpose: Returns the flag of parallel processing + fields myAllocator: BaseAllocator from BOPCol is protected; myLength : Integer from Standard is protected; myDS : PDS from BOPDS is protected; myLists : VectorOfListOfPassKeyBoolean from BOPDS is protected; - myIterator : ListIteratorOfListOfPassKeyBoolean from BOPDS is protected; - + myIterator : ListIteratorOfListOfPassKeyBoolean from BOPDS is protected; + myRunParallel : Boolean from Standard is protected; + end Iterator; diff --git a/src/BOPDS/BOPDS_Iterator.cxx b/src/BOPDS/BOPDS_Iterator.cxx index f95a3db2a2..5d6b0428cc 100644 --- a/src/BOPDS/BOPDS_Iterator.cxx +++ b/src/BOPDS/BOPDS_Iterator.cxx @@ -22,21 +22,57 @@ #include #include // -#include -#include #include // -#include -#include -#include -#include -// +#include +#include #include +// #include #include #include #include -#include + +///////////////////////////////////////////////////////////////////////// +//======================================================================= +//class : BOPDS_TreeSelector +//purpose : +//======================================================================= +class BOPDS_TSR : public BOPCol_BoxBndTreeSelector{ + public: + BOPDS_TSR() : + BOPCol_BoxBndTreeSelector(), + myHasBRep(Standard_False), + myTree(NULL) { + } + // + virtual ~BOPDS_TSR() { + } + // + void SetHasBRep(const Standard_Boolean bFlag) { + myHasBRep=bFlag; + } + // + void SetTree(BOPCol_BoxBndTree& aTree) { + myTree=&aTree; + } + // + void Perform() { + if (myHasBRep) { + myTree->Select(*this); + } + } + // + protected: + Standard_Boolean myHasBRep; + BOPCol_BoxBndTree *myTree; +}; +// +//======================================================================= +typedef BOPCol_NCVector BOPDS_VectorOfTSR; +typedef BOPCol_TBBFunctor BOPDS_TSRFunctor; +typedef BOPCol_TBBCnt BOPDS_TSRCnt; +///////////////////////////////////////////////////////////////////////// //======================================================================= @@ -45,7 +81,8 @@ //======================================================================= BOPDS_Iterator::BOPDS_Iterator() : - myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()) + myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()), + myRunParallel(Standard_False) { myDS=NULL; myLength=0; @@ -61,7 +98,8 @@ BOPDS_Iterator::BOPDS_Iterator (const Handle(NCollection_BaseAllocator)& theAllocator) : myAllocator(theAllocator), - myLists(theAllocator) + myLists(theAllocator), + myRunParallel(Standard_False) { myDS=NULL; myLength=0; @@ -77,6 +115,22 @@ BOPDS_Iterator::~BOPDS_Iterator() { } //======================================================================= +//function : SetRunParallel +//purpose : +//======================================================================= +void BOPDS_Iterator::SetRunParallel(const Standard_Boolean theFlag) +{ + myRunParallel=theFlag; +} +//======================================================================= +//function : RunParallel +//purpose : +//======================================================================= +Standard_Boolean BOPDS_Iterator::RunParallel()const +{ + return myRunParallel; +} +//======================================================================= // function: SetDS // purpose: //======================================================================= @@ -123,7 +177,7 @@ Standard_Integer BOPDS_Iterator::BlockLength() const // purpose: //======================================================================= void BOPDS_Iterator::Initialize(const TopAbs_ShapeEnum aType1, - const TopAbs_ShapeEnum aType2) + const TopAbs_ShapeEnum aType2) { Standard_Integer iX; // @@ -154,9 +208,10 @@ void BOPDS_Iterator::Next() // function: Value // purpose: //======================================================================= -void BOPDS_Iterator::Value(Standard_Integer& theI1, - Standard_Integer& theI2, - Standard_Boolean& theWithSubShape) const +void BOPDS_Iterator::Value + (Standard_Integer& theI1, + Standard_Integer& theI2, + Standard_Boolean& theWithSubShape) const { Standard_Integer iT1, iT2, n1, n2; // @@ -175,7 +230,6 @@ void BOPDS_Iterator::Value(Standard_Integer& theI1, // theWithSubShape=aPKB.Flag(); } - //======================================================================= // function: Prepare // purpose: @@ -195,6 +249,7 @@ void BOPDS_Iterator::Prepare() } Intersect(); } +// //======================================================================= // function: Intersect // purpose: @@ -202,20 +257,16 @@ void BOPDS_Iterator::Prepare() void BOPDS_Iterator::Intersect() { Standard_Boolean bFlag; - Standard_Integer aNb, i, aNbB, aNbR, iTi, iTj; - Standard_Integer i1, i2, aNbSD, iX, j, iDS, jB, iR; + Standard_Integer aNb, i, aNbR, iTi, iTj; + Standard_Integer i1, i2, aNbSD, iX, j, iR; TopAbs_ShapeEnum aTi, aTj; Handle(NCollection_IncAllocator) aAllocator; - // BOPCol_ListIteratorOfListOfInteger aIt; // //-----------------------------------------------------scope_1 f aAllocator=new NCollection_IncAllocator(); // - BOPCol_DataMapOfShapeInteger aMSI(100, aAllocator); - BOPCol_DataMapOfIntegerInteger aMII(100, aAllocator); BOPDS_MapOfPassKeyBoolean aMPKXB(100, aAllocator); - BOPCol_IndexedDataMapOfShapeBox aMSB(100, aAllocator); BOPDS_PassKeyBoolean aPKXB; // BOPCol_BoxBndTreeSelector aSelector; @@ -223,29 +274,32 @@ void BOPDS_Iterator::Intersect() NCollection_UBTreeFiller aTreeFiller(aBBTree); // aNb=myDS->NbSourceShapes(); + BOPDS_VectorOfTSR aVTSR(aNb, aAllocator); + // for (i=0; iShapeInfo(i); - if (aSI.HasBRep()) { - const TopoDS_Shape& aS=aSI.Shape(); - const Bnd_Box& aBoxEx=aSI.Box(); - aMSI.Bind(aS, i); - aMSB.Add(aS, aBoxEx); + bFlag=aSI.HasBRep(); + // + BOPDS_TSR& aTSR=aVTSR.Append1(); + // + aTSR.SetHasBRep(bFlag); + if (!bFlag) { + continue; } - } - // - aNbB=aMSB.Extent(); - for (i=1; i<=aNbB; ++i) { - const TopoDS_Shape& aS=aMSB.FindKey(i); - const Bnd_Box& aBoxEx=aMSB(i); // - aTreeFiller.Add(i, aBoxEx); + const Bnd_Box& aBoxEx=aSI.Box(); + aTSR.SetTree(aBBTree); + aTSR.SetBox(aBoxEx); // - iDS=aMSI.Find(aS); - aMII.Bind(i, iDS); + aTreeFiller.Add(i, aBoxEx); } // aTreeFiller.Fill(); // + //=========================================== + BOPDS_TSRCnt::Perform(myRunParallel, aVTSR); + //=========================================== + // aNbR=myDS->NbRanges()-1; for (iR=0; iRRange(iR); @@ -255,67 +309,60 @@ void BOPDS_Iterator::Intersect() const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i); // if (!aSI.HasBRep()){ - continue; + continue; } // aTi=aSI.ShapeType(); - const TopoDS_Shape& aSi=aSI.Shape(); - const Bnd_Box& aBoxEx=aMSB.FindFromKey(aSi); - aSelector.Clear(); - aSelector.SetBox(aBoxEx); + const Bnd_Box& aBoxi=aSI.Box(); // - aNbSD=aBBTree.Select(aSelector); + BOPDS_TSR& aTSRi=aVTSR(i); + const BOPCol_ListOfInteger& aLI=aTSRi.Indices(); + aNbSD=aLI.Extent(); if (!aNbSD){ - continue; + continue; } // - const Bnd_Box& aBoxi=myDS->ShapeInfo(i).Box(); - // - const BOPCol_ListOfInteger& aLI=aSelector.Indices(); aIt.Initialize(aLI); for (; aIt.More(); aIt.Next()) { - jB=aIt.Value(); // box index in MII - j=aMII.Find(jB); // DS index - if (j>=i1 && j<=i2) { - continue;// same range - } - // - const BOPDS_ShapeInfo& aSIj=myDS->ShapeInfo(j); - aTj=aSIj.ShapeType(); - iTi=BOPDS_Tools::TypeToInteger(aTi); - iTj=BOPDS_Tools::TypeToInteger(aTj); - bFlag=Standard_False; - if (iTiShapeInfo(j).Box(); - if (aBoxi.IsOut(aBoxj)) { - bFlag=!bFlag; //Bounding boxes of Sub-shapes are intersected - } - // - iX=BOPDS_Tools::TypeToInteger(aTi, aTj); - aPKXB.SetFlag(bFlag); - myLists(iX).Append(aPKXB); - }// if (aMPKXB.Add(aPKXB)) { + j=aIt.Value(); // DS index + if (j>=i1 && j<=i2) { + continue;// same range + } + // + const BOPDS_ShapeInfo& aSIj=myDS->ShapeInfo(j); + aTj=aSIj.ShapeType(); + iTi=BOPDS_Tools::TypeToInteger(aTi); + iTj=BOPDS_Tools::TypeToInteger(aTj); + // + bFlag=Standard_False; + if (iTi