0024157: Parallelization of assembly part of BO
authorpkv <pkv@opencascade.com>
Tue, 10 Dec 2013 05:08:44 +0000 (09:08 +0400)
committerbugmaster <bugmaster@opencascade.com>
Thu, 19 Dec 2013 09:47:39 +0000 (13:47 +0400)
New features
class BOPAlgo_BuilderSolid
-method:
void BOPAlgo_BuilderSolid::SetSolid(const TopoDS_Solid& theSolid) has been added.
Purpose: Sets the source solid <theSolid>

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 <theShell> is open

class BOPTools_AlgoTools
-method:
Standard_Boolean  BOPTools_AlgoTools::IsInvertedSolid(const TopoDS_Solid& theSolid) has been added.
Purpose: Returns true if the solid <theSolid> 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 <theBoxS> for the solid with DS-index <theIndex>

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

src/BOPAlgo/BOPAlgo_Builder.cdl
src/BOPAlgo/BOPAlgo_BuilderSolid.cdl
src/BOPAlgo/BOPAlgo_BuilderSolid.cxx
src/BOPAlgo/BOPAlgo_Builder_2Cnt.hxx
src/BOPAlgo/BOPAlgo_Builder_3.cxx
src/BOPDS/BOPDS_DS.cdl
src/BOPDS/BOPDS_DS.cxx
src/BOPTools/BOPTools_AlgoTools.cdl
src/BOPTools/BOPTools_AlgoTools.cxx

index 65a9895..9d1cf10 100644 (file)
@@ -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; 
     --  
index 2cfc0aa..bd54868 100644 (file)
@@ -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 <theSolid>   
+     
+    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; 
index 1f44fd4..f2cb38d 100644 (file)
@@ -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;
   //
index 50fb818..4943d31 100755 (executable)
 #include <BOPInt_Context.hxx>
 
 #include <BOPAlgo_BuilderFace.hxx>
+#include <BOPAlgo_BuilderSolid.hxx>
 
-//=======================================================================
-//class    : BOPAlgo_VectorOfBuilderFace
-//purpose  : 
-//=======================================================================
 typedef BOPCol_NCVector<BOPAlgo_BuilderFace> 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<TopoDS_Shape> BOPAlgo_VectorOfShape;
-typedef BOPCol_NCVector<BOPAlgo_VectorOfShape> BOPAlgo_VectorOfVectorOfShape;
-
+//
+typedef BOPCol_NCVector<BOPAlgo_VectorOfShape> \
+  BOPAlgo_VectorOfVectorOfShape;
+//
 typedef NCollection_IndexedDataMap\
   <BOPTools_Set, Standard_Integer, BOPTools_SetMapHasher> \
     BOPAlgo_IndexedDataMapOfSetInteger;
@@ -124,13 +124,14 @@ class BOPAlgo_PairOfShapeBoolean {
   TopoDS_Shape myShape1;
   TopoDS_Shape myShape2;
 };
-
-typedef BOPCol_NCVector<BOPAlgo_PairOfShapeBoolean> BOPAlgo_VectorOfPairOfShapeBoolean;
 //
-
+typedef BOPCol_NCVector<BOPAlgo_PairOfShapeBoolean> \
+  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_BuilderSolid> 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<Standard_Integer>& 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<Standard_Integer>(0,aNbBS), aBSF);
+    }
+    else {
+      aBSF.operator()(flexible_range<Standard_Integer>(0,aNbBS));
+    }
+  }
+  //
+};
 
 #endif
index c06bbfd..387a12d 100644 (file)
 #include <BOPDS_BoxBndTree.hxx>
 #include <BOPCol_ListOfInteger.hxx>
 #include <BOPInt_Context.hxx>
+#include <BOPAlgo_Builder_2Cnt.hxx>
 
 
-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<aNbS; ++i) {
@@ -220,6 +217,23 @@ void BOPAlgo_Builder::FillIn3DParts(BOPCol_DataMapOfShapeListOfShape& theInParts
     }
   }//for (i=0; i<aNbS; ++i) {
   //
+  // 1.2. Prepare TreeFiller
+  BOPDS_BoxBndTree aBBTree;
+  NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> 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; i<aNbS; ++i) {
     const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(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 <Standard_Integer, Bnd_Box> 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; i<aNbS; ++i) {
+  //
+  Standard_Integer k, aNbBS;
+  //
+  aNbBS=aVBS.Extent();
+  //
+  //===================================================
+  BOPAlgo_BuilderSolidCnt::Perform(myRunParallel, aVBS);
+  //===================================================
+  //
+  for (k=0; k<aNbBS; ++k) {
+    BOPAlgo_BuilderSolid& aBS=aVBS(k);
+    const TopoDS_Solid& aS=aBS.Solid();
+    const BOPCol_ListOfShape& aLSR=aBS.Areas();
     //
-    // 1.4 Collect resulting solids and theirs set of faces. 
-    //     Update Images.
     if (!myImages.IsBound(aS)) {
       BOPCol_ListOfShape aLSx;
       //
@@ -589,9 +590,8 @@ void BOPAlgo_Builder::BuildSplitSolids(BOPCol_DataMapOfShapeListOfShape& theInPa
         }
       }
     }
-  }// for (i=0; i<aNbS; ++i) {
+  }
 }
-
 //=======================================================================
 //function :FillInternalShapes 
 //purpose  : 
@@ -812,85 +812,6 @@ void BOPAlgo_Builder::FillInternalShapes()
   aMSx.Clear();
 }
 //=======================================================================
-//function : BuildBndBox
-//purpose  : 
-//=======================================================================
-void BOPAlgo_Builder::BuildBndBox(const Standard_Integer theIndex,
-                                 Bnd_Box& aBoxS)
-{
-  Standard_Boolean bIsOpenBox;
-  Standard_Integer nSh, nFc;
-  Standard_Real aTolS, aTolFc;
-  TopAbs_State aState; 
-  BOPCol_ListIteratorOfListOfInteger aItLI, aItLI1;
-  //
-  const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(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  : 
 //=======================================================================
index ae9535b..bf291f0 100644 (file)
@@ -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 <theIndex>.
              ---
-               
+    BuildBndBoxSolid (me:out; 
+               theIndex:Integer from Standard;  
+               theBox:out Box from Bnd) 
+       is protected;  
+           ---Purpose: 
+            --- Computes bouding box <theBox> for the solid with DS-index <theIndex>
+            ---
 fields  
     myAllocator        : BaseAllocator from BOPCol is protected;
     myArguments        : ListOfShape from BOPCol is protected;   
index 58caf37..09f3eb1 100644 (file)
@@ -522,6 +522,17 @@ void BOPDS_DS::Init()
     }//if (aTS==TopAbs_FACE) {
   }//for (j=0; j<myNbSourceShapes; ++j) {
   //
+  // 2.4 Solids
+  for (j=0; j<myNbSourceShapes; ++j) {
+    BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
+    //
+    aTS=aSI.ShapeType();
+    if (aTS==TopAbs_SOLID) {
+      Bnd_Box& aBox=aSI.ChangeBox();
+      BuildBndBoxSolid(j, aBox); 
+    }
+  }//for (j=0; j<myNbSourceShapes; ++j) {
+  //
   aMI.Clear();
   aAllocator.Nullify();
   //-----------------------------------------------------scope_1 t
@@ -1832,3 +1843,79 @@ void SortShell(const int n, BOPDS_Pave *a)
     }//for (i=0; i<nd; ++i) 
   }//while (1)
 }
+//=======================================================================
+//function : BuildBndBoxSolid
+//purpose  : 
+//=======================================================================
+void BOPDS_DS::BuildBndBoxSolid(const Standard_Integer theIndex,
+                               Bnd_Box& aBoxS)
+{
+  Standard_Boolean bIsOpenBox, bIsInverted;
+  Standard_Integer nSh, nFc;
+  Standard_Real aTolS, aTolFc;
+  BOPCol_ListIteratorOfListOfInteger aItLI, aItLI1;
+  //
+  const BOPDS_ShapeInfo& aSI=ShapeInfo(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=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=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=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(); 
+    }
+  }
+}
index e57cf4b..2835b9b 100644 (file)
@@ -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 <theS>. 
-    
+     
+    IsOpenShell(myclass; 
+           theShell:Shell from TopoDS)  
+       returns Boolean from Standard;  
+       ---Purpose: Returns true if the  shell <theShell> is open  
+     
+    IsInvertedSolid(myclass; 
+           theSolid:Solid from TopoDS)  
+       returns Boolean from Standard;  
+       ---Purpose: Returns true if the solid <theSolid> is inverted    
 end AlgoTools;
index a5958ed..610ab6d 100644 (file)
@@ -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); 
+}