Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-21 09:16:42

0001 // Created on: 2013-12-20
0002 // Created by: Denis BOGOLEPOV
0003 // Copyright (c) 2013-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef BVH_Builder_HeaderFile
0017 #define BVH_Builder_HeaderFile
0018 
0019 #include <BVH_Set.hxx>
0020 #include <BVH_BinaryTree.hxx>
0021 
0022 //! A non-template class for using as base for BVH_Builder
0023 //! (just to have a named base class).
0024 class BVH_BuilderTransient : public Standard_Transient
0025 {
0026   DEFINE_STANDARD_RTTIEXT(BVH_BuilderTransient, Standard_Transient)
0027 public:
0028   //! Returns the maximum depth of constructed BVH.
0029   int MaxTreeDepth() const { return myMaxTreeDepth; }
0030 
0031   //! Returns the maximum number of sub-elements in the leaf.
0032   int LeafNodeSize() const { return myLeafNodeSize; }
0033 
0034   //! Returns parallel flag.
0035   inline bool IsParallel() const { return myIsParallel; }
0036 
0037   //! Set parallel flag controlling possibility of parallel execution.
0038   inline void SetParallel(const bool isParallel) { myIsParallel = isParallel; }
0039 
0040 protected:
0041   //! Creates new abstract BVH builder.
0042   BVH_BuilderTransient(const int theLeafNodeSize, const int theMaxTreeDepth)
0043       : myMaxTreeDepth(theMaxTreeDepth),
0044         myLeafNodeSize(theLeafNodeSize),
0045         myIsParallel(false)
0046   {
0047   }
0048 
0049 protected:
0050   int  myMaxTreeDepth; //!< Maximum depth of constructed BVH
0051   int  myLeafNodeSize; //!< Maximum number of objects per leaf
0052   bool myIsParallel;   //!< Parallel execution flag.
0053 };
0054 
0055 //! Performs construction of BVH tree using bounding
0056 //! boxes (AABBs) of abstract objects.
0057 //! \tparam T Numeric data type
0058 //! \tparam N Vector dimension
0059 template <class T, int N>
0060 class BVH_Builder : public BVH_BuilderTransient
0061 {
0062 public:
0063   //! Builds BVH using specific algorithm.
0064   virtual void Build(BVH_Set<T, N>*       theSet,
0065                      BVH_Tree<T, N>*      theBVH,
0066                      const BVH_Box<T, N>& theBox) const = 0;
0067 
0068 protected:
0069   //! Creates new abstract BVH builder.
0070   BVH_Builder(const int theLeafNodeSize, const int theMaxTreeDepth)
0071       : BVH_BuilderTransient(theLeafNodeSize, theMaxTreeDepth)
0072   {
0073   }
0074 
0075   //! Updates depth of constructed BVH tree.
0076   void updateDepth(BVH_Tree<T, N>* theBVH, const int theLevel) const
0077   {
0078     if (theLevel > theBVH->myDepth)
0079     {
0080       theBVH->myDepth = theLevel;
0081     }
0082   }
0083 };
0084 
0085 #endif // _BVH_Builder_Header