]> OCCT Git - occt-copy.git/commitdiff
Update BVH to support extended metadata.
authordbp <dbp@opencascade.com>
Fri, 22 Apr 2016 11:26:21 +0000 (14:26 +0300)
committerdbp <dbp@opencascade.com>
Fri, 22 Apr 2016 11:26:21 +0000 (14:26 +0300)
src/BVH/BVH_Builder.hxx
src/BVH/BVH_Builder.lxx
src/BVH/BVH_QueueBuilder.lxx

index d42ff32b54efaaf73be4c6196d484499b66ceaf1..9dbeedd0ed12189f150015d4a1ca85832ee964b6 100644 (file)
@@ -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<T, N>*      theBVH,
                       const BVH_Box<T, N>& 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
 
 };
 
index ebb173a5505ebdb9000e0105ed8b5e37c70dadab..c7b39a94c4868bb949450a6a0605e85dc9e4b93f 100644 (file)
@@ -21,7 +21,8 @@ template<class T, int N>
 BVH_Builder<T, N>::BVH_Builder (const Standard_Integer theLeafNodeSize,
                                 const Standard_Integer theMaxTreeDepth)
 : myMaxTreeDepth (theMaxTreeDepth),
-  myLeafNodeSize (theLeafNodeSize)
+  myLeafNodeSize (theLeafNodeSize),
+  myMetadataType (BVH_NODE_LEVEL)
 {
   //
 }
index 20ecff23dd8460a3ec283a649424c54fa2f09bf0..49a35e9d41114d3cf600e1e50999b8cbbcace2ec 100644 (file)
@@ -88,6 +88,13 @@ void BVH_QueueBuilder<T, N>::AddChildren (BVH_Tree<T, N>*
       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;
+  }
 }
 
 // =======================================================================