1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

0028789: Visualization, TKV3d - extend API for accessing and assigning BVH builders

Several methods in Selection classes have been moved to header files for better inlining.

BVH_Constants - added new enumeration defining common constant values used with BVH trees.
BVH - replaced NCollection_Handle with Standard_Transient handle
in classes BVH_Properties, BVH_Builder, BVH_Tree, BVH_Object.

Defined global BVH-builders instead of allocating a new one for each object set.
SelectMgr_ViewerSelector - added new method ::SetEntitySetBuilder() defining
default BVH Tree builder for SelectMgr_SensitiveEntitySet.

Added new method SelectMgr_SensitiveEntitySet::SetBuilder()
for overriding default BVH tree builder.
This commit is contained in:
kgv
2017-05-26 10:45:22 +03:00
committed by bugmaster
parent 645f581fbe
commit f5b7241978
54 changed files with 561 additions and 357 deletions

View File

@@ -1,4 +1,5 @@
Select3D_BndBox3d.hxx
Select3D_BVHBuilder3d.hxx
Select3D_BVHIndexBuffer.hxx
Select3D_EntitySequence.hxx
Select3D_InteriorSensitivePointSet.cxx

View File

@@ -0,0 +1,22 @@
// 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 _Select3D_BVHBuilder3d_Header
#define _Select3D_BVHBuilder3d_Header
#include <BVH_Builder.hxx>
#include <Standard_Real.hxx>
typedef BVH_Builder<Standard_Real, 3> Select3D_BVHBuilder3d;
#endif // _Select3D_BVHBuilder3d_Header

View File

@@ -19,6 +19,30 @@
IMPLEMENT_STANDARD_RTTIEXT(Select3D_SensitiveSet,Select3D_SensitiveEntity)
namespace
{
//! Default BVH tree builder for sensitive set (optimal for large set of small primitives - for not too long construction time).
static Handle(Select3D_BVHBuilder3d) THE_SENS_SET_BUILDER = new BVH_LinearBuilder<Standard_Real, 3> (BVH_Constants_LeafNodeSizeSmall, BVH_Constants_MaxTreeDepth);
}
//=======================================================================
// function : DefaultBVHBuilder
// purpose :
//=======================================================================
const Handle(Select3D_BVHBuilder3d)& Select3D_SensitiveSet::DefaultBVHBuilder()
{
return THE_SENS_SET_BUILDER;
}
//=======================================================================
// function : SetDefaultBVHBuilder
// purpose :
//=======================================================================
void Select3D_SensitiveSet::SetDefaultBVHBuilder (const Handle(Select3D_BVHBuilder3d)& theBuilder)
{
THE_SENS_SET_BUILDER = theBuilder;
}
//=======================================================================
// function : Select3D_SensitiveSet
// purpose : Creates new empty sensitive set and its content
@@ -27,9 +51,8 @@ Select3D_SensitiveSet::Select3D_SensitiveSet (const Handle(SelectBasics_EntityOw
: Select3D_SensitiveEntity (theOwnerId),
myDetectedIdx (-1)
{
NCollection_Handle< BVH_Builder<Standard_Real, 3> > aBuilder = new BVH_LinearBuilder<Standard_Real, 3> (myLeafNodeSize, 32);
myContent.SetSensitiveSet (this);
myContent.SetBuilder (aBuilder);
myContent.SetBuilder (THE_SENS_SET_BUILDER);
myContent.MarkDirty();
}
@@ -61,7 +84,7 @@ Standard_Boolean Select3D_SensitiveSet::Matches (SelectBasics_SelectingVolumeMan
return Standard_False;
}
Standard_Integer aStack[32];
Standard_Integer aStack[BVH_Constants_MaxTreeDepth];
Standard_Integer aNode = 0;
Standard_Integer aHead = -1;

View File

@@ -16,8 +16,9 @@
#ifndef _Select3D_SensitiveSet_Header
#define _Select3D_SensitiveSet_Header
#include <BVH_PrimitiveSet.hxx>
#include <BVH_PrimitiveSet3d.hxx>
#include <Select3D_BndBox3d.hxx>
#include <Select3D_BVHBuilder3d.hxx>
#include <Select3D_SensitiveEntity.hxx>
#include <SelectBasics_EntityOwner.hxx>
@@ -31,15 +32,20 @@
//! 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:
//! Return global instance to default BVH builder.
Standard_EXPORT static const Handle(Select3D_BVHBuilder3d)& DefaultBVHBuilder();
//! Assign new BVH builder to be used by default for new sensitive sets (assigning is NOT thread-safe!).
Standard_EXPORT static void SetDefaultBVHBuilder (const Handle(Select3D_BVHBuilder3d)& theBuilder);
public:
//! Creates new empty sensitive set and its content
Standard_EXPORT Select3D_SensitiveSet (const Handle(SelectBasics_EntityOwner)& theOwnerId);
~Select3D_SensitiveSet() {}
public:
//! Returns the amount of sub-entities of the complex entity
@@ -67,6 +73,9 @@ public:
//! but element by element
Standard_EXPORT virtual void BVH() Standard_OVERRIDE;
//! Sets the method (builder) used to construct BVH.
void SetBuilder (const Handle(Select3D_BVHBuilder3d)& theBuilder) { myContent.SetBuilder (theBuilder); }
//! Marks BVH tree of the set as outdated. It will be rebuild
//! at the next call of BVH()
void MarkDirty() { myContent.MarkDirty(); }
@@ -83,7 +92,7 @@ public:
Standard_EXPORT virtual void Clear() Standard_OVERRIDE;
//! Returns a number of nodes in 1 BVH leaf
Standard_Integer GetLeafNodeSize() const { return myLeafNodeSize; }
Standard_Integer GetLeafNodeSize() const { return myContent.Builder()->LeafNodeSize(); }
protected:
@@ -104,12 +113,12 @@ protected:
//! 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<Standard_Real, 3>
class BvhPrimitiveSet : public BVH_PrimitiveSet3d
{
public:
//! Empty constructor.
BvhPrimitiveSet() {}
BvhPrimitiveSet() : BVH_PrimitiveSet3d (Handle(Select3D_BVHBuilder3d)()) {}
//! Destructor.
~BvhPrimitiveSet() {}
@@ -128,7 +137,7 @@ protected:
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<Standard_Real, 3>::Box;
using BVH_PrimitiveSet3d::Box;
//! Returns center of sensitive with index theIdx in the set along the given axis theAxis
virtual Standard_Real Center (const Standard_Integer theIdx,
@@ -139,7 +148,7 @@ protected:
const Standard_Integer theIdx2) Standard_OVERRIDE { mySensitiveSet->Swap (theIdx1, theIdx2); }
//! Returns the tree built for set of sensitives
const NCollection_Handle<BVH_Tree<Standard_Real, 3> >& GetBVH() { return BVH(); }
const opencascade::handle<BVH_Tree<Standard_Real, 3> >& GetBVH() { return BVH(); }
protected:
Select3D_SensitiveSet* mySensitiveSet; //!< Set of sensitive entities