public InverseSolverViewModel() { _showOpticalProperties = true; _useSpectralPanelData = false; _allRangeVMs = new[] { new RangeViewModel { Title = Resources.Strings.IndependentVariableAxis_Rho } }; SolutionDomainTypeOptionVM = new SolutionDomainOptionViewModel("Solution Domain", SolutionDomainType.ROfRho); SolutionDomainTypeOptionVM.EnableMultiAxis = false; SolutionDomainTypeOptionVM.AllowMultiAxis = false; Action<double> updateSolutionDomainWithWavelength = wv => { var wvAxis = SolutionDomainTypeOptionVM.ConstantAxesVMs.FirstOrDefault(axis => axis.AxisType == IndependentVariableAxis.Wavelength); if (wvAxis != null) { wvAxis.AxisValue = wv; } }; SolutionDomainTypeOptionVM.PropertyChanged += (sender, args) => { if (args.PropertyName == "UseSpectralInputs") { UseSpectralPanelData = SolutionDomainTypeOptionVM.UseSpectralInputs; } if (args.PropertyName == "IndependentAxesVMs") { var useSpectralPanelDataAndNotNull = UseSpectralPanelData && SolverDemoViewModel.Current != null && SolverDemoViewModel.Current.SpectralMappingVM != null; AllRangeVMs = (from i in Enumerable.Range(0, SolutionDomainTypeOptionVM.IndependentVariableAxisOptionVM.SelectedValues.Length) orderby i descending // descending so that wavelength takes highest priority, then time/time frequency, then space/spatial frequency select useSpectralPanelDataAndNotNull && SolutionDomainTypeOptionVM.IndependentVariableAxisOptionVM.SelectedValues[i] == IndependentVariableAxis.Wavelength ? SolverDemoViewModel.Current.SpectralMappingVM.WavelengthRangeVM // bind to same instance, not a copy : SolutionDomainTypeOptionVM.IndependentAxesVMs[i].AxisRangeVM).ToArray(); // if the independent axis is wavelength, then hide optical properties (because they come from spectral panel) ShowOpticalProperties = !_allRangeVMs.Any(value => value.AxisType == IndependentVariableAxis.Wavelength); // update solution domain wavelength constant if applicable if (useSpectralPanelDataAndNotNull && SolutionDomainTypeOptionVM.ConstantAxesVMs.Any(axis => axis.AxisType == IndependentVariableAxis.Wavelength)) { updateSolutionDomainWithWavelength(SolverDemoViewModel.Current.SpectralMappingVM.Wavelength); } } }; #if WHITELIST MeasuredForwardSolverTypeOptionVM = new OptionViewModel<ForwardSolverType>( "Forward Model Engine",false, WhiteList.InverseForwardSolverTypes); #else MeasuredForwardSolverTypeOptionVM = new OptionViewModel<ForwardSolverType>( "Forward Model Engine",false); #endif #if WHITELIST InverseForwardSolverTypeOptionVM = new OptionViewModel<ForwardSolverType>("Inverse Model Engine",false, WhiteList.InverseForwardSolverTypes); #else InverseForwardSolverTypeOptionVM = new OptionViewModel<ForwardSolverType>("Inverse Model Engine", false); #endif InverseForwardSolverTypeOptionVM.PropertyChanged += (sender, args) => OnPropertyChanged("InverseForwardSolver"); OptimizerTypeOptionVM = new OptionViewModel<OptimizerType>("Optimizer Type", true); OptimizerTypeOptionVM.PropertyChanged += (sender, args) => OnPropertyChanged("Optimizer"); InverseFitTypeOptionVM = new OptionViewModel<InverseFitType>("Optimization Parameters", true); MeasuredOpticalPropertyVM = new OpticalPropertyViewModel() { Title = "" }; InitialGuessOpticalPropertyVM = new OpticalPropertyViewModel() { Title = "" }; ResultOpticalPropertyVM = new OpticalPropertyViewModel() { Title = "" }; SimulateMeasuredDataCommand = new RelayCommand(() => SimulateMeasuredDataCommand_Executed(null, null)); CalculateInitialGuessCommand = new RelayCommand(() => CalculateInitialGuessCommand_Executed(null, null)); SolveInverseCommand = new RelayCommand(() => SolveInverseCommand_Executed(null, null)); Commands.Spec_UpdateWavelength.Executed += (sender, args) => { //need to get the value from the checkbox in case UseSpectralPanelData has not yet been updated if (SolutionDomainTypeOptionVM != null) { UseSpectralPanelData = SolutionDomainTypeOptionVM.UseSpectralInputs; } if (UseSpectralPanelData && SolverDemoViewModel.Current != null && SolverDemoViewModel.Current.SpectralMappingVM != null) { updateSolutionDomainWithWavelength(SolverDemoViewModel.Current.SpectralMappingVM.Wavelength); } }; Commands.Spec_UpdateOpticalProperties.Executed += (sender, args) => { //need to get the value from the checkbox in case UseSpectralPanelData has not yet been updated if (SolutionDomainTypeOptionVM != null) { UseSpectralPanelData = SolutionDomainTypeOptionVM.UseSpectralInputs; } if (UseSpectralPanelData && SolverDemoViewModel.Current != null && SolverDemoViewModel.Current.SpectralMappingVM != null) { //if (IsMultiRegion && MultiRegionTissueVM != null) //{ // MultiRegionTissueVM.RegionsVM.ForEach(region => // ((dynamic)region).OpticalPropertyVM.SetOpticalProperties( // SolverDemoViewModel.Current.SpectralMappingVM.OpticalProperties)); //} //else if (MeasuredOpticalPropertyVM != null) { MeasuredOpticalPropertyVM.SetOpticalProperties(SolverDemoViewModel.Current.SpectralMappingVM.OpticalProperties); } } }; }
public ForwardSolverViewModel() { _showOpticalProperties = true; _useSpectralPanelData = false; _allRangeVMs = new[] { new RangeViewModel { Title = Resources.Strings.IndependentVariableAxis_Rho } }; #if WHITELIST ForwardSolverTypeOptionVM = new OptionViewModel <ForwardSolverType>("Forward Model", false, WhiteList.ForwardSolverTypes); #else ForwardSolverTypeOptionVM = new OptionViewModel <ForwardSolverType>("Forward Model", false); #endif SolutionDomainTypeOptionVM = new SolutionDomainOptionViewModel("Solution Domain", SolutionDomainType.ROfRho); ForwardAnalysisTypeOptionVM = new OptionViewModel <ForwardAnalysisType>("Model/Analysis Output", true); ForwardSolverTypeOptionVM.PropertyChanged += (sender, args) => { OnPropertyChanged("IsGaussianForwardModel"); OnPropertyChanged("ForwardSolver"); OnPropertyChanged("IsMultiRegion"); OnPropertyChanged("IsSemiInfinite"); TissueInputVM = GetTissueInputVM(IsMultiRegion ? "MultiLayer" : "SemiInfinite"); if (SolutionDomainTypeOptionVM != null) { if (ForwardSolverTypeOptionVM.SelectedValue == ForwardSolverType.TwoLayerSDA) { SolutionDomainTypeOptionVM.AllowMultiAxis = false; SolutionDomainTypeOptionVM.UseSpectralInputs = false; } SolutionDomainTypeOptionVM.EnableMultiAxis = ForwardSolverTypeOptionVM.SelectedValue != ForwardSolverType.TwoLayerSDA; SolutionDomainTypeOptionVM.EnableSpectralPanelInputs = ForwardSolverTypeOptionVM.SelectedValue != ForwardSolverType.TwoLayerSDA; } if (ForwardAnalysisTypeOptionVM != null) { if (ForwardSolverTypeOptionVM.SelectedValue == ForwardSolverType.TwoLayerSDA) { ForwardAnalysisTypeOptionVM.Options[ForwardAnalysisType.R].IsSelected = true; } ForwardAnalysisTypeOptionVM.Options[ForwardAnalysisType.dRdMua].IsEnabled = ForwardSolverTypeOptionVM.SelectedValue != ForwardSolverType.TwoLayerSDA; ForwardAnalysisTypeOptionVM.Options[ForwardAnalysisType.dRdMusp].IsEnabled = ForwardSolverTypeOptionVM.SelectedValue != ForwardSolverType.TwoLayerSDA; ForwardAnalysisTypeOptionVM.Options[ForwardAnalysisType.dRdG].IsEnabled = ForwardSolverTypeOptionVM.SelectedValue != ForwardSolverType.TwoLayerSDA; ForwardAnalysisTypeOptionVM.Options[ForwardAnalysisType.dRdN].IsEnabled = ForwardSolverTypeOptionVM.SelectedValue != ForwardSolverType.TwoLayerSDA; } }; ForwardSolverTypeOptionVM.SelectedValue = ForwardSolverType.PointSourceSDA; // force the model choice here? Action <double> updateSolutionDomainWithWavelength = wv => { var wvAxis = SolutionDomainTypeOptionVM.ConstantAxesVMs.FirstOrDefault(axis => axis.AxisType == IndependentVariableAxis.Wavelength); if (wvAxis != null) { wvAxis.AxisValue = wv; } }; SolutionDomainTypeOptionVM.PropertyChanged += (sender, args) => { if (args.PropertyName == "UseSpectralInputs") { UseSpectralPanelData = SolutionDomainTypeOptionVM.UseSpectralInputs; } if (args.PropertyName == "IndependentAxesVMs") { var useSpectralPanelDataAndNotNull = SolutionDomainTypeOptionVM.UseSpectralInputs && SolverDemoViewModel.Current != null && SolverDemoViewModel.Current.SpectralMappingVM != null; AllRangeVMs = (from i in Enumerable.Range(0, SolutionDomainTypeOptionVM.IndependentVariableAxisOptionVM.SelectedValues.Length) orderby i descending // descending so that wavelength takes highest priority, then time/time frequency, then space/spatial frequency select useSpectralPanelDataAndNotNull&& SolutionDomainTypeOptionVM.IndependentVariableAxisOptionVM.SelectedValues[i] == IndependentVariableAxis.Wavelength ? SolverDemoViewModel.Current.SpectralMappingVM.WavelengthRangeVM // bind to same instance, not a copy : SolutionDomainTypeOptionVM.IndependentAxesVMs[i].AxisRangeVM).ToArray(); // if the independent axis is wavelength, then hide optical properties (because they come from spectral panel) ShowOpticalProperties = !_allRangeVMs.Any(value => value.AxisType == IndependentVariableAxis.Wavelength); // update solution domain wavelength constant if applicable if (useSpectralPanelDataAndNotNull && SolutionDomainTypeOptionVM.ConstantAxesVMs.Any(axis => axis.AxisType == IndependentVariableAxis.Wavelength)) { updateSolutionDomainWithWavelength(SolverDemoViewModel.Current.SpectralMappingVM.Wavelength); } } }; ExecuteForwardSolverCommand = new RelayCommand(() => ExecuteForwardSolver_Executed(null, null)); Commands.Spec_UpdateWavelength.Executed += (sender, args) => { //need to get the value from the checkbox in case UseSpectralPanelData has not yet been updated if (SolutionDomainTypeOptionVM != null) { UseSpectralPanelData = SolutionDomainTypeOptionVM.UseSpectralInputs; } if (UseSpectralPanelData && SolverDemoViewModel.Current != null && SolverDemoViewModel.Current.SpectralMappingVM != null) { updateSolutionDomainWithWavelength(SolverDemoViewModel.Current.SpectralMappingVM.Wavelength); } }; Commands.Spec_UpdateOpticalProperties.Executed += (sender, args) => { //need to get the value from the checkbox in case UseSpectralPanelData has not yet been updated if (SolutionDomainTypeOptionVM != null) { UseSpectralPanelData = SolutionDomainTypeOptionVM.UseSpectralInputs; } if (UseSpectralPanelData && SolverDemoViewModel.Current != null && SolverDemoViewModel.Current.SpectralMappingVM != null) { if (IsMultiRegion && MultiRegionTissueVM != null) { MultiRegionTissueVM.RegionsVM.ForEach(region => ((dynamic)region).OpticalPropertyVM.SetOpticalProperties( SolverDemoViewModel.Current.SpectralMappingVM.OpticalProperties)); } else if (OpticalPropertyVM != null) { OpticalPropertyVM.SetOpticalProperties(SolverDemoViewModel.Current.SpectralMappingVM.OpticalProperties); } } }; }