0029702: Foundation Classes - Introduce possibility to control parallel execution...
[occt.git] / src / BVH / BVH_Builder.hxx
CommitLineData
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_Builder_Header
17#define _BVH_Builder_Header
18
19#include <BVH_Set.hxx>
f2474958 20#include <BVH_BinaryTree.hxx>
3c4e78f2 21
f5b72419 22//! A non-template class for using as base for BVH_Builder
23//! (just to have a named base class).
24class BVH_BuilderTransient : public Standard_Transient
3c4e78f2 25{
f5b72419 26 DEFINE_STANDARD_RTTIEXT(BVH_BuilderTransient, Standard_Transient)
27public:
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
3c7a61ea 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
f5b72419 47protected:
48
49 //! Creates new abstract BVH builder.
50 BVH_BuilderTransient (const Standard_Integer theLeafNodeSize,
51 const Standard_Integer theMaxTreeDepth)
52 : myMaxTreeDepth (theMaxTreeDepth),
3c7a61ea 53 myLeafNodeSize (theLeafNodeSize),
54 myIsParallel (Standard_False) {}
f5b72419 55
56protected:
57
58 Standard_Integer myMaxTreeDepth; //!< Maximum depth of constructed BVH
59 Standard_Integer myLeafNodeSize; //!< Maximum number of objects per leaf
3c7a61ea 60 Standard_Boolean myIsParallel; //!< Parallel execution flag.
f5b72419 61};
3c4e78f2 62
679d3878 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
3c4e78f2 67template<class T, int N>
f5b72419 68class BVH_Builder : public BVH_BuilderTransient
3c4e78f2 69{
70public:
71
679d3878 72 //! Builds BVH using specific algorithm.
0ef61b50 73 virtual void Build (BVH_Set<T, N>* theSet,
74 BVH_Tree<T, N>* theBVH,
e28f12b3 75 const BVH_Box<T, N>& theBox) const = 0;
3c4e78f2 76
679d3878 77protected:
78
f5b72419 79 //! Creates new abstract BVH builder.
80 BVH_Builder (const Standard_Integer theLeafNodeSize,
81 const Standard_Integer theMaxTreeDepth)
82 : BVH_BuilderTransient (theLeafNodeSize, theMaxTreeDepth) {}
83
fc73a202 84 //! Updates depth of constructed BVH tree.
e28f12b3 85 void updateDepth (BVH_Tree<T, N>* theBVH,
86 const Standard_Integer theLevel) const
fc73a202 87 {
88 if (theLevel > theBVH->myDepth)
89 {
90 theBVH->myDepth = theLevel;
91 }
92 }
93
3c4e78f2 94};
95
3c4e78f2 96#endif // _BVH_Builder_Header