Switching the Boolean Operations algorithm to use the BVH tree instead of UB tree as selection of the elements from BVH tree is usually faster.
explode _model e
# Make a weld at joint edges of platform and wedge
-blend _model _model 2 _model_26
blend _model _model 2 _model_27
blend _model _model 2 _model_28
blend _model _model 2 _model_29
-blend _model _model 2 _model_31
+blend _model _model 2 _model_30
+blend _model _model 2 _model_32
# Cylinder on wedge
blend result _model 2 _model_161
#include <BOPAlgo_Alerts.hxx>
#include <BOPTools_AlgoTools.hxx>
#include <BOPTools_AlgoTools2D.hxx>
-#include <BOPTools_BoxSelector.hxx>
+#include <BOPTools_BoxTree.hxx>
+#include <Bnd_Tools.hxx>
#include <BRep_Builder.hxx>
#include <BRep_Tool.hxx>
#include <BRepBndLib.hxx>
#include <IntTools_Context.hxx>
#include <IntTools_FClass2d.hxx>
#include <NCollection_DataMap.hxx>
-#include <NCollection_UBTreeFiller.hxx>
-#include <TColStd_MapIntegerHasher.hxx>
+#include <TColStd_MapOfInteger.hxx>
#include <TopAbs.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
{
// No holes, stop the analysis
myAreas.Append(aNewFaces);
+ return;
}
// Classify holes relatively faces
// Prepare tree filler with the boxes of the hole faces
- NCollection_UBTree<Standard_Integer, Bnd_Box2d> aBBTree;
- NCollection_UBTreeFiller <Standard_Integer, Bnd_Box2d> aTreeFiller(aBBTree);
-
+ Handle(BOPTools_Box2dTree) aBoxTree = new BOPTools_Box2dTree();
Standard_Integer i, aNbH = aHoleFaces.Extent();
+ aBoxTree->SetSize (aNbH);
for (i = 1; i <= aNbH; ++i)
{
const TopoDS_Face& aHFace = TopoDS::Face(aHoleFaces(i));
//
Bnd_Box2d aBox;
BRepTools::AddUVBounds(aHFace, aBox);
- aTreeFiller.Add(i, aBox);
+ aBoxTree->Add(i, Bnd_Tools::Bnd2BVH (aBox));
}
- // Shake TreeFiller
- aTreeFiller.Fill();
+ // Build BVH
+ aBoxTree->Build();
// Find outer growth face that is most close to each hole face
TopTools_IndexedDataMapOfShapeShape aHoleFaceMap;
// Selector
- BOPTools_BoxSelector<Bnd_Box2d> aSelector;
+ BOPTools_Box2dTreeSelector aSelector;
+ aSelector.SetBVHSet (aBoxTree.get());
TopTools_ListIteratorOfListOfShape aItLS(aNewFaces);
for (; aItLS.More(); aItLS.Next())
BRepTools::AddUVBounds(aFace, aBox);
aSelector.Clear();
- aSelector.SetBox(aBox);
- aBBTree.Select(aSelector);
+ aSelector.SetBox(Bnd_Tools::Bnd2BVH (aBox));
+ aSelector.Select();
const TColStd_ListOfInteger& aLI = aSelector.Indices();
TColStd_ListIteratorOfListOfInteger aItLI(aLI);
#include <BOPAlgo_Tools.hxx>
#include <BOPTools_AlgoTools.hxx>
#include <BOPTools_AlgoTools3D.hxx>
-#include <BOPTools_BoxBndTree.hxx>
+#include <BOPTools_BoxTree.hxx>
#include <BOPTools_CoupleOfShape.hxx>
#include <BOPTools_Parallel.hxx>
+#include <Bnd_Tools.hxx>
#include <BRep_Builder.hxx>
#include <BRep_Tool.hxx>
#include <BRepBndLib.hxx>
#include <IntTools_Context.hxx>
#include <NCollection_DataMap.hxx>
#include <NCollection_List.hxx>
-#include <NCollection_UBTreeFiller.hxx>
#include <NCollection_Vector.hxx>
#include <TColStd_MapIntegerHasher.hxx>
#include <TopAbs.hxx>
// Classify holes relatively solids
// Prepare tree filler with the boxes of the hole shells
- BOPTools_BoxBndTree aBBTree;
- NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
-
+ Handle(BOPTools_BoxTree) aBBTree = new BOPTools_BoxTree();
Standard_Integer i, aNbH = aHoleShells.Extent();
+ aBBTree->SetSize (aNbH);
for (i = 1; i <= aNbH; ++i)
{
const TopoDS_Shape& aHShell = aHoleShells(i);
//
Bnd_Box aBox;
BRepBndLib::Add(aHShell, aBox);
- aTreeFiller.Add(i, aBox);
+ aBBTree->Add(i, Bnd_Tools::Bnd2BVH(aBox));
myBoxes.Bind(aHShell, aBox);
}
// Shake TreeFiller
- aTreeFiller.Fill();
+ aBBTree->Build();
// Find outer growth shell that is most close to each hole shell
TopTools_IndexedDataMapOfShapeShape aHoleSolidMap;
myBoxes.Bind(aSolid, aBox);
- BOPTools_BoxBndTreeSelector aSelector;
- aSelector.SetBox(aBox);
- aBBTree.Select(aSelector);
+ BOPTools_BoxTreeSelector aSelector;
+ aSelector.SetBox(Bnd_Tools::Bnd2BVH(aBox));
+ aSelector.SetBVHSet (aBBTree.get());
+ aSelector.Select();
const TColStd_ListOfInteger& aLI = aSelector.Indices();
TColStd_ListIteratorOfListOfInteger aItLI(aLI);
//
MakeSplitEdges();
if (HasErrors()) {
- return;
+ return;
}
//
UpdatePaveBlocksWithSDVertices();
#include <BOPDS_PaveBlock.hxx>
#include <BOPTools_AlgoTools.hxx>
#include <BOPTools_AlgoTools2D.hxx>
-#include <BOPTools_BoxBndTree.hxx>
+#include <BOPTools_BoxTree.hxx>
#include <BOPTools_Parallel.hxx>
#include <BRep_Builder.hxx>
#include <BRep_Tool.hxx>
#include <BRepBndLib.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepLib.hxx>
+#include <Bnd_Tools.hxx>
#include <GeomAPI_ProjectPointOnCurve.hxx>
#include <GeomAPI_ProjectPointOnSurf.hxx>
#include <gp_Circ.hxx>
#include <gp_Vec.hxx>
#include <IntTools_Context.hxx>
#include <NCollection_IncAllocator.hxx>
-#include <NCollection_UBTreeFiller.hxx>
#include <NCollection_Vector.hxx>
#include <Standard_ErrorHandler.hxx>
#include <Standard_Failure.hxx>
<BOPAlgo_TNVFunctor,
BOPAlgo_VectorOfTNV> BOPAlgo_TNVCnt;
//=======================================================================
-class BOPAlgo_TNV : public BOPTools_BoxBndTreeSelector{
+class BOPAlgo_TNV : public BOPTools_BoxTreeSelector{
public:
BOPAlgo_TNV()
- : BOPTools_BoxBndTreeSelector(),
- myTol (0.), myFuzzyValue(0.), myTree(NULL), myVecTNV(NULL) {
+ : BOPTools_BoxTreeSelector(),
+ myTol (0.), myFuzzyValue(0.), myVecTNV(NULL) {
};
//
- ~BOPAlgo_TNV(){
+ virtual ~BOPAlgo_TNV(){
};
//
void SetVertex(const TopoDS_Vertex& aV) {
return myV;
}
//
- void SetTree(BOPTools_BoxBndTree& aTree) {
- myTree=&aTree;
- }
- //
void SetTolerance(const Standard_Real theTol) {
myTol = theTol;
}
myVecTNV = &theVec;
}
//
- virtual Standard_Boolean Accept(const Standard_Integer& theIndex)
+ virtual Standard_Boolean Accept(const Standard_Integer theIndex,
+ const Standard_Boolean& theIsInside) override
{
- const BOPAlgo_TNV& aTNV = myVecTNV->Value(theIndex - 1);
- Standard_Real aTolSum2 = myTol + aTNV.Tolerance() + myFuzzyValue;
- aTolSum2 *= aTolSum2;
- Standard_Real aD2 = myPnt.SquareDistance(aTNV.Pnt());
- if (aD2 < aTolSum2)
- return BOPTools_BoxBndTreeSelector::Accept(theIndex);
+ if (theIsInside || !RejectElement (theIndex))
+ {
+ const Standard_Integer anInd = myBVHSet->Element (theIndex);
+ const BOPAlgo_TNV& aTNV = myVecTNV->Value(anInd - 1);
+ Standard_Real aTolSum2 = myTol + aTNV.Tolerance() + myFuzzyValue;
+ aTolSum2 *= aTolSum2;
+ Standard_Real aD2 = myPnt.SquareDistance(aTNV.Pnt());
+ if (aD2 < aTolSum2)
+ return BOPTools_BoxTreeSelector::Accept(theIndex, Standard_True);
+ }
return Standard_False;
}
//
void Perform() {
- myTree->Select(*this);
+ Select();
}
//
protected:
Standard_Real myFuzzyValue;
gp_Pnt myPnt;
TopoDS_Vertex myV;
- BOPTools_BoxBndTree *myTree;
const BOPAlgo_VectorOfTNV *myVecTNV;
};
//
}
//
// Use unbalanced binary tree of bounding boxes for sorting of the vertices.
- BOPTools_BoxBndTree aBBTree;
- NCollection_UBTreeFiller <Standard_Integer,
- Bnd_Box> aTreeFiller(aBBTree);
+ Handle(BOPTools_BoxTree) aBBTree = new BOPTools_BoxTree();
+ aBBTree->SetSize (aNbV);
// Perform intersection of the vertices
BOPAlgo_VectorOfTNV aVTNV;
//
aBox.Add(BRep_Tool::Pnt(aV));
aBox.SetGap(aTol + aTolAdd);
//
- aTreeFiller.Add(i, aBox);
+ aBBTree->Add(i, Bnd_Tools::Bnd2BVH(aBox));
//
BOPAlgo_TNV& aTNV=aVTNV.Appended();
- aTNV.SetTree(aBBTree);
- aTNV.SetBox(aBox);
+ aTNV.SetBVHSet (aBBTree.get());
+ aTNV.SetBox(Bnd_Tools::Bnd2BVH(aBox));
aTNV.SetVertex(aV);
aTNV.SetTolerance(aTol);
aTNV.SetFuzzyValue(theFuzzyValue);
aTNV.SetVectorOfTNV(aVTNV);
}
// Shake the tree
- aTreeFiller.Fill();
+ aBBTree->Build();
//
// Perform intersection
BOPAlgo_TNVCnt::Perform(theRunParallel, aVTNV);
};
//! Sets the Bounding Box tree
- void SetBBTree(const BOPTools_BoxBndTree& theBBTree)
+ void SetBBTree(const Handle(BOPTools_BoxTree)& theBBTree)
{
- myBBTree = (BOPTools_BoxBndTree*)&theBBTree;
+ myBBTree = theBBTree;
};
//! Sets the ShapeBox structure
TopTools_ListOfShape myOwnIF; //! Own INTERNAL faces of the solid
TopTools_ListOfShape myInFaces; //! Faces classified as IN
- BOPTools_BoxBndTree* myBBTree; //! UB tree of bounding boxes
+ Handle(BOPTools_BoxTree) myBBTree; //! UB tree of bounding boxes
BOPAlgo_VectorOfShapeBox* myVShapeBox; //! ShapeBoxMap
TopoDS_Iterator myItF; //! Iterators
myInFaces.Clear();
// 1. Select boxes of faces that are not out of aBoxS
- BOPTools_BoxBndTreeSelector aSelector;
- aSelector.SetBox(myBoxS);
+ BOPTools_BoxTreeSelector aSelector;
+ aSelector.SetBox(Bnd_Tools::Bnd2BVH(myBoxS));
+ aSelector.SetBVHSet (myBBTree.get());
//
- if (!myBBTree->Select(aSelector))
+ if (!aSelector.Select())
return;
const TColStd_ListOfInteger& aLIFP = aSelector.Indices();
// Prepare UB tree of bounding boxes of the faces to classify
// taking the bounding boxes from the just prepared vector
- BOPTools_BoxBndTree aBBTree;
- NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
+ Handle(BOPTools_BoxTree) aBBTree = new BOPTools_BoxTree();
Standard_Integer aNbF = aVSB.Length();
for (Standard_Integer i = 0; i < aNbF; ++i)
{
- aTreeFiller.Add(i, aVSB(i).Box());
+ aBBTree->Add(i, Bnd_Tools::Bnd2BVH(aVSB(i).Box()));
}
// Shake tree filler
- aTreeFiller.Fill();
+ aBBTree->Build();
// Prepare vector of solids to classify
BOPAlgo_VectorOfFillIn3DParts aVFIP;
#include <Bnd_Box.hxx>
#include <Bnd_OBB.hxx>
+#include <Bnd_Tools.hxx>
#include <BOPDS_DS.hxx>
#include <BOPDS_IndexRange.hxx>
#include <BOPDS_Iterator.hxx>
#include <BOPDS_Pair.hxx>
#include <BOPDS_MapOfPair.hxx>
#include <BOPDS_Tools.hxx>
-#include <BOPTools_BoxBndTree.hxx>
+#include <BOPTools_BoxTree.hxx>
#include <BOPTools_Parallel.hxx>
#include <IntTools_Context.hxx>
-#include <NCollection_UBTreeFiller.hxx>
#include <NCollection_Vector.hxx>
#include <TopoDS_Shape.hxx>
#include <algorithm>
-/////////////////////////////////////////////////////////////////////////
-//=======================================================================
-//class : BOPDS_TreeSelector
-//purpose :
-//=======================================================================
-class BOPDS_TSR : public BOPTools_BoxBndTreeSelector{
- public:
- BOPDS_TSR() :
- BOPTools_BoxBndTreeSelector(),
- myHasBRep(Standard_False),
- myTree(NULL) {
- }
- //
- virtual ~BOPDS_TSR() {
- }
- //
- void SetHasBRep(const Standard_Boolean bFlag) {
- myHasBRep=bFlag;
- }
- //
- void SetTree(BOPTools_BoxBndTree& aTree) {
- myTree=&aTree;
- }
- //
- void Perform() {
- if (myHasBRep) {
- myTree->Select(*this);
- }
- }
- //
- protected:
- Standard_Boolean myHasBRep;
- BOPTools_BoxBndTree *myTree;
-};
-//
-//=======================================================================
-typedef NCollection_Vector <BOPDS_TSR> BOPDS_VectorOfTSR;
-typedef BOPTools_Functor <BOPDS_TSR,BOPDS_VectorOfTSR> BOPDS_TSRFunctor;
-typedef BOPTools_Cnt <BOPDS_TSRFunctor, BOPDS_VectorOfTSR> BOPDS_TSRCnt;
-/////////////////////////////////////////////////////////////////////////
-
-
//=======================================================================
//function :
//purpose :
const Standard_Boolean theCheckOBB,
const Standard_Real theFuzzyValue)
{
- Standard_Integer i, j, iX, i1, i2, iR, aNb, aNbR;
- Standard_Integer iTi, iTj;
- TopAbs_ShapeEnum aTi, aTj;
- //
- BOPTools_BoxBndTree aBBTree;
- NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
- //
- aNb = myDS->NbSourceShapes();
- BOPDS_VectorOfTSR aVTSR(aNb);
- //
- for (i=0; i<aNb; ++i) {
- const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
- Standard_Boolean bHasBrep = aSI.IsInterfering() && !(aSI.ShapeType() == TopAbs_SOLID);
- //
- BOPDS_TSR& aTSR=aVTSR.Appended();
- //
- aTSR.SetHasBRep(bHasBrep);
- if (!bHasBrep) {
+ const Standard_Integer aNb = myDS->NbSourceShapes();
+
+ // Prepare BVH
+ Handle(BOPTools_BoxTree) aBoxTree = new BOPTools_BoxTree();
+ aBoxTree->SetSize (aNb);
+ for (Standard_Integer i = 0; i < aNb; ++i)
+ {
+ const BOPDS_ShapeInfo& aSI = myDS->ShapeInfo(i);
+ if (!aSI.HasBRep())
continue;
- }
- //
- const Bnd_Box& aBoxEx=aSI.Box();
- aTSR.SetTree(aBBTree);
- aTSR.SetBox(aBoxEx);
- //
- aTreeFiller.Add(i, aBoxEx);
+ const Bnd_Box& aBox = aSI.Box();
+ aBoxTree->Add (i, Bnd_Tools::Bnd2BVH (aBox));
}
- //
- aTreeFiller.Fill();
- //
- //===========================================
- BOPDS_TSRCnt::Perform(myRunParallel, aVTSR);
- //===========================================
- //
- BOPDS_MapOfPair aMPFence;
- //
- aNbR = myDS->NbRanges() - 1;
- for (iR = 0; iR < aNbR; ++iR) {
- const BOPDS_IndexRange& aR = myDS->Range(iR);
- i1 = aR.First();
- i2 = aR.Last();
- for (i = i1; i <= i2; ++i) {
- const BOPDS_ShapeInfo& aSI = myDS->ShapeInfo(i);
- //
- if (!aSI.IsInterfering() || (aSI.ShapeType() == TopAbs_SOLID)) {
+
+ // Build BVH
+ aBoxTree->Build();
+
+ // Select pairs of shapes with interfering bounding boxes
+ BOPTools_BoxPairSelector aPairSelector;
+ aPairSelector.SetBVHSets (aBoxTree.get(), aBoxTree.get());
+ aPairSelector.SetSame (Standard_True);
+ aPairSelector.Select();
+ aPairSelector.Sort();
+
+ // Treat the selected pairs
+ const std::vector<BOPTools_BoxPairSelector::PairIDs>& aPairs = aPairSelector.Pairs();
+ const Standard_Integer aNbPairs = static_cast<Standard_Integer> (aPairs.size());
+
+ Standard_Integer iPair = 0;
+
+ const Standard_Integer aNbR = myDS->NbRanges();
+ for (Standard_Integer iR = 0; iR < aNbR; ++iR)
+ {
+ const BOPDS_IndexRange& aRange = myDS->Range(iR);
+
+ for (; iPair < aNbPairs; ++iPair)
+ {
+ const BOPTools_BoxPairSelector::PairIDs& aPair = aPairs[iPair];
+ if (!aRange.Contains (aPair.ID1))
+ // Go to the next range
+ break;
+
+ if (aRange.Contains (aPair.ID2))
+ // Go to the next pair
continue;
- }
- //
- BOPDS_TSR& aTSRi = aVTSR(i);
- const TColStd_ListOfInteger& aLI = aTSRi.Indices();
- Standard_Integer aNbSD = aLI.Extent();
- if (!aNbSD) {
+
+ const BOPDS_ShapeInfo& aSI1 = myDS->ShapeInfo (aPair.ID1);
+ const BOPDS_ShapeInfo& aSI2 = myDS->ShapeInfo (aPair.ID2);
+
+ const TopAbs_ShapeEnum aType1 = aSI1.ShapeType();
+ const TopAbs_ShapeEnum aType2 = aSI2.ShapeType();
+
+ Standard_Integer iType1 = BOPDS_Tools::TypeToInteger (aType1);
+ Standard_Integer iType2 = BOPDS_Tools::TypeToInteger (aType2);
+
+ // avoid interfering of the same shapes and shape with its sub-shapes
+ if (((iType1 < iType2) && aSI1.HasSubShape (aPair.ID2)) ||
+ ((iType1 > iType2) && aSI2.HasSubShape (aPair.ID1)))
continue;
- }
- //
- aTi = aSI.ShapeType();
- iTi = BOPDS_Tools::TypeToInteger(aTi);
- //
- TColStd_ListIteratorOfListOfInteger aIt(aLI);
- for (; aIt.More(); aIt.Next()) {
- j = aIt.Value(); // DS index
- if (j >= i1 && j <= i2) {
- continue;// same range
- }
- //
- const BOPDS_ShapeInfo& aSJ = myDS->ShapeInfo(j);
- aTj = aSJ.ShapeType();
- iTj = BOPDS_Tools::TypeToInteger(aTj);
- //
- // avoid interfering of the same shapes and shape with its sub-shapes
- if (((iTi < iTj) && aSI.HasSubShape(j)) ||
- ((iTi > iTj) && aSJ.HasSubShape(i))) {
- continue;
- }
- //
- BOPDS_Pair aPair(i, j);
- if (aMPFence.Add(aPair)) {
- if (theCheckOBB)
- {
- // Check intersection of Oriented bounding boxes of the shapes
- Bnd_OBB& anOBBi = theCtx->OBB(aSI.Shape(), theFuzzyValue);
- Bnd_OBB& anOBBj = theCtx->OBB(aSJ.Shape(), theFuzzyValue);
- if (anOBBi.IsOut(anOBBj))
- continue;
- }
+ if (theCheckOBB)
+ {
+ // Check intersection of Oriented bounding boxes of the shapes
+ Bnd_OBB& anOBB1 = theCtx->OBB (aSI1.Shape(), theFuzzyValue);
+ Bnd_OBB& anOBB2 = theCtx->OBB (aSI2.Shape(), theFuzzyValue);
- iX = BOPDS_Tools::TypeToInteger(aTi, aTj);
- myLists(iX).Append(aPair);
- }// if (aMPFence.Add(aPair)) {
- }// for (; aIt.More(); aIt.Next()) {
- }//for (i=i1; i<=i2; ++i) {
- }//for (iR=1; iR<aNbR; ++iR) {
- //
- aMPFence.Clear();
- aVTSR.Clear();
- //-----------------------------------------------------scope_1 t
+ if (anOBB1.IsOut (anOBB2))
+ continue;
+ }
+
+ Standard_Integer iX = BOPDS_Tools::TypeToInteger (aType1, aType2);
+ myLists(iX).Append (BOPDS_Pair (Min (aPair.ID1, aPair.ID2),
+ Max (aPair.ID1, aPair.ID2)));
+ }
+ }
}
+
#include <Bnd_Box.hxx>
#include <Bnd_OBB.hxx>
+#include <Bnd_Tools.hxx>
#include <BOPDS_DS.hxx>
#include <BOPDS_IndexRange.hxx>
#include <BOPDS_IteratorSI.hxx>
#include <BOPDS_Pair.hxx>
#include <BOPDS_ShapeInfo.hxx>
#include <BOPDS_Tools.hxx>
-#include <BOPTools_BoxBndTree.hxx>
+#include <BOPTools_BoxTree.hxx>
#include <BRep_Tool.hxx>
#include <gp_Pnt.hxx>
#include <IntTools_Context.hxx>
-#include <NCollection_UBTreeFiller.hxx>
#include <TopAbs_ShapeEnum.hxx>
#include <TColStd_DataMapOfIntegerInteger.hxx>
#include <TColStd_DataMapOfIntegerListOfInteger.hxx>
Standard_Integer iTi, iTj;
TopAbs_ShapeEnum aTi, aTj;
//
- BOPTools_BoxBndTreeSelector aSelector;
- BOPTools_BoxBndTree aBBTree;
- NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
- //
+ Handle(BOPTools_BoxTree) aBBTree = new BOPTools_BoxTree();
aNbS = myDS->NbSourceShapes();
+ aBBTree->SetSize (aNbS);
for (i=0; i<aNbS; ++i) {
const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
if (!aSI.IsInterfering()) {
}
//
const Bnd_Box& aBoxEx = aSI.Box();
- aTreeFiller.Add(i, aBoxEx);
+ aBBTree->Add(i, Bnd_Tools::Bnd2BVH(aBoxEx));
}
//
- aTreeFiller.Fill();
+ aBBTree->Build();
//
BOPDS_MapOfPair aMPFence;
//
//
const Bnd_Box& aBoxEx = aSI.Box();
//
- aSelector.Clear();
- aSelector.SetBox(aBoxEx);
+ BOPTools_BoxTreeSelector aSelector;
+ aSelector.SetBox (Bnd_Tools::Bnd2BVH (aBoxEx));
+ aSelector.SetBVHSet (aBBTree.get());
//
- Standard_Integer aNbSD = aBBTree.Select(aSelector);
+ Standard_Integer aNbSD = aSelector.Select();
if (!aNbSD) {
continue;
}
inline Standard_Boolean BOPDS_ShapeInfo::HasSubShape
(const Standard_Integer theI)const
{
- Standard_Boolean bRet;
- TColStd_ListIteratorOfListOfInteger aIt;
- //
- bRet=Standard_False;
- aIt.Initialize(mySubShapes);
- for (; aIt.More(); aIt.Next()) {
- bRet=(theI==aIt.Value());
- if (bRet) {
- return bRet;
- }
- }
- return bRet;
+ return mySubShapes.Contains (theI);
}
//=======================================================================
//function : HasReference
#include <BOPDS_SubIterator.hxx>
#include <Bnd_Box.hxx>
+#include <Bnd_Tools.hxx>
#include <BOPDS_DS.hxx>
#include <BOPDS_Pair.hxx>
#include <BOPDS_MapOfPair.hxx>
-#include <BOPTools_BoxBndTree.hxx>
-
-#include <NCollection_UBTreeFiller.hxx>
+#include <BOPTools_BoxTree.hxx>
#include <TopoDS_Shape.hxx>
void BOPDS_SubIterator::Intersect()
{
Standard_Integer i, j, iTi, iTj;
- BOPTools_BoxBndTree aBBTree;
- NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
- //
+ Handle(BOPTools_BoxTree) aBBTree = new BOPTools_BoxTree();
+ aBBTree->SetSize (mySubSet1->Extent());
+
TColStd_ListIteratorOfListOfInteger aIt(*mySubSet1);
for (; aIt.More(); aIt.Next()) {
i = aIt.Value();
const BOPDS_ShapeInfo& aSI = myDS->ShapeInfo(i);
const Bnd_Box& aBoxEx = aSI.Box();
//
- aTreeFiller.Add(i, aBoxEx);
+ aBBTree->Add(i, Bnd_Tools::Bnd2BVH (aBoxEx));
}
//
- aTreeFiller.Fill();
+ aBBTree->Build();
//
BOPDS_MapOfPair aMPKFence;
//
const BOPDS_ShapeInfo& aSI = myDS->ShapeInfo(i);
const Bnd_Box& aBoxEx = aSI.Box();
//
- BOPTools_BoxBndTreeSelector aSelector;
- aSelector.SetBox(aBoxEx);
- Standard_Integer aNbSD = aBBTree.Select(aSelector);
+ BOPTools_BoxTreeSelector aSelector;
+ aSelector.SetBox(Bnd_Tools::Bnd2BVH(aBoxEx));
+ aSelector.SetBVHSet (aBBTree.get());
+ Standard_Integer aNbSD = aSelector.Select();
if (!aNbSD) {
continue;
}
+++ /dev/null
-// Created by: Eugeny MALTCHIKOV
-// Copyright (c) 2017 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#ifndef BOPTools_BoxBndTree_HeaderFile
-#define BOPTools_BoxBndTree_HeaderFile
-
-#include <Bnd_Box.hxx>
-#include <BOPTools_BoxSelector.hxx>
-#include <NCollection_UBTree.hxx>
-#include <Standard_Integer.hxx>
-
-typedef NCollection_UBTree<Standard_Integer, Bnd_Box> BOPTools_BoxBndTree;
-typedef BOPTools_BoxSelector<Bnd_Box> BOPTools_BoxBndTreeSelector;
-
-#endif
#ifndef BOPTools_BoxSelector_HeaderFile
#define BOPTools_BoxSelector_HeaderFile
-#include <TColStd_ListOfInteger.hxx>
-#include <NCollection_UBTree.hxx>
+#include <BVH_Traverse.hxx>
+#include <BVH_BoxSet.hxx>
+
#include <Standard_Integer.hxx>
+#include <TColStd_ListOfInteger.hxx>
-//! Template Selector for the unbalanced binary tree
-//! of overlapped bounding boxes.
-template <class BoxType> class BOPTools_BoxSelector :
- public NCollection_UBTree<Standard_Integer, BoxType>::Selector
+//! Template Selector for elements selection from BVH tree.
+template <int Dimension>
+class BOPTools_BoxSelector :
+ public BVH_Traverse <Standard_Real, Dimension, BVH_BoxSet <Standard_Real, Dimension, Standard_Integer>, Standard_Boolean>
{
public:
+ typedef typename BVH::VectorType<Standard_Real, Dimension>::Type BVH_VecNd;
+
+public: //! @name Constructor
+
//! Empty constructor
BOPTools_BoxSelector() {};
- //! Checks if the box should be rejected
- virtual Standard_Boolean Reject(const BoxType& theOther) const
- {
- return myBox.IsOut(theOther);
- }
-
- //! Accepts the index
- virtual Standard_Boolean Accept(const Standard_Integer& theIndex)
- {
- myIndices.Append(theIndex);
- return Standard_True;
- }
+public: //! @name public interfaces
//! Clears the indices
void Clear()
}
//! Sets the box
- void SetBox(const BoxType& theBox)
+ void SetBox (const BVH_Box <Standard_Real, Dimension>& theBox)
{
myBox = theBox;
}
return myIndices;
}
-private:
+public: //! @name Rejection/Acceptance rules
+
+ //! Checks if the box should be rejected
+ virtual Standard_Boolean RejectNode (const BVH_VecNd& theCMin,
+ const BVH_VecNd& theCMax,
+ Standard_Boolean& theIsInside) const Standard_OVERRIDE
+ {
+ Standard_Boolean hasOverlap;
+ theIsInside = myBox.Contains (theCMin, theCMax, hasOverlap);
+ return !hasOverlap;
+ }
+
+ //! Rejects the element by the index
+ Standard_Boolean RejectElement (const Standard_Integer theIndex)
+ {
+ return myBox.IsOut (this->myBVHSet->Box (theIndex));
+ }
+
+ //! Accepts the index
+ virtual Standard_Boolean AcceptMetric (const Standard_Boolean& theIsInside) const Standard_OVERRIDE
+ {
+ return theIsInside;
+ }
+
+ //! Accepts the index
+ virtual Standard_Boolean Accept (const Standard_Integer theIndex,
+ const Standard_Boolean& theIsInside) Standard_OVERRIDE
+ {
+ if (theIsInside || !RejectElement (theIndex))
+ {
+ myIndices.Append (this->myBVHSet->Element (theIndex));
+ return Standard_True;
+ }
+ return Standard_False;
+ }
- BoxType myBox;
- TColStd_ListOfInteger myIndices;
+protected: //! @name Fields
+ BVH_Box <Standard_Real, Dimension> myBox; //!< Selection box
+ TColStd_ListOfInteger myIndices; //!< Selected indices
};
#endif
--- /dev/null
+// Created by: Eugeny MALTCHIKOV
+// Copyright (c) 2017 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef BOPTools_BoxTree_HeaderFile
+#define BOPTools_BoxTree_HeaderFile
+
+#include <BVH_BoxSet.hxx>
+#include <BOPTools_BoxSelector.hxx>
+#include <BOPTools_PairSelector.hxx>
+#include <Standard_Integer.hxx>
+#include <Standard_Real.hxx>
+#include <BVH_LinearBuilder.hxx>
+
+//! Redefines BoxSet to use the Linear builder by default
+
+template <class NumType, int Dimension, class DataType>
+class BOPTools_BoxSet : public BVH_BoxSet <NumType, Dimension, DataType>
+{
+public: //! @name Constructors
+ //! Empty constructor for use the default BVH_Builder
+ BOPTools_BoxSet (const opencascade::handle <BVH_Builder <NumType, Dimension> >& theBuilder = NULL)
+ : BVH_BoxSet <NumType, Dimension, DataType> (theBuilder.IsNull() ? new BVH_LinearBuilder<NumType, Dimension>() : theBuilder)
+ {}
+};
+
+//! 2D definitions
+typedef BOPTools_BoxSet <Standard_Real, 2, Standard_Integer> BOPTools_Box2dTree;
+typedef BOPTools_BoxSelector<2> BOPTools_Box2dTreeSelector;
+typedef BOPTools_PairSelector<2> BOPTools_Box2dPairSelector;
+
+//! 3D definitions
+typedef BOPTools_BoxSet <Standard_Real, 3, Standard_Integer> BOPTools_BoxTree;
+typedef BOPTools_BoxSelector<3> BOPTools_BoxTreeSelector;
+typedef BOPTools_PairSelector<3> BOPTools_BoxPairSelector;
+
+#endif
--- /dev/null
+// Created by: Eugeny MALTCHIKOV
+// Copyright (c) 2017 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef BOPTools_PairSelector_HeaderFile
+#define BOPTools_PairSelector_HeaderFile
+
+#include <BVH_Traverse.hxx>
+#include <BVH_BoxSet.hxx>
+
+#include <Standard_Integer.hxx>
+#include <TColStd_ListOfInteger.hxx>
+#include <algorithm>
+
+//! Template Selector for elements selection from BVH tree.
+template <int Dimension>
+class BOPTools_PairSelector :
+ public BVH_PairTraverse <Standard_Real, Dimension, BVH_BoxSet <Standard_Real, Dimension, Standard_Integer>>
+{
+public: //! @name public types
+
+ //! Auxiliary structure to keep the pair of indices
+ struct PairIDs
+ {
+ PairIDs (const Standard_Integer theId1 = -1,
+ const Standard_Integer theId2 = -1)
+ : ID1 (theId1), ID2 (theId2)
+ {}
+
+ Standard_Boolean operator< (const PairIDs& theOther) const
+ {
+ return ID1 < theOther.ID1 ||
+ (ID1 == theOther.ID1 && ID2 < theOther.ID2);
+ }
+
+ Standard_Integer ID1;
+ Standard_Integer ID2;
+ };
+
+ typedef typename BVH::VectorType<Standard_Real, Dimension>::Type BVH_VecNd;
+
+public: //! @name Constructor
+
+ //! Empty constructor
+ BOPTools_PairSelector()
+ : mySameBVHs (Standard_False)
+ {}
+
+public: //! @name public interfaces
+
+ //! Clears the indices
+ void Clear()
+ {
+ myPairs.Clear();
+ }
+
+ //! Sorts the indices
+ void Sort()
+ {
+ std::sort (myPairs.begin(), myPairs.end());
+ }
+
+ //! Tells to selector that BVH trees are the same
+ void SetSame (const Standard_Boolean theIsSame)
+ {
+ mySameBVHs = theIsSame;
+ }
+
+ //! Returns the list of accepted indices
+ const std::vector<PairIDs>& Pairs() const
+ {
+ return myPairs;
+ }
+
+public: //! @name Rejection/Acceptance rules
+
+ //! Checks if the box should be rejected
+ virtual Standard_Boolean RejectNode (const BVH_VecNd& theCMin1,
+ const BVH_VecNd& theCMax1,
+ const BVH_VecNd& theCMin2,
+ const BVH_VecNd& theCMax2,
+ Standard_Real&) const Standard_OVERRIDE
+ {
+ return BVH_Box<Standard_Real, 3> (theCMin1, theCMax1).IsOut (theCMin2, theCMax2);
+ }
+
+ //! Rejects the element by the index
+ Standard_Boolean RejectElement (const Standard_Integer theID1,
+ const Standard_Integer theID2)
+ {
+ return (mySameBVHs && theID1 >= theID2) ||
+ this->myBVHSet1->Box (theID1).IsOut(
+ this->myBVHSet2->Box (theID2));
+ }
+
+ //! Accepts the index
+ virtual Standard_Boolean Accept (const Standard_Integer theID1,
+ const Standard_Integer theID2) Standard_OVERRIDE
+ {
+ if (!RejectElement (theID1, theID2))
+ {
+ myPairs.push_back (PairIDs (this->myBVHSet1->Element (theID1),
+ this->myBVHSet2->Element (theID2)));
+ return Standard_True;
+ }
+ return Standard_False;
+ }
+
+protected: //! @name Fields
+
+ std::vector<PairIDs> myPairs; //!< Selected pairs of indices
+ Standard_Boolean mySameBVHs; //!< Selection is performed from the same BVH trees
+};
+
+#endif
BOPTools_AlgoTools_1.cxx
BOPTools_AlgoTools_2.cxx
BOPTools_BoxSelector.hxx
-BOPTools_BoxBndTree.hxx
+BOPTools_BoxTree.hxx
BOPTools_ConnexityBlock.hxx
BOPTools_CoupleOfShape.hxx
BOPTools_IndexedDataMapOfSetShape.hxx
BOPTools_ListOfConnexityBlock.hxx
BOPTools_ListOfCoupleOfShape.hxx
BOPTools_MapOfSet.hxx
+BOPTools_PairSelector.hxx
BOPTools_Parallel.hxx
BOPTools_Set.cxx
BOPTools_Set.hxx
// Modified by skv - Fri Dec 26 12:20:14 2003 OCC4455
+#include <Bnd_Tools.hxx>
#include <BRep_Builder.hxx>
#include <BRep_Tool.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <TopTools_MapOfShape.hxx>
//
#include <BRepBndLib.hxx>
-#include <BOPTools_BoxBndTree.hxx>
-#include <NCollection_UBTreeFiller.hxx>
+#include <BOPTools_BoxTree.hxx>
//
#include <BOPTools_AlgoTools.hxx>
//---------------------------------------------------------------
// Prepare tools for sorting the bounding boxes
- BOPTools_BoxBndTree aBBTree;
- NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
+ Handle(BOPTools_BoxTree) aBBTree = new BOPTools_BoxTree();
+ aBBTree->SetSize (SetOfFaces.Extent());
//
NCollection_IndexedDataMap<TopoDS_Shape, Bnd_Box, TopTools_ShapeMapHasher> aMFaces;
// Construct bounding boxes for faces and add them to the tree
//
Standard_Integer i = aMFaces.Add(aF, aBoxF);
//
- aTreeFiller.Add(i, aBoxF);
+ aBBTree->Add(i, Bnd_Tools::Bnd2BVH(aBoxF));
}
//
// shake tree filler
- aTreeFiller.Fill();
+ aBBTree->Build();
//
// get faces with interfering bounding boxes
aItL.Initialize(SetOfFaces);
const TopoDS_Face& aF1 = TopoDS::Face(aItL.Value());
const Bnd_Box& aBoxF1 = aMFaces.FindFromKey(aF1);
//
- BOPTools_BoxBndTreeSelector aSelector;
- aSelector.SetBox(aBoxF1);
- aBBTree.Select(aSelector);
+ BOPTools_BoxTreeSelector aSelector;
+ aSelector.SetBox (Bnd_Tools::Bnd2BVH(aBoxF1));
+ aSelector.SetBVHSet (aBBTree.get());
+ aSelector.Select ();
//
const TColStd_ListOfInteger& aLI = aSelector.Indices();
TColStd_ListIteratorOfListOfInteger aItLI(aLI);