supervisely_format/
objects.rs

1use crate::tags::Tag;
2use noisy_float::types::R64;
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
6pub struct Object {
7    pub id: Option<usize>,
8    #[serde(rename = "classId")]
9    pub class_id: Option<usize>,
10    #[serde(rename = "labelerLogin")]
11    pub labeler_login: Option<String>,
12    #[serde(rename = "createdAt")]
13    pub created_at: Option<String>,
14    #[serde(rename = "updatedAt")]
15    pub updated_at: Option<String>,
16    #[serde(flatten)]
17    pub geometry: ObjectGeometry,
18}
19
20#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
21#[serde(tag = "geometryType")]
22pub enum ObjectGeometry {
23    #[serde(rename = "point")]
24    Point(PointGeometry),
25    #[serde(rename = "rectangle")]
26    Rectangle(RectangleGeometry),
27    #[serde(rename = "polygon")]
28    Polygon(PolygonGeometry),
29    #[serde(rename = "polyline")]
30    Polyline(PolylineGeometry),
31    #[serde(rename = "bitmap")]
32    Bitmap(BitmapGeometry),
33}
34
35#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
36pub struct PointGeometry {
37    pub tags: Option<Vec<Tag>>,
38    #[serde(rename = "classTitle")]
39    pub class_title: String,
40    pub points: Points,
41}
42
43#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
44pub struct RectangleGeometry {
45    pub tags: Option<Vec<Tag>>,
46    #[serde(rename = "classTitle")]
47    pub class_title: String,
48    pub points: Points,
49}
50
51#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
52pub struct PolygonGeometry {
53    pub tags: Option<Vec<Tag>>,
54    #[serde(rename = "classTitle")]
55    pub class_title: String,
56    pub points: Points,
57}
58
59#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
60pub struct PolylineGeometry {
61    pub tags: Option<Vec<Tag>>,
62    #[serde(rename = "classTitle")]
63    pub class_title: String,
64    pub points: Points,
65}
66
67#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
68pub struct BitmapGeometry {
69    pub tags: Option<Vec<Tag>>,
70    #[serde(rename = "classTitle")]
71    pub class_title: String,
72    pub bitmap: Bitmap,
73}
74
75#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
76pub struct Points {
77    pub exterior: Vec<(R64, R64)>,
78    pub interior: Vec<(R64, R64)>,
79}
80
81#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
82pub struct Bitmap {
83    #[serde(with = "serde_bytes")]
84    pub data: Vec<u8>,
85    pub origin: (R64, R64),
86}