rvlib/
drawme.rs

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
93
94
95
use crate::{types::ViewImage, BrushLine, GeoFig};
use rvimage_domain::{BbF, Canvas, Circle, TPtF};
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 canvas: Canvas,
    pub tmp_line: Option<BrushLine>,
    pub color: [u8; 3],
    pub label: Option<String>,
    pub is_selected: Option<bool>,
    pub fill_alpha: u8,
}

#[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
pub type UpdatePermAnnos = Update<Vec<Annotation>>;
// temporary annotation
pub type UpdateTmpAnno = Update<Annotation>;
pub type UpdateZoomBox = Update<Option<BbF>>;

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

#[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 perm_annos: UpdatePermAnnos,
    pub tmp_annos: UpdateTmpAnno,
    pub zoom_box: UpdateZoomBox,
    pub image_info: Option<ImageInfo>,
}

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