rvlib/
drawme.rs

1use crate::{tools_data::InstanceLabelDisplay, types::ViewImage, world::DataRaw, GeoFig};
2use rvimage_domain::{BbF, Canvas, Circle, TPtF};
3use std::default::Default;
4
5#[derive(Clone, Debug)]
6pub struct Stroke {
7    pub thickness: TPtF,
8    pub color: [u8; 3],
9}
10
11impl Stroke {
12    pub fn from_color(color: [u8; 3]) -> Self {
13        Stroke {
14            thickness: 2.0,
15            color,
16        }
17    }
18}
19
20#[derive(Clone, Debug)]
21pub struct BboxAnnotation {
22    pub geofig: GeoFig,
23    pub fill_color: Option<[u8; 3]>,
24    pub fill_alpha: u8,
25    pub outline: Stroke,
26    pub outline_alpha: u8,
27    pub label: Option<String>,
28    pub is_selected: Option<bool>,
29    pub highlight_circles: Vec<Circle>,
30    pub instance_label_display: InstanceLabelDisplay,
31}
32
33#[derive(Clone, Debug)]
34pub struct BrushAnnotation {
35    pub canvas: Canvas,
36    pub color: [u8; 3],
37    pub label: Option<String>,
38    pub is_selected: Option<bool>,
39    pub fill_alpha: u8,
40    pub instance_display_label: InstanceLabelDisplay,
41}
42
43#[derive(Clone, Debug)]
44pub enum Annotation {
45    Bbox(BboxAnnotation),
46    Brush(BrushAnnotation),
47}
48
49#[derive(Clone, Debug, Default)]
50pub enum Update<T> {
51    Yes(T),
52    #[default]
53    No,
54}
55
56pub type UpdateImage = Update<ViewImage>;
57// permament annotations
58pub type UpdatePermAnnos = Update<Vec<Annotation>>;
59// temporary annotation
60pub type UpdateTmpAnno = Update<Annotation>;
61pub type UpdateZoomBox = Update<Option<BbF>>;
62
63impl UpdatePermAnnos {
64    pub fn clear() -> Self {
65        Self::Yes(vec![])
66    }
67}
68
69#[derive(Clone, Debug, Default)]
70pub struct ImageInfo {
71    pub filename: String,
72    pub shape_info: String,
73    pub pixel_value: String,
74    pub tool_info: String,
75}
76
77#[derive(Clone, Debug, Default)]
78pub struct UpdateView {
79    pub image: UpdateImage,
80    pub perm_annos: UpdatePermAnnos,
81    pub tmp_annos: UpdateTmpAnno,
82    pub zoom_box: UpdateZoomBox,
83    pub image_info: Option<ImageInfo>,
84
85    // to enable memory re-use.
86    pub tmp_anno_buffer: Option<Annotation>,
87}
88
89impl UpdateView {
90    pub fn new(image: &DataRaw, zoom_box: Option<BbF>) -> Self {
91        let im_uncropped_view = image.bg_to_uncropped_view();
92        UpdateView {
93            image: UpdateImage::Yes(im_uncropped_view),
94            perm_annos: UpdatePermAnnos::No,
95            tmp_annos: UpdateTmpAnno::No,
96            zoom_box: UpdateZoomBox::Yes(zoom_box),
97            image_info: None,
98            tmp_anno_buffer: None,
99        }
100    }
101    pub fn from_zoombox(zoom_box: Option<BbF>) -> Self {
102        UpdateView {
103            image: UpdateImage::No,
104            perm_annos: UpdatePermAnnos::No,
105            tmp_annos: UpdateTmpAnno::No,
106            zoom_box: UpdateZoomBox::Yes(zoom_box),
107            image_info: None,
108            tmp_anno_buffer: None,
109        }
110    }
111}