ROOT
master
Reference Guide
Loading...
Searching...
No Matches
stack.h
Go to the documentation of this file.
1
#ifndef BVH_V2_STACK_H
2
#define BVH_V2_STACK_H
3
4
#include <vector>
5
#include <cassert>
6
7
namespace
bvh::v2
{
8
9
/// Fixed-size stack that can be used for a BVH traversal.
10
template
<
typename
T,
unsigned
Capacity>
11
struct
SmallStack
{
12
static
constexpr
unsigned
capacity
= Capacity;
13
14
T
elems
[
capacity
];
15
unsigned
size
= 0;
16
17
bool
is_empty
()
const
{
return
size
== 0; }
18
bool
is_full
()
const
{
return
size
>=
capacity
; }
19
20
void
push
(
const
T& t) {
21
assert(!
is_full
());
22
elems
[
size
++] = t;
23
}
24
25
T
pop
() {
26
assert(!
is_empty
());
27
return
elems
[--
size
];
28
}
29
};
30
31
/// Growing stack that can be used for BVH traversal. Its performance may be lower than a small,
32
/// fixed-size stack, depending on the architecture.
33
template
<
typename
T>
34
struct
GrowingStack
{
35
std::vector<T>
elems
;
36
37
bool
is_empty
()
const
{
return
elems
.empty(); }
38
void
push
(
const
T& t) {
elems
.push_back(t); }
39
40
T
pop
() {
41
assert(!
is_empty
());
42
auto
top = std::move(
elems
.back());
43
elems
.pop_back();
44
return
top;
45
}
46
47
void
clear
() {
48
elems
.clear();
49
}
50
};
51
52
}
// namespace bvh::v2
53
54
#endif
bvh::v2
Definition
bbox.h:9
bvh::v2::GrowingStack
Growing stack that can be used for BVH traversal.
Definition
stack.h:34
bvh::v2::GrowingStack::clear
void clear()
Definition
stack.h:47
bvh::v2::GrowingStack::elems
std::vector< T > elems
Definition
stack.h:35
bvh::v2::GrowingStack::is_empty
bool is_empty() const
Definition
stack.h:37
bvh::v2::GrowingStack::pop
T pop()
Definition
stack.h:40
bvh::v2::GrowingStack::push
void push(const T &t)
Definition
stack.h:38
bvh::v2::SmallStack
Fixed-size stack that can be used for a BVH traversal.
Definition
stack.h:11
bvh::v2::SmallStack::size
unsigned size
Definition
stack.h:15
bvh::v2::SmallStack::is_full
bool is_full() const
Definition
stack.h:18
bvh::v2::SmallStack::is_empty
bool is_empty() const
Definition
stack.h:17
bvh::v2::SmallStack::capacity
static constexpr unsigned capacity
Definition
stack.h:12
bvh::v2::SmallStack::pop
T pop()
Definition
stack.h:25
bvh::v2::SmallStack::elems
T elems[capacity]
Definition
stack.h:14
bvh::v2::SmallStack::push
void push(const T &t)
Definition
stack.h:20
geom
geom
inc
bvh
v2
stack.h
ROOT master - Reference Guide Generated on Tue Nov 5 2024 09:40:13 (GVA Time) using Doxygen 1.9.8