autd3_holo_gain/linear_synthesis/
naive.rs1use crate::{
15    macros::{generate_propagation_matrix, set_from_complex_drive},
16    Backend, Complex, Transpose, VectorXc,
17};
18use anyhow::Result;
19use autd3_core::{
20    gain::Gain,
21    geometry::{Geometry, Vector3},
22    hardware_defined::{Drive, NUM_TRANS_IN_UNIT},
23};
24use autd3_traits::Gain;
25use std::marker::PhantomData;
26
27#[derive(Gain)]
29pub struct Naive<B: Backend> {
30    data: Vec<Drive>,
31    built: bool,
32    foci: Vec<Vector3>,
33    amps: Vec<f64>,
34    backend: PhantomData<B>,
35}
36
37impl<B: Backend> Naive<B> {
38    pub fn new(foci: Vec<Vector3>, amps: Vec<f64>) -> Self {
39        assert!(foci.len() == amps.len());
40        Self {
41            data: vec![],
42            built: false,
43            foci,
44            amps,
45            backend: PhantomData,
46        }
47    }
48
49    #[allow(clippy::many_single_char_names)]
50    #[allow(clippy::unnecessary_wraps)]
51    fn calc(&mut self, geometry: &Geometry) -> Result<()> {
52        let m = self.foci.len();
53        let n = geometry.num_devices() * NUM_TRANS_IN_UNIT;
54
55        let g = generate_propagation_matrix(geometry, &self.foci);
56        let p = VectorXc::from_iterator(m, self.amps.iter().map(|&a| Complex::new(a, 0.0)));
57        let mut q = VectorXc::zeros(n);
58        B::matrix_mul_vec(
59            Transpose::ConjTrans,
60            Complex::new(1.0, 0.0),
61            &g,
62            &p,
63            Complex::new(0.0, 0.0),
64            &mut q,
65        );
66
67        set_from_complex_drive(&mut self.data, &q, true, 1.0);
68        Ok(())
69    }
70}