Commit e8ece769 authored by Francesco Carraro's avatar Francesco Carraro
Browse files

fixed fit of selected segment (now only selected segment is re-drawn)

parent 55ada495
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -112,17 +112,20 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart
            /* clear existing segments before creating new ones */
            var segmentsFitModelContainer = serviceProvider.GetRequiredService<SegmentsFitModelContainer>();

            SegmentFitModel newSegment = null;

            /* create segments starting from ordered points */
            var pointsNum = chart.Annotations.Count(x => x is CartesianCustomAnnotation);
            for (int i = 0; i < pointsNum - 1; i++)
            {
                segmentsFitModelContainer.tryAddSegment(orderedPoints.ElementAt(i).ToPointModel(), orderedPoints.ElementAt(i + 1).ToPointModel());
                /* try adding new segment, only the new segment is returned, if segment is already existant, then method returns null */
                var testNewSegment = segmentsFitModelContainer.tryAddSegment(orderedPoints.ElementAt(i).ToPointModel(), orderedPoints.ElementAt(i + 1).ToPointModel());
                if (testNewSegment != null)
                    newSegment = testNewSegment;
            }

            var viewModel = serviceProvider.GetRequiredService<ChartViewModel>();
            await viewModel.fitSegmentsAsync();
            /* await viewModel.fitSegmentsAsync(); 
             is automatically called by selection of 1st fit method in SegmentFitModel constructor */
            await viewModel.fitSelectedSegmentAsync(newSegment);
        }

        public void removePointsForContinuum(RadCartesianChart chart)
+1 −86
Original line number Diff line number Diff line
@@ -296,92 +296,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart.ProcessingHelpers
        }
        #endregion

        #region TEST continuum ALgLib
        //public async Task fitContinuumAsync(SpectrumModel continuumFittedSpectrum)
        //{
        //    SpectrumModel continuumFittedSpectrum = cloneSpectrum(SpectrumType.Continuum);
        //    if (continuumFittedSpectrum == null)
        //    {
        //        UpdateUIHelper.UpdateUIAsync(() =>
        //        {
        //            DialogMessageType = DialogMessageType.Warning;
        //            DialogMessage = "NoAlignedSpectrumAvailableWarningMessage".GetText();
        //            raiseIsDialogRequired();
        //        });
        //        return;
        //    }

        //    var splineFitHelper = serviceProvider.GetRequiredService<SplineFitHelper>();
        //    var rawSpectrum = workingItems.SpectraContainer.tryGetSpectrumOfType(SpectrumType.Raw);

        //    double[] xValues = rawSpectrum.getXvalues();
        //    //var spline1dinterpolant = splineFitHelper.buildSpline1DFitInterpolant(xValues, rawSpectrum.getYvalues());

        //    string exMsg = string.Empty;
        //    await Task.Run(() =>
        //    {
        //        //try
        //        //{
        //        //    int xValuesNum = xValues.Length;

        //        //    for (int i = 0; i < xValuesNum; i++)
        //        //    {
        //        //        continuumFittedSpectrum.Elements[i].updateY(splineFitHelper.getSpline1dValue(xValues[i], spline1dinterpolant));
        //        //    }
        //        //}
        //        //catch (Exception ex)
        //        //{
        //        //    exMsg = ex.Message;
        //        //    logger.Write<SpectrumProcessingHelper>($"{nameof(fitContinuumAsync)} - ex: {ex.Message}", Serilog.Events.LogEventLevel.Error);
        //        //}
        //    });

        //    if (string.IsNullOrEmpty(exMsg))
        //    {
        //        //Ioc.Default.GetRequiredService<ChartViewModel>().IsAddingPointsForContinuumRemovalAllowed = false;
        //        //workingItems.SpectraContainer.IsSpectrumContinuumRemoved = true;
        //        await workingItems.SpectraContainer.addOrUpdateSpectrumAsync(continuumFittedSpectrum);

        //        await workingItems.SpectraContainer.updateBoundariesAsync();
        //    }
        //    else
        //    {
        //        DialogMessage = exMsg;
        //        raiseIsDialogRequired();
        //    }
        //}

        //private T fitContinuum<T>(FitMethodModel fitMethod,
        //                          double[] x,
        //                          double[] y,
        //                          double? parameterValue = null)
        //{
        //    Type type = typeof(SplineFitHelper);

        //    MethodInfo methodInfo = type.GetMethod(fitMethod.MethodName);
        //    if (methodInfo == null)
        //        return default;

        //    object result = null;

        //    ParameterInfo[] parameters = methodInfo.GetParameters();
        //    object classInstance = Activator.CreateInstance(type, null);

        //    if (parameters.Length == 0)
        //        result = methodInfo.Invoke(classInstance, null);

        //    else
        //    {
        //        List<object> parametersList = new List<object>(new object[] { x, y });
        //        if (parameterValue != null)
        //            parametersList.Add((double)parameterValue);

        //        result = methodInfo.Invoke(classInstance, parametersList.ToArray());
        //    }

        //    return (T)result;
        //}

        #region fit continuum
        public async Task<ProcessingResult> fitContinuumProcedureAsync(SpectrumModel spectrumForContinuumRemoval,
                                                                       FitMethodModel fitMethod)
        {
+0 −7
Original line number Diff line number Diff line
@@ -241,9 +241,6 @@
    <Compile Include="Views\ContinuumAnalysisPage.xaml.cs">
      <DependentUpon>ContinuumAnalysisPage.xaml</DependentUpon>
    </Compile>
    <Compile Include="Views\ContinuumFitPage.xaml.cs">
      <DependentUpon>ContinuumFitPage.xaml</DependentUpon>
    </Compile>
    <Compile Include="Views\LoginCheckPage.xaml.cs">
      <DependentUpon>LoginCheckPage.xaml</DependentUpon>
    </Compile>
@@ -318,10 +315,6 @@
      <SubType>Designer</SubType>
      <Generator>MSBuild:Compile</Generator>
    </Page>
    <Page Include="Views\ContinuumFitPage.xaml">
      <SubType>Designer</SubType>
      <Generator>MSBuild:Compile</Generator>
    </Page>
    <Page Include="Views\LoginCheckPage.xaml">
      <SubType>Designer</SubType>
      <Generator>MSBuild:Compile</Generator>
+8 −2
Original line number Diff line number Diff line
@@ -71,13 +71,19 @@ namespace INAF.Apps.Uwp.SLabDataManager.Models.Fit
            }
        }

        public void tryAddSegment(PointModel p1, PointModel p2)
        public SegmentFitModel tryAddSegment(PointModel p1, PointModel p2)
        {
            SegmentFitModel newSegment = null;

            if (!SegmentsFitModels.Any(x => x.P1.X == p1.X && x.P2.X == p2.X))
            {
                SegmentsFitModels.Add(segmentFitModelsFactory.createSegmentFitModel(p1, p2));
                /* if not already existant, then add a new one... */
                newSegment = segmentFitModelsFactory.createSegmentFitModel(p1, p2);
                SegmentsFitModels.Add(newSegment);
                AreSegmentsAvailable = true;
            }

            return newSegment;
        }
        #endregion
    }
+6 −2
Original line number Diff line number Diff line
@@ -76,6 +76,12 @@ namespace INAF.Apps.Uwp.SLabDataManager.Models.Spectrum
                return (SolidColorBrush)Application.Current.Resources[colorkey.ToLowerInvariant()];
        }

        public void empty()
        {
            Elements.Clear();
            Elements = new ObservableCollection<ElementModel>();
        }

        public void setColor(SolidColorBrush color = null)
        {
            if (color != null)
@@ -118,8 +124,6 @@ namespace INAF.Apps.Uwp.SLabDataManager.Models.Spectrum
            foreach (var element in Elements)
                clonedSpectrum.add((ElementModel)element.Clone());



            return clonedSpectrum;
        }

Loading