use super::Complex;
use std::collections::{HashMap, BTreeMap};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PropagationMethod {
AngularSpectrum,
Fresnel,
RayleighSommerfeld,
FFT,
}
impl Default for PropagationMethod {
fn default() -> Self {
Self::Fresnel
}
}
pub struct WavefrontPropagator {
method: PropagationMethod,
wavelength: f64,
pixel_pitch: f64,
}
impl WavefrontPropagator {
pub fn new(method: PropagationMethod) -> Result<Self, PropagatorError> {
Ok(Self {
method,
wavelength: 532e-9, pixel_pitch: 8e-6, })
}
pub fn set_wavelength(&mut self, wavelength: f64) {
self.wavelength = wavelength;
}
pub fn set_pixel_pitch(&mut self, pitch: f64) {
self.pixel_pitch = pitch;
}
pub fn propagate(&self, wavefront: &[Complex], distance: f64) -> Result<Vec<Complex>, PropagatorError> {
let result: _ = match self.method {
PropagationMethod::AngularSpectrum => self.propagate_angular_spectrum(wavefront, distance),
PropagationMethod::Fresnel => self.propagate_fresnel(wavefront, distance),
PropagationMethod::RayleighSommerfeld => self.propagate_rayleigh_sommerfeld(wavefront, distance),
PropagationMethod::FFT => self.propagate_fft(wavefront, distance),
};
result
}
fn propagate_angular_spectrum(&self, wavefront: &[Complex], _distance: f64) -> Result<Vec<Complex>, PropagatorError> {
Ok(wavefront.to_vec())
}
fn propagate_fresnel(&self, wavefront: &[Complex], _distance: f64) -> Result<Vec<Complex>, PropagatorError> {
Ok(wavefront.to_vec())
}
fn propagate_rayleigh_sommerfeld(&self, wavefront: &[Complex], _distance: f64) -> Result<Vec<Complex>, PropagatorError> {
Ok(wavefront.to_vec())
}
fn propagate_fft(&self, wavefront: &[Complex], _distance: f64) -> Result<Vec<Complex>, PropagatorError> {
Ok(wavefront.to_vec())
}
pub fn method(&self) -> PropagationMethod {
self.method
}
}
#[derive(Debug, Clone)]
pub enum PropagatorError {
InitializationFailed(String),
ComputationFailed(String),
InvalidParameter(String),
}
impl std::fmt::Display for PropagatorError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::InitializationFailed(msg) => write!(f, "初始化失败: {}", msg),
Self::ComputationFailed(msg) => write!(f, "计算失败: {}", msg),
Self::InvalidParameter(msg) => write!(f, "参数无效: {}", msg),
}
}
}
impl std::error::Error for PropagatorError {}