0028824: Possibility to build OCCT 7.1.0 and above using Visual Studio 2008
[occt.git] / src / BVH / BVH_Geometry.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_Geometry_Header
17#define _BVH_Geometry_Header
18
19#include <BVH_ObjectSet.hxx>
20#include <BVH_Builder.hxx>
e28f12b3 21#include <BVH_BinnedBuilder.hxx>
3c4e78f2 22
679d3878 23//! BVH geometry as a set of abstract geometric objects
24//! organized with bounding volume hierarchy (BVH).
25//! \tparam T Numeric data type
26//! \tparam N Vector dimension
3c4e78f2 27template<class T, int N>
28class BVH_Geometry : public BVH_ObjectSet<T, N>
29{
30public:
31
32 //! Creates uninitialized BVH geometry.
e28f12b3 33 BVH_Geometry()
34 : myIsDirty (Standard_False),
f5b72419 35 myBVH (new BVH_Tree<T, N>()),
36 // set default builder - binned SAH split
37 myBuilder (new BVH_BinnedBuilder<T, N, BVH_Constants_NbBinsOptimal> (BVH_Constants_LeafNodeSizeSingle))
e28f12b3 38 {
f5b72419 39 //
40 }
41
42 //! Creates uninitialized BVH geometry.
43 BVH_Geometry (const opencascade::handle<BVH_Builder<T, N> >& theBuilder)
44 : myIsDirty (Standard_False),
45 myBVH (new BVH_Tree<T, N>()),
46 myBuilder (theBuilder)
47 {
48 //
e28f12b3 49 }
3c4e78f2 50
51 //! Releases resources of BVH geometry.
e28f12b3 52 virtual ~BVH_Geometry()
53 {
54 myBVH.Nullify();
55 myBuilder.Nullify();
56 }
3c4e78f2 57
58public:
59
a228288f 60 //! Returns TRUE if geometry state should be updated.
61 virtual Standard_Boolean IsDirty() const { return myIsDirty; }
62
3c4e78f2 63 //! Marks geometry as outdated.
e28f12b3 64 virtual void MarkDirty() { myIsDirty = Standard_True; }
3c4e78f2 65
7c58a2ab 66 //! Returns AABB of the given object.
67 using BVH_ObjectSet<T, N>::Box;
68
679d3878 69 //! Returns AABB of the whole geometry.
e28f12b3 70 virtual BVH_Box<T, N> Box() const Standard_OVERRIDE
71 {
72 if (myIsDirty)
73 {
74 myBox = BVH_Set<T, N>::Box();
75 }
76 return myBox;
77 }
3c4e78f2 78
679d3878 79 //! Returns BVH tree (and builds it if necessary).
f5b72419 80 virtual const opencascade::handle<BVH_Tree<T, N> >& BVH()
e28f12b3 81 {
82 if (myIsDirty)
83 {
84 Update();
85 }
86 return myBVH;
87 }
3c4e78f2 88
679d3878 89 //! Returns the method (builder) used to construct BVH.
f5b72419 90 virtual const opencascade::handle<BVH_Builder<T, N> >& Builder() const { return myBuilder; }
3c4e78f2 91
679d3878 92 //! Sets the method (builder) used to construct BVH.
f5b72419 93 virtual void SetBuilder (const opencascade::handle<BVH_Builder<T, N> >& theBuilder) { myBuilder = theBuilder; }
3c4e78f2 94
95protected:
96
97 //! Updates internal geometry state.
e28f12b3 98 virtual void Update()
99 {
100 if (myIsDirty)
101 {
102 myBuilder->Build (this, myBVH.operator->(), Box());
103 myIsDirty = Standard_False;
104 }
105 }
3c4e78f2 106
107protected:
108
f5b72419 109 Standard_Boolean myIsDirty; //!< Is geometry state outdated?
110 opencascade::handle<BVH_Tree<T, N> > myBVH; //!< Constructed hight-level BVH
111 opencascade::handle<BVH_Builder<T, N> > myBuilder; //!< Builder for hight-level BVH
3c4e78f2 112
113 mutable BVH_Box<T, N> myBox; //!< Cached bounding box of geometric objects
114
115};
116
3c4e78f2 117#endif // _BVH_Geometry_Header