f2474958 |
1 | // Created on: 2016-06-20 |
2 | // Created by: Denis BOGOLEPOV |
3 | // Copyright (c) 2016 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_BinaryTree_Header |
17 | #define _BVH_BinaryTree_Header |
18 | |
19 | #include <BVH_QuadTree.hxx> |
20 | |
21 | //! Specialization of binary BVH tree. |
22 | template<class T, int N> |
23 | class BVH_Tree<T, N, BVH_BinaryTree> : public BVH_TreeBase<T, N> |
24 | { |
25 | public: //! @name custom data types |
26 | |
27 | typedef typename BVH_TreeBase<T, N>::BVH_VecNt BVH_VecNt; |
28 | |
29 | public: //! @name methods for accessing individual nodes |
30 | |
31 | //! Creates new empty BVH tree. |
32 | BVH_Tree() : BVH_TreeBase<T, N>() { } |
33 | |
34 | //! Sets node type to 'outer'. |
35 | void SetOuter (const int theNodeIndex); |
36 | |
37 | //! Sets node type to 'inner'. |
38 | void SetInner (const int theNodeIndex); |
39 | |
40 | //! Returns index of the K-th child of the given inner node. |
41 | //! \tparam K the index of node child (0 or 1) |
42 | template<int K> |
43 | int Child (const int theNodeIndex) const; |
44 | |
45 | //! Returns index of the K-th child of the given inner node. |
46 | //! \tparam K the index of node child (0 or 1) |
47 | template<int K> |
48 | int& Child (const int theNodeIndex); |
49 | |
50 | public: //! @name methods for adding/removing tree nodes |
51 | |
52 | //! Removes all nodes from the tree. |
53 | void Clear(); |
54 | |
55 | //! Reserves internal BVH storage, so that it |
56 | //! can contain the given number of BVH nodes. |
57 | void Reserve (const int theNbNodes); |
58 | |
59 | //! Adds new leaf node to the BVH. |
60 | int AddLeafNode (const BVH_VecNt& theMinPoint, |
61 | const BVH_VecNt& theMaxPoint, |
62 | const int theBegElem, |
63 | const int theEndElem); |
64 | |
65 | //! Adds new inner node to the BVH. |
66 | int AddInnerNode (const BVH_VecNt& theMinPoint, |
67 | const BVH_VecNt& theMaxPoint, |
68 | const int theLftChild, |
69 | const int theRghChild); |
70 | |
71 | //! Adds new leaf node to the BVH. |
72 | int AddLeafNode (const BVH_Box<T, N>& theAABB, |
73 | const int theBegElem, |
74 | const int theEndElem); |
75 | |
76 | //! Adds new inner node to the BVH. |
77 | int AddInnerNode (const BVH_Box<T, N>& theAABB, |
78 | const int theLftChild, |
79 | const int theRghChild); |
80 | |
81 | //! Adds new leaf node to the BVH with UNINITIALIZED bounds. |
82 | int AddLeafNode (const int theBegElem, |
83 | const int theEndElem); |
84 | |
85 | //! Adds new inner node to the BVH with UNINITIALIZED bounds. |
86 | int AddInnerNode (const int theLftChild, |
87 | const int theRghChild); |
88 | |
89 | public: //! @name methods specific to binary BVH |
90 | |
91 | //! Returns value of SAH (surface area heuristic). |
92 | //! Allows to compare the quality of BVH trees constructed for |
93 | //! the same sets of geometric objects with different methods. |
94 | T EstimateSAH() const; |
95 | |
96 | //! Collapses the tree into QBVH an returns it. As a result, each |
97 | //! 2-nd level of current tree is kept and the rest are discarded. |
98 | BVH_Tree<T, N, BVH_QuadTree>* CollapseToQuadTree() const; |
99 | |
100 | }; |
101 | |
102 | #include <BVH_BinaryTree.lxx> |
103 | |
104 | #endif // _BVH_BinaryTree_Header |