Gainの自作

Rust版のライブラリでは自前のGainを作成することができる.

NOTE: C++, C#, Python版のライブラリでは, この機能は提供されていない. しかし, 同様の目的で, Customを使用することができる.

ここでは, Focusと同じように単一焦点を生成するFocalPointを実際に定義してみることにする.

use autd3::core::derive::*; use autd3::prelude::*; #[derive(Gain, Debug)] pub struct FocalPoint { pos: Point3, } pub struct Impl { pos: Point3, wavenumber: f32, } impl GainCalculator for Impl { fn calc(&self, tr: &Transducer) -> Drive { Drive { phase: Phase::from(-(self.pos - tr.position()).norm() * self.wavenumber * rad), intensity: EmitIntensity::MAX, } } } impl GainCalculatorGenerator for FocalPoint { type Calculator = Impl; fn generate(&mut self, device: &Device) -> Self::Calculator { Impl { pos: self.pos, wavenumber: device.wavenumber(), } } } impl Gain for FocalPoint { type G = FocalPoint; fn init(self) -> Result<Self::G, GainError> { Ok(self) } } fn main() {}

Gain::initは各デバイス毎に, GainCalculator (を実装した型) を生成するGainContextGenerator (を実装した型) を返す. 実際の位相, 振幅の計算はGainCalculator::calc関数内で行う.