0028849: [Regression to 7.1.0] Exception in Boolean operation
[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
60 //! Marks geometry as outdated.
e28f12b3 61 virtual void MarkDirty() { myIsDirty = Standard_True; }
3c4e78f2 62
7c58a2ab 63 //! Returns AABB of the given object.
64 using BVH_ObjectSet<T, N>::Box;
65
679d3878 66 //! Returns AABB of the whole geometry.
e28f12b3 67 virtual BVH_Box<T, N> Box() const Standard_OVERRIDE
68 {
69 if (myIsDirty)
70 {
71 myBox = BVH_Set<T, N>::Box();
72 }
73 return myBox;
74 }
3c4e78f2 75
679d3878 76 //! Returns BVH tree (and builds it if necessary).
f5b72419 77 virtual const opencascade::handle<BVH_Tree<T, N> >& BVH()
e28f12b3 78 {
79 if (myIsDirty)
80 {
81 Update();
82 }
83 return myBVH;
84 }
3c4e78f2 85
679d3878 86 //! Returns the method (builder) used to construct BVH.
f5b72419 87 virtual const opencascade::handle<BVH_Builder<T, N> >& Builder() const { return myBuilder; }
3c4e78f2 88
679d3878 89 //! Sets the method (builder) used to construct BVH.
f5b72419 90 virtual void SetBuilder (const opencascade::handle<BVH_Builder<T, N> >& theBuilder) { myBuilder = theBuilder; }
3c4e78f2 91
92protected:
93
94 //! Updates internal geometry state.
e28f12b3 95 virtual void Update()
96 {
97 if (myIsDirty)
98 {
99 myBuilder->Build (this, myBVH.operator->(), Box());
100 myIsDirty = Standard_False;
101 }
102 }
3c4e78f2 103
104protected:
105
f5b72419 106 Standard_Boolean myIsDirty; //!< Is geometry state outdated?
107 opencascade::handle<BVH_Tree<T, N> > myBVH; //!< Constructed hight-level BVH
108 opencascade::handle<BVH_Builder<T, N> > myBuilder; //!< Builder for hight-level BVH
3c4e78f2 109
110 mutable BVH_Box<T, N> myBox; //!< Cached bounding box of geometric objects
111
112};
113
3c4e78f2 114#endif // _BVH_Geometry_Header