Skip to main content

nd2_rs/types/
experiment.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4#[repr(u32)]
5pub enum LoopType {
6    Unknown = 0,
7    TimeLoop = 1,
8    XYPosLoop = 2,
9    XYDiscrLoop = 3,
10    ZStackLoop = 4,
11    PolarLoop = 5,
12    SpectLoop = 6,
13    CustomLoop = 7,
14    NETimeLoop = 8,
15    ManTimeLoop = 9,
16    ZStackLoopAccurate = 10,
17}
18
19#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
20#[serde(tag = "type")]
21pub enum ExpLoop {
22    TimeLoop(TimeLoop),
23    NETimeLoop(NETimeLoop),
24    XYPosLoop(XYPosLoop),
25    ZStackLoop(ZStackLoop),
26    CustomLoop(CustomLoop),
27}
28
29#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
30pub struct TimeLoop {
31    pub count: u32,
32    pub nesting_level: u32,
33    pub parameters: TimeLoopParams,
34}
35
36#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
37pub struct TimeLoopParams {
38    pub start_ms: f64,
39    pub period_ms: f64,
40    pub duration_ms: f64,
41    pub period_diff: Option<PeriodDiff>,
42}
43
44#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
45pub struct PeriodDiff {
46    pub avg: f64,
47    pub max: f64,
48    pub min: f64,
49}
50
51#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
52pub struct ZStackLoop {
53    pub count: u32,
54    pub nesting_level: u32,
55    pub parameters: ZStackLoopParams,
56}
57
58#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
59pub struct ZStackLoopParams {
60    pub home_index: i32,
61    pub step_um: f64,
62    pub bottom_to_top: bool,
63    pub device_name: Option<String>,
64}
65
66#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
67pub struct XYPosLoop {
68    pub count: u32,
69    pub nesting_level: u32,
70    pub parameters: XYPosLoopParams,
71}
72
73#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
74pub struct XYPosLoopParams {
75    pub is_setting_z: bool,
76    pub points: Vec<Position>,
77}
78
79#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
80pub struct Position {
81    pub stage_position_um: StagePosition,
82    pub pfs_offset: Option<f64>,
83    pub name: Option<String>,
84}
85
86#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
87pub struct StagePosition {
88    pub x: f64,
89    pub y: f64,
90    pub z: f64,
91}
92
93#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
94pub struct NETimeLoop {
95    pub count: u32,
96    pub nesting_level: u32,
97    pub parameters: NETimeLoopParams,
98}
99
100#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
101pub struct NETimeLoopParams {
102    pub periods: Vec<Period>,
103}
104
105#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
106pub struct Period {
107    pub count: u32,
108    pub start_ms: f64,
109    pub period_ms: f64,
110    pub duration_ms: f64,
111    pub period_diff: Option<PeriodDiff>,
112}
113
114#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
115pub struct CustomLoop {
116    pub count: u32,
117    pub nesting_level: u32,
118}
119
120impl ExpLoop {
121    pub fn count(&self) -> u32 {
122        match self {
123            ExpLoop::TimeLoop(t) => t.count,
124            ExpLoop::ZStackLoop(z) => z.count,
125            ExpLoop::XYPosLoop(xy) => xy.count,
126            ExpLoop::NETimeLoop(n) => n.count,
127            ExpLoop::CustomLoop(c) => c.count,
128        }
129    }
130}