1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use ndarray::Array2;
use ndarray_stats::QuantileExt;
use palette::LinSrgba;
use std::path::Path;
use crate::{parse::png, render::Shader};
pub struct Output {
pub colour: Array2<LinSrgba>,
pub time: Array2<f64>,
}
impl Output {
#[inline]
#[must_use]
pub fn new(res: [usize; 2]) -> Self {
let colour = Array2::from_elem(res, LinSrgba::new(0.0, 0.0, 0.0, 0.0));
let time = Array2::zeros(res);
Self {
colour,
time,
}
}
#[inline]
pub fn save(&self, shader: &Shader, output_dir: &Path, tag: &str) {
png::save(
self.colour.view(),
&output_dir
.join(&format!("colour_{}", tag))
.with_extension("png"),
);
let max_time = self.time.max().expect("Failed to resolve time data.");
png::save(
self.time
.map(|t| shader.data_grad.get((t / max_time) as f32))
.view(),
&output_dir
.join(&format!("time_{}", tag))
.with_extension("png"),
);
}
}