Optimize iterative search
This commit is contained in:
parent
e3dd4861d2
commit
f6b11e56b8
1 changed files with 5 additions and 16 deletions
|
@ -96,7 +96,7 @@ impl<'a> AccelerationData<'a> {
|
||||||
if self.recursive {
|
if self.recursive {
|
||||||
self.traverse_tree_recursively(f, 0);
|
self.traverse_tree_recursively(f, 0);
|
||||||
} else {
|
} else {
|
||||||
self.traverse_tree_iteratively(f);
|
self.traverse_tree_iteratively(f, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,42 +117,31 @@ impl<'a> AccelerationData<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn traverse_tree_iteratively<F>(&self, f: &mut F)
|
fn traverse_tree_iteratively<F>(&self, f: &mut F, index: usize)
|
||||||
where
|
where
|
||||||
F: FnMut(usize, &AABB) -> bool,
|
F: FnMut(usize, &AABB) -> bool,
|
||||||
{
|
{
|
||||||
let mut discovered = vec![false; 1024];
|
|
||||||
let mut stack = Vec::new();
|
let mut stack = Vec::new();
|
||||||
|
|
||||||
// push root node
|
// push root node
|
||||||
stack.push(0);
|
stack.push(index);
|
||||||
|
|
||||||
while !stack.is_empty() {
|
while !stack.is_empty() {
|
||||||
let v = stack.pop().unwrap();
|
let v = stack.pop().unwrap();
|
||||||
|
|
||||||
if discovered[v] {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
discovered[v] = true;
|
|
||||||
|
|
||||||
if (*f)(v, &self.data[v]) {
|
if (*f)(v, &self.data[v]) {
|
||||||
let left_child = self.data[v].left_child;
|
let left_child = self.data[v].left_child;
|
||||||
if left_child != -1 {
|
if left_child != -1 {
|
||||||
if !discovered[left_child as usize] {
|
|
||||||
stack.push(left_child as usize);
|
stack.push(left_child as usize);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let right_child = self.data[v].right_child;
|
let right_child = self.data[v].right_child;
|
||||||
if right_child != -1 {
|
if right_child != -1 {
|
||||||
if !discovered[right_child as usize] {
|
|
||||||
stack.push(right_child as usize);
|
stack.push(right_child as usize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn create_leaf_nodes(input_data: &[Triangle], triangles_per_as: u32) -> Vec<AABB> {
|
fn create_leaf_nodes(input_data: &[Triangle], triangles_per_as: u32) -> Vec<AABB> {
|
||||||
let mut acceleration_data = Vec::new();
|
let mut acceleration_data = Vec::new();
|
||||||
|
|
Loading…
Reference in a new issue