Remove dead code.
This commit is contained in:
parent
08ea5ca089
commit
fecd7b6a00
@ -98,80 +98,7 @@ fn vec_split_into<T>(v: Vec<T>, offset: usize) -> (Vec<T>, Vec<T>) {
|
||||
}
|
||||
|
||||
impl BVHNode {
|
||||
fn new_sah(l: Vec<Box<Hit>>, t_min: f32, t_max: f32) -> BVHNode {
|
||||
eprintln!("l.len() {}", l.len());
|
||||
let mut l: Vec<Box<Hit>> = l.into_iter().collect();
|
||||
let n = l.len();
|
||||
let main_box =
|
||||
l[1..]
|
||||
.iter()
|
||||
.fold(l[0].bounding_box(t_min, t_max).unwrap(), |acc, h| {
|
||||
match h.bounding_box(t_min, t_max) {
|
||||
Some(new_box) => surrounding_box(&new_box, &acc),
|
||||
None => panic!("hit without bounding box"),
|
||||
}
|
||||
});
|
||||
|
||||
let axis = main_box.longest_axis();
|
||||
match axis {
|
||||
0 => l.sort_by(box_x_compare),
|
||||
1 => l.sort_by(box_y_compare),
|
||||
2 => l.sort_by(box_z_compare),
|
||||
val @ _ => panic!("unknown axis {}", val),
|
||||
};
|
||||
let boxes: Vec<_> = l
|
||||
.iter()
|
||||
.map(|hit| hit.bounding_box(t_min, t_max).unwrap())
|
||||
.collect();
|
||||
|
||||
let mut left_area = Vec::with_capacity(n);
|
||||
let mut left_box = boxes[0].clone();
|
||||
for i in 1..n - 1 {
|
||||
left_box = surrounding_box(&left_box, &boxes[i]);
|
||||
left_area[i] = left_box.volume();
|
||||
}
|
||||
|
||||
let mut right_area = Vec::with_capacity(n);
|
||||
right_area[n - 1] = boxes[n - 1].volume();
|
||||
let mut right_box = boxes[n - 1].clone();
|
||||
for i in (0..n - 2).rev() {
|
||||
right_box = surrounding_box(&right_box, &boxes[i]);
|
||||
right_area[i] = right_box.volume();
|
||||
}
|
||||
|
||||
let mut min_sah = std::f32::MAX;
|
||||
let mut min_sah_idx = 0;
|
||||
for i in 0..n - 1 {
|
||||
let sah = i as f32 * left_area[i] + (n - i - 1) as f32 * right_area[i + 1];
|
||||
if sah < min_sah {
|
||||
min_sah_idx = i;
|
||||
min_sah = sah;
|
||||
}
|
||||
}
|
||||
|
||||
let left: Box<BVHNode>;
|
||||
let right: Box<BVHNode>;
|
||||
if min_sah_idx == 0 {
|
||||
let (l, r) = vec_split_into(l, 1);
|
||||
left = Box::new(BVHNode::Leaf(vec_first_into(l)));
|
||||
right = Box::new(BVHNode::new_sah(r, t_min, t_max));
|
||||
} else if min_sah_idx == n - 2 {
|
||||
let (l, r) = vec_split_into(l, min_sah_idx + 1);
|
||||
left = Box::new(BVHNode::new_sah(l, t_min, t_max));
|
||||
right = Box::new(BVHNode::Leaf(vec_first_into(r)));
|
||||
} else {
|
||||
let (l, r) = vec_split_into(l, min_sah_idx + 1);
|
||||
left = Box::new(BVHNode::new_sah(l, t_min, t_max));
|
||||
right = Box::new(BVHNode::new_sah(r, t_min, t_max));
|
||||
}
|
||||
|
||||
BVHNode::Branch {
|
||||
left,
|
||||
right,
|
||||
bbox: Some(main_box),
|
||||
}
|
||||
}
|
||||
fn new_dumb(l: Vec<Box<Hit>>, t_min: f32, t_max: f32) -> BVHNode {
|
||||
fn new(l: Vec<Box<Hit>>, t_min: f32, t_max: f32) -> BVHNode {
|
||||
if l.len() == 1 {
|
||||
return BVHNode::Leaf(vec_first_into(l));
|
||||
} else {
|
||||
@ -186,8 +113,8 @@ impl BVHNode {
|
||||
|
||||
let half = l.len() / 2;
|
||||
let (left_half, right_half) = vec_split_into(l, half);
|
||||
let left = Box::new(BVHNode::new_dumb(left_half, t_min, t_max));
|
||||
let right = Box::new(BVHNode::new_dumb(right_half, t_min, t_max));
|
||||
let left = Box::new(BVHNode::new(left_half, t_min, t_max));
|
||||
let right = Box::new(BVHNode::new(right_half, t_min, t_max));
|
||||
let bbox = BVHNode::surrounding_box(left.as_ref(), right.as_ref(), t_min, t_max);
|
||||
return BVHNode::Branch { left, right, bbox };
|
||||
}
|
||||
@ -261,7 +188,7 @@ impl BVH {
|
||||
let count = l.len();
|
||||
let start = Instant::now();
|
||||
let bvh = BVH {
|
||||
root: BVHNode::new_dumb(l, t_min, t_max),
|
||||
root: BVHNode::new(l, t_min, t_max),
|
||||
};
|
||||
let runtime = start.elapsed();
|
||||
info!(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user