mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-09-08 14:17:06 +03:00
0030656: Modeling Algorithms - Change Boolean Operations algorithm to use BVH tree instead of UBTree
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.
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
// 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_EBTree.hxx>
|
||||
#include <Standard_Integer.hxx>
|
||||
|
||||
typedef NCollection_EBTree<Standard_Integer, Bnd_Box> BOPTools_BoxBndTree;
|
||||
typedef BOPTools_BoxSelector<Bnd_Box> BOPTools_BoxBndTreeSelector;
|
||||
|
||||
#endif
|
@@ -15,32 +15,27 @@
|
||||
#ifndef BOPTools_BoxSelector_HeaderFile
|
||||
#define BOPTools_BoxSelector_HeaderFile
|
||||
|
||||
#include <TColStd_ListOfInteger.hxx>
|
||||
#include <NCollection_UBTree.hxx>
|
||||
#include <Standard_Integer.hxx>
|
||||
#include <BVH_Traverse.hxx>
|
||||
#include <BVH_BoxSet.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
|
||||
#include <Standard_Integer.hxx>
|
||||
#include <TColStd_ListOfInteger.hxx>
|
||||
|
||||
//! 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()
|
||||
@@ -49,7 +44,7 @@ public:
|
||||
}
|
||||
|
||||
//! Sets the box
|
||||
void SetBox(const BoxType& theBox)
|
||||
void SetBox (const BVH_Box <Standard_Real, Dimension>& theBox)
|
||||
{
|
||||
myBox = theBox;
|
||||
}
|
||||
@@ -60,11 +55,46 @@ public:
|
||||
return myIndices;
|
||||
}
|
||||
|
||||
private:
|
||||
public: //! @name Rejection/Acceptance rules
|
||||
|
||||
BoxType myBox;
|
||||
TColStd_ListOfInteger myIndices;
|
||||
//! 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;
|
||||
}
|
||||
|
||||
//! Checks if the element should be rejected
|
||||
Standard_Boolean RejectElement (const Standard_Integer theIndex)
|
||||
{
|
||||
return myBox.IsOut (this->myBVHSet->Box (theIndex));
|
||||
}
|
||||
|
||||
//! Checks if the metric of the node may be accepted
|
||||
virtual Standard_Boolean AcceptMetric (const Standard_Boolean& theIsInside) const Standard_OVERRIDE
|
||||
{
|
||||
return theIsInside;
|
||||
}
|
||||
|
||||
//! Accepts the element with the index <theIndex> in BVH tree
|
||||
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;
|
||||
}
|
||||
|
||||
protected: //! @name Fields
|
||||
|
||||
BVH_Box <Standard_Real, Dimension> myBox; //!< Selection box
|
||||
TColStd_ListOfInteger myIndices; //!< Selected indices
|
||||
};
|
||||
|
||||
#endif
|
||||
|
47
src/BOPTools/BOPTools_BoxTree.hxx
Normal file
47
src/BOPTools/BOPTools_BoxTree.hxx
Normal file
@@ -0,0 +1,47 @@
|
||||
// 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
|
131
src/BOPTools/BOPTools_PairSelector.hxx
Normal file
131
src/BOPTools/BOPTools_PairSelector.hxx
Normal file
@@ -0,0 +1,131 @@
|
||||
// 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 selection of the elements from two BVH trees.
|
||||
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.
|
||||
//! If the flag is set to true the resulting vector will contain
|
||||
//! only unique pairs (mirrored pairs will be rejected,
|
||||
//! e.g. (1, 2) will be taken, (2, 1) will be rejected) and will
|
||||
//! not contain pairs in which IDs are the same (pair (1, 1) will be rejected).
|
||||
//! If it is required to have a full vector of pairs even
|
||||
//! for the same BVH trees, just keep the false value of this flag.
|
||||
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
|
||||
|
||||
//! Basing on the bounding boxes of the nodes checks if the pair of nodes 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);
|
||||
}
|
||||
|
||||
//! Checks if the pair of elements should be rejected.
|
||||
Standard_Boolean RejectElement (const Standard_Integer theID1,
|
||||
const Standard_Integer theID2)
|
||||
{
|
||||
return (mySameBVHs && theID1 >= theID2) ||
|
||||
this->myBVHSet1->Box (theID1).IsOut(
|
||||
this->myBVHSet2->Box (theID2));
|
||||
}
|
||||
|
||||
//! Checks and accepts the pair of elements.
|
||||
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
|
@@ -8,13 +8,14 @@ BOPTools_AlgoTools3D.hxx
|
||||
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
|
||||
|
Reference in New Issue
Block a user