From: pkv Date: Tue, 10 Dec 2013 05:08:44 +0000 (+0400) Subject: 0024157: Parallelization of assembly part of BO X-Git-Tag: HYDRO-2014-01-31~64 X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=30ecd5f8bf5f3f094aa3c8dba92020de0cd90678;p=occt-copy.git 0024157: Parallelization of assembly part of BO New features class BOPAlgo_BuilderSolid -method: void BOPAlgo_BuilderSolid::SetSolid(const TopoDS_Solid& theSolid) has been added. Purpose: Sets the source solid class BOPAlgo_BuilderSolid -method: const TopoDS_Solid& BOPAlgo_BuilderSolid::Solid()const has been added. Purpose: Returns the source solid Auxiliary classes BOPAlgo_BuilderSolidFunctor BOPAlgo_BuilderSolidCnt have been added. Purpose: The classes provide the interface and implementation of the parallel computations. class BOPTools_AlgoTools -method: Standard_Boolean BOPTools_AlgoTools::IsOpenShell(const TopoDS_Shell& theShell) has been added. Purpose: Returns true if the shell is open class BOPTools_AlgoTools -method: Standard_Boolean BOPTools_AlgoTools::IsInvertedSolid(const TopoDS_Solid& theSolid) has been added. Purpose: Returns true if the solid is inverted class BOPDS_DS -protected method: void BOPDS_DS::BuildBndBoxSolid(const Standard_Integer theIndex, Bnd_Box& theBoxS) has been added. The method computes bouding box for the solid with DS-index Changes class BOPDS_DS - method: void BOPDS_DS::Init() The block to compute bouding box for the solids has been added. class BOPAlgo_Builder - method: void BOPAlgo_Builder::FillIn3DParts (BOPCol_DataMapOfShapeListOfShape& theInParts, BOPCol_DataMapOfShapeShape& theDraftSolids, const BOPCol_BaseAllocator& theAllocator) The order of treatment of the unbalanced binary tree of overlapped bounding boxes has been changed class BOPAlgo_Builder - method: void BOPAlgo_Builder::BuildSplitSolids (BOPCol_DataMapOfShapeListOfShape& theInParts, BOPCol_DataMapOfShapeShape& theDraftSolids, const BOPCol_BaseAllocator& theAllocator) The algorithm has been adapted to provide the parallel computations --- diff --git a/src/BOPAlgo/BOPAlgo_Builder.cdl b/src/BOPAlgo/BOPAlgo_Builder.cdl index 65a9895056..9d1cf10f06 100644 --- a/src/BOPAlgo/BOPAlgo_Builder.cdl +++ b/src/BOPAlgo/BOPAlgo_Builder.cdl @@ -203,13 +203,8 @@ is theInParts:out DataMapOfShapeListOfShape from BOPCol; theDraftSolids:out DataMapOfShapeShape from BOPCol; theAllocator:BaseAllocator from BOPCol) - is protected; - - BuildBndBox(me:out; - theIndex:Integer from Standard; - theBox: out Box from Bnd) - is protected; - + is protected; + FillInternalShapes(me:out) is protected; -- diff --git a/src/BOPAlgo/BOPAlgo_BuilderSolid.cdl b/src/BOPAlgo/BOPAlgo_BuilderSolid.cdl index 2cfc0aa3f5..bd548687b6 100644 --- a/src/BOPAlgo/BOPAlgo_BuilderSolid.cdl +++ b/src/BOPAlgo/BOPAlgo_BuilderSolid.cdl @@ -21,8 +21,9 @@ class BuilderSolid from BOPAlgo ---Purpose: The algorithm to build solids from set of faces uses - BaseAllocator from BOPCol - + BaseAllocator from BOPCol, + Solid from TopoDS + --raises is @@ -33,6 +34,15 @@ is Create (theAllocator: BaseAllocator from BOPCol) returns BuilderSolid from BOPAlgo; + + SetSolid(me:out; + theSolid:Solid from TopoDS); + ---Purpose: Sets the source solid + + Solid(me) + returns Solid from TopoDS; + ---C++: return const & + ---Purpose: Returns the source solid Perform(me:out) ---Purpose: Performs the algorithm @@ -60,6 +70,7 @@ is ---Purpose: Build finalized solids with internal shells is redefined protected; ---fields +fields + mySolid:Solid from TopoDS is protected; end BuilderSolid; diff --git a/src/BOPAlgo/BOPAlgo_BuilderSolid.cxx b/src/BOPAlgo/BOPAlgo_BuilderSolid.cxx index 1f44fd4849..f2cb38dc50 100644 --- a/src/BOPAlgo/BOPAlgo_BuilderSolid.cxx +++ b/src/BOPAlgo/BOPAlgo_BuilderSolid.cxx @@ -90,7 +90,7 @@ static //function : //purpose : //======================================================================= - BOPAlgo_BuilderSolid::BOPAlgo_BuilderSolid(const Handle(NCollection_BaseAllocator)& theAllocator) +BOPAlgo_BuilderSolid::BOPAlgo_BuilderSolid(const Handle(NCollection_BaseAllocator)& theAllocator) : BOPAlgo_BuilderArea(theAllocator) { @@ -99,14 +99,30 @@ static //function : ~ //purpose : //======================================================================= - BOPAlgo_BuilderSolid::~BOPAlgo_BuilderSolid() +BOPAlgo_BuilderSolid::~BOPAlgo_BuilderSolid() { } //======================================================================= +//function : SetSolid +//purpose : +//======================================================================= +void BOPAlgo_BuilderSolid::SetSolid(const TopoDS_Solid& aS) +{ + mySolid=aS; +} +//======================================================================= +//function : Solid +//purpose : +//======================================================================= +const TopoDS_Solid& BOPAlgo_BuilderSolid::Solid()const +{ + return mySolid; +} +//======================================================================= //function : Perform //purpose : //======================================================================= - void BOPAlgo_BuilderSolid::Perform() +void BOPAlgo_BuilderSolid::Perform() { myErrorStatus=0; // @@ -150,7 +166,7 @@ static //function :PerformShapesToAvoid //purpose : //======================================================================= - void BOPAlgo_BuilderSolid::PerformShapesToAvoid() +void BOPAlgo_BuilderSolid::PerformShapesToAvoid() { Standard_Boolean bFound; Standard_Integer i, iCnt, aNbE, aNbF; @@ -227,7 +243,7 @@ static //function : PerformLoops //purpose : //======================================================================= - void BOPAlgo_BuilderSolid::PerformLoops() +void BOPAlgo_BuilderSolid::PerformLoops() { myErrorStatus=0; // @@ -447,7 +463,7 @@ static //function : PerformAreas //purpose : //======================================================================= - void BOPAlgo_BuilderSolid::PerformAreas() +void BOPAlgo_BuilderSolid::PerformAreas() { myErrorStatus=0; // @@ -583,7 +599,7 @@ static //function : PerformInternalShapes //purpose : //======================================================================= - void BOPAlgo_BuilderSolid::PerformInternalShapes() +void BOPAlgo_BuilderSolid::PerformInternalShapes() { myErrorStatus=0; // diff --git a/src/BOPAlgo/BOPAlgo_Builder_2Cnt.hxx b/src/BOPAlgo/BOPAlgo_Builder_2Cnt.hxx index 50fb818910..4943d31748 100755 --- a/src/BOPAlgo/BOPAlgo_Builder_2Cnt.hxx +++ b/src/BOPAlgo/BOPAlgo_Builder_2Cnt.hxx @@ -30,16 +30,14 @@ #include #include +#include -//======================================================================= -//class : BOPAlgo_VectorOfBuilderFace -//purpose : -//======================================================================= typedef BOPCol_NCVector BOPAlgo_VectorOfBuilderFace; // //======================================================================= //class : BOPAlgo_BuilderFaceFunctor -//purpose : +//purpose : The class provides the interface and implementation +// of the parallel computations //======================================================================= class BOPAlgo_BuilderFaceFunctor { protected: @@ -67,7 +65,8 @@ class BOPAlgo_BuilderFaceFunctor { }; //======================================================================= //class : BOPAlgo_BuilderFaceCnt -//purpose : +//purpose : The class provides the interface and implementation +// of the parallel computations //======================================================================= class BOPAlgo_BuilderFaceCnt { public: @@ -89,10 +88,11 @@ class BOPAlgo_BuilderFaceCnt { // }; // -//------------------------------------------------------------------------- typedef BOPCol_NCVector BOPAlgo_VectorOfShape; -typedef BOPCol_NCVector BOPAlgo_VectorOfVectorOfShape; - +// +typedef BOPCol_NCVector \ + BOPAlgo_VectorOfVectorOfShape; +// typedef NCollection_IndexedDataMap\ \ BOPAlgo_IndexedDataMapOfSetInteger; @@ -124,13 +124,14 @@ class BOPAlgo_PairOfShapeBoolean { TopoDS_Shape myShape1; TopoDS_Shape myShape2; }; - -typedef BOPCol_NCVector BOPAlgo_VectorOfPairOfShapeBoolean; // - +typedef BOPCol_NCVector \ + BOPAlgo_VectorOfPairOfShapeBoolean; +// //======================================================================= //function : BOPAlgo_BuilderSDFaceFunctor -//purpose : +//purpose : The class provides the interface and implementation +// of the parallel computations //======================================================================= class BOPAlgo_BuilderSDFaceFunctor { protected: @@ -167,7 +168,8 @@ class BOPAlgo_BuilderSDFaceFunctor { // //======================================================================= //function : BOPAlgo_BuilderSDFaceCnt -//purpose : +//purpose : The class provides the interface and implementation +// of the parallel computations //======================================================================= class BOPAlgo_BuilderSDFaceCnt { public: @@ -190,6 +192,61 @@ class BOPAlgo_BuilderSDFaceCnt { } // }; - +// +typedef BOPCol_NCVector BOPAlgo_VectorOfBuilderSolid; +// +//======================================================================= +//class : BOPAlgo_BuilderSolidFunctor +//purpose : The class provides the interface and implementation +// of the parallel computations +//======================================================================= +class BOPAlgo_BuilderSolidFunctor { + protected: + BOPAlgo_VectorOfBuilderSolid* myPVBS; + // + public: + // + BOPAlgo_BuilderSolidFunctor(BOPAlgo_VectorOfBuilderSolid& aVBS) + : myPVBS(&aVBS) { + } + // + void operator()( const flexible_range& aBR ) const{ + Standard_Integer i, iBeg, iEnd; + // + BOPAlgo_VectorOfBuilderSolid& aVBS=*myPVBS; + // + iBeg=aBR.begin(); + iEnd=aBR.end(); + for(i=iBeg; i!=iEnd; ++i) { + BOPAlgo_BuilderSolid& aBS=aVBS(i); + // + aBS.Perform(); + } + } +}; +//======================================================================= +//class : BOPAlgo_BuilderSolidCnt +//purpose : The class provides the interface and implementation +// of the parallel computations +//======================================================================= +class BOPAlgo_BuilderSolidCnt { + public: + //------------------------------- + // Perform + Standard_EXPORT static void Perform(const Standard_Boolean bRunParallel, + BOPAlgo_VectorOfBuilderSolid& aVBS) { + + Standard_Size aNbBS=aVBS.Extent(); + BOPAlgo_BuilderSolidFunctor aBSF(aVBS); + // + if (bRunParallel) { + flexible_for(flexible_range(0,aNbBS), aBSF); + } + else { + aBSF.operator()(flexible_range(0,aNbBS)); + } + } + // +}; #endif diff --git a/src/BOPAlgo/BOPAlgo_Builder_3.cxx b/src/BOPAlgo/BOPAlgo_Builder_3.cxx index c06bbfd781..387a12d674 100644 --- a/src/BOPAlgo/BOPAlgo_Builder_3.cxx +++ b/src/BOPAlgo/BOPAlgo_Builder_3.cxx @@ -63,11 +63,9 @@ #include #include #include +#include -static - Standard_Boolean IsClosedShell(const TopoDS_Shell& aSh); - static void OwnInternalShapes(const TopoDS_Shape& , BOPCol_IndexedMapOfShape& ); @@ -146,11 +144,10 @@ void BOPAlgo_Builder::FillImagesSolids() Handle(NCollection_IncAllocator) aAlr; // aAlr=new NCollection_IncAllocator(); - // BOPCol_DataMapOfShapeListOfShape theInParts(100, aAlr); BOPCol_DataMapOfShapeShape theDraftSolids(100, aAlr); // - FillIn3DParts(theInParts, theDraftSolids, aAlr); + FillIn3DParts(theInParts, theDraftSolids, aAlr); BuildSplitSolids(theInParts, theDraftSolids, aAlr); FillInternalShapes(); // @@ -182,7 +179,7 @@ void BOPAlgo_Builder::FillIn3DParts(BOPCol_DataMapOfShapeListOfShape& theInParts myErrorStatus=0; theDraftSolids.Clear(); // - // 1. aDMISB map Index/FaceBox + // 1. aDMISB map Index/FaceBox k=0; aNbS=myDS->NbSourceShapes(); for (i=0; i aTreeFiller(aBBTree); + // + aItDMISB.Initialize(aDMISB); + for (; aItDMISB.More(); aItDMISB.Next()) { + k=aItDMISB.Key(); + const BOPAlgo_ShapeBox& aSBk=aItDMISB.Value(); + const Bnd_Box& aBk=aSBk.Box(); + // + aTreeFiller.Add(k, aBk); + } + // + // 1.3. Shake TreeFiller + aTreeFiller.Fill(); + // + //--------------------------------------------- // 2. Solids for (i=0; iShapeInfo(i); @@ -236,10 +250,7 @@ void BOPAlgo_Builder::FillIn3DParts(BOPCol_DataMapOfShapeListOfShape& theInParts BOPCol_ListOfShape aLIF(aAlr1); BOPCol_IndexedMapOfShape aMF(100, aAlr1); BOPCol_IndexedDataMapOfShapeListOfShape aMEF(100, aAlr1); - // BOPDS_BoxBndTreeSelector aSelector; - BOPDS_BoxBndTree aBBTree; - NCollection_UBTreeFiller aTreeFiller(aBBTree); Bnd_Box aBoxS; // const TopoDS_Shape& aS=aSI.Shape(); @@ -256,8 +267,8 @@ void BOPAlgo_Builder::FillIn3DParts(BOPCol_DataMapOfShapeListOfShape& theInParts } } // - // 2.1 Compute Bnd_Box for the solid aS [ aBoxS ] - BuildBndBox(i, aBoxS); + // 2.1 Bounding box for the solid aS [ aBoxS ] + aBoxS=aSI.Box(); //----- // // 2.2 Build Draft Solid [aSD] @@ -277,25 +288,7 @@ void BOPAlgo_Builder::FillIn3DParts(BOPCol_DataMapOfShapeListOfShape& theInParts aMF.Add(aFI); } // - // 2.4. Prepare TreeFiller - aItDMISB.Initialize(aDMISB); - for (; aItDMISB.More(); aItDMISB.Next()) { - k=aItDMISB.Key(); - const BOPAlgo_ShapeBox& aSBk=aItDMISB.Value(); - const TopoDS_Shape& aFk=aSBk.Shape(); - if (aMF.Contains(aFk)) { - continue; - } - // - const Bnd_Box& aBk=aSBk.Box(); - // - aTreeFiller.Add(k, aBk); - } - // - // 2.5. Shake TreeFiller - aTreeFiller.Fill(); - // - // 2.6. Select boxes of faces that are not out of aBoxS + // 2.4. Select boxes of faces that are not out of aBoxS aSelector.Clear(); aSelector.SetBox(aBoxS); // @@ -303,7 +296,7 @@ void BOPAlgo_Builder::FillIn3DParts(BOPCol_DataMapOfShapeListOfShape& theInParts // const BOPCol_ListOfInteger& aLIFP=aSelector.Indices(); // - // 2.7. Collect faces that are IN aSolid [ aLFIN ] + // 2.5. Collect faces that are IN aSolid [ aLFIN ] BOPCol_ListOfShape aLFP(aAlr1); BOPCol_ListOfShape aLCBF(aAlr1); BOPCol_MapOfShape aMFDone(100, aAlr1); @@ -316,6 +309,9 @@ void BOPAlgo_Builder::FillIn3DParts(BOPCol_DataMapOfShapeListOfShape& theInParts nFP=aItLI.Value(); const BOPAlgo_ShapeBox& aSBF=aDMISB.Find(nFP); const TopoDS_Face& aFP=(*(TopoDS_Face*)&aSBF.Shape()); + if (aMF.Contains(aFP)) { + continue; + } if (aMFDone.Contains(aFP)) { continue; } @@ -354,7 +350,7 @@ void BOPAlgo_Builder::FillIn3DParts(BOPCol_DataMapOfShapeListOfShape& theInParts } }// for (; aItLI.More(); aItLI.Next()) { // - // 2.8. Store the results in theInParts, theDraftSolids + // 2.6. Store the results in theInParts, theDraftSolids aNbFIN=aLFIN.Extent(); if (aNbFIN || aNbLIF) { aItLS.Initialize(aLIF); @@ -474,7 +470,7 @@ void BOPAlgo_Builder::BuildSplitSolids(BOPCol_DataMapOfShapeListOfShape& theInPa myErrorStatus=0; // Standard_Boolean bFlagSD; - Standard_Integer i, aNbS, iErr, aNbSFS; + Standard_Integer i, aNbS, aNbSFS;//, iErr TopExp_Explorer aExp; BOPCol_ListIteratorOfListOfShape aIt; BOPCol_DataMapIteratorOfDataMapOfShapeShape aIt1; @@ -485,6 +481,7 @@ void BOPAlgo_Builder::BuildSplitSolids(BOPCol_DataMapOfShapeListOfShape& theInPa BOPCol_ListOfShape aSFS(aAlr0), aLSEmpty(aAlr0); BOPCol_MapOfShape aMFence(100, aAlr0); BOPTools_MapOfSet aMST(100, aAlr0); + BOPAlgo_VectorOfBuilderSolid aVBS; // // 0. Find same domain solids for non-interferred solids aNbS=myDS->NbSourceShapes(); @@ -519,6 +516,7 @@ void BOPAlgo_Builder::BuildSplitSolids(BOPCol_DataMapOfShapeListOfShape& theInPa } // const TopoDS_Shape& aS=aSI.Shape(); + const TopoDS_Solid& aSolid=(*(TopoDS_Solid*)(&aS)); if(!theDraftSolids.IsBound(aS)) { continue; } @@ -550,21 +548,24 @@ void BOPAlgo_Builder::BuildSplitSolids(BOPCol_DataMapOfShapeListOfShape& theInPa Handle(NCollection_IncAllocator) aAlr1; aAlr1=new NCollection_IncAllocator(); // - BOPAlgo_BuilderSolid aSB(aAlr1); - // - //aSB.SetContext(myContext); - aSB.SetShapes(aSFS); - aSB.Perform(); - iErr=aSB.ErrorStatus(); - if (iErr) { - myErrorStatus=30; // SolidBuilder failed - return; - } - // - const BOPCol_ListOfShape& aLSR=aSB.Areas(); + BOPAlgo_BuilderSolid& aBS=aVBS.Append1(); + aBS.SetSolid(aSolid); + aBS.SetShapes(aSFS); + }//for (i=0; iShapeInfo(theIndex); - const TopoDS_Shape& aS=aSI.Shape(); - const TopoDS_Solid& aSolid=(*(TopoDS_Solid*)(&aS)); - // - bIsOpenBox=Standard_False; - // - aTolS=0.; - const BOPCol_ListOfInteger& aLISh=aSI.SubShapes(); - aItLI.Initialize(aLISh); - for (; aItLI.More(); aItLI.Next()) { - nSh=aItLI.Value(); - const BOPDS_ShapeInfo& aSISh=myDS->ShapeInfo(nSh); - if (aSISh.ShapeType()!=TopAbs_SHELL) { - continue; - } - // - const BOPCol_ListOfInteger& aLIFc=aSISh.SubShapes(); - aItLI1.Initialize(aLIFc); - for (; aItLI1.More(); aItLI1.Next()) { - nFc=aItLI1.Value(); - const BOPDS_ShapeInfo& aSIFc=myDS->ShapeInfo(nFc); - if (aSIFc.ShapeType()!=TopAbs_FACE) { - continue; - } - // - const Bnd_Box& aBFc=aSIFc.Box(); - aBoxS.Add(aBFc); - // - if (!bIsOpenBox) { - bIsOpenBox=(aBFc.IsOpenXmin() || aBFc.IsOpenXmax() || - aBFc.IsOpenYmin() || aBFc.IsOpenYmax() || - aBFc.IsOpenZmin() || aBFc.IsOpenZmax()); - if (bIsOpenBox) { - break; - } - } - // - const TopoDS_Face& aFc=*((TopoDS_Face*)&aSIFc.Shape()); - aTolFc=BRep_Tool::Tolerance(aFc); - if (aTolFc>aTolS) { - aTolS=aTolFc; - } - }//for (; aItLI1.More(); aItLI1.Next()) { - if (bIsOpenBox) { - break; - } - // - const TopoDS_Shell& aSh=*((TopoDS_Shell*)&aSISh.Shape()); - bIsOpenBox=IsClosedShell(aSh); - if (bIsOpenBox) { - break; - } - }//for (; aItLI.More(); aItLI.Next()) { - // - if (bIsOpenBox) { - aBoxS.SetWhole(); - } - else { - BRepClass3d_SolidClassifier& aSC=myContext->SolidClassifier(aSolid); - aSC.PerformInfinitePoint(aTolS); - aState=aSC.State(); - if (aState==TopAbs_IN) { - aBoxS.SetWhole(); - } - } -} -//======================================================================= //function : OwnInternalShapes //purpose : //======================================================================= @@ -908,49 +829,6 @@ void BOPAlgo_Builder::BuildBndBox(const Standard_Integer theIndex, } } //======================================================================= -//function : IsClosedShell -//purpose : -//======================================================================= -Standard_Boolean IsClosedShell(const TopoDS_Shell& aSh) -{ - Standard_Boolean bRet; - Standard_Integer i, aNbE, aNbF; - TopAbs_Orientation aOrF; - BOPCol_IndexedDataMapOfShapeListOfShape aMEF; - BOPCol_ListIteratorOfListOfShape aItLS; - // - bRet=Standard_False; - // - BOPTools::MapShapesAndAncestors(aSh, TopAbs_EDGE, TopAbs_FACE, aMEF); - // - aNbE=aMEF.Extent(); - for (i=1; i<=aNbE; ++i) { - const TopoDS_Edge& aE=*((TopoDS_Edge*)&aMEF.FindKey(i)); - if (BRep_Tool::Degenerated(aE)) { - continue; - } - // - aNbF=0; - const BOPCol_ListOfShape& aLF=aMEF(i); - aItLS.Initialize(aLF); - for (; aItLS.More(); aItLS.Next()) { - const TopoDS_Shape& aF=aItLS.Value(); - aOrF=aF.Orientation(); - if (aOrF==TopAbs_INTERNAL || aOrF==TopAbs_EXTERNAL) { - continue; - } - ++aNbF; - } - // - if (aNbF==1) { - bRet=!bRet; // True - break; - } - } - // - return bRet; -} -//======================================================================= //function : TreatCompound //purpose : //======================================================================= diff --git a/src/BOPDS/BOPDS_DS.cdl b/src/BOPDS/BOPDS_DS.cdl index ae9535bd62..bf291f03a2 100644 --- a/src/BOPDS/BOPDS_DS.cdl +++ b/src/BOPDS/BOPDS_DS.cdl @@ -33,7 +33,8 @@ class DS from BOPDS -- myInterfVV,..myInterfFF] uses - ShapeEnum from TopAbs, + ShapeEnum from TopAbs, + Box from Bnd, Shape from TopoDS, -- ListOfShape from BOPCol, @@ -580,7 +581,14 @@ is ---Purpose: --- Updates tolerance of the sub-shapes of the shape with index . --- - + + BuildBndBoxSolid (me:out; + theIndex:Integer from Standard; + theBox:out Box from Bnd) + is protected; + ---Purpose: + --- Computes bouding box for the solid with DS-index + --- fields myAllocator : BaseAllocator from BOPCol is protected; myArguments : ListOfShape from BOPCol is protected; diff --git a/src/BOPDS/BOPDS_DS.cxx b/src/BOPDS/BOPDS_DS.cxx index 58caf378c6..09f3eb1d66 100644 --- a/src/BOPDS/BOPDS_DS.cxx +++ b/src/BOPDS/BOPDS_DS.cxx @@ -522,6 +522,17 @@ void BOPDS_DS::Init() }//if (aTS==TopAbs_FACE) { }//for (j=0; jaTolS) { + aTolS=aTolFc; + } + }//for (; aItLI1.More(); aItLI1.Next()) { + if (bIsOpenBox) { + break; + } + // + const TopoDS_Shell& aSh=*((TopoDS_Shell*)&aSISh.Shape()); + bIsOpenBox=BOPTools_AlgoTools::IsOpenShell(aSh); + if (bIsOpenBox) { + break; + } + }//for (; aItLI.More(); aItLI.Next()) { + // + if (bIsOpenBox) { + aBoxS.SetWhole(); + } + else { + bIsInverted=BOPTools_AlgoTools::IsInvertedSolid(aSolid); + if (bIsInverted) { + aBoxS.SetWhole(); + } + } +} diff --git a/src/BOPTools/BOPTools_AlgoTools.cdl b/src/BOPTools/BOPTools_AlgoTools.cdl index e57cf4b653..2835b9b2de 100644 --- a/src/BOPTools/BOPTools_AlgoTools.cdl +++ b/src/BOPTools/BOPTools_AlgoTools.cdl @@ -30,7 +30,8 @@ uses Vertex from TopoDS, Edge from TopoDS, Face from TopoDS, - Wire from TopoDS, + Wire from TopoDS, + Shell from TopoDS, Solid from TopoDS, -- BaseAllocator from BOPCol, @@ -446,5 +447,15 @@ is returns Integer from Standard; ---Purpose: --- Retutns dimension of the shape . - + + IsOpenShell(myclass; + theShell:Shell from TopoDS) + returns Boolean from Standard; + ---Purpose: Returns true if the shell is open + + IsInvertedSolid(myclass; + theSolid:Solid from TopoDS) + returns Boolean from Standard; + ---Purpose: Returns true if the solid is inverted + end AlgoTools; diff --git a/src/BOPTools/BOPTools_AlgoTools.cxx b/src/BOPTools/BOPTools_AlgoTools.cxx index a5958ed244..610ab6d852 100644 --- a/src/BOPTools/BOPTools_AlgoTools.cxx +++ b/src/BOPTools/BOPTools_AlgoTools.cxx @@ -1880,3 +1880,63 @@ Standard_Boolean FindPointInFace(const TopoDS_Edge& aE, bRet = aDist < Precision::Angular(); return bRet; } +//======================================================================= +//function : IsOpenShell +//purpose : +//======================================================================= +Standard_Boolean + BOPTools_AlgoTools::IsOpenShell(const TopoDS_Shell& aSh) +{ + Standard_Boolean bRet; + Standard_Integer i, aNbE, aNbF; + TopAbs_Orientation aOrF; + BOPCol_IndexedDataMapOfShapeListOfShape aMEF; + BOPCol_ListIteratorOfListOfShape aItLS; + // + bRet=Standard_False; + // + BOPTools::MapShapesAndAncestors(aSh, TopAbs_EDGE, TopAbs_FACE, aMEF); + // + aNbE=aMEF.Extent(); + for (i=1; i<=aNbE; ++i) { + const TopoDS_Edge& aE=*((TopoDS_Edge*)&aMEF.FindKey(i)); + if (BRep_Tool::Degenerated(aE)) { + continue; + } + // + aNbF=0; + const BOPCol_ListOfShape& aLF=aMEF(i); + aItLS.Initialize(aLF); + for (; aItLS.More(); aItLS.Next()) { + const TopoDS_Shape& aF=aItLS.Value(); + aOrF=aF.Orientation(); + if (aOrF==TopAbs_INTERNAL || aOrF==TopAbs_EXTERNAL) { + continue; + } + ++aNbF; + } + // + if (aNbF==1) { + bRet=!bRet; // True + break; + } + } + // + return bRet; +} +//======================================================================= +//function : IsInvertedSolid +//purpose : +//======================================================================= +Standard_Boolean + BOPTools_AlgoTools::IsInvertedSolid(const TopoDS_Solid& aSolid) +{ + Standard_Real aTolS; + TopAbs_State aState; + BRepClass3d_SolidClassifier aSC(aSolid); + // + aTolS=1.e-7; + aSC.PerformInfinitePoint(aTolS); + aState=aSC.State(); + return (aState==TopAbs_IN); +}