gmt_dos_clients_crseo/
pyramid.rs1use std::{
2 ops::{DivAssign, MulAssign, SubAssign},
3 sync::Arc,
4};
5
6use crseo::{
7 wavefrontsensor::{LensletArray, Pyramid, PyramidBuilder},
8 Builder,
9};
10use interface::UniqueIdentifier;
11use serde::Serialize;
12
13pub use calibrating::{PyramidCalibrator, PyramidCommand};
14
15use crate::Processor;
16
17use crseo::Frame;
18
19#[derive(Default, Debug, Serialize)]
20pub struct PyramidData<T> {
21 sx: Vec<T>,
22 sy: Vec<T>,
23 flux: Vec<T>,
24}
25
26impl<T> IntoIterator for PyramidData<T> {
27 type Item = T;
28
29 type IntoIter = std::iter::Chain<std::vec::IntoIter<T>, std::vec::IntoIter<T>>;
30
31 fn into_iter(self) -> Self::IntoIter {
32 self.sx.into_iter().chain(self.sy.into_iter())
33 }
34}
35
36#[derive(Default, Debug)]
37pub struct PyramidProcessor<T = f32> {
38 pub frame: Arc<Frame<T>>,
39 lenslet_array: LensletArray,
40}
41
42impl From<&Pyramid> for Processor<PyramidProcessor> {
43 fn from(value: &Pyramid) -> Self {
44 Self(value.into())
45 }
46}
47
48impl TryFrom<&PyramidBuilder> for Processor<PyramidProcessor> {
49 type Error = crseo::CrseoError;
50
51 fn try_from(pymb: &PyramidBuilder) -> Result<Self, Self::Error> {
52 Ok((&pymb.clone().build()?).into())
53 }
54}
55
56impl<T: Default> PyramidProcessor<T> {
57 pub fn new(pym: &Pyramid) -> Self {
58 Self {
59 lenslet_array: pym.lenslet_array,
60 ..Default::default()
61 }
62 }
63}
64
65impl From<&Pyramid> for PyramidProcessor<f32> {
66 fn from(pym: &Pyramid) -> Self {
67 Self {
68 lenslet_array: pym.lenslet_array,
69 frame: Arc::new(pym.into()),
70 }
71 }
72}
73
74impl SubAssign for PyramidData<f32> {
75 fn sub_assign(&mut self, rhs: Self) {
76 self.sx
77 .iter_mut()
78 .zip(self.sy.iter_mut())
79 .zip(rhs.sx.into_iter().zip(rhs.sy.into_iter()))
80 .for_each(|((sx, sy), (rhs_sx, rhs_sy))| {
81 *sx -= rhs_sx;
82 *sy -= rhs_sy;
83 });
84 }
85}
86
87impl DivAssign<f32> for PyramidData<f32> {
88 fn div_assign(&mut self, rhs: f32) {
89 self.sx
90 .iter_mut()
91 .zip(self.sy.iter_mut())
92 .for_each(|(sx, sy)| {
93 *sx /= rhs;
94 *sy /= rhs;
95 })
96 }
97}
98
99impl MulAssign<f32> for PyramidData<f32> {
100 fn mul_assign(&mut self, rhs: f32) {
101 self.sx
102 .iter_mut()
103 .zip(self.sy.iter_mut())
104 .for_each(|(sx, sy)| {
105 *sx *= rhs;
106 *sy *= rhs;
107 })
108 }
109}
110
111mod calibrating;
112mod processing;
113
114pub enum PyramidMeasurements {}
116impl UniqueIdentifier for PyramidMeasurements {
117 type DataType = PyramidData<f32>;
118}