From 927a86c1fc865398b7273878d3fe1fb09176fb2a Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Tue, 20 Jun 2017 23:28:49 -0700 Subject: [PATCH] Update LightArray to work with current code. It's useful for checking correctness. --- src/accel/light_array.rs | 33 +++++++++++++++++++-------------- src/accel/mod.rs | 1 + 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/accel/light_array.rs b/src/accel/light_array.rs index f071810..f75e7e5 100644 --- a/src/accel/light_array.rs +++ b/src/accel/light_array.rs @@ -1,40 +1,45 @@ +use mem_arena::MemArena; + use bbox::BBox; use math::{Vector, Point, Normal}; use shading::surface_closure::SurfaceClosure; use super::LightAccel; -#[derive(Debug, Clone)] -pub struct LightArray { - indices: Vec, +#[derive(Debug, Copy, Clone)] +pub struct LightArray<'a> { + indices: &'a [usize], aprx_energy: f32, } -impl LightArray { +impl<'a> LightArray<'a> { #[allow(dead_code)] - pub fn new<'a, T, F>(things: &mut [T], q: F) -> LightArray + pub fn from_objects<'b, T, F>( + arena: &'a MemArena, + objects: &mut [T], + info_getter: F, + ) -> LightArray<'a> where - F: 'a + Fn(&T) -> Option<(&'a [BBox], f32)>, + F: 'b + Fn(&T) -> (&'b [BBox], f32), { let mut indices = Vec::new(); let mut aprx_energy = 0.0; - for (i, thing) in things.iter().enumerate() { - if let Some((_, power)) = q(thing) { - if power > 0.0 { - indices.push(i); - aprx_energy += power; - } + for (i, thing) in objects.iter().enumerate() { + let (_, power) = info_getter(thing); + if power > 0.0 { + indices.push(i); + aprx_energy += power; } } LightArray { - indices: indices, + indices: arena.copy_slice(&indices), aprx_energy: aprx_energy, } } } -impl LightAccel for LightArray { +impl<'a> LightAccel for LightArray<'a> { fn select( &self, inc: Vector, diff --git a/src/accel/mod.rs b/src/accel/mod.rs index 2a05378..9de5a68 100644 --- a/src/accel/mod.rs +++ b/src/accel/mod.rs @@ -11,6 +11,7 @@ use shading::surface_closure::SurfaceClosure; pub use self::bvh::{BVH, BVHNode}; pub use self::light_tree::LightTree; +pub use self::light_array::LightArray; // Track BVH traversal time thread_local! {