use serde::{Deserialize, Serialize};
use std::path::Path;
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(default)]
pub struct Config {
pub file_name: String,
pub backend: String,
pub algorithm: String,
pub filter_name: String,
pub rotation_axis: Option<f32>,
pub remove_stripe_method: String,
pub retrieve_phase_method: String,
pub num_iter: usize,
pub reg_par: Vec<f32>,
pub nsino_per_chunk: usize,
pub save_format: String,
pub fw_sigma: f32,
pub fw_level: usize,
pub ti_nblock: usize,
pub ti_beta: f32,
pub sf_size: usize,
pub vo_snr: f32,
pub vo_la_size: usize,
pub vo_sm_size: usize,
pub pixel_size: f64,
pub propagation_distance: f64,
pub energy: f64,
pub alpha: f64,
pub db: f64,
pub w: f64,
}
impl Default for Config {
fn default() -> Self {
Config {
file_name: String::new(),
backend: "auto".into(),
algorithm: "fbp".into(),
filter_name: "parzen".into(),
rotation_axis: None,
remove_stripe_method: "none".into(),
retrieve_phase_method: "none".into(),
num_iter: 1,
reg_par: Vec::new(),
nsino_per_chunk: 8,
save_format: "tiff".into(),
fw_sigma: 2.0,
fw_level: 0,
ti_nblock: 0,
ti_beta: 1.5,
sf_size: 5,
vo_snr: 3.0,
vo_la_size: 61,
vo_sm_size: 21,
pixel_size: 1e-4,
propagation_distance: 50.0,
energy: 30.0,
alpha: 1e-3,
db: 1000.0,
w: 2e-4,
}
}
}
impl Config {
pub fn to_toml(&self) -> anyhow::Result<String> {
Ok(toml::to_string_pretty(self)?)
}
pub fn write(&self, path: &Path) -> anyhow::Result<()> {
std::fs::write(path, self.to_toml()?)?;
Ok(())
}
pub fn load(path: &Path) -> anyhow::Result<Self> {
let text = std::fs::read_to_string(path)?;
Ok(toml::from_str(&text)?)
}
}