From fecd7b6a0010a32bea00eb81df92b1d8926f8068 Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Sat, 22 Sep 2018 12:09:05 -0700 Subject: [PATCH] Remove dead code. --- rtiow/src/bvh.rs | 81 +++--------------------------------------------- 1 file changed, 4 insertions(+), 77 deletions(-) diff --git a/rtiow/src/bvh.rs b/rtiow/src/bvh.rs index 38cf032..13f6931 100644 --- a/rtiow/src/bvh.rs +++ b/rtiow/src/bvh.rs @@ -98,80 +98,7 @@ fn vec_split_into(v: Vec, offset: usize) -> (Vec, Vec) { } impl BVHNode { - fn new_sah(l: Vec>, t_min: f32, t_max: f32) -> BVHNode { - eprintln!("l.len() {}", l.len()); - let mut l: Vec> = 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; - let right: Box; - 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>, t_min: f32, t_max: f32) -> BVHNode { + fn new(l: Vec>, 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!(