//! The quality cost of `wai-splat-render:i1` (extensions/splat-exact.md §12): each scene of the
//! corpus at its canonical poses and at the pose of the sink's own views, rendered by the
//! integer renderer and by the float renderer of the same model in `f64` and in `f32`.
//!
//!   wai_splat_exact_measure [scale]
//!
//! `scale` (default 1) multiplies each frame's side and focal length. For each view it prints
//! the PSNR of the integer frame against the `f64` frame, the PSNR of the `f32` frame against
//! the `f64` frame, how many bytes the `f32` and `f64` frames differ in, and the largest
//! difference of a byte between the integer and the `f64` frames.

use wai::splat_exact::{corpus, float, gaussians, render};

fn main() {
    let scale: u64 = std::env::args().nth(1).map_or(1, |s| s.parse().expect("a scale"));
    println!("scene\tview\tsize\tpsnr_int_f64_db\tpsnr_f32_f64_db\tbytes_f32_ne_f64\tmax_abs_int_f64");
    for (name, planes, poses) in corpus::scenes() {
        let gs = gaussians(&planes).expect("renderable");
        let a64 = float::attributes::<f64>(&planes).expect("fourteen planes");
        let a32 = float::attributes::<f32>(&planes).expect("fourteen planes");
        let n = poses.len();
        for (i, p) in poses.into_iter().enumerate() {
            let mut p = p;
            p.width *= scale;
            p.height *= scale;
            p.focal *= scale;
            let fi = render(&gs, &p).expect("a frame");
            let f64r = float::render(&a64, &p);
            let f32r = float::render(&a32, &p);
            let ne = f32r.iter().zip(&f64r).filter(|(a, b)| a != b).count();
            let max = fi.iter().zip(&f64r).map(|(&a, &b)| (a as i32 - b as i32).abs()).max().unwrap_or(0);
            let view = if i + 1 == n { "own".to_string() } else { i.to_string() };
            println!(
                "{name}\t{view}\t{}x{}\t{:.2}\t{:.2}\t{ne}/{}\t{max}",
                p.width,
                p.height,
                float::psnr(&fi, &f64r),
                float::psnr(&f32r, &f64r),
                f64r.len()
            );
        }
    }
}
