a45d5996a2ec5c4143ac405b778451d8b113b62e
[occt.git] / src / BVH / BVH_Builder.hxx
1 // Created on: 2013-12-20
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2013-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _BVH_Builder_Header
17 #define _BVH_Builder_Header
18
19 #include <BVH_Set.hxx>
20 #include <BVH_BinaryTree.hxx>
21
22 //! A non-template class for using as base for BVH_Builder
23 //! (just to have a named base class).
24 class BVH_BuilderTransient : public Standard_Transient
25 {
26   DEFINE_STANDARD_RTTIEXT(BVH_BuilderTransient, Standard_Transient)
27 public:
28
29   //! Returns the maximum depth of constructed BVH.
30   Standard_Integer MaxTreeDepth() const { return myMaxTreeDepth; }
31
32   //! Returns the maximum number of sub-elements in the leaf.
33   Standard_Integer LeafNodeSize() const { return myLeafNodeSize; }
34
35 protected:
36
37   //! Creates new abstract BVH builder.
38   BVH_BuilderTransient (const Standard_Integer theLeafNodeSize,
39                         const Standard_Integer theMaxTreeDepth)
40   : myMaxTreeDepth (theMaxTreeDepth),
41     myLeafNodeSize (theLeafNodeSize) {}
42
43 protected:
44
45   Standard_Integer myMaxTreeDepth; //!< Maximum depth of constructed BVH
46   Standard_Integer myLeafNodeSize; //!< Maximum number of objects per leaf
47
48 };
49
50 //! Performs construction of BVH tree using bounding
51 //! boxes (AABBs) of abstract objects.
52 //! \tparam T Numeric data type
53 //! \tparam N Vector dimension
54 template<class T, int N>
55 class BVH_Builder : public BVH_BuilderTransient
56 {
57 public:
58
59   //! Builds BVH using specific algorithm.
60   virtual void Build (BVH_Set<T, N>*       theSet,
61                       BVH_Tree<T, N>*      theBVH,
62                       const BVH_Box<T, N>& theBox) const = 0;
63
64 protected:
65
66   //! Creates new abstract BVH builder.
67   BVH_Builder (const Standard_Integer theLeafNodeSize,
68                const Standard_Integer theMaxTreeDepth)
69   : BVH_BuilderTransient (theLeafNodeSize, theMaxTreeDepth) {}
70
71   //! Updates depth of constructed BVH tree.
72   void updateDepth (BVH_Tree<T, N>*        theBVH,
73                     const Standard_Integer theLevel) const
74   {
75     if (theLevel > theBVH->myDepth)
76     {
77       theBVH->myDepth = theLevel;
78     }
79   }
80
81 };
82
83 #endif // _BVH_Builder_Header