public void RefreshBSplineInCanvas(BSpline changedSpline, Canvas canvas, SplineDrawer engine)
        {
            RemoveInCanvas(canvas, changedSpline.LinesOfSpline);
            List <Line> lines = engine.BSplineLines(changedSpline.Degree, changedSpline.Knots.ToArray(), changedSpline.ControlPoints.ToArray(), true);

            changedSpline.LinesOfSpline = lines;
        }
        public void SetNewWorldArea(double newXMin, double newXMax, double newYMin, double newYMax)
        {
            //if (newXMin < 0.5 || newYMin < 0.5 || newXMax < 0.5 || newYMax < 0.5)
            //{
            //    haha.Text = "Too high zoom";
            //    return;
            //}

            WorldArea oldWA = _worldArea;

            _worldArea = new WorldArea(newXMin, newXMax, newYMin, newYMax);

            _waZeroPointInPACoordinates = TransformCoordinates.WorldAreaToPlotArea(0, 0, _plotArea, _worldArea);
            _engine            = new SplineDrawer(canvas1, _plotArea, _worldArea, DrawPrecision);
            x_min_TextBox.Text = newXMin.ToString();
            x_max_TextBox.Text = newXMax.ToString();
            y_min_TextBox.Text = newYMin.ToString();
            y_max_TextBox.Text = newYMax.ToString();

            ResetCanvas();
        }
Example #3
0
        public void LoadSplinesFromFile(StreamReader reader, List <BSpline> _bSplineList, List <GlobalBSpline> _globalBSplineList, List <HermiteSpline> _hermiteSplineList,
                                        List <ClampedSpline> _clampedSplineList, SplineDrawer engine)
        {
            var bSplinesStringBuilder       = new StringBuilder();
            var hSplinesStringBuilder       = new StringBuilder();
            var cSplinesStringBuilder       = new StringBuilder();
            var globalBSplinesStringBuilder = new StringBuilder();

            var line = reader.ReadLine();

            if (line.Equals(BSPLINE_HEADER))
            {
                line = reader.ReadLine();
                while (!line.Equals(GLOBAL_BSPLINE_HEADER))
                {
                    bSplinesStringBuilder.Append(line);
                    line = reader.ReadLine();
                }
                line = reader.ReadLine();
                while (!line.Equals(HSPLINE_HEADER))
                {
                    globalBSplinesStringBuilder.Append(line);
                    line = reader.ReadLine();
                }

                line = reader.ReadLine();
                while (!line.Equals(CSPLINE_HEADER))
                {
                    hSplinesStringBuilder.Append(line);
                    line = reader.ReadLine();
                }
                line = reader.ReadLine();
                while (line != null)
                {
                    cSplinesStringBuilder.Append(line);
                    line = reader.ReadLine();
                }
                //System.Diagnostics.Debug.WriteLine(bSplinesStringBuilder.ToString());
                // System.Diagnostics.Debug.WriteLine(hSplinesStringBuilder.ToString());
                var     bSplinesDefinitions       = JsonConvert.DeserializeObject <List <Tuple <int, List <double>, List <double> > > >(bSplinesStringBuilder.ToString());
                var     globalBSplinesDefinitions = JsonConvert.DeserializeObject <List <Tuple <int, List <double>, List <double>, List <double>, double, double> > >(globalBSplinesStringBuilder.ToString());
                var     hSplinesDefinitions       = JsonConvert.DeserializeObject <List <Tuple <List <double>, List <double>, List <double> > > >(hSplinesStringBuilder.ToString());
                var     cSplinesDefinitions       = JsonConvert.DeserializeObject <List <Tuple <List <double>, List <double>, List <double> > > >(cSplinesStringBuilder.ToString());
                BSpline bSpline;
                for (int i = 0; i < bSplinesDefinitions.Count; i++)
                {
                    bSpline = engine.InteractiveBSpline(bSplinesDefinitions[i].Item1, bSplinesDefinitions[i].Item2.ToArray(), bSplinesDefinitions[i].Item3.ToArray(), true);
                    _bSplineList.Add(bSpline);
                }
                GlobalBSpline gBSpline;
                for (int i = 0; i < bSplinesDefinitions.Count; i++)
                {
                    gBSpline = engine.InteractiveGlobalBSpline(globalBSplinesDefinitions[i].Item1, globalBSplinesDefinitions[i].Item2.ToArray(),
                                                               globalBSplinesDefinitions[i].Item3.ToArray(), globalBSplinesDefinitions[i].Item4.ToArray(), true);
                    gBSpline.LeftDerivation  = globalBSplinesDefinitions[i].Item5;
                    gBSpline.RightDerivation = globalBSplinesDefinitions[i].Item6;
                    _bSplineList.Add(gBSpline);
                }
                HermiteSpline hSpline;
                for (int i = 0; i < hSplinesDefinitions.Count; i++)
                {
                    hSpline = engine.InteractiveHermiteSpline(hSplinesDefinitions[i].Item1.ToArray(), hSplinesDefinitions[i].Item2.ToArray(), hSplinesDefinitions[i].Item3.ToArray());
                    _hermiteSplineList.Add(hSpline);
                }
                ClampedSpline cSpline;
                for (int i = 0; i < cSplinesDefinitions.Count; i++)
                {
                    cSpline = engine.InteractiveClampedSpline(cSplinesDefinitions[i].Item1.ToArray(), cSplinesDefinitions[i].Item2.ToArray(), cSplinesDefinitions[i].Item3[0], cSplinesDefinitions[i].Item3[cSplinesDefinitions[i].Item3.Count - 1]);
                    _clampedSplineList.Add(cSpline);
                }
            }
        }
Example #4
0
        // private object _selectedSpline;
        //private FunctionComboBoxViewModel functionComboBoxViewModel;
        /**********************/

        public MainPage()
        {
            InitializeComponent();
            this.DrawPrecision      = DEFAULT_DRAW_PRECISION;
            this.RedrawingPrecision = DEFAULT_REDRAWING_PRECISION;
            //functionComboBoxViewModel = new FunctionComboBoxViewModel();
            _plotArea  = new PlotArea(PLOT_AREA_MIN_X, PLOT_AREA_MAX_X, PLOT_AREA_MIN_Y, PLOT_AREA_MAX_Y);
            _worldArea = new WorldArea(WORLD_AREA_DEFAULT_MIN_XY, WORLD_AREA_DEFAULT_MAX_XY, WORLD_AREA_DEFAULT_MIN_XY, WORLD_AREA_DEFAULT_MAX_XY);
            // _pa.x_min = 0; _pa.x_max = 775; _pa.y_min = 0; _pa.y_max = 575; _wa.x_min = -10; _wa.x_max = 10; _wa.y_min = -10; _wa.y_max = 10;
            _engine = new SplineDrawer(canvas1, _plotArea, _worldArea, DrawPrecision);
            //_auxiliaryEngine = new AuxiliaryDrawer(canvas1);
            _isMoving = false;
            _waZeroPointInPACoordinates = TransformCoordinates.WorldAreaToPlotArea(0, 0, _plotArea, _worldArea);

            _parser = new Parser();
            InitSplineLists();
            _canvasUtilities = new CanvasUtilities(_plotArea, _worldArea);

            _openFileDialog = new OpenFileDialog();
            _saveFileDialog = new SaveFileDialog();
            InitColors();
            FunctionSelect_ComboBox.SelectedIndex = 0;
            _dragInfoLabel = new DragInfoLabel(CANVAS_TEXT_COLOR);
            //_dragInfoLabel.Margin = new Thickness(20, 30, 0, 0);
            //_dragInfoLabel.Content = "SDAS";
            canvas1.Children.Add(_dragInfoLabel);
            _dragInfoLabel.Visibility = Visibility.Collapsed;
            VersionLabel.Content      = Version();

            try
            {
                this._saveFileDialog.DefaultExt  = ".spline";
                this._openFileDialog.Filter      = "Spline Files|*.spline";
                this._openFileDialog.FilterIndex = 2;
                this._saveFileDialog.Filter      = "Spline Files|*.spline";
                this._saveFileDialog.FilterIndex = 2;
                // this._saveFileDialog.DefaultFileName = "newSplines.spline";
            }
            catch (Exception)
            {
            }
            DefaultCanvas();
            //var s = BSpline.ServiceKnots(new double[] {2,3.75,5},3,true);

            // _engine.BellFunctionOfDegree3(0, 1, 2, 3, 4);
            // _engine.BSplineBasisFunctionsOfDegree3(0, 1, 2, 3, 4, 5, 6, 7);
            //_engine.BSplineBasisFunction(new double[]{0, 1, 2, 3, 4, 5, 6, 7});
            // double[] knots = new double[] {-1,1,2,2.5, 3, 4, 5, 6};
            // Tuple<double[][], double[]> A = GlobalBSplineMatrix(3, knots);
            // double[][] B = A.Item1; //MathMyUtils.MatrixInvert(A.Item1);
            // //double[][] F = MathMyUtils.MatrixInvert(B);
            //// double[][] C = MathMyUtils.TransposeMatrix(B);

            //// //double[][] D = MathMyUtils.MatrixInvert(MathMyUtils.MultiplyMatrices(C, B));
            //// //double[][] E = MathMyUtils.MultiplyMatrices(B, C);
            ////// double[][] YMatrix = MathMyUtils.ArrayToMatrix(knotsFunctionValues);
            // for (int i = 0; i < B.Length; i++)
            // {
            //     String s = "";
            //     for (int j = 0; j < B[i].Length; j++)
            //     {

            //         s += B[i][j].ToString() + " | ";
            //     }
            //     System.Diagnostics.Debug.WriteLine(s);
            // }
        }
        public void TotalRefreshHermiteSplineInCanvas(HermiteSpline changedSpline, Canvas canvas, SplineDrawer engine)
        {
            RemoveInCanvas(canvas, changedSpline.LinesOfSpline);
            RemoveInCanvas(canvas, changedSpline.DerivationEllipses);
            RemoveInCanvas(canvas, changedSpline.DragEllipses);

            var spline = engine.InteractiveHermiteSpline(changedSpline.Knots.ToArray(), changedSpline.ControlPoints.ToArray(), changedSpline.Derivations.ToArray());
            //changedSpline.LinesOfSpline = spline.LinesOfSpline;
            //changedSpline.DerivationEllipses = spline.DerivationEllipses;
            //changedSpline.DragEllipses = spline.DragEllipses;
            //List<Line> lines = engine.HermiteSplineLines(changedSpline.Knots.ToArray(), changedSpline.ControlPoints.ToArray(), changedSpline.Derivations.ToArray());
            //changedSpline.LinesOfSpline = lines;
        }
        public void RefreshHermiteSplineInCanvas(HermiteSpline changedSpline, Canvas canvas, SplineDrawer engine)
        {
            //treba zmazat vsetky liny meneneho splinu
            RemoveInCanvas(canvas, changedSpline.LinesOfSpline);

            List <Line> lines = engine.HermiteSplineLines(changedSpline.Knots.ToArray(), changedSpline.ControlPoints.ToArray(), changedSpline.Derivations.ToArray());

            changedSpline.LinesOfSpline = lines;
        }
        public void RefreshGlobalBSplineInCanvas(GlobalBSpline changedSpline, Canvas canvas, SplineDrawer engine)
        {
            RemoveInCanvas(canvas, changedSpline.LinesOfSpline);
            // RemoveInCanvas(canvas, changedSpline.ControlPointsEllipses);
            // RemoveInCanvas(canvas, changedSpline.DragEllipses);
            // canvas.Children.Remove(changedSpline.LeftDerivationEllipse);
            //canvas.Children.Remove(changedSpline.RightDerivationEllipse);
            List <Line> lines = engine.GlobalBSplineLines(changedSpline.Degree, changedSpline.Knots.ToArray(), changedSpline.FunctionValues.ToArray(), changedSpline.LeftDerivation, changedSpline.RightDerivation, true);

            changedSpline.LinesOfSpline = lines;
            //changedSpline = engine.InteractiveGlobalBSpline(changedSpline.Degree,
            //    changedSpline.Knots.ToArray(),
            //    changedSpline.FunctionValues.ToArray(),changedSpline.LeftDerivation, changedSpline.RightDerivation,
            //    true);
        }
        public void RemoveCPFromHermiteSpline(HermiteSpline changedSpline, int changedCPIndex, Canvas canvas, SplineDrawer engine)
        {
            try
            {
                //TREBA PORIESIT DERIVACIE
                RemoveInCanvas(canvas, changedSpline.DragEllipses);
                RemoveInCanvas(canvas, changedSpline.LinesOfSpline);
                changedSpline.Knots.RemoveAt(changedCPIndex);
                changedSpline.ControlPoints.RemoveAt(changedCPIndex);

                changedSpline = engine.InteractiveHermiteSpline(changedSpline.Knots.ToArray(), changedSpline.ControlPoints.ToArray(), changedSpline.Derivations.ToArray());
            }
            catch (ArgumentOutOfRangeException) { }
        }
        public void RefreshClampedSplineInCanvas(ClampedSpline changedSpline, Canvas canvas, SplineDrawer engine)
        {
            //treba zmazat vsetky liny meneneho splinu
            RemoveInCanvas(canvas, changedSpline.LinesOfSpline);

            var dersAndLines = engine.ClampedSplineDerivationsAndLines(changedSpline.Knots.ToArray(), changedSpline.ControlPoints.ToArray(), changedSpline.Derivations[0], changedSpline.Derivations[changedSpline.Derivations.Count - 1]);

            changedSpline.Derivations   = dersAndLines.Item1;
            changedSpline.LinesOfSpline = dersAndLines.Item2;
            //Canvas.SetLeft(changedSpline.LeftDerivationEllipse,MathOperations.);
            // var leftDerWACoord =
            //     MathOperations.LinearFunction(changedSpline.Knots[0]-1,changedSpline.Knots[0],changedSpline.ControlPoints[0],changedSpline.Derivations[0]);
            // Canvas.SetTop(changedSpline.LeftDerivationEllipse,TransformCoordinates.WorldAreaToPlotAreaY(leftDerWACoord,_plotArea,_worldArea));
        }