gmt_dos_clients_crseo/ngao/optical_model/
m2.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
use crseo::SegmentWiseSensor;
use gmt_dos_clients_io::{
    gmt_m2::{
        asm::{segment::FaceSheetFigure, M2ASMFaceSheetFigure, M2ASMReferenceBodyNodes},
        M2RigidBodyMotions,
    },
    optics::M2modes,
};
use interface::{Data, Read};

use crate::OpticalModel;

impl<T: SegmentWiseSensor> Read<M2modes> for OpticalModel<T> {
    fn read(&mut self, data: Data<M2modes>) {
        if 7 * self.gmt.m2_n_mode > data.len() {
            let augmented_data: Vec<_> = data
                .chunks(data.len() / 7)
                .flat_map(|data| {
                    let mut v = vec![0f64];
                    v.extend_from_slice(data);
                    v
                })
                .collect();
            assert_eq!(augmented_data.len(), self.gmt.m2_n_mode * 7);
            self.gmt.m2_modes(&augmented_data);
        } else {
            self.gmt.m2_modes(&data);
        }
    }
}
impl<T: SegmentWiseSensor, const ID: u8> Read<FaceSheetFigure<ID>> for OpticalModel<T> {
    fn read(&mut self, data: Data<FaceSheetFigure<ID>>) {
        self.gmt.m2_segment_modes(ID, &data);
    }
}
impl<T: SegmentWiseSensor> Read<M2ASMFaceSheetFigure> for OpticalModel<T> {
    fn read(&mut self, data: Data<M2ASMFaceSheetFigure>) {
        let q: Vec<_> = data.iter().flatten().cloned().collect();
        self.gmt.m2_modes(q.as_slice());
    }
}
impl<T: SegmentWiseSensor> Read<M2RigidBodyMotions> for OpticalModel<T> {
    fn read(&mut self, data: Data<M2RigidBodyMotions>) {
        data.chunks(6).enumerate().for_each(|(id, v)| {
            let (t_xyz, r_xyz) = v.split_at(3);
            self.gmt.m2_segment_state((id + 1) as i32, t_xyz, r_xyz);
        });
    }
}
impl<T: SegmentWiseSensor> Read<M2ASMReferenceBodyNodes> for OpticalModel<T> {
    fn read(&mut self, data: Data<M2ASMReferenceBodyNodes>) {
        data.chunks(6).enumerate().for_each(|(id, v)| {
            let (t_xyz, r_xyz) = v.split_at(3);
            self.gmt.m2_segment_state((id + 1) as i32, t_xyz, r_xyz);
        });
    }
}