diff --git a/src/Select3D/FILES b/src/Select3D/FILES index ea12ef8249..3146054e36 100755 --- a/src/Select3D/FILES +++ b/src/Select3D/FILES @@ -1,7 +1,5 @@ Select3D_BndBox3d.hxx Select3D_BVHIndexBuffer.hxx -Select3D_BVHPrimitiveContent.cxx -Select3D_BVHPrimitiveContent.hxx Select3D_EntitySequence.hxx Select3D_InteriorSensitivePointSet.cxx Select3D_InteriorSensitivePointSet.hxx diff --git a/src/Select3D/Select3D_BVHPrimitiveContent.cxx b/src/Select3D/Select3D_BVHPrimitiveContent.cxx deleted file mode 100644 index 08cad7aefc..0000000000 --- a/src/Select3D/Select3D_BVHPrimitiveContent.cxx +++ /dev/null @@ -1,80 +0,0 @@ -// Created on: 2014-05-30 -// Created by: Varvara POSKONINA -// Copyright (c) 2005-2014 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. - -#include - -#include -#include - -//======================================================================= -// function : Select3D_BVHPrimitiveContent -// purpose : Initializes new linear BVH builder for the set of sensitives -// theSensitiveSet given -//======================================================================= -Select3D_BVHPrimitiveContent::Select3D_BVHPrimitiveContent (const Handle(Select3D_SensitiveSet)& theSensitiveSet) -{ - mySensitiveSet = theSensitiveSet; - myBuilder = new BVH_LinearBuilder (myLeafNodeSize, 32); - - MarkDirty(); -} - -//======================================================================= -// function : Size -// purpose : Returns the length of set of sensitives -//======================================================================= -Standard_Integer Select3D_BVHPrimitiveContent::Size() const -{ - return mySensitiveSet->Size(); -} - -//======================================================================= -// function : Box -// purpose : Returns bounding box of sensitive with index theIdx -//======================================================================= -Select3D_BndBox3d Select3D_BVHPrimitiveContent::Box (const Standard_Integer theIdx) const -{ - return mySensitiveSet->Box (theIdx); -} - -//======================================================================= -// function : Center -// purpose : Returns center of sensitive with index theIdx in the set -// along the given axis theAxis -//======================================================================= -Standard_Real Select3D_BVHPrimitiveContent::Center (const Standard_Integer theIdx, - const Standard_Integer theAxis) const -{ - return mySensitiveSet->Center (theIdx, theAxis); -} - -//======================================================================= -// function : Swap -// purpose : Swaps items with indexes theIdx1 and theIdx2 in the set -//======================================================================= -void Select3D_BVHPrimitiveContent::Swap (const Standard_Integer theIdx1, - const Standard_Integer theIdx2) -{ - mySensitiveSet->Swap (theIdx1, theIdx2); -} - -//======================================================================= -// function : GetBVH -// purpose : Returns the tree built for set of sensitives -//======================================================================= -const NCollection_Handle >& Select3D_BVHPrimitiveContent::GetBVH() -{ - return BVH(); -} diff --git a/src/Select3D/Select3D_BVHPrimitiveContent.hxx b/src/Select3D/Select3D_BVHPrimitiveContent.hxx deleted file mode 100644 index 14b3a5e342..0000000000 --- a/src/Select3D/Select3D_BVHPrimitiveContent.hxx +++ /dev/null @@ -1,66 +0,0 @@ -// Created on: 2014-05-30 -// Created by: Varvara POSKONINA -// Copyright (c) 2005-2014 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 _Select3D_BVHPrimitiveContent_Header -#define _Select3D_BVHPrimitiveContent_Header - -#include - -class Select3D_SensitiveSet; - -//! The purpose of this class is to provide a link between BVH_PrimitiveSet -//! and Select3D_SensitiveSet instance to build BVH tree for set of sensitives -class Select3D_BVHPrimitiveContent : public BVH_PrimitiveSet -{ -public: - - //! Initializes new linear BVH builder for the set of sensitives - //! theSensitiveSet given - Select3D_BVHPrimitiveContent (const Handle(Select3D_SensitiveSet)& theSensitiveSet); - - ~Select3D_BVHPrimitiveContent() {}; - - //! Returns the length of set of sensitives - Standard_EXPORT virtual Standard_Integer Size() const Standard_OVERRIDE; - - //! Returns bounding box of sensitive with index theIdx - Standard_EXPORT virtual Select3D_BndBox3d Box (const Standard_Integer theIdx) const Standard_OVERRIDE; - - //! Make inherited method Box() visible to avoid CLang warning - using BVH_PrimitiveSet::Box; - - //! Returns center of sensitive with index theIdx in the set along the - //! given axis theAxis - Standard_EXPORT virtual Standard_Real Center (const Standard_Integer theIdx, - const Standard_Integer theAxis) const Standard_OVERRIDE; - - //! Swaps items with indexes theIdx1 and theIdx2 in the set - Standard_EXPORT virtual void Swap (const Standard_Integer theIdx1, - const Standard_Integer theIdx2) Standard_OVERRIDE; - - //! Returns the tree built for set of sensitives - Standard_EXPORT const NCollection_Handle >& GetBVH(); - - //! Returns a number of nodes in 1 BVH leaf - Standard_Integer GetLeafNodeSize() const { return myLeafNodeSize; } - -protected: - Handle(Select3D_SensitiveSet) mySensitiveSet; //!< Set of sensitive entities - -private: - static const Standard_Integer myLeafNodeSize = 8; //!< Number of sub-elements in the leaf -}; - -#endif // _Select3D_BVHPrimitiveContent_Header diff --git a/src/Select3D/Select3D_SensitiveSet.cxx b/src/Select3D/Select3D_SensitiveSet.cxx index fabd0238ec..a6b8a8e146 100644 --- a/src/Select3D/Select3D_SensitiveSet.cxx +++ b/src/Select3D/Select3D_SensitiveSet.cxx @@ -14,8 +14,8 @@ // commercial license or contractual agreement. #include -#include +#include IMPLEMENT_STANDARD_RTTIEXT(Select3D_SensitiveSet,Select3D_SensitiveEntity) @@ -24,11 +24,13 @@ IMPLEMENT_STANDARD_RTTIEXT(Select3D_SensitiveSet,Select3D_SensitiveEntity) // purpose : Creates new empty sensitive set and its content //======================================================================= Select3D_SensitiveSet::Select3D_SensitiveSet (const Handle(SelectBasics_EntityOwner)& theOwnerId) -: Select3D_SensitiveEntity (theOwnerId) +: Select3D_SensitiveEntity (theOwnerId), + myDetectedIdx (-1) { - myDetectedIdx = -1; - myIsLeftChildQueuedFirst = Standard_False; - myContent = new Select3D_BVHPrimitiveContent (this); + NCollection_Handle< BVH_Builder > aBuilder = new BVH_LinearBuilder (myLeafNodeSize, 32); + myContent.SetSensitiveSet (this); + myContent.SetBuilder (aBuilder); + myContent.MarkDirty(); } //======================================================================= @@ -37,7 +39,7 @@ Select3D_SensitiveSet::Select3D_SensitiveSet (const Handle(SelectBasics_EntityOw //======================================================================= void Select3D_SensitiveSet::BVH() { - myContent->GetBVH(); + myContent.GetBVH(); } //======================================================================= @@ -49,12 +51,12 @@ void Select3D_SensitiveSet::BVH() Standard_Boolean Select3D_SensitiveSet::Matches (SelectBasics_SelectingVolumeManager& theMgr, SelectBasics_PickResult& thePickResult) { - const BVH_Tree* aBVH = myContent->GetBVH().get(); + const BVH_Tree* aBVH = myContent.GetBVH().get(); thePickResult = SelectBasics_PickResult (RealLast(), RealLast()); - if (myContent->Size() < 1 || !theMgr.Overlaps (aBVH->MinPoint (0), - aBVH->MaxPoint (0))) + if (myContent.Size() < 1 || !theMgr.Overlaps (aBVH->MinPoint (0), + aBVH->MaxPoint (0))) { return Standard_False; } @@ -180,30 +182,11 @@ gp_Pnt Select3D_SensitiveSet::CenterOfGeometry() const return gp_Pnt (RealLast(), RealLast(), RealLast()); } -//======================================================================= -// function : MarkDirty -// purpose : Marks BVH tree of the set as outdated. It will be rebuild -// at the next call of BVH() -//======================================================================= -void Select3D_SensitiveSet::MarkDirty() -{ - myContent->MarkDirty(); -} - //======================================================================= // function : Clear // purpose : Destroys cross-reference to avoid memory leak //======================================================================= void Select3D_SensitiveSet::Clear() { - myContent.Nullify(); -} - -//======================================================================= -// function : GetLeafNodeSize -// purpose : Returns a number of nodes in 1 BVH leaf -//======================================================================= -Standard_Integer Select3D_SensitiveSet::GetLeafNodeSize() const -{ - return myContent->GetLeafNodeSize(); + // } diff --git a/src/Select3D/Select3D_SensitiveSet.hxx b/src/Select3D/Select3D_SensitiveSet.hxx index bf69aa67d9..56c5cc8247 100644 --- a/src/Select3D/Select3D_SensitiveSet.hxx +++ b/src/Select3D/Select3D_SensitiveSet.hxx @@ -16,17 +16,12 @@ #ifndef _Select3D_SensitiveSet_Header #define _Select3D_SensitiveSet_Header +#include #include #include -#include - -#include - #include -#include #include - -class Select3D_BVHPrimitiveContent; +#include //! This class is base class for handling overlap detection of complex sensitive //! entities. It provides an interface for building BVH tree for some set of entities. @@ -38,12 +33,14 @@ class Select3D_BVHPrimitiveContent; //! For example of usage see Select3D_SensitiveTriangulation. class Select3D_SensitiveSet : public Select3D_SensitiveEntity { + static const Standard_Integer myLeafNodeSize = 8; //!< Number of sub-elements in the leaf + DEFINE_STANDARD_RTTIEXT(Select3D_SensitiveSet, Select3D_SensitiveEntity) public: //! Creates new empty sensitive set and its content Standard_EXPORT Select3D_SensitiveSet (const Handle(SelectBasics_EntityOwner)& theOwnerId); - ~Select3D_SensitiveSet() {}; + ~Select3D_SensitiveSet() {} public: @@ -70,11 +67,11 @@ public: //! Must be called manually to build BVH tree for any sensitive set //! in case if its content was initialized not in a constructor, //! but element by element - Standard_EXPORT void BVH() Standard_OVERRIDE; + Standard_EXPORT virtual void BVH() Standard_OVERRIDE; //! Marks BVH tree of the set as outdated. It will be rebuild //! at the next call of BVH() - Standard_EXPORT void MarkDirty(); + void MarkDirty() { myContent.MarkDirty(); } //! Returns bounding box of the whole set. //! This method should be redefined in Select3D_SensitiveSet descendants @@ -88,10 +85,7 @@ public: Standard_EXPORT virtual void Clear() Standard_OVERRIDE; //! Returns a number of nodes in 1 BVH leaf - Standard_EXPORT Standard_Integer GetLeafNodeSize() const; - -public: - DEFINE_STANDARD_RTTIEXT(Select3D_SensitiveSet,Select3D_SensitiveEntity) + Standard_Integer GetLeafNodeSize() const { return myLeafNodeSize; } protected: @@ -109,12 +103,55 @@ protected: virtual Standard_Real distanceToCOG (SelectBasics_SelectingVolumeManager& theMgr) = 0; protected: - Standard_Integer myDetectedIdx; //!< Index of detected primitive in BVH sorted primitive array -private: + //! The purpose of this class is to provide a link between BVH_PrimitiveSet + //! and Select3D_SensitiveSet instance to build BVH tree for set of sensitives. + class BvhPrimitiveSet : public BVH_PrimitiveSet + { + public: + + //! Empty constructor. + BvhPrimitiveSet() {} + + //! Destructor. + ~BvhPrimitiveSet() {} + + //! Setup sensitivity set. + void SetSensitiveSet (Select3D_SensitiveSet* theSensitiveSet) + { + mySensitiveSet = theSensitiveSet; + MarkDirty(); + } + + //! Returns the length of set of sensitives + virtual Standard_Integer Size() const Standard_OVERRIDE { return mySensitiveSet->Size(); } + + //! Returns bounding box of sensitive with index theIdx + virtual Select3D_BndBox3d Box (const Standard_Integer theIdx) const Standard_OVERRIDE { return mySensitiveSet->Box (theIdx); } + + //! Make inherited method Box() visible to avoid CLang warning + using BVH_PrimitiveSet::Box; + + //! Returns center of sensitive with index theIdx in the set along the given axis theAxis + virtual Standard_Real Center (const Standard_Integer theIdx, + const Standard_Integer theAxis) const Standard_OVERRIDE { return mySensitiveSet->Center (theIdx, theAxis); } + + //! Swaps items with indexes theIdx1 and theIdx2 in the set + virtual void Swap (const Standard_Integer theIdx1, + const Standard_Integer theIdx2) Standard_OVERRIDE { mySensitiveSet->Swap (theIdx1, theIdx2); } + + //! Returns the tree built for set of sensitives + const NCollection_Handle >& GetBVH() { return BVH(); } + + protected: + Select3D_SensitiveSet* mySensitiveSet; //!< Set of sensitive entities + }; + +protected: + + BvhPrimitiveSet myContent; //!< A link between sensitive entity and BVH_PrimitiveSet + Standard_Integer myDetectedIdx; //!< Index of detected primitive in BVH sorted primitive array - Standard_Boolean myIsLeftChildQueuedFirst; //!< Flag for slight randomization of BVH traverse - NCollection_Handle myContent; //!< A link between sensitive entity and BVH_PrimitiveSet }; DEFINE_STANDARD_HANDLE(Select3D_SensitiveSet, Select3D_SensitiveEntity)