use shared::Float;
use shared::Ptr;
use shared::core::bssrdf::BSSRDFTable;

pub struct BSSRDFTableData {
    pub rho_samples: Vec<Float>,
    pub radius_samples: Vec<Float>,
    pub profile: Vec<Float>,
    pub rho_eff: Vec<Float>,
    pub profile_cdf: Vec<Float>,
}

impl BSSRDFTableData {
    pub fn new(n_rho_samples: usize, n_radius_samples: usize) -> Self {
        let rho_samples: Vec<Float> = Vec::with_capacity(n_rho_samples);
        let radius_samples: Vec<Float> = Vec::with_capacity(n_radius_samples);
        let profile: Vec<Float> = Vec::with_capacity(n_radius_samples * n_rho_samples);
        let rho_eff: Vec<Float> = Vec::with_capacity(n_rho_samples);
        let profile_cdf: Vec<Float> = Vec::with_capacity(n_radius_samples * n_rho_samples);
        Self {
            rho_samples,
            radius_samples,
            profile,
            rho_eff,
            profile_cdf,
        }
    }

    pub fn view(&self, rho_ptr: *const Float, radius_ptr: *const Float) -> BSSRDFTable {
        BSSRDFTable {
            rho_samples: rho_ptr.into(),
            n_rho: self.rho_samples.len() as u32,
            radius_samples: radius_ptr.into(),
            n_radius: self.radius_samples.len() as u32,
            profile: Ptr::from(self.profile.as_ptr()),
            profile_cdf: Ptr::from(self.profile_cdf.as_ptr()),
            rho_eff: Ptr::from(self.rho_eff.as_ptr()),
        }
    }
}
