0030655: Modeling Data - Provide interfaces for selection of the elements from BVH...
[occt.git] / src / BVH / BVH_PrimitiveSet.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_PrimitiveSet_Header
17#define _BVH_PrimitiveSet_Header
18
19#include <BVH_Object.hxx>
20#include <BVH_Builder.hxx>
e28f12b3 21#include <BVH_BinnedBuilder.hxx>
3c4e78f2 22
679d3878 23//! Set of abstract geometric primitives organized with bounding
24//! volume hierarchy (BVH). Unlike an object set, this collection
25//! is designed for storing structural elements of a single object
26//! (such as triangles in the object triangulation). Because there
27//! may be a large number of such elements, the implementations of
28//! this interface should be sufficiently optimized.
29//! \tparam T Numeric data type
30//! \tparam N Vector dimension
3c4e78f2 31template<class T, int N>
32class BVH_PrimitiveSet : public BVH_Object<T, N>, public BVH_Set<T, N>
33{
b7cd4ba7 34protected:
35
3c4e78f2 36 using BVH_Set<T, N>::Box;
37
38public:
f5b72419 39 static const Standard_Integer MaxTreeDepth = BVH_Constants_MaxTreeDepth;
3c4e78f2 40
41 //! Creates set of abstract primitives.
e28f12b3 42 BVH_PrimitiveSet()
f5b72419 43 : myBVH (new BVH_Tree<T, N>()),
44 // set default builder - binned SAH split
45 myBuilder (new BVH_BinnedBuilder<T, N, BVH_Constants_NbBinsBest> (BVH_Constants_LeafNodeSizeDefault, BVH_Constants_MaxTreeDepth))
e28f12b3 46 {
f5b72419 47 //
48 }
49
50 //! Creates set of abstract primitives.
51 BVH_PrimitiveSet (const opencascade::handle<BVH_Builder<T, N> >& theBuilder)
52 : myBVH (new BVH_Tree<T, N>()),
53 myBuilder (theBuilder)
54 {
55 //
e28f12b3 56 }
3c4e78f2 57
58 //! Releases resources of set of abstract primitives.
e28f12b3 59 virtual ~BVH_PrimitiveSet()
60 {
61 myBVH.Nullify();
62 myBuilder.Nullify();
63 }
3c4e78f2 64
65public:
66
67 //! Returns AABB of primitive set.
e28f12b3 68 virtual BVH_Box<T, N> Box() const Standard_OVERRIDE
69 {
70 if (BVH_Object<T, N>::myIsDirty)
71 {
72 myBox = BVH_Set<T, N>::Box();
73 }
74 return myBox;
75 }
3c4e78f2 76
679d3878 77 //! Returns BVH tree (and builds it if necessary).
f5b72419 78 virtual const opencascade::handle<BVH_Tree<T, N> >& BVH()
e28f12b3 79 {
80 if (BVH_Object<T, N>::myIsDirty)
81 {
82 Update();
83 }
84 return myBVH;
85 }
3c4e78f2 86
679d3878 87 //! Returns the method (builder) used to construct BVH.
f5b72419 88 virtual const opencascade::handle<BVH_Builder<T, N> >& Builder() const { return myBuilder; }
3c4e78f2 89
679d3878 90 //! Sets the method (builder) used to construct BVH.
f5b72419 91 virtual void SetBuilder (const opencascade::handle<BVH_Builder<T, N> >& theBuilder) { myBuilder = theBuilder; }
3c4e78f2 92
93protected:
94
95 //! Updates BVH of primitive set.
e28f12b3 96 virtual void Update()
97 {
98 if (BVH_Object<T, N>::myIsDirty)
99 {
100 myBuilder->Build (this, myBVH.operator->(), Box());
101 BVH_Object<T, N>::myIsDirty = Standard_False;
102 }
103 }
3c4e78f2 104
105protected:
106
f5b72419 107 opencascade::handle<BVH_Tree<T, N> > myBVH; //!< Constructed bottom-level BVH
108 opencascade::handle<BVH_Builder<T, N> > myBuilder; //!< Builder for bottom-level BVH
3c4e78f2 109
110 mutable BVH_Box<T, N> myBox; //!< Cached bounding box of geometric primitives
111
112};
113
3c4e78f2 114#endif // _BVH_PrimitiveSet_Header