3c4e78f2 |
1 | // Created on: 2013-12-20 |
2 | // Created by: Denis BOGOLEPOV |
d5f74e42 |
3 | // Copyright (c) 2013-2014 OPEN CASCADE SAS |
3c4e78f2 |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
d5f74e42 |
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 |
3c4e78f2 |
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_BinnedBuilder_Header |
17 | #define _BVH_BinnedBuilder_Header |
18 | |
0ef61b50 |
19 | #include <BVH_QueueBuilder.hxx> |
3c4e78f2 |
20 | |
a096a7a5 |
21 | #include <algorithm> |
22 | |
65578e1c |
23 | //! Stores parameters of single bin (slice of AABB). |
3c4e78f2 |
24 | template<class T, int N> |
25 | struct BVH_Bin |
26 | { |
27 | //! Creates new node bin. |
28 | BVH_Bin() : Count (0) {} |
29 | |
30 | Standard_Integer Count; //!< Number of primitives in the bin |
228de226 |
31 | BVH_Box<T, N> Box; //!< AABB of primitives in the bin |
3c4e78f2 |
32 | }; |
33 | |
65578e1c |
34 | //! Performs construction of BVH tree using binned SAH algorithm. Number |
35 | //! of bins controls BVH quality in cost of construction time (greater - |
36 | //! better). For optimal results, use 32 - 48 bins. However, reasonable |
37 | //! performance is provided even for 4 - 8 bins (it is only 10-20% lower |
38 | //! in comparison with optimal settings). Note that multiple threads can |
39 | //! be used only with thread safe BVH primitive sets. |
3c4e78f2 |
40 | template<class T, int N, int Bins = 32> |
0ef61b50 |
41 | class BVH_BinnedBuilder : public BVH_QueueBuilder<T, N> |
3c4e78f2 |
42 | { |
43 | public: |
44 | |
45 | //! Type for the array of bins of BVH tree node. |
46 | typedef BVH_Bin<T, N> BVH_BinVector[Bins]; |
47 | |
48 | public: |
49 | |
50 | //! Creates binned SAH BVH builder. |
51 | BVH_BinnedBuilder (const Standard_Integer theLeafNodeSize = 5, |
f751596e |
52 | const Standard_Integer theMaxTreeDepth = 32, |
65578e1c |
53 | const Standard_Boolean theDoMainSplits = 0, |
54 | const Standard_Integer theNumOfThreads = 1); |
3c4e78f2 |
55 | |
56 | //! Releases resources of binned SAH BVH builder. |
57 | virtual ~BVH_BinnedBuilder(); |
58 | |
59 | protected: |
60 | |
65578e1c |
61 | //! Performs splitting of the given BVH node. |
62 | typename BVH_QueueBuilder<T, N>::BVH_ChildNodes BuildNode (BVH_Set<T, N>* theSet, |
63 | BVH_Tree<T, N>* theBVH, |
64 | const Standard_Integer theNode); |
3c4e78f2 |
65 | |
66 | //! Arranges node primitives into bins. |
67 | virtual void GetSubVolumes (BVH_Set<T, N>* theSet, |
68 | BVH_Tree<T, N>* theBVH, |
69 | const Standard_Integer theNode, |
70 | BVH_BinVector& theBins, |
71 | const Standard_Integer theAxis); |
72 | |
f751596e |
73 | private: |
74 | |
75 | Standard_Boolean myUseMainAxis; //!< Defines whether to search for the best split or use the widest axis |
76 | |
3c4e78f2 |
77 | }; |
78 | |
79 | #include <BVH_BinnedBuilder.lxx> |
80 | |
81 | #endif // _BVH_BinnedBuilder_Header |