aboutsummaryrefslogtreecommitdiff
path: root/src/camera/film.rs
blob: 6661529d0b4d441346d02edd8922ad0a7fd682f7 (plain)
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
67
use crate::vector::*;
use crate::Float;
use crate::bound;
use crate::spectrum::Spectrum;

use bound::{Bound2i, Bound2f};
use super::filter::Filter;
use std::rc::Rc;

#[derive(Clone)]
pub struct Pixel {
    pub rgb: [Float; 3],
}

pub struct Film {
    pub resolution: Vector2i,
    drawingBound: Bound2i,

    pixels: Vec<Pixel>,
    filter: Rc<Filter>,
}

pub struct FilmTile {
    pub bounds: Bound2i,
    filter: Rc<Filter>,
}

impl Pixel {
    fn new() -> Pixel {
        Pixel { rgb: [0.0, 0.0, 0.0] }
    }
}

impl Film {
    pub fn new(resolution: Vector2i, filter: Rc<Filter>) -> Film {
        let area = resolution.x * resolution.y;
        Film {
            resolution,
            drawingBound: Bound2i::new(&Vector2::new(0), &resolution),
            pixels: vec![Pixel::new(); area as usize],
            filter,
        }
    }

    pub fn get_tile(&self, bound: &Bound2i) -> FilmTile {
        // Used to calculate descrete coordinates into continues
        let halfpixel = Vector2f::new_xy(0.5, 0.5);
        let fbound = Bound2f::from(bound);

        let p0 = Vector2i::from((fbound.min - halfpixel - self.filter.radius).ceil());
        let p1 = Vector2i::from((fbound.min - halfpixel + self.filter.radius).floor());

        let tilebound = bound::intersect(&Bound2i::new(&p0, &p1), &self.drawingBound);

        FilmTile { 
            bounds: tilebound,
            filter: self.filter.clone(),
        }

    }
}

impl FilmTile {
    fn add_sample(point: &Vector2f, c: Spectrum) {
        
    }
}