public void OnAfterFittingStep()
        {
            if (_view != null)
            {
                _view.SetChiSquare(this._chiSquare);
            }



            if (_doc.FitContext is Altaxo.Graph.GUI.GraphController)
            {
                // for every dependent variable in the FitEnsemble, create a function graph
                Altaxo.Graph.GUI.GraphController graph = _doc.FitContext as Altaxo.Graph.GUI.GraphController;

                int funcNumber = 0;
                for (int i = 0; i < _doc.FitEnsemble.Count; i++)
                {
                    FitElement fitEle = _doc.FitEnsemble[i];

                    for (int k = 0; k < fitEle.NumberOfDependentVariables; k++, funcNumber++)
                    {
                        if (funcNumber < _functionPlotItems.Count && _functionPlotItems[funcNumber] != null)
                        {
                            XYFunctionPlotItem plotItem = (XYFunctionPlotItem)_functionPlotItems[funcNumber];
                            FitFunctionToScalarFunctionDDWrapper wrapper = (FitFunctionToScalarFunctionDDWrapper)plotItem.Data.Function;
                            wrapper.Initialize(fitEle.FitFunction, k, 0, _doc.GetParametersForFitElement(i));
                        }
                        else
                        {
                            FitFunctionToScalarFunctionDDWrapper wrapper = new FitFunctionToScalarFunctionDDWrapper(fitEle.FitFunction, k, _doc.GetParametersForFitElement(i));
                            XYFunctionPlotData plotdata = new XYFunctionPlotData(wrapper);
                            XYFunctionPlotItem plotItem = new XYFunctionPlotItem(plotdata, new G2DPlotStyleCollection(LineScatterPlotStyleKind.Line));
                            graph.ActiveLayer.PlotItems.Add(plotItem);
                            _functionPlotItems.Add(plotItem);
                        }
                    }
                }

                // if there are more elements in _functionPlotItems, remove them from the graph
                for (int i = _functionPlotItems.Count - 1; i >= funcNumber; --i)
                {
                    if (_functionPlotItems[i] != null)
                    {
                        graph.ActiveLayer.PlotItems.Remove((IGPlotItem)_functionPlotItems[i]);
                        _functionPlotItems.RemoveAt(i);
                    }
                }
                graph.RefreshGraph();
            }
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XYNonlinearFitFunctionPlotData"/> class.
        /// </summary>
        /// <param name="fitDocumentIdentifier">The fit document identifier.</param>
        /// <param name="fitDocument">The fit document. The document will be cloned before stored in this instance.</param>
        /// <param name="fitElementIndex">Index of the fit element.</param>
        /// <param name="dependentVariableIndex">Index of the dependent variable of the fit element.</param>
        /// <param name="dependentVariableTransformation">Transformation, which is applied to the result of the fit function to be then shown in the plot. Can be null.</param>
        /// <param name="independentVariableIndex">Index of the independent variable of the fit element.</param>
        /// <param name="independentVariableTransformation">Transformation, which is applied to the x value before it is applied to the fit function. Can be null.</param>
        public XYNonlinearFitFunctionPlotData(string fitDocumentIdentifier, NonlinearFitDocument fitDocument, int fitElementIndex, int dependentVariableIndex, IVariantToVariantTransformation dependentVariableTransformation, int independentVariableIndex, IVariantToVariantTransformation independentVariableTransformation)
        {
            if (null == fitDocumentIdentifier)
            {
                throw new ArgumentNullException(nameof(fitDocumentIdentifier));
            }
            if (null == fitDocument)
            {
                throw new ArgumentNullException(nameof(fitDocument));
            }

            ChildCloneToMember(ref _fitDocument, fitDocument); // clone here, because we want to have a local copy which can not change.
            _fitDocumentIdentifier  = fitDocumentIdentifier;
            _fitElementIndex        = fitElementIndex;
            _dependentVariableIndex = dependentVariableIndex;
            Function = new FitFunctionToScalarFunctionDDWrapper(_fitDocument.FitEnsemble[fitElementIndex].FitFunction, dependentVariableIndex, dependentVariableTransformation, independentVariableIndex, independentVariableTransformation, _fitDocument.GetParametersForFitElement(fitElementIndex));
        }