1 // Created on: 2013-12-20
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2013-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _BVH_Geometry_Header
17 #define _BVH_Geometry_Header
19 #include <BVH_ObjectSet.hxx>
20 #include <BVH_Builder.hxx>
21 #include <BVH_BinnedBuilder.hxx>
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
27 template<class T, int N>
28 class BVH_Geometry : public BVH_ObjectSet<T, N>
32 //! Creates uninitialized BVH geometry.
34 : myIsDirty (Standard_False),
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))
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)
51 //! Releases resources of BVH geometry.
52 virtual ~BVH_Geometry()
60 //! Returns TRUE if geometry state should be updated.
61 virtual Standard_Boolean IsDirty() const { return myIsDirty; }
63 //! Marks geometry as outdated.
64 virtual void MarkDirty() { myIsDirty = Standard_True; }
66 //! Returns AABB of the given object.
67 using BVH_ObjectSet<T, N>::Box;
69 //! Returns AABB of the whole geometry.
70 virtual BVH_Box<T, N> Box() const Standard_OVERRIDE
74 myBox = BVH_Set<T, N>::Box();
79 //! Returns BVH tree (and builds it if necessary).
80 virtual const opencascade::handle<BVH_Tree<T, N> >& BVH()
89 //! Returns the method (builder) used to construct BVH.
90 virtual const opencascade::handle<BVH_Builder<T, N> >& Builder() const { return myBuilder; }
92 //! Sets the method (builder) used to construct BVH.
93 virtual void SetBuilder (const opencascade::handle<BVH_Builder<T, N> >& theBuilder) { myBuilder = theBuilder; }
97 //! Updates internal geometry state.
102 myBuilder->Build (this, myBVH.operator->(), Box());
103 myIsDirty = Standard_False;
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
113 mutable BVH_Box<T, N> myBox; //!< Cached bounding box of geometric objects
117 #endif // _BVH_Geometry_Header