From e367fede3185da2e409c2c4900b537cd6d2e895e Mon Sep 17 00:00:00 2001 From: dbp Date: Fri, 22 Apr 2016 14:26:21 +0300 Subject: [PATCH] Update BVH to support extended metadata. --- src/BVH/BVH_Builder.hxx | 21 +++++++++++++++++++++ src/BVH/BVH_Builder.lxx | 3 ++- src/BVH/BVH_QueueBuilder.lxx | 7 +++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/BVH/BVH_Builder.hxx b/src/BVH/BVH_Builder.hxx index d42ff32b54..9dbeedd0ed 100644 --- a/src/BVH/BVH_Builder.hxx +++ b/src/BVH/BVH_Builder.hxx @@ -25,6 +25,14 @@ namespace BVH const Standard_Real THE_NODE_MIN_SIZE = 1e-5; } +//! Type of metadata written in W component of +//! BVH data vector corresponding to the node. +enum BVH_NodeMetadata +{ + BVH_NODE_LEVEL = 0, //!< level (depth) of the node + BVH_NODE_PRIMS = 1 //!< number of node primitives +}; + //! Performs construction of BVH tree using bounding //! boxes (AABBs) of abstract objects. //! \tparam T Numeric data type @@ -46,6 +54,18 @@ public: BVH_Tree* theBVH, const BVH_Box& theBox) = 0; + //! Returns type of metadata written in BVH node. + BVH_NodeMetadata MetadataType() const + { + return myMetadataType; + } + + //! Sets type of metadata written in BVH node. + void SetMetadataType (const BVH_NodeMetadata theMetadata) + { + myMetadataType = theMetadata; + } + protected: //! Updates depth of constructed BVH tree. @@ -62,6 +82,7 @@ protected: Standard_Integer myMaxTreeDepth; //!< Maximum depth of constructed BVH Standard_Integer myLeafNodeSize; //!< Maximum number of objects per leaf + BVH_NodeMetadata myMetadataType; //!< Type of metadata written in BVH node }; diff --git a/src/BVH/BVH_Builder.lxx b/src/BVH/BVH_Builder.lxx index ebb173a550..c7b39a94c4 100644 --- a/src/BVH/BVH_Builder.lxx +++ b/src/BVH/BVH_Builder.lxx @@ -21,7 +21,8 @@ template BVH_Builder::BVH_Builder (const Standard_Integer theLeafNodeSize, const Standard_Integer theMaxTreeDepth) : myMaxTreeDepth (theMaxTreeDepth), - myLeafNodeSize (theLeafNodeSize) + myLeafNodeSize (theLeafNodeSize), + myMetadataType (BVH_NODE_LEVEL) { // } diff --git a/src/BVH/BVH_QueueBuilder.lxx b/src/BVH/BVH_QueueBuilder.lxx index 20ecff23dd..49a35e9d41 100644 --- a/src/BVH/BVH_QueueBuilder.lxx +++ b/src/BVH/BVH_QueueBuilder.lxx @@ -88,6 +88,13 @@ void BVH_QueueBuilder::AddChildren (BVH_Tree* myBuildQueue.Enqueue (aChildIndex); } } + + // Correct node's metadata if necessary + if (myMetadataType != BVH_NODE_LEVEL) + { + theBVH->NodeInfoBuffer()[theNode].w() = + theSubNodes.Ranges[1].Final - theSubNodes.Ranges[0].Start + 1; + } } // ======================================================================= -- 2.39.5