Exemplo n.º 1
0
 public LayerRegionViewModel(LayerTissueRegion region, string name)
 {
     _region            = region;
     _name              = name ?? "";
     _zRangeVM          = new RangeViewModel(_region.ZRange, StringLookup.GetLocalizedString("Measurement_mm"), IndependentVariableAxis.Z, "", false);
     _opticalPropertyVM = new OpticalPropertyViewModel(_region.RegionOP, StringLookup.GetLocalizedString("Measurement_Inv_mm"), "", true, true, true, true);
     _opticalPropertyVM.PropertyChanged += (s, a) => OnPropertyChanged("Name");
 }
Exemplo n.º 2
0
 public VoxelRegionViewModel(VoxelTissueRegion region, string name)
 {
     _region            = region;
     _name              = name ?? "";
     _opticalPropertyVM = new OpticalPropertyViewModel(_region.RegionOP, StringLookup.GetLocalizedString("Measurement_Inv_mm"), "", true, true, true, false);
 }
        public InverseSolverViewModel()
        {
            _showOpticalProperties = true;
            _useSpectralPanelData  = false;

            _allRangeVMs = new[] { new RangeViewModel {
                                       Title = 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 && WindowViewModel.Current != null &&
                                                         WindowViewModel.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
                                    ? WindowViewModel.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(WindowViewModel.Current.SpectralMappingVM.Wavelength);
                    }
                }
            };

#if WHITELIST
            MeasuredForwardSolverTypeOptionVM = new OptionViewModel <ForwardSolverType>(
                "Forward Model Engine", false, WhiteList.InverseForwardSolverTypes);
#else
            MeasuredForwardSolverTypeOptionVM = new OptionViewModel <ForwardSolverType>(
                "Forward Model Engine", false); //These titles are not diplayed so we can hard-code strings
#endif

#if WHITELIST
            InverseForwardSolverTypeOptionVM = new OptionViewModel <ForwardSolverType>("Inverse Model Engine", false, WhiteList.InverseForwardSolverTypes);
#else
            InverseForwardSolverTypeOptionVM = new OptionViewModel <ForwardSolverType>("Inverse Model Engine", false); //These titles are not diplayed so we can hard-code strings
#endif
            InverseForwardSolverTypeOptionVM.PropertyChanged += (sender, args) =>
                                                                OnPropertyChanged("InverseForwardSolver");

            OptimizerTypeOptionVM = new OptionViewModel <OptimizerType>(StringLookup.GetLocalizedString("Heading_OptimizerType"), true);
            OptimizerTypeOptionVM.PropertyChanged += (sender, args) =>
                                                     OnPropertyChanged("Optimizer");

            InverseFitTypeOptionVM = new OptionViewModel <InverseFitType>(StringLookup.GetLocalizedString("Heading_OptimizationParameters"), 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));

            if (WindowViewModel.Current.SpectralMappingVM != null)
            {
                WindowViewModel.Current.SpectralMappingVM.PropertyChanged += (sender, args) =>
                {
                    if (args.PropertyName == "Wavelength")
                    {
                        //need to get the value from the checkbox in case UseSpectralPanelData has not yet been updated
                        if (SolutionDomainTypeOptionVM != null)
                        {
                            UseSpectralPanelData = SolutionDomainTypeOptionVM.UseSpectralInputs;
                        }
                        if (UseSpectralPanelData && WindowViewModel.Current != null &&
                            WindowViewModel.Current.SpectralMappingVM != null)
                        {
                            updateSolutionDomainWithWavelength(WindowViewModel.Current.SpectralMappingVM.Wavelength);
                        }
                    }

                    if (args.PropertyName == "OpticalProperties")
                    {
                        //need to get the value from the checkbox in case UseSpectralPanelData has not yet been updated
                        if (SolutionDomainTypeOptionVM != null)
                        {
                            UseSpectralPanelData = SolutionDomainTypeOptionVM.UseSpectralInputs;
                        }
                        if (UseSpectralPanelData && WindowViewModel.Current != null &&
                            WindowViewModel.Current.SpectralMappingVM != null &&
                            MeasuredOpticalPropertyVM != null)
                        {
                            MeasuredOpticalPropertyVM.SetOpticalProperties(
                                WindowViewModel.Current.SpectralMappingVM.OpticalProperties);
                        }
                    }
                };
            }
        }