0030655: Modeling Data - Provide interfaces for selection of the elements from BVH...
[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   //! Returns parallel flag.
36   inline Standard_Boolean IsParallel() const
37   {
38     return myIsParallel;
39   }
40
41   //! Set parallel flag contolling possibility of parallel execution.
42   inline void SetParallel(const Standard_Boolean isParallel)
43   {
44     myIsParallel = isParallel;
45   }
46
47 protected:
48
49   //! Creates new abstract BVH builder.
50   BVH_BuilderTransient (const Standard_Integer theLeafNodeSize,
51                         const Standard_Integer theMaxTreeDepth)
52   : myMaxTreeDepth (theMaxTreeDepth),
53     myLeafNodeSize (theLeafNodeSize),
54     myIsParallel   (Standard_False) {}
55
56 protected:
57
58   Standard_Integer myMaxTreeDepth; //!< Maximum depth of constructed BVH
59   Standard_Integer myLeafNodeSize; //!< Maximum number of objects per leaf
60   Standard_Boolean myIsParallel;   //!< Parallel execution flag.
61 };
62
63 //! Performs construction of BVH tree using bounding
64 //! boxes (AABBs) of abstract objects.
65 //! \tparam T Numeric data type
66 //! \tparam N Vector dimension
67 template<class T, int N>
68 class BVH_Builder : public BVH_BuilderTransient
69 {
70 public:
71
72   //! Builds BVH using specific algorithm.
73   virtual void Build (BVH_Set<T, N>*       theSet,
74                       BVH_Tree<T, N>*      theBVH,
75                       const BVH_Box<T, N>& theBox) const = 0;
76
77 protected:
78
79   //! Creates new abstract BVH builder.
80   BVH_Builder (const Standard_Integer theLeafNodeSize,
81                const Standard_Integer theMaxTreeDepth)
82   : BVH_BuilderTransient (theLeafNodeSize, theMaxTreeDepth) {}
83
84   //! Updates depth of constructed BVH tree.
85   void updateDepth (BVH_Tree<T, N>*        theBVH,
86                     const Standard_Integer theLevel) const
87   {
88     if (theLevel > theBVH->myDepth)
89     {
90       theBVH->myDepth = theLevel;
91     }
92   }
93
94 };
95
96 #endif // _BVH_Builder_Header