diff --git a/lib/cppbind/mmlens/README.md b/lib/cppbind/mmlens/README.md index c178ded3..e96453b8 100644 --- a/lib/cppbind/mmlens/README.md +++ b/lib/cppbind/mmlens/README.md @@ -59,6 +59,7 @@ lib/cppbind/mmlens/src/distortion_layers.rs lib/cppbind/mmlens/src/distortion_process.cpp lib/cppbind/mmlens/src/distortion_process.rs lib/cppbind/mmlens/src/distortion_structs.h +lib/cppbind/mmlens/src/lens_parameters/mod.rs lib/cppbind/mmlens/src/option_lens_parameters.rs lib/mmsolverlibs/src/CMakeLists.txt ``` @@ -67,6 +68,7 @@ Add files: ``` lib/cppbind/mmlens/include/mmlens/lens_model_EXAMPLE.h lib/cppbind/mmlens/src/lens_model_EXAMPLE.cpp +lib/cppbind/mmlens/src/lens_parameters/EXAMPLE.rs ``` ### Important Implementation Considerations @@ -111,17 +113,16 @@ Documentation: -### 0) option_lens_parameters.rs and cxxbridge.rs - -#### Add Option Parameter Type +### 0) option_lens_parameters.rs and cxxbridge.rs - Add Option Parameter Type In `option_lens_parameters.rs` add: ```rust -struct OptionParametersExample { - exists: bool, - value: ParametersExample, -} +impl_option_parameters_trait!( + BindOptionParametersExample, + BindParametersExample +); + ``` Define parameter structures in `cxxbridge.rs`: @@ -134,22 +135,60 @@ struct OptionParametersExample { } ``` +### 1) lens_parameters/mod.rs and lens_parameters/example.rs - Create Main Parameter Struct -### 1) cxxbridge.rs - -#### Add New Type Enum - -Add a new variant to `LensModelType` enum in `cxxbridge.rs`: +Create a new file `lens_parameters/example.rs`, and add default values +and functions to set each value via a slice: ```rust -#[repr(u8)] -pub(crate) enum LensModelType { - // ... existing types ... - TdeExample = , // Add new type +impl Default for BindParametersExample { + fn default() -> Self { + Self { + distortion: 0.0, + anamorphic_squeeze: 1.0, + curvature_x: 0.0, + curvature_y: 0.0, + quartic_distortion: 0.0, + } + } +} + +impl LensParameters for BindParametersExample { + impl_LensParameters_hash_parameters_method!( + distortion, + anamorphic_squeeze, + curvature_x, + curvature_y, + quartic_distortion + ); + + fn from_slice(data: &[f64]) -> Self { + Self { + distortion: data[0], + anamorphic_squeeze: data[1], + curvature_x: data[2], + curvature_y: data[3], + quartic_distortion: data[4], + } + } + + fn into_args(self) -> Vec { + vec![ + self.distortion, + self.anamorphic_squeeze, + self.curvature_x, + self.curvature_y, + self.quartic_distortion, + ] + } } ``` -#### Create Main Parameter Struct + +Then add the newly created file to `lens_parameters/mod.rs`: +```rust +mod example; +``` Define parameter structures in `cxxbridge.rs`: @@ -163,7 +202,19 @@ pub(crate) struct ParametersExample { } ``` -### 2) lens_model_example.cpp/.h - Create Lens Model Class +### 2) cxxbridge.rs - Add New Type Enum + +Add a new variant to `LensModelType` enum in `cxxbridge.rs`: + +```rust +#[repr(u8)] +pub(crate) enum LensModelType { + // ... existing types ... + TdeExample = , // Add new type +} +``` + +### 3) lens_model_example.cpp/.h - Create Lens Model Class Add `lens_model_example.cpp` and `lens_model_example.h`, define the 'Example' lens model class inheriting from LensModel, and implement @@ -189,9 +240,7 @@ private: }; ``` -### 3) distortion_structs.h - -#### Implement Distortion Operations +### 4) distortion_structs.h - Implement Distortion Operations Create distortion class implementing the Distortion interface in `distortion_structs.h`. @@ -216,7 +265,6 @@ void apply_f64_to_f64(...); void apply_f64_to_f32(...); ``` - ### 5) constants.rs Add parameter count constant in `constants.rs`: diff --git a/lib/cppbind/mmlens/src/cxxbridge.rs b/lib/cppbind/mmlens/src/cxxbridge.rs index 1057f6fe..e1a0790e 100644 --- a/lib/cppbind/mmlens/src/cxxbridge.rs +++ b/lib/cppbind/mmlens/src/cxxbridge.rs @@ -160,7 +160,7 @@ pub mod ffi { lens_center_offset_y_cm: f64, } - #[derive(Debug, Default, Copy, Clone, PartialEq, PartialOrd)] + #[derive(Debug, Copy, Clone, PartialEq, PartialOrd)] pub(crate) struct Parameters3deClassic { distortion: f64, // "Distortion" anamorphic_squeeze: f64, // "Anamorphic Squeeze" @@ -169,7 +169,7 @@ pub mod ffi { quartic_distortion: f64, // "Quartic Distortion" } - #[derive(Debug, Default, Copy, Clone, PartialEq, PartialOrd)] + #[derive(Debug, Copy, Clone, PartialEq, PartialOrd)] pub(crate) struct Parameters3deRadialStdDeg4 { degree2_distortion: f64, // "Distortion - Degree 2" degree2_u: f64, // "U - Degree 2" @@ -183,7 +183,7 @@ pub mod ffi { cylindric_bending: f64, // "B - Cylindric Bending" } - #[derive(Debug, Default, Copy, Clone, PartialEq, PartialOrd)] + #[derive(Debug, Copy, Clone, PartialEq, PartialOrd)] pub(crate) struct Parameters3deAnamorphicStdDeg4 { degree2_cx02: f64, // "Cx02 - Degree 2" degree2_cy02: f64, // "Cy02 - Degree 2" @@ -202,7 +202,7 @@ pub mod ffi { squeeze_y: f64, // "Squeeze-Y" } - #[derive(Debug, Default, Copy, Clone, PartialEq, PartialOrd)] + #[derive(Debug, Copy, Clone, PartialEq, PartialOrd)] pub(crate) struct Parameters3deAnamorphicStdDeg4Rescaled { degree2_cx02: f64, // "Cx02 - Degree 2" degree2_cy02: f64, // "Cy02 - Degree 2" @@ -222,7 +222,7 @@ pub mod ffi { rescale: f64, // "Rescale" } - #[derive(Debug, Default, Copy, Clone, PartialEq, PartialOrd)] + #[derive(Debug, Copy, Clone, PartialEq, PartialOrd)] pub(crate) struct Parameters3deAnamorphicStdDeg6 { degree2_cx02: f64, // "Cx02 - Degree 2" degree2_cy02: f64, // "Cy02 - Degree 2" @@ -250,7 +250,7 @@ pub mod ffi { squeeze_y: f64, // "Squeeze-Y" } - #[derive(Debug, Default, Copy, Clone, PartialEq, PartialOrd)] + #[derive(Debug, Copy, Clone, PartialEq, PartialOrd)] pub(crate) struct Parameters3deAnamorphicStdDeg6Rescaled { degree2_cx02: f64, // "Cx02 - Degree 2" degree2_cy02: f64, // "Cy02 - Degree 2" diff --git a/lib/cppbind/mmlens/src/distortion_layers.rs b/lib/cppbind/mmlens/src/distortion_layers.rs index 3ff3ec31..bc3b6639 100644 --- a/lib/cppbind/mmlens/src/distortion_layers.rs +++ b/lib/cppbind/mmlens/src/distortion_layers.rs @@ -33,6 +33,12 @@ use crate::cxxbridge::ffi::OptionParameters3deAnamorphicStdDeg6 as BindOptionPar use crate::cxxbridge::ffi::OptionParameters3deAnamorphicStdDeg6Rescaled as BindOptionParameters3deAnamorphicStdDeg6Rescaled; use crate::cxxbridge::ffi::OptionParameters3deClassic as BindOptionParameters3deClassic; use crate::cxxbridge::ffi::OptionParameters3deRadialStdDeg4 as BindOptionParameters3deRadialStdDeg4; +use crate::cxxbridge::ffi::Parameters3deAnamorphicStdDeg4 as BindParameters3deAnamorphicStdDeg4; +use crate::cxxbridge::ffi::Parameters3deAnamorphicStdDeg4Rescaled as BindParameters3deAnamorphicStdDeg4Rescaled; +use crate::cxxbridge::ffi::Parameters3deAnamorphicStdDeg6 as BindParameters3deAnamorphicStdDeg6; +use crate::cxxbridge::ffi::Parameters3deAnamorphicStdDeg6Rescaled as BindParameters3deAnamorphicStdDeg6Rescaled; +use crate::cxxbridge::ffi::Parameters3deClassic as BindParameters3deClassic; +use crate::cxxbridge::ffi::Parameters3deRadialStdDeg4 as BindParameters3deRadialStdDeg4; use crate::data::FrameNumber; use crate::data::FrameSize; use crate::data::HashValue64; @@ -42,6 +48,8 @@ use crate::data::ParameterBlock; use crate::data::ParameterIndex; use crate::data::ParameterSize; use crate::hash_float::HashableF64; +use crate::lens_parameters::LensParameters; +use crate::option_lens_parameters::OptionParametersTrait; use rustc_hash::FxHasher; use smallvec::SmallVec; use std::collections::HashMap; @@ -49,34 +57,77 @@ use std::convert::TryInto; use std::hash::Hash; use std::hash::Hasher; -impl BindLensModelType { - fn parameters_size(&self) -> ParameterSize { - match *self { - BindLensModelType::TdeClassic => PARAMETER_COUNT_3DE_CLASSIC, - BindLensModelType::TdeRadialStdDeg4 => { - PARAMETER_COUNT_3DE_RADIAL_STD_DEG4 - } - BindLensModelType::TdeAnamorphicStdDeg4 => { - PARAMETER_COUNT_3DE_ANAMORPHIC_STD_DEG4 - } - BindLensModelType::TdeAnamorphicStdDeg4Rescaled => { - PARAMETER_COUNT_3DE_ANAMORPHIC_STD_DEG4_RESCALED - } - BindLensModelType::TdeAnamorphicStdDeg6 => { - PARAMETER_COUNT_3DE_ANAMORPHIC_STD_DEG6 - } - BindLensModelType::TdeAnamorphicStdDeg6Rescaled => { - PARAMETER_COUNT_3DE_ANAMORPHIC_STD_DEG6_RESCALED +macro_rules! hash_lens_model_params { + ( + $lens_layers:expr, + $layer_num:expr, + $frame:expr, + $state:expr, + $lens_model_type:expr, + [$( + ($variant:path, $param_fn:ident) + ),*] + ) => { + match $lens_model_type { + $( + $variant => { + let option_params = $lens_layers.$param_fn($layer_num, $frame); + if option_params.exists { + $lens_model_type.hash($state); + option_params.value.hash_parameters($state); + } + } + )* + _ => { + panic!("Unsupported Lens Model Type: {:?}", $lens_model_type) } - _ => 0, } - } + }; +} + +fn hash_lens_layer_params( + lens_layers: &ShimDistortionLayers, + layer_num: LayerIndex, + frame: FrameNumber, + state: &mut FxHasher, +) { + let lens_model_type = lens_layers.layer_lens_model_type(layer_num); + + hash_lens_model_params!( + lens_layers, + layer_num, + frame, + state, + lens_model_type, + [ + ( + BindLensModelType::TdeClassic, + layer_lens_parameters_3de_classic + ), + ( + BindLensModelType::TdeRadialStdDeg4, + layer_lens_parameters_3de_radial_std_deg4 + ), + ( + BindLensModelType::TdeAnamorphicStdDeg4, + layer_lens_parameters_3de_anamorphic_std_deg4 + ), + ( + BindLensModelType::TdeAnamorphicStdDeg4Rescaled, + layer_lens_parameters_3de_anamorphic_std_deg4_rescaled + ), + ( + BindLensModelType::TdeAnamorphicStdDeg6, + layer_lens_parameters_3de_anamorphic_std_deg6 + ), + ( + BindLensModelType::TdeAnamorphicStdDeg6Rescaled, + layer_lens_parameters_3de_anamorphic_std_deg6_rescaled + ) + ] + ); } -/// Get the parameters values in a block of output values. -/// -/// output_values is assumed to be pre-allocated with at least enough -/// memory to old enough values for the lens_model_type given. fn set_parameter_block_values( layer_num: LayerIndex, frame_number: FrameNumber, @@ -84,111 +135,16 @@ fn set_parameter_block_values( lens_parameters: &HashMap<(LayerIndex, FrameNumber), ParameterBlock>, output_values: &mut [f64], ) { - assert!(output_values.len() > 0); match lens_parameters.get(&(layer_num, frame_number)) { - Some(input_values) => match lens_model_type { - BindLensModelType::TdeClassic => { - output_values[0] = input_values[0]; - output_values[1] = input_values[1]; - output_values[2] = input_values[2]; - output_values[3] = input_values[3]; - output_values[4] = input_values[4]; - } - BindLensModelType::TdeRadialStdDeg4 => { - output_values[0] = input_values[0]; - output_values[1] = input_values[1]; - output_values[2] = input_values[2]; - output_values[3] = input_values[3]; - output_values[4] = input_values[4]; - output_values[5] = input_values[5]; - output_values[6] = input_values[6]; - output_values[7] = input_values[7]; - } - BindLensModelType::TdeAnamorphicStdDeg4 => { - output_values[0] = input_values[0]; - output_values[1] = input_values[1]; - output_values[2] = input_values[2]; - output_values[3] = input_values[3]; - output_values[4] = input_values[4]; - output_values[5] = input_values[5]; - output_values[6] = input_values[6]; - output_values[7] = input_values[7]; - output_values[8] = input_values[8]; - output_values[9] = input_values[9]; - output_values[10] = input_values[10]; - output_values[11] = input_values[11]; - output_values[12] = input_values[12]; - } - BindLensModelType::TdeAnamorphicStdDeg4Rescaled => { - output_values[0] = input_values[0]; - output_values[1] = input_values[1]; - output_values[2] = input_values[2]; - output_values[3] = input_values[3]; - output_values[4] = input_values[4]; - output_values[5] = input_values[5]; - output_values[6] = input_values[6]; - output_values[7] = input_values[7]; - output_values[8] = input_values[8]; - output_values[9] = input_values[9]; - output_values[10] = input_values[10]; - output_values[11] = input_values[11]; - output_values[12] = input_values[12]; - output_values[13] = input_values[13]; - } - BindLensModelType::TdeAnamorphicStdDeg6 => { - output_values[0] = input_values[0]; - output_values[1] = input_values[1]; - output_values[2] = input_values[2]; - output_values[3] = input_values[3]; - output_values[4] = input_values[4]; - output_values[5] = input_values[5]; - output_values[6] = input_values[6]; - output_values[7] = input_values[7]; - output_values[8] = input_values[8]; - output_values[9] = input_values[9]; - output_values[10] = input_values[10]; - output_values[11] = input_values[11]; - output_values[12] = input_values[12]; - output_values[13] = input_values[13]; - output_values[14] = input_values[14]; - output_values[15] = input_values[15]; - output_values[16] = input_values[16]; - output_values[17] = input_values[17]; - output_values[18] = input_values[18]; - output_values[19] = input_values[19]; - output_values[20] = input_values[20]; - } - BindLensModelType::TdeAnamorphicStdDeg6Rescaled => { - output_values[0] = input_values[0]; - output_values[1] = input_values[1]; - output_values[2] = input_values[2]; - output_values[3] = input_values[3]; - output_values[4] = input_values[4]; - output_values[5] = input_values[5]; - output_values[6] = input_values[6]; - output_values[7] = input_values[7]; - output_values[8] = input_values[8]; - output_values[9] = input_values[9]; - output_values[10] = input_values[10]; - output_values[11] = input_values[11]; - output_values[12] = input_values[12]; - output_values[13] = input_values[13]; - output_values[14] = input_values[14]; - output_values[15] = input_values[15]; - output_values[16] = input_values[16]; - output_values[17] = input_values[17]; - output_values[18] = input_values[18]; - output_values[19] = input_values[19]; - output_values[20] = input_values[20]; - output_values[21] = input_values[21]; - } - _ => (), - }, + Some(input_values) => { + let count = lens_model_type.parameters_size() as usize; + output_values[..count].copy_from_slice(&input_values[..count]); + } None => { panic!("Could not find frame number in lens_parameters HashMap: layer_num={} frame_number={}.", layer_num, frame_number) } - }; + } } /// Count how many frames are in the layer. @@ -208,6 +164,35 @@ fn count_lens_layer_frame_count( frame_count } +/// Add parameters_size as an actual trait. +pub trait ModelParameters { + fn parameters_size(&self) -> ParameterSize; +} + +impl ModelParameters for BindLensModelType { + fn parameters_size(&self) -> ParameterSize { + match *self { + BindLensModelType::TdeClassic => PARAMETER_COUNT_3DE_CLASSIC, + BindLensModelType::TdeRadialStdDeg4 => { + PARAMETER_COUNT_3DE_RADIAL_STD_DEG4 + } + BindLensModelType::TdeAnamorphicStdDeg4 => { + PARAMETER_COUNT_3DE_ANAMORPHIC_STD_DEG4 + } + BindLensModelType::TdeAnamorphicStdDeg4Rescaled => { + PARAMETER_COUNT_3DE_ANAMORPHIC_STD_DEG4_RESCALED + } + BindLensModelType::TdeAnamorphicStdDeg6 => { + PARAMETER_COUNT_3DE_ANAMORPHIC_STD_DEG6 + } + BindLensModelType::TdeAnamorphicStdDeg6Rescaled => { + PARAMETER_COUNT_3DE_ANAMORPHIC_STD_DEG6_RESCALED + } + _ => 0, + } + } +} + /// Count up all the parameters that will be used for a set of layers. fn total_parameter_count( layer_count: LayerSize, @@ -254,9 +239,32 @@ fn sum_parameter_count( parameter_count } +fn construct_lens_parameter_object( + layer_num: LayerIndex, + lens_model_type: BindLensModelType, + frame: FrameNumber, + layer_count: LayerSize, + layer_frame_range: &SmallVec<[(FrameNumber, FrameNumber); 4]>, + layer_lens_model_types: &SmallVec<[BindLensModelType; 4]>, + parameter_block: &Vec, + parameter_indices: &Vec<(ParameterIndex, ParameterSize)>, +) -> Option { + construct_lens_parameter_value_array( + layer_num, + lens_model_type, + frame, + layer_count, + layer_frame_range, + layer_lens_model_types, + parameter_block, + parameter_indices, + ) + .map(|params| T::from_slice(params)) +} + /// When a 'frame' outside the frame range is requested, the /// returned values come from the first or last frame. -pub fn construct_lens_parameters<'a>( +pub fn construct_lens_parameter_value_array<'a>( layer_num: LayerIndex, lens_model_type: BindLensModelType, frame: FrameNumber, @@ -297,6 +305,36 @@ pub fn construct_lens_parameters<'a>( Some(values) } +macro_rules! impl_layer_lens_parameters_method { + ($name:ident, $model_type:expr, $param_type:ty, $option_type:ty) => { + /// When a 'frame' outside the frame range is requested, the + /// returned values come from the first or last frame. + pub fn $name( + &self, + layer_num: LayerIndex, + frame: FrameNumber, + ) -> $option_type { + let lens_model_type = $model_type; + match construct_lens_parameter_object::<$param_type>( + layer_num, + lens_model_type, + frame, + self.layer_count, + &self.layer_frame_range, + &self.layer_lens_model_types, + &self.parameter_block, + &self.parameter_indices, + ) { + Some(params) => { + let args = params.into_args(); + <$option_type>::new_as_some_from_vec(&args) + } + None => <$option_type>::new_as_none(), + } + } + }; +} + /// Represents "Layers" of (lens) distortion data. /// /// The layers are conceptually stacked top-to-bottom, so the zeroth @@ -338,258 +376,6 @@ pub fn shim_create_distortion_layers_box() -> Box { Box::new(ShimDistortionLayers::new()) } -fn hash_lens_layer_params( - lens_layers: &ShimDistortionLayers, - layer_num: LayerIndex, - frame: FrameNumber, - state: &mut FxHasher, -) { - let lens_model_type = lens_layers.layer_lens_model_type(layer_num); - match lens_model_type { - BindLensModelType::Uninitialized => { - // This lens model is a no-op, nothing is done. - () - } - BindLensModelType::TdeClassic => { - let option_parameters = - lens_layers.layer_lens_parameters_3de_classic(layer_num, frame); - assert!(option_parameters.exists == true); - let parameters = option_parameters.value; - - let distortion = HashableF64::new(parameters.distortion); - let anamorphic_squeeze = - HashableF64::new(parameters.anamorphic_squeeze); - let curvature_x = HashableF64::new(parameters.curvature_x); - let curvature_y = HashableF64::new(parameters.curvature_y); - let quartic_distortion = - HashableF64::new(parameters.quartic_distortion); - - lens_model_type.hash(state); - distortion.hash(state); - anamorphic_squeeze.hash(state); - curvature_x.hash(state); - curvature_y.hash(state); - quartic_distortion.hash(state); - } - BindLensModelType::TdeRadialStdDeg4 => { - let option_parameters = lens_layers - .layer_lens_parameters_3de_radial_std_deg4(layer_num, frame); - assert!(option_parameters.exists == true); - let parameters = option_parameters.value; - - let degree2_distortion = - HashableF64::new(parameters.degree2_distortion); - let degree2_u = HashableF64::new(parameters.degree2_u); - let degree2_v = HashableF64::new(parameters.degree2_v); - let degree4_distortion = - HashableF64::new(parameters.degree4_distortion); - let degree4_u = HashableF64::new(parameters.degree4_u); - let degree4_v = HashableF64::new(parameters.degree4_v); - let cylindric_direction = - HashableF64::new(parameters.cylindric_direction); - let cylindric_bending = - HashableF64::new(parameters.cylindric_bending); - - lens_model_type.hash(state); - degree2_distortion.hash(state); - degree2_u.hash(state); - degree2_v.hash(state); - degree4_distortion.hash(state); - degree4_u.hash(state); - degree4_v.hash(state); - cylindric_direction.hash(state); - cylindric_bending.hash(state); - } - BindLensModelType::TdeAnamorphicStdDeg4 => { - let option_parameters = lens_layers - .layer_lens_parameters_3de_anamorphic_std_deg4( - layer_num, frame, - ); - assert!(option_parameters.exists == true); - let parameters = option_parameters.value; - - let degree2_cx02 = HashableF64::new(parameters.degree2_cx02); - let degree2_cy02 = HashableF64::new(parameters.degree2_cy02); - let degree2_cx22 = HashableF64::new(parameters.degree2_cx22); - let degree2_cy22 = HashableF64::new(parameters.degree2_cy22); - let degree4_cx04 = HashableF64::new(parameters.degree4_cx04); - let degree4_cy04 = HashableF64::new(parameters.degree4_cy04); - let degree4_cx24 = HashableF64::new(parameters.degree4_cx24); - let degree4_cy24 = HashableF64::new(parameters.degree4_cy24); - let degree4_cx44 = HashableF64::new(parameters.degree4_cx44); - let degree4_cy44 = HashableF64::new(parameters.degree4_cy44); - let lens_rotation = HashableF64::new(parameters.lens_rotation); - let squeeze_x = HashableF64::new(parameters.squeeze_x); - let squeeze_y = HashableF64::new(parameters.squeeze_y); - - lens_model_type.hash(state); - degree2_cx02.hash(state); - degree2_cy02.hash(state); - degree2_cx22.hash(state); - degree2_cy22.hash(state); - degree4_cx04.hash(state); - degree4_cy04.hash(state); - degree4_cx24.hash(state); - degree4_cy24.hash(state); - degree4_cx44.hash(state); - degree4_cy44.hash(state); - lens_rotation.hash(state); - squeeze_x.hash(state); - squeeze_y.hash(state); - } - BindLensModelType::TdeAnamorphicStdDeg4Rescaled => { - let option_parameters = lens_layers - .layer_lens_parameters_3de_anamorphic_std_deg4_rescaled( - layer_num, frame, - ); - assert!(option_parameters.exists == true); - let parameters = option_parameters.value; - - let degree2_cx02 = HashableF64::new(parameters.degree2_cx02); - let degree2_cy02 = HashableF64::new(parameters.degree2_cy02); - let degree2_cx22 = HashableF64::new(parameters.degree2_cx22); - let degree2_cy22 = HashableF64::new(parameters.degree2_cy22); - let degree4_cx04 = HashableF64::new(parameters.degree4_cx04); - let degree4_cy04 = HashableF64::new(parameters.degree4_cy04); - let degree4_cx24 = HashableF64::new(parameters.degree4_cx24); - let degree4_cy24 = HashableF64::new(parameters.degree4_cy24); - let degree4_cx44 = HashableF64::new(parameters.degree4_cx44); - let degree4_cy44 = HashableF64::new(parameters.degree4_cy44); - let lens_rotation = HashableF64::new(parameters.lens_rotation); - let squeeze_x = HashableF64::new(parameters.squeeze_x); - let squeeze_y = HashableF64::new(parameters.squeeze_y); - let rescale = HashableF64::new(parameters.rescale); - - lens_model_type.hash(state); - degree2_cx02.hash(state); - degree2_cy02.hash(state); - degree2_cx22.hash(state); - degree2_cy22.hash(state); - degree4_cx04.hash(state); - degree4_cy04.hash(state); - degree4_cx24.hash(state); - degree4_cy24.hash(state); - degree4_cx44.hash(state); - degree4_cy44.hash(state); - lens_rotation.hash(state); - squeeze_x.hash(state); - squeeze_y.hash(state); - rescale.hash(state); - } - BindLensModelType::TdeAnamorphicStdDeg6 => { - let option_parameters = lens_layers - .layer_lens_parameters_3de_anamorphic_std_deg6( - layer_num, frame, - ); - assert!(option_parameters.exists == true); - let parameters = option_parameters.value; - - let degree2_cx02 = HashableF64::new(parameters.degree2_cx02); - let degree2_cy02 = HashableF64::new(parameters.degree2_cy02); - let degree2_cx22 = HashableF64::new(parameters.degree2_cx22); - let degree2_cy22 = HashableF64::new(parameters.degree2_cy22); - let degree4_cx04 = HashableF64::new(parameters.degree4_cx04); - let degree4_cy04 = HashableF64::new(parameters.degree4_cy04); - let degree4_cx24 = HashableF64::new(parameters.degree4_cx24); - let degree4_cy24 = HashableF64::new(parameters.degree4_cy24); - let degree4_cx44 = HashableF64::new(parameters.degree4_cx44); - let degree4_cy44 = HashableF64::new(parameters.degree4_cy44); - let degree6_cx06 = HashableF64::new(parameters.degree6_cx06); - let degree6_cy06 = HashableF64::new(parameters.degree6_cy06); - let degree6_cx26 = HashableF64::new(parameters.degree6_cx26); - let degree6_cy26 = HashableF64::new(parameters.degree6_cy26); - let degree6_cx46 = HashableF64::new(parameters.degree6_cx46); - let degree6_cy46 = HashableF64::new(parameters.degree6_cy46); - let degree6_cx66 = HashableF64::new(parameters.degree6_cx66); - let degree6_cy66 = HashableF64::new(parameters.degree6_cy66); - let lens_rotation = HashableF64::new(parameters.lens_rotation); - let squeeze_x = HashableF64::new(parameters.squeeze_x); - let squeeze_y = HashableF64::new(parameters.squeeze_y); - - lens_model_type.hash(state); - degree2_cx02.hash(state); - degree2_cy02.hash(state); - degree2_cx22.hash(state); - degree2_cy22.hash(state); - degree4_cx04.hash(state); - degree4_cy04.hash(state); - degree4_cx24.hash(state); - degree4_cy24.hash(state); - degree4_cx44.hash(state); - degree4_cy44.hash(state); - degree6_cx06.hash(state); - degree6_cy06.hash(state); - degree6_cx26.hash(state); - degree6_cy26.hash(state); - degree6_cx46.hash(state); - degree6_cy46.hash(state); - degree6_cx66.hash(state); - degree6_cy66.hash(state); - lens_rotation.hash(state); - squeeze_x.hash(state); - squeeze_y.hash(state); - } - BindLensModelType::TdeAnamorphicStdDeg6Rescaled => { - let option_parameters = lens_layers - .layer_lens_parameters_3de_anamorphic_std_deg6_rescaled( - layer_num, frame, - ); - assert!(option_parameters.exists == true); - let parameters = option_parameters.value; - - let degree2_cx02 = HashableF64::new(parameters.degree2_cx02); - let degree2_cy02 = HashableF64::new(parameters.degree2_cy02); - let degree2_cx22 = HashableF64::new(parameters.degree2_cx22); - let degree2_cy22 = HashableF64::new(parameters.degree2_cy22); - let degree4_cx04 = HashableF64::new(parameters.degree4_cx04); - let degree4_cy04 = HashableF64::new(parameters.degree4_cy04); - let degree4_cx24 = HashableF64::new(parameters.degree4_cx24); - let degree4_cy24 = HashableF64::new(parameters.degree4_cy24); - let degree4_cx44 = HashableF64::new(parameters.degree4_cx44); - let degree4_cy44 = HashableF64::new(parameters.degree4_cy44); - let degree6_cx06 = HashableF64::new(parameters.degree6_cx06); - let degree6_cy06 = HashableF64::new(parameters.degree6_cy06); - let degree6_cx26 = HashableF64::new(parameters.degree6_cx26); - let degree6_cy26 = HashableF64::new(parameters.degree6_cy26); - let degree6_cx46 = HashableF64::new(parameters.degree6_cx46); - let degree6_cy46 = HashableF64::new(parameters.degree6_cy46); - let degree6_cx66 = HashableF64::new(parameters.degree6_cx66); - let degree6_cy66 = HashableF64::new(parameters.degree6_cy66); - let lens_rotation = HashableF64::new(parameters.lens_rotation); - let squeeze_x = HashableF64::new(parameters.squeeze_x); - let squeeze_y = HashableF64::new(parameters.squeeze_y); - let rescale = HashableF64::new(parameters.rescale); - - lens_model_type.hash(state); - degree2_cx02.hash(state); - degree2_cy02.hash(state); - degree2_cx22.hash(state); - degree2_cy22.hash(state); - degree4_cx04.hash(state); - degree4_cy04.hash(state); - degree4_cx24.hash(state); - degree4_cy24.hash(state); - degree4_cx44.hash(state); - degree4_cy44.hash(state); - degree6_cx06.hash(state); - degree6_cy06.hash(state); - degree6_cx26.hash(state); - degree6_cy26.hash(state); - degree6_cx46.hash(state); - degree6_cy46.hash(state); - degree6_cx66.hash(state); - degree6_cy66.hash(state); - lens_rotation.hash(state); - squeeze_x.hash(state); - squeeze_y.hash(state); - rescale.hash(state); - } - _ => { - panic!("Unsupported Lens Model Type: {:?}", lens_model_type) - } - } -} - impl ShimDistortionLayers { pub fn new() -> ShimDistortionLayers { return ShimDistortionLayers { @@ -811,333 +597,47 @@ impl ShimDistortionLayers { } } - /// When a 'frame' outside the frame range is requested, the - /// returned values come from the first or last frame. - pub fn layer_lens_parameters_3de_classic( - &self, - layer_num: LayerIndex, - frame: FrameNumber, - ) -> BindOptionParameters3deClassic { - let lens_model_type = BindLensModelType::TdeClassic; - let layer_parameters = construct_lens_parameters( - layer_num, - lens_model_type, - frame, - self.layer_count, - &self.layer_frame_range, - &self.layer_lens_model_types, - &self.parameter_block, - &self.parameter_indices, - ); - - if let Some(parameters) = layer_parameters { - let distortion = parameters[0]; - let anamorphic_squeeze = parameters[1]; - let curvature_x = parameters[2]; - let curvature_y = parameters[3]; - let quartic_distortion = parameters[4]; - BindOptionParameters3deClassic::new_as_some( - distortion, - anamorphic_squeeze, - curvature_x, - curvature_y, - quartic_distortion, - ) - } else { - BindOptionParameters3deClassic::new_as_none() - } - } - - /// When a 'frame' outside the frame range is requested, the - /// returned values come from the first or last frame. - pub fn layer_lens_parameters_3de_radial_std_deg4( - &self, - layer_num: LayerIndex, - frame: FrameNumber, - ) -> BindOptionParameters3deRadialStdDeg4 { - let lens_model_type = BindLensModelType::TdeRadialStdDeg4; - let layer_parameters = construct_lens_parameters( - layer_num, - lens_model_type, - frame, - self.layer_count, - &self.layer_frame_range, - &self.layer_lens_model_types, - &self.parameter_block, - &self.parameter_indices, - ); - - if let Some(parameters) = layer_parameters { - let degree2_distortion = parameters[0]; - let degree2_u = parameters[1]; - let degree2_v = parameters[2]; - let degree4_distortion = parameters[3]; - let degree4_u = parameters[4]; - let degree4_v = parameters[5]; - let cylindric_direction = parameters[6]; - let cylindric_bending = parameters[7]; - BindOptionParameters3deRadialStdDeg4::new_as_some( - degree2_distortion, - degree2_u, - degree2_v, - degree4_distortion, - degree4_u, - degree4_v, - cylindric_direction, - cylindric_bending, - ) - } else { - BindOptionParameters3deRadialStdDeg4::new_as_none() - } - } - - /// When a 'frame' outside the frame range is requested, the - /// returned values come from the first or last frame. - pub fn layer_lens_parameters_3de_anamorphic_std_deg4( - &self, - layer_num: LayerIndex, - frame: FrameNumber, - ) -> BindOptionParameters3deAnamorphicStdDeg4 { - let lens_model_type = BindLensModelType::TdeAnamorphicStdDeg4; - let layer_parameters = construct_lens_parameters( - layer_num, - lens_model_type, - frame, - self.layer_count, - &self.layer_frame_range, - &self.layer_lens_model_types, - &self.parameter_block, - &self.parameter_indices, - ); - - if let Some(parameters) = layer_parameters { - let degree2_cx02 = parameters[0]; - let degree2_cy02 = parameters[1]; - let degree2_cx22 = parameters[2]; - let degree2_cy22 = parameters[3]; - let degree4_cx04 = parameters[4]; - let degree4_cy04 = parameters[5]; - let degree4_cx24 = parameters[6]; - let degree4_cy24 = parameters[7]; - let degree4_cx44 = parameters[8]; - let degree4_cy44 = parameters[9]; - let lens_rotation = parameters[10]; - let squeeze_x = parameters[11]; - let squeeze_y = parameters[12]; - BindOptionParameters3deAnamorphicStdDeg4::new_as_some( - degree2_cx02, - degree2_cy02, - degree2_cx22, - degree2_cy22, - degree4_cx04, - degree4_cy04, - degree4_cx24, - degree4_cy24, - degree4_cx44, - degree4_cy44, - lens_rotation, - squeeze_x, - squeeze_y, - ) - } else { - BindOptionParameters3deAnamorphicStdDeg4::new_as_none() - } - } - - /// When a 'frame' outside the frame range is requested, the - /// returned values come from the first or last frame. - pub fn layer_lens_parameters_3de_anamorphic_std_deg4_rescaled( - &self, - layer_num: LayerIndex, - frame: FrameNumber, - ) -> BindOptionParameters3deAnamorphicStdDeg4Rescaled { - let lens_model_type = BindLensModelType::TdeAnamorphicStdDeg4Rescaled; - let layer_parameters = construct_lens_parameters( - layer_num, - lens_model_type, - frame, - self.layer_count, - &self.layer_frame_range, - &self.layer_lens_model_types, - &self.parameter_block, - &self.parameter_indices, - ); - - if let Some(parameters) = layer_parameters { - let degree2_cx02 = parameters[0]; - let degree2_cy02 = parameters[1]; - let degree2_cx22 = parameters[2]; - let degree2_cy22 = parameters[3]; - let degree4_cx04 = parameters[4]; - let degree4_cy04 = parameters[5]; - let degree4_cx24 = parameters[6]; - let degree4_cy24 = parameters[7]; - let degree4_cx44 = parameters[8]; - let degree4_cy44 = parameters[9]; - let lens_rotation = parameters[10]; - let squeeze_x = parameters[11]; - let squeeze_y = parameters[12]; - let rescale = parameters[13]; - BindOptionParameters3deAnamorphicStdDeg4Rescaled::new_as_some( - degree2_cx02, - degree2_cy02, - degree2_cx22, - degree2_cy22, - degree4_cx04, - degree4_cy04, - degree4_cx24, - degree4_cy24, - degree4_cx44, - degree4_cy44, - lens_rotation, - squeeze_x, - squeeze_y, - rescale, - ) - } else { - BindOptionParameters3deAnamorphicStdDeg4Rescaled::new_as_none() - } - } - - /// When a 'frame' outside the frame range is requested, the - /// returned values come from the first or last frame. - pub fn layer_lens_parameters_3de_anamorphic_std_deg6( - &self, - layer_num: LayerIndex, - frame: FrameNumber, - ) -> BindOptionParameters3deAnamorphicStdDeg6 { - let lens_model_type = BindLensModelType::TdeAnamorphicStdDeg6; - let layer_parameters = construct_lens_parameters( - layer_num, - lens_model_type, - frame, - self.layer_count, - &self.layer_frame_range, - &self.layer_lens_model_types, - &self.parameter_block, - &self.parameter_indices, - ); - - if let Some(parameters) = layer_parameters { - let degree2_cx02 = parameters[0]; - let degree2_cy02 = parameters[1]; - let degree2_cx22 = parameters[2]; - let degree2_cy22 = parameters[3]; - let degree4_cx04 = parameters[4]; - let degree4_cy04 = parameters[5]; - let degree4_cx24 = parameters[6]; - let degree4_cy24 = parameters[7]; - let degree4_cx44 = parameters[8]; - let degree4_cy44 = parameters[9]; - let degree6_cx06 = parameters[10]; - let degree6_cy06 = parameters[11]; - let degree6_cx26 = parameters[12]; - let degree6_cy26 = parameters[13]; - let degree6_cx46 = parameters[14]; - let degree6_cy46 = parameters[15]; - let degree6_cx66 = parameters[16]; - let degree6_cy66 = parameters[17]; - let lens_rotation = parameters[18]; - let squeeze_x = parameters[19]; - let squeeze_y = parameters[20]; - BindOptionParameters3deAnamorphicStdDeg6::new_as_some( - degree2_cx02, - degree2_cy02, - degree2_cx22, - degree2_cy22, - degree4_cx04, - degree4_cy04, - degree4_cx24, - degree4_cy24, - degree4_cx44, - degree4_cy44, - degree6_cx06, - degree6_cy06, - degree6_cx26, - degree6_cy26, - degree6_cx46, - degree6_cy46, - degree6_cx66, - degree6_cy66, - lens_rotation, - squeeze_x, - squeeze_y, - ) - } else { - BindOptionParameters3deAnamorphicStdDeg6::new_as_none() - } - } - - /// When a 'frame' outside the frame range is requested, the - /// returned values come from the first or last frame. - pub fn layer_lens_parameters_3de_anamorphic_std_deg6_rescaled( - &self, - layer_num: LayerIndex, - frame: FrameNumber, - ) -> BindOptionParameters3deAnamorphicStdDeg6Rescaled { - let lens_model_type = BindLensModelType::TdeAnamorphicStdDeg6Rescaled; - let layer_parameters = construct_lens_parameters( - layer_num, - lens_model_type, - frame, - self.layer_count, - &self.layer_frame_range, - &self.layer_lens_model_types, - &self.parameter_block, - &self.parameter_indices, - ); - - if let Some(parameters) = layer_parameters { - let degree2_cx02 = parameters[0]; - let degree2_cy02 = parameters[1]; - let degree2_cx22 = parameters[2]; - let degree2_cy22 = parameters[3]; - let degree4_cx04 = parameters[4]; - let degree4_cy04 = parameters[5]; - let degree4_cx24 = parameters[6]; - let degree4_cy24 = parameters[7]; - let degree4_cx44 = parameters[8]; - let degree4_cy44 = parameters[9]; - let degree6_cx06 = parameters[10]; - let degree6_cy06 = parameters[11]; - let degree6_cx26 = parameters[12]; - let degree6_cy26 = parameters[13]; - let degree6_cx46 = parameters[14]; - let degree6_cy46 = parameters[15]; - let degree6_cx66 = parameters[16]; - let degree6_cy66 = parameters[17]; - let lens_rotation = parameters[18]; - let squeeze_x = parameters[19]; - let squeeze_y = parameters[20]; - let rescale = parameters[21]; - BindOptionParameters3deAnamorphicStdDeg6Rescaled::new_as_some( - degree2_cx02, - degree2_cy02, - degree2_cx22, - degree2_cy22, - degree4_cx04, - degree4_cy04, - degree4_cx24, - degree4_cy24, - degree4_cx44, - degree4_cy44, - degree6_cx06, - degree6_cy06, - degree6_cx26, - degree6_cy26, - degree6_cx46, - degree6_cy46, - degree6_cx66, - degree6_cy66, - lens_rotation, - squeeze_x, - squeeze_y, - rescale, - ) - } else { - BindOptionParameters3deAnamorphicStdDeg6Rescaled::new_as_none() - } - } + impl_layer_lens_parameters_method!( + layer_lens_parameters_3de_classic, + BindLensModelType::TdeClassic, + BindParameters3deClassic, + BindOptionParameters3deClassic + ); + + impl_layer_lens_parameters_method!( + layer_lens_parameters_3de_radial_std_deg4, + BindLensModelType::TdeRadialStdDeg4, + BindParameters3deRadialStdDeg4, + BindOptionParameters3deRadialStdDeg4 + ); + + impl_layer_lens_parameters_method!( + layer_lens_parameters_3de_anamorphic_std_deg4, + BindLensModelType::TdeAnamorphicStdDeg4, + BindParameters3deAnamorphicStdDeg4, + BindOptionParameters3deAnamorphicStdDeg4 + ); + + impl_layer_lens_parameters_method!( + layer_lens_parameters_3de_anamorphic_std_deg4_rescaled, + BindLensModelType::TdeAnamorphicStdDeg4Rescaled, + BindParameters3deAnamorphicStdDeg4Rescaled, + BindOptionParameters3deAnamorphicStdDeg4Rescaled + ); + + impl_layer_lens_parameters_method!( + layer_lens_parameters_3de_anamorphic_std_deg6, + BindLensModelType::TdeAnamorphicStdDeg6, + BindParameters3deAnamorphicStdDeg6, + BindOptionParameters3deAnamorphicStdDeg6 + ); + + impl_layer_lens_parameters_method!( + layer_lens_parameters_3de_anamorphic_std_deg6_rescaled, + BindLensModelType::TdeAnamorphicStdDeg6Rescaled, + BindParameters3deAnamorphicStdDeg6Rescaled, + BindOptionParameters3deAnamorphicStdDeg6Rescaled + ); pub fn as_string(&self) -> String { format!("{:#?}", self).to_string() diff --git a/lib/cppbind/mmlens/src/lens_parameters/mod.rs b/lib/cppbind/mmlens/src/lens_parameters/mod.rs index 682e0724..d14bdfb1 100644 --- a/lib/cppbind/mmlens/src/lens_parameters/mod.rs +++ b/lib/cppbind/mmlens/src/lens_parameters/mod.rs @@ -18,31 +18,28 @@ // ==================================================================== // -use crate::constants::MAX_LENS_PARAMETER_COUNT; -use crate::cxxbridge::ffi::LensModelType as BindLensModelType; -use crate::cxxbridge::ffi::Parameters3deClassic as BindParameters3deClassic; - +mod tde_anamorphic_deg_4_rotate_squeeze_xy; +mod tde_anamorphic_deg_4_rotate_squeeze_xy_rescaled; +mod tde_anamorphic_deg_6_rotate_squeeze_xy; +mod tde_anamorphic_deg_6_rotate_squeeze_xy_rescaled; mod tde_classic; +mod tde_radial_decentered_deg_4_cylindric; + +use rustc_hash::FxHasher; -impl BindLensParameters { - pub fn new() -> BindLensParameters { - BindLensParameters { - mode: BindLensModelType::Uninitialized, - values: [0.0; MAX_LENS_PARAMETER_COUNT], - } - } +pub trait LensParameters { + fn hash_parameters(&self, state: &mut FxHasher); + fn from_slice(data: &[f64]) -> Self; + fn into_args(self) -> Vec; +} - pub fn as_tde_classic(&self) -> BindParameters3deClassic { - if self.mode != BindLensModelType::TdeClassic { - BindParameters3deClassic::default() - } else { - BindParameters3deClassic::new( - self.values[0], - self.values[1], - self.values[2], - self.values[3], - self.values[4], - ) - } - } +#[macro_export] +macro_rules! impl_LensParameters_hash_parameters_method { + ($($field:ident),*) => { + fn hash_parameters(&self, state: &mut rustc_hash::FxHasher) { + $( + crate::hash_float::HashableF64::new(self.$field).hash(state); + )* + } + }; } diff --git a/lib/cppbind/mmlens/src/lens_parameters/tde_anamorphic_deg_4_rotate_squeeze_xy.rs b/lib/cppbind/mmlens/src/lens_parameters/tde_anamorphic_deg_4_rotate_squeeze_xy.rs new file mode 100644 index 00000000..c306ce25 --- /dev/null +++ b/lib/cppbind/mmlens/src/lens_parameters/tde_anamorphic_deg_4_rotate_squeeze_xy.rs @@ -0,0 +1,98 @@ +// +// Copyright (C) 2023, 2024 David Cattermole. +// +// This file is part of mmSolver. +// +// mmSolver is free software: you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// mmSolver is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with mmSolver. If not, see . +// ==================================================================== +// +/// 3DE Anamorphic Standard Degree 4 +use crate::cxxbridge::ffi::Parameters3deAnamorphicStdDeg4 as BindParameters3deAnamorphicStdDeg4; +use crate::impl_LensParameters_hash_parameters_method; +use crate::lens_parameters::LensParameters; +use std::hash::Hash; + +impl Default for BindParameters3deAnamorphicStdDeg4 { + fn default() -> Self { + Self { + degree2_cx02: 0.0, + degree2_cy02: 0.0, + degree2_cx22: 0.0, + degree2_cy22: 0.0, + degree4_cx04: 0.0, + degree4_cy04: 0.0, + degree4_cx24: 0.0, + degree4_cy24: 0.0, + degree4_cx44: 0.0, + degree4_cy44: 0.0, + lens_rotation: 0.0, + squeeze_x: 1.0, + squeeze_y: 1.0, + } + } +} + +impl LensParameters for BindParameters3deAnamorphicStdDeg4 { + impl_LensParameters_hash_parameters_method!( + degree2_cx02, + degree2_cy02, + degree2_cx22, + degree2_cy22, + degree4_cx04, + degree4_cy04, + degree4_cx24, + degree4_cy24, + degree4_cx44, + degree4_cy44, + lens_rotation, + squeeze_x, + squeeze_y + ); + + fn from_slice(data: &[f64]) -> Self { + Self { + degree2_cx02: data[0], + degree2_cy02: data[1], + degree2_cx22: data[2], + degree2_cy22: data[3], + degree4_cx04: data[4], + degree4_cy04: data[5], + degree4_cx24: data[6], + degree4_cy24: data[7], + degree4_cx44: data[8], + degree4_cy44: data[9], + lens_rotation: data[10], + squeeze_x: data[11], + squeeze_y: data[12], + } + } + + fn into_args(self) -> Vec { + vec![ + self.degree2_cx02, + self.degree2_cy02, + self.degree2_cx22, + self.degree2_cy22, + self.degree4_cx04, + self.degree4_cy04, + self.degree4_cx24, + self.degree4_cy24, + self.degree4_cx44, + self.degree4_cy44, + self.lens_rotation, + self.squeeze_x, + self.squeeze_y, + ] + } +} diff --git a/lib/cppbind/mmlens/src/lens_parameters/tde_anamorphic_deg_4_rotate_squeeze_xy_rescaled.rs b/lib/cppbind/mmlens/src/lens_parameters/tde_anamorphic_deg_4_rotate_squeeze_xy_rescaled.rs new file mode 100644 index 00000000..67039813 --- /dev/null +++ b/lib/cppbind/mmlens/src/lens_parameters/tde_anamorphic_deg_4_rotate_squeeze_xy_rescaled.rs @@ -0,0 +1,102 @@ +// +// Copyright (C) 2023, 2024 David Cattermole. +// +// This file is part of mmSolver. +// +// mmSolver is free software: you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// mmSolver is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with mmSolver. If not, see . +// ==================================================================== +// +/// 3DE Anamorphic Standard Degree 4 Rescaled +use crate::cxxbridge::ffi::Parameters3deAnamorphicStdDeg4Rescaled as BindParameters3deAnamorphicStdDeg4Rescaled; +use crate::impl_LensParameters_hash_parameters_method; +use crate::lens_parameters::LensParameters; +use std::hash::Hash; + +impl Default for BindParameters3deAnamorphicStdDeg4Rescaled { + fn default() -> Self { + Self { + degree2_cx02: 0.0, + degree2_cy02: 0.0, + degree2_cx22: 0.0, + degree2_cy22: 0.0, + degree4_cx04: 0.0, + degree4_cy04: 0.0, + degree4_cx24: 0.0, + degree4_cy24: 0.0, + degree4_cx44: 0.0, + degree4_cy44: 0.0, + lens_rotation: 0.0, + squeeze_x: 1.0, + squeeze_y: 1.0, + rescale: 1.0, + } + } +} + +impl LensParameters for BindParameters3deAnamorphicStdDeg4Rescaled { + impl_LensParameters_hash_parameters_method!( + degree2_cx02, + degree2_cy02, + degree2_cx22, + degree2_cy22, + degree4_cx04, + degree4_cy04, + degree4_cx24, + degree4_cy24, + degree4_cx44, + degree4_cy44, + lens_rotation, + squeeze_x, + squeeze_y, + rescale + ); + + fn from_slice(data: &[f64]) -> Self { + Self { + degree2_cx02: data[0], + degree2_cy02: data[1], + degree2_cx22: data[2], + degree2_cy22: data[3], + degree4_cx04: data[4], + degree4_cy04: data[5], + degree4_cx24: data[6], + degree4_cy24: data[7], + degree4_cx44: data[8], + degree4_cy44: data[9], + lens_rotation: data[10], + squeeze_x: data[11], + squeeze_y: data[12], + rescale: data[13], + } + } + + fn into_args(self) -> Vec { + vec![ + self.degree2_cx02, + self.degree2_cy02, + self.degree2_cx22, + self.degree2_cy22, + self.degree4_cx04, + self.degree4_cy04, + self.degree4_cx24, + self.degree4_cy24, + self.degree4_cx44, + self.degree4_cy44, + self.lens_rotation, + self.squeeze_x, + self.squeeze_y, + self.rescale, + ] + } +} diff --git a/lib/cppbind/mmlens/src/lens_parameters/tde_anamorphic_deg_6_rotate_squeeze_xy.rs b/lib/cppbind/mmlens/src/lens_parameters/tde_anamorphic_deg_6_rotate_squeeze_xy.rs new file mode 100644 index 00000000..998d5389 --- /dev/null +++ b/lib/cppbind/mmlens/src/lens_parameters/tde_anamorphic_deg_6_rotate_squeeze_xy.rs @@ -0,0 +1,130 @@ +// +// Copyright (C) 2023, 2024 David Cattermole. +// +// This file is part of mmSolver. +// +// mmSolver is free software: you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// mmSolver is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with mmSolver. If not, see . +// ==================================================================== +// +/// 3DE Anamorphic Standard Degree 6 +use crate::cxxbridge::ffi::Parameters3deAnamorphicStdDeg6 as BindParameters3deAnamorphicStdDeg6; +use crate::impl_LensParameters_hash_parameters_method; +use crate::lens_parameters::LensParameters; +use std::hash::Hash; + +impl Default for BindParameters3deAnamorphicStdDeg6 { + fn default() -> Self { + Self { + degree2_cx02: 0.0, + degree2_cy02: 0.0, + degree2_cx22: 0.0, + degree2_cy22: 0.0, + degree4_cx04: 0.0, + degree4_cy04: 0.0, + degree4_cx24: 0.0, + degree4_cy24: 0.0, + degree4_cx44: 0.0, + degree4_cy44: 0.0, + degree6_cx06: 0.0, + degree6_cy06: 0.0, + degree6_cx26: 0.0, + degree6_cy26: 0.0, + degree6_cx46: 0.0, + degree6_cy46: 0.0, + degree6_cx66: 0.0, + degree6_cy66: 0.0, + lens_rotation: 0.0, + squeeze_x: 1.0, + squeeze_y: 1.0, + } + } +} + +impl LensParameters for BindParameters3deAnamorphicStdDeg6 { + impl_LensParameters_hash_parameters_method!( + degree2_cx02, + degree2_cy02, + degree2_cx22, + degree2_cy22, + degree4_cx04, + degree4_cy04, + degree4_cx24, + degree4_cy24, + degree4_cx44, + degree4_cy44, + degree6_cx06, + degree6_cy06, + degree6_cx26, + degree6_cy26, + degree6_cx46, + degree6_cy46, + degree6_cx66, + degree6_cy66, + lens_rotation, + squeeze_x, + squeeze_y + ); + + fn from_slice(data: &[f64]) -> Self { + Self { + degree2_cx02: data[0], + degree2_cy02: data[1], + degree2_cx22: data[2], + degree2_cy22: data[3], + degree4_cx04: data[4], + degree4_cy04: data[5], + degree4_cx24: data[6], + degree4_cy24: data[7], + degree4_cx44: data[8], + degree4_cy44: data[9], + degree6_cx06: data[10], + degree6_cy06: data[11], + degree6_cx26: data[12], + degree6_cy26: data[13], + degree6_cx46: data[14], + degree6_cy46: data[15], + degree6_cx66: data[16], + degree6_cy66: data[17], + lens_rotation: data[18], + squeeze_x: data[19], + squeeze_y: data[20], + } + } + + fn into_args(self) -> Vec { + vec![ + self.degree2_cx02, + self.degree2_cy02, + self.degree2_cx22, + self.degree2_cy22, + self.degree4_cx04, + self.degree4_cy04, + self.degree4_cx24, + self.degree4_cy24, + self.degree4_cx44, + self.degree4_cy44, + self.degree6_cx06, + self.degree6_cy06, + self.degree6_cx26, + self.degree6_cy26, + self.degree6_cx46, + self.degree6_cy46, + self.degree6_cx66, + self.degree6_cy66, + self.lens_rotation, + self.squeeze_x, + self.squeeze_y, + ] + } +} diff --git a/lib/cppbind/mmlens/src/lens_parameters/tde_anamorphic_deg_6_rotate_squeeze_xy_rescaled.rs b/lib/cppbind/mmlens/src/lens_parameters/tde_anamorphic_deg_6_rotate_squeeze_xy_rescaled.rs new file mode 100644 index 00000000..3a8df327 --- /dev/null +++ b/lib/cppbind/mmlens/src/lens_parameters/tde_anamorphic_deg_6_rotate_squeeze_xy_rescaled.rs @@ -0,0 +1,134 @@ +// +// Copyright (C) 2023, 2024 David Cattermole. +// +// This file is part of mmSolver. +// +// mmSolver is free software: you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// mmSolver is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with mmSolver. If not, see . +// ==================================================================== +// +/// 3DE Anamorphic Standard Degree 6 Rescaled +use crate::cxxbridge::ffi::Parameters3deAnamorphicStdDeg6Rescaled as BindParameters3deAnamorphicStdDeg6Rescaled; +use crate::impl_LensParameters_hash_parameters_method; +use crate::lens_parameters::LensParameters; +use std::hash::Hash; + +impl Default for BindParameters3deAnamorphicStdDeg6Rescaled { + fn default() -> Self { + Self { + degree2_cx02: 0.0, + degree2_cy02: 0.0, + degree2_cx22: 0.0, + degree2_cy22: 0.0, + degree4_cx04: 0.0, + degree4_cy04: 0.0, + degree4_cx24: 0.0, + degree4_cy24: 0.0, + degree4_cx44: 0.0, + degree4_cy44: 0.0, + degree6_cx06: 0.0, + degree6_cy06: 0.0, + degree6_cx26: 0.0, + degree6_cy26: 0.0, + degree6_cx46: 0.0, + degree6_cy46: 0.0, + degree6_cx66: 0.0, + degree6_cy66: 0.0, + lens_rotation: 0.0, + squeeze_x: 1.0, + squeeze_y: 1.0, + rescale: 1.0, + } + } +} + +impl LensParameters for BindParameters3deAnamorphicStdDeg6Rescaled { + impl_LensParameters_hash_parameters_method!( + degree2_cx02, + degree2_cy02, + degree2_cx22, + degree2_cy22, + degree4_cx04, + degree4_cy04, + degree4_cx24, + degree4_cy24, + degree4_cx44, + degree4_cy44, + degree6_cx06, + degree6_cy06, + degree6_cx26, + degree6_cy26, + degree6_cx46, + degree6_cy46, + degree6_cx66, + degree6_cy66, + lens_rotation, + squeeze_x, + squeeze_y, + rescale + ); + + fn from_slice(data: &[f64]) -> Self { + Self { + degree2_cx02: data[0], + degree2_cy02: data[1], + degree2_cx22: data[2], + degree2_cy22: data[3], + degree4_cx04: data[4], + degree4_cy04: data[5], + degree4_cx24: data[6], + degree4_cy24: data[7], + degree4_cx44: data[8], + degree4_cy44: data[9], + degree6_cx06: data[10], + degree6_cy06: data[11], + degree6_cx26: data[12], + degree6_cy26: data[13], + degree6_cx46: data[14], + degree6_cy46: data[15], + degree6_cx66: data[16], + degree6_cy66: data[17], + lens_rotation: data[18], + squeeze_x: data[19], + squeeze_y: data[20], + rescale: data[21], + } + } + + fn into_args(self) -> Vec { + vec![ + self.degree2_cx02, + self.degree2_cy02, + self.degree2_cx22, + self.degree2_cy22, + self.degree4_cx04, + self.degree4_cy04, + self.degree4_cx24, + self.degree4_cy24, + self.degree4_cx44, + self.degree4_cy44, + self.degree6_cx06, + self.degree6_cy06, + self.degree6_cx26, + self.degree6_cy26, + self.degree6_cx46, + self.degree6_cy46, + self.degree6_cx66, + self.degree6_cy66, + self.lens_rotation, + self.squeeze_x, + self.squeeze_y, + self.rescale, + ] + } +} diff --git a/lib/cppbind/mmlens/src/lens_parameters/tde_classic.rs b/lib/cppbind/mmlens/src/lens_parameters/tde_classic.rs index c32e720c..b29ee1f3 100644 --- a/lib/cppbind/mmlens/src/lens_parameters/tde_classic.rs +++ b/lib/cppbind/mmlens/src/lens_parameters/tde_classic.rs @@ -1,5 +1,5 @@ // -// Copyright (C) 2023 David Cattermole. +// Copyright (C) 2023, 2024 David Cattermole. // // This file is part of mmSolver. // @@ -17,28 +17,15 @@ // along with mmSolver. If not, see . // ==================================================================== // - +/// 3DE Classic use crate::cxxbridge::ffi::Parameters3deClassic as BindParameters3deClassic; +use crate::impl_LensParameters_hash_parameters_method; +use crate::lens_parameters::LensParameters; +use std::hash::Hash; -impl BindParameters3deClassic { - pub fn new( - distortion: f64, - anamorphic_squeeze: f64, - curvature_x: f64, - curvature_y: f64, - quartic_distortion: f64, - ) -> BindParameters3deClassic { - BindParameters3deClassic { - distortion, - anamorphic_squeeze, - curvature_x, - curvature_y, - quartic_distortion, - } - } - - pub fn default() -> BindParameters3deClassic { - BindParameters3deClassic { +impl Default for BindParameters3deClassic { + fn default() -> Self { + Self { distortion: 0.0, anamorphic_squeeze: 1.0, curvature_x: 0.0, @@ -47,3 +34,33 @@ impl BindParameters3deClassic { } } } + +impl LensParameters for BindParameters3deClassic { + impl_LensParameters_hash_parameters_method!( + distortion, + anamorphic_squeeze, + curvature_x, + curvature_y, + quartic_distortion + ); + + fn from_slice(data: &[f64]) -> Self { + Self { + distortion: data[0], + anamorphic_squeeze: data[1], + curvature_x: data[2], + curvature_y: data[3], + quartic_distortion: data[4], + } + } + + fn into_args(self) -> Vec { + vec![ + self.distortion, + self.anamorphic_squeeze, + self.curvature_x, + self.curvature_y, + self.quartic_distortion, + ] + } +} diff --git a/lib/cppbind/mmlens/src/lens_parameters/tde_radial_decentered_deg_4_cylindric.rs b/lib/cppbind/mmlens/src/lens_parameters/tde_radial_decentered_deg_4_cylindric.rs new file mode 100644 index 00000000..cc63c517 --- /dev/null +++ b/lib/cppbind/mmlens/src/lens_parameters/tde_radial_decentered_deg_4_cylindric.rs @@ -0,0 +1,78 @@ +// +// Copyright (C) 2023, 2024 David Cattermole. +// +// This file is part of mmSolver. +// +// mmSolver is free software: you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// mmSolver is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with mmSolver. If not, see . +// ==================================================================== +// +/// 3DE Radial Standard Degree 4 +use crate::cxxbridge::ffi::Parameters3deRadialStdDeg4 as BindParameters3deRadialStdDeg4; +use crate::impl_LensParameters_hash_parameters_method; +use crate::lens_parameters::LensParameters; +use std::hash::Hash; + +impl Default for BindParameters3deRadialStdDeg4 { + fn default() -> Self { + Self { + degree2_distortion: 0.0, + degree2_u: 0.0, + degree2_v: 0.0, + degree4_distortion: 0.0, + degree4_u: 0.0, + degree4_v: 0.0, + cylindric_direction: 0.0, + cylindric_bending: 0.0, + } + } +} + +impl LensParameters for BindParameters3deRadialStdDeg4 { + impl_LensParameters_hash_parameters_method!( + degree2_distortion, + degree2_u, + degree2_v, + degree4_distortion, + degree4_u, + degree4_v, + cylindric_direction, + cylindric_bending + ); + + fn from_slice(data: &[f64]) -> Self { + Self { + degree2_distortion: data[0], + degree2_u: data[1], + degree2_v: data[2], + degree4_distortion: data[3], + degree4_u: data[4], + degree4_v: data[5], + cylindric_direction: data[6], + cylindric_bending: data[7], + } + } + + fn into_args(self) -> Vec { + vec![ + self.degree2_distortion, + self.degree2_u, + self.degree2_v, + self.degree4_distortion, + self.degree4_u, + self.degree4_v, + self.cylindric_direction, + self.cylindric_bending, + ] + } +} diff --git a/lib/cppbind/mmlens/src/lib.rs b/lib/cppbind/mmlens/src/lib.rs index e9c4eff2..04600f67 100644 --- a/lib/cppbind/mmlens/src/lib.rs +++ b/lib/cppbind/mmlens/src/lib.rs @@ -25,4 +25,5 @@ mod distortion_layers; mod distortion_process; mod hash_float; mod lens_io; +mod lens_parameters; mod option_lens_parameters; diff --git a/lib/cppbind/mmlens/src/option_lens_parameters.rs b/lib/cppbind/mmlens/src/option_lens_parameters.rs index 9e605608..46d51c3b 100644 --- a/lib/cppbind/mmlens/src/option_lens_parameters.rs +++ b/lib/cppbind/mmlens/src/option_lens_parameters.rs @@ -18,379 +18,82 @@ // ==================================================================== // -use crate::cxxbridge::ffi::OptionParameters3deAnamorphicStdDeg4; -use crate::cxxbridge::ffi::OptionParameters3deAnamorphicStdDeg4Rescaled; -use crate::cxxbridge::ffi::OptionParameters3deAnamorphicStdDeg6; -use crate::cxxbridge::ffi::OptionParameters3deAnamorphicStdDeg6Rescaled; -use crate::cxxbridge::ffi::OptionParameters3deClassic; -use crate::cxxbridge::ffi::OptionParameters3deRadialStdDeg4; -use crate::cxxbridge::ffi::Parameters3deAnamorphicStdDeg4; -use crate::cxxbridge::ffi::Parameters3deAnamorphicStdDeg4Rescaled; -use crate::cxxbridge::ffi::Parameters3deAnamorphicStdDeg6; -use crate::cxxbridge::ffi::Parameters3deAnamorphicStdDeg6Rescaled; -use crate::cxxbridge::ffi::Parameters3deClassic; -use crate::cxxbridge::ffi::Parameters3deRadialStdDeg4; +use crate::cxxbridge::ffi::OptionParameters3deAnamorphicStdDeg4 as BindOptionParameters3deAnamorphicStdDeg4; +use crate::cxxbridge::ffi::OptionParameters3deAnamorphicStdDeg4Rescaled as BindOptionParameters3deAnamorphicStdDeg4Rescaled; +use crate::cxxbridge::ffi::OptionParameters3deAnamorphicStdDeg6 as BindOptionParameters3deAnamorphicStdDeg6; +use crate::cxxbridge::ffi::OptionParameters3deAnamorphicStdDeg6Rescaled as BindOptionParameters3deAnamorphicStdDeg6Rescaled; +use crate::cxxbridge::ffi::OptionParameters3deClassic as BindOptionParameters3deClassic; +use crate::cxxbridge::ffi::OptionParameters3deRadialStdDeg4 as BindOptionParameters3deRadialStdDeg4; -impl OptionParameters3deClassic { - pub fn new_as_none() -> OptionParameters3deClassic { - OptionParameters3deClassic { - exists: false, - value: Parameters3deClassic { - distortion: 0.0, - anamorphic_squeeze: 1.0, - curvature_x: 0.0, - curvature_y: 0.0, - quartic_distortion: 0.0, - }, - } - } +use crate::cxxbridge::ffi::Parameters3deAnamorphicStdDeg4 as BindParameters3deAnamorphicStdDeg4; +use crate::cxxbridge::ffi::Parameters3deAnamorphicStdDeg4Rescaled as BindParameters3deAnamorphicStdDeg4Rescaled; +use crate::cxxbridge::ffi::Parameters3deAnamorphicStdDeg6 as BindParameters3deAnamorphicStdDeg6; +use crate::cxxbridge::ffi::Parameters3deAnamorphicStdDeg6Rescaled as BindParameters3deAnamorphicStdDeg6Rescaled; +use crate::cxxbridge::ffi::Parameters3deClassic as BindParameters3deClassic; +use crate::cxxbridge::ffi::Parameters3deRadialStdDeg4 as BindParameters3deRadialStdDeg4; - pub fn new_as_some( - distortion: f64, - anamorphic_squeeze: f64, +use crate::lens_parameters::LensParameters; - curvature_x: f64, - curvature_y: f64, - quartic_distortion: f64, - ) -> OptionParameters3deClassic { - OptionParameters3deClassic { - exists: true, - value: Parameters3deClassic { - distortion, - anamorphic_squeeze, - curvature_x, - curvature_y, - quartic_distortion, - }, - } - } -} +/// A trait for optional parameters with an existence flag. +pub trait OptionParametersTrait { + type InnerType; -impl OptionParameters3deRadialStdDeg4 { - pub fn new_as_none() -> OptionParameters3deRadialStdDeg4 { - OptionParameters3deRadialStdDeg4 { - exists: false, - value: Parameters3deRadialStdDeg4 { - degree2_distortion: 0.0, - degree2_u: 0.0, - degree2_v: 0.0, - degree4_distortion: 0.0, - degree4_u: 0.0, - degree4_v: 0.0, - cylindric_direction: 0.0, - cylindric_bending: 0.0, - }, - } - } + /// Create a new instance with no value + fn new_as_none() -> Self; - pub fn new_as_some( - degree2_distortion: f64, - degree2_u: f64, - degree2_v: f64, - degree4_distortion: f64, - degree4_u: f64, - degree4_v: f64, - cylindric_direction: f64, - cylindric_bending: f64, - ) -> OptionParameters3deRadialStdDeg4 { - OptionParameters3deRadialStdDeg4 { - exists: true, - value: Parameters3deRadialStdDeg4 { - degree2_distortion, - degree2_u, - degree2_v, - degree4_distortion, - degree4_u, - degree4_v, - cylindric_direction, - cylindric_bending, - }, - } - } + /// Create a new instance with a specific value + fn new_as_some_from_vec(args: &[f64]) -> Self; } -impl OptionParameters3deAnamorphicStdDeg4 { - pub fn new_as_none() -> OptionParameters3deAnamorphicStdDeg4 { - OptionParameters3deAnamorphicStdDeg4 { - exists: false, - value: Parameters3deAnamorphicStdDeg4 { - degree2_cx02: 0.0, - degree2_cy02: 0.0, - degree2_cx22: 0.0, - degree2_cy22: 0.0, - degree4_cx04: 0.0, - degree4_cy04: 0.0, - degree4_cx24: 0.0, - degree4_cy24: 0.0, - degree4_cx44: 0.0, - degree4_cy44: 0.0, - lens_rotation: 0.0, - squeeze_x: 1.0, - squeeze_y: 1.0, - }, - } - } +macro_rules! impl_option_parameters_trait { + ($option_type:ty, $inner_type:ty) => { + impl OptionParametersTrait for $option_type { + type InnerType = $inner_type; - pub fn new_as_some( - degree2_cx02: f64, - degree2_cy02: f64, - degree2_cx22: f64, - degree2_cy22: f64, - degree4_cx04: f64, - degree4_cy04: f64, - degree4_cx24: f64, - degree4_cy24: f64, - degree4_cx44: f64, - degree4_cy44: f64, - lens_rotation: f64, - squeeze_x: f64, - squeeze_y: f64, - ) -> OptionParameters3deAnamorphicStdDeg4 { - OptionParameters3deAnamorphicStdDeg4 { - exists: true, - value: Parameters3deAnamorphicStdDeg4 { - degree2_cx02, - degree2_cy02, - degree2_cx22, - degree2_cy22, - degree4_cx04, - degree4_cy04, - degree4_cx24, - degree4_cy24, - degree4_cx44, - degree4_cy44, - lens_rotation, - squeeze_x, - squeeze_y, - }, + fn new_as_none() -> Self { + let value: Self::InnerType = Default::default(); + Self { + exists: false, + value, + } + } + + fn new_as_some_from_vec(args: &[f64]) -> Self { + Self { + exists: true, + value: Self::InnerType::from_slice(args), + } + } } - } + }; } -impl OptionParameters3deAnamorphicStdDeg4Rescaled { - pub fn new_as_none() -> OptionParameters3deAnamorphicStdDeg4Rescaled { - OptionParameters3deAnamorphicStdDeg4Rescaled { - exists: false, - value: Parameters3deAnamorphicStdDeg4Rescaled { - degree2_cx02: 0.0, - degree2_cy02: 0.0, - degree2_cx22: 0.0, - degree2_cy22: 0.0, - degree4_cx04: 0.0, - degree4_cy04: 0.0, - degree4_cx24: 0.0, - degree4_cy24: 0.0, - degree4_cx44: 0.0, - degree4_cy44: 0.0, - lens_rotation: 0.0, - squeeze_x: 1.0, - squeeze_y: 1.0, - rescale: 1.0, - }, - } - } +impl_option_parameters_trait!( + BindOptionParameters3deClassic, + BindParameters3deClassic +); - pub fn new_as_some( - degree2_cx02: f64, - degree2_cy02: f64, - degree2_cx22: f64, - degree2_cy22: f64, - degree4_cx04: f64, - degree4_cy04: f64, - degree4_cx24: f64, - degree4_cy24: f64, - degree4_cx44: f64, - degree4_cy44: f64, - lens_rotation: f64, - squeeze_x: f64, - squeeze_y: f64, - rescale: f64, - ) -> OptionParameters3deAnamorphicStdDeg4Rescaled { - OptionParameters3deAnamorphicStdDeg4Rescaled { - exists: true, - value: Parameters3deAnamorphicStdDeg4Rescaled { - degree2_cx02, - degree2_cy02, - degree2_cx22, - degree2_cy22, - degree4_cx04, - degree4_cy04, - degree4_cx24, - degree4_cy24, - degree4_cx44, - degree4_cy44, - lens_rotation, - squeeze_x, - squeeze_y, - rescale, - }, - } - } -} +impl_option_parameters_trait!( + BindOptionParameters3deRadialStdDeg4, + BindParameters3deRadialStdDeg4 +); -impl OptionParameters3deAnamorphicStdDeg6 { - pub fn new_as_none() -> OptionParameters3deAnamorphicStdDeg6 { - OptionParameters3deAnamorphicStdDeg6 { - exists: false, - value: Parameters3deAnamorphicStdDeg6 { - degree2_cx02: 0.0, - degree2_cy02: 0.0, - degree2_cx22: 0.0, - degree2_cy22: 0.0, - degree4_cx04: 0.0, - degree4_cy04: 0.0, - degree4_cx24: 0.0, - degree4_cy24: 0.0, - degree4_cx44: 0.0, - degree4_cy44: 0.0, - degree6_cx06: 0.0, - degree6_cy06: 0.0, - degree6_cx26: 0.0, - degree6_cy26: 0.0, - degree6_cx46: 0.0, - degree6_cy46: 0.0, - degree6_cx66: 0.0, - degree6_cy66: 0.0, - lens_rotation: 0.0, - squeeze_x: 1.0, - squeeze_y: 1.0, - }, - } - } +impl_option_parameters_trait!( + BindOptionParameters3deAnamorphicStdDeg4, + BindParameters3deAnamorphicStdDeg4 +); - pub fn new_as_some( - degree2_cx02: f64, - degree2_cy02: f64, - degree2_cx22: f64, - degree2_cy22: f64, - degree4_cx04: f64, - degree4_cy04: f64, - degree4_cx24: f64, - degree4_cy24: f64, - degree4_cx44: f64, - degree4_cy44: f64, - degree6_cx06: f64, - degree6_cy06: f64, - degree6_cx26: f64, - degree6_cy26: f64, - degree6_cx46: f64, - degree6_cy46: f64, - degree6_cx66: f64, - degree6_cy66: f64, - lens_rotation: f64, - squeeze_x: f64, - squeeze_y: f64, - ) -> OptionParameters3deAnamorphicStdDeg6 { - OptionParameters3deAnamorphicStdDeg6 { - exists: true, - value: Parameters3deAnamorphicStdDeg6 { - degree2_cx02, - degree2_cy02, - degree2_cx22, - degree2_cy22, - degree4_cx04, - degree4_cy04, - degree4_cx24, - degree4_cy24, - degree4_cx44, - degree4_cy44, - degree6_cx06, - degree6_cy06, - degree6_cx26, - degree6_cy26, - degree6_cx46, - degree6_cy46, - degree6_cx66, - degree6_cy66, - lens_rotation, - squeeze_x, - squeeze_y, - }, - } - } -} +impl_option_parameters_trait!( + BindOptionParameters3deAnamorphicStdDeg4Rescaled, + BindParameters3deAnamorphicStdDeg4Rescaled +); -impl OptionParameters3deAnamorphicStdDeg6Rescaled { - pub fn new_as_none() -> OptionParameters3deAnamorphicStdDeg6Rescaled { - OptionParameters3deAnamorphicStdDeg6Rescaled { - exists: false, - value: Parameters3deAnamorphicStdDeg6Rescaled { - degree2_cx02: 0.0, - degree2_cy02: 0.0, - degree2_cx22: 0.0, - degree2_cy22: 0.0, - degree4_cx04: 0.0, - degree4_cy04: 0.0, - degree4_cx24: 0.0, - degree4_cy24: 0.0, - degree4_cx44: 0.0, - degree4_cy44: 0.0, - degree6_cx06: 0.0, - degree6_cy06: 0.0, - degree6_cx26: 0.0, - degree6_cy26: 0.0, - degree6_cx46: 0.0, - degree6_cy46: 0.0, - degree6_cx66: 0.0, - degree6_cy66: 0.0, - lens_rotation: 0.0, - squeeze_x: 1.0, - squeeze_y: 1.0, - rescale: 1.0, - }, - } - } +impl_option_parameters_trait!( + BindOptionParameters3deAnamorphicStdDeg6, + BindParameters3deAnamorphicStdDeg6 +); - pub fn new_as_some( - degree2_cx02: f64, - degree2_cy02: f64, - degree2_cx22: f64, - degree2_cy22: f64, - degree4_cx04: f64, - degree4_cy04: f64, - degree4_cx24: f64, - degree4_cy24: f64, - degree4_cx44: f64, - degree4_cy44: f64, - degree6_cx06: f64, - degree6_cy06: f64, - degree6_cx26: f64, - degree6_cy26: f64, - degree6_cx46: f64, - degree6_cy46: f64, - degree6_cx66: f64, - degree6_cy66: f64, - lens_rotation: f64, - squeeze_x: f64, - squeeze_y: f64, - rescale: f64, - ) -> OptionParameters3deAnamorphicStdDeg6Rescaled { - OptionParameters3deAnamorphicStdDeg6Rescaled { - exists: true, - value: Parameters3deAnamorphicStdDeg6Rescaled { - degree2_cx02, - degree2_cy02, - degree2_cx22, - degree2_cy22, - degree4_cx04, - degree4_cy04, - degree4_cx24, - degree4_cy24, - degree4_cx44, - degree4_cy44, - degree6_cx06, - degree6_cy06, - degree6_cx26, - degree6_cy26, - degree6_cx46, - degree6_cy46, - degree6_cx66, - degree6_cy66, - lens_rotation, - squeeze_x, - squeeze_y, - rescale, - }, - } - } -} +impl_option_parameters_trait!( + BindOptionParameters3deAnamorphicStdDeg6Rescaled, + BindParameters3deAnamorphicStdDeg6Rescaled +);