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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use crate::{
    domain::{BbF, Circle, TPtF},
    types::ViewImage,
    BrushLine, GeoFig,
};
use std::default::Default;

#[derive(Clone, Debug)]
pub struct Stroke {
    pub thickness: TPtF,
    pub color: [u8; 3],
}

impl Stroke {
    pub fn from_color(color: [u8; 3]) -> Self {
        Stroke {
            thickness: 2.0,
            color,
        }
    }
}

#[derive(Clone, Debug)]
pub struct BboxAnnotation {
    pub geofig: GeoFig,
    pub fill_color: Option<[u8; 3]>,
    pub fill_alpha: u8,
    pub outline: Stroke,
    pub outline_alpha: u8,
    pub label: Option<String>,
    pub is_selected: Option<bool>,
    pub highlight_circles: Vec<Circle>,
}

#[derive(Clone, Debug)]
pub struct BrushAnnotation {
    pub brush_line: BrushLine,
    pub color: [u8; 3],
    pub label: Option<String>,
    pub is_selected: Option<bool>,
}

#[derive(Clone, Debug)]
pub enum Annotation {
    Bbox(BboxAnnotation),
    Brush(BrushAnnotation),
}

#[derive(Clone, Debug, Default)]
pub enum Update<T> {
    Yes(T),
    #[default]
    No,
}

pub type UpdateImage = Update<ViewImage>;
// permament annotations in the Vec, one temporary annotation in the Option
pub type UpdateAnnos = Update<(Vec<Annotation>, Option<Annotation>)>;
pub type UpdateZoomBox = Update<Option<BbF>>;

impl UpdateAnnos {
    pub fn clear() -> Self {
        Self::Yes((vec![], None))
    }
}

#[derive(Clone, Debug, Default)]
pub struct ImageInfo {
    pub filename: String,
    pub shape_info: String,
    pub pixel_value: String,
    pub tool_info: String,
}

#[derive(Clone, Debug, Default)]
pub struct UpdateView {
    pub image: UpdateImage,
    pub annos: UpdateAnnos,
    pub zoom_box: UpdateZoomBox,
    pub image_info: Option<ImageInfo>,
}

impl UpdateView {
    pub fn from_zoombox(zoom_box: Option<BbF>) -> Self {
        UpdateView {
            image: UpdateImage::No,
            annos: UpdateAnnos::No,
            zoom_box: UpdateZoomBox::Yes(zoom_box),
            image_info: None,
        }
    }
}