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)); }
protected void CSplineDemoButtonClick(object sender, RoutedEventArgs e) { double x1 = -1; double x2 = 5; double[] Y = new double[] { 2, 2, 2, 2, 2, 2, 2 }; //double[] Y = new double[] { 3, 2, -1, 1, 3, 0 }; double leftDerivation = 1; double rightDerivation = 2; ClampedSpline spline = _engine.InteractiveClampedSpline(x1, x2, Y, leftDerivation, rightDerivation); _clampedSplineList.Add(spline); //OptimalWorldArea(); //System.Diagnostics.Debug.WriteLine("CS ders: " + string.Join(",", spline.Derivations)); }
protected void ClampedSplineButtonClick(object sender, RoutedEventArgs e) { double waLX; double waRX; double[] waY; double leftDer; double rightDer; try { waLX = double.Parse(clamped_XLeft_TextBox.Text); waRX = double.Parse(clamped_XRight_TextBox.Text); waY = _parser.StringOfDecimalsToArray(clamped_Y_TextBox.Text); leftDer = double.Parse(left_derivation_TextBox.Text); rightDer = double.Parse(right_derivation_TextBox.Text); if (waLX >= waRX) { this.haha.Text = "Incorrect interval definition"; return; } if (waY.Length < 3) { this.haha.Text = "Small number of definition points"; return; } } catch (Exception) { this.haha.Text = "Incorect numeric input"; return; } ClampedSpline cSpline = _engine.InteractiveClampedSpline(waLX, waRX, waY, leftDer, rightDer); _clampedSplineList.Add(cSpline); }
public ClampedSpline InteractiveClampedSpline(double[] knots, double[] controlPoints, double leftDerivation, double rightDerivation) { var ellipses = new List <Ellipse>(knots.Length); Ellipse leftDerEll, rightDerEll; double pax, pay; var auxKnot = knots.First() - DERIVATIVE_AUX_KNOT_DISTANCE; var auxControlPoint = MathOperations.LinearFunction(auxKnot, knots.First(), controlPoints.First(), leftDerivation); pax = TransformCoordinates.WorldAreaToPlotAreaX(auxKnot, _plotArea, _worldArea); pay = TransformCoordinates.WorldAreaToPlotAreaY(auxControlPoint, _plotArea, _worldArea); leftDerEll = _auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, AUX_KNOT_COLOR2); auxKnot = knots.Last() + DERIVATIVE_AUX_KNOT_DISTANCE; auxControlPoint = MathOperations.LinearFunction(auxKnot, knots.Last(), controlPoints.Last(), rightDerivation); pax = TransformCoordinates.WorldAreaToPlotAreaX(auxKnot, _plotArea, _worldArea); pay = TransformCoordinates.WorldAreaToPlotAreaY(auxControlPoint, _plotArea, _worldArea); rightDerEll = _auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, AUX_KNOT_COLOR2); for (int i = 0; i < knots.Length; i++) { pax = TransformCoordinates.WorldAreaToPlotAreaX(knots[i], _plotArea, _worldArea); pay = TransformCoordinates.WorldAreaToPlotAreaY(controlPoints[i], _plotArea, _worldArea); ellipses.Add(_auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, KNOT_COLOR2)); } // List<Line> linesOfSpline = HermiteSplineLines(knots,controlPoints); ClampedSpline spline = ClampedSpline(knots, controlPoints, leftDerivation, rightDerivation); spline.DragEllipses = ellipses; spline.LeftDerivationEllipse = leftDerEll; spline.RightDerivationEllipse = rightDerEll; return(spline); }
private void canvas1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { // pri kliknuti si ulozime poziciu bodu //Point point = e.GetPosition(null); // pri double kliku pridavame objekty switch (e.ClickCount) { case 2: var cursorPosition = CursorPosition(e); var cursorPositionInWA = TransformCoordinates.PlotAreaToWorldArea(cursorPosition, _plotArea, _worldArea); if (_selectedSpline != null) { if (_selectedSpline is BSpline) { //_selectedBSpline = (BSpline) _selectedSpline; //var knots = _selectedBSpline.KnotsWithoutServiceKnots().ToList(); //var idx = ArrayMyUtils.FindFirstIndexInSortedListWhichValueIsBiggerThanDesiredNumber(knots, cursorPositionInWA.X); //if (idx != -1) //{ // knots.Insert(idx, cursorPositionInWA.X); //} //else //{ // knots.Add(cursorPositionInWA.X); //} } else if (_selectedSpline is HermiteSpline) { _selectedHermiteSpline = (HermiteSpline)_selectedSpline; for (int i = 0; i < _selectedHermiteSpline.LinesOfSpline.Count; i++) { var b = canvas1.Children.Remove(_selectedHermiteSpline.LinesOfSpline[i]); if (!b) { haha.Text = "cannot remove line"; } else { haha.Text = "line removed"; } } var knots = _selectedHermiteSpline.Knots; var controlPoints = _selectedHermiteSpline.ControlPoints; var derivations = _selectedHermiteSpline.Derivations; var idx = ArrayMyUtils.FindFirstIndexInSortedListWhichValueIsBiggerThanDesiredNumber(knots, cursorPositionInWA.X); if (idx != -1) { knots.Insert(idx, cursorPositionInWA.X); controlPoints.Insert(idx, cursorPositionInWA.Y); derivations.Insert(idx, 0); } else { knots.Add(cursorPositionInWA.X); controlPoints.Add(cursorPositionInWA.Y); derivations.Add(0); } //_selectedHermiteSpline.Knots = knots; //_selectedHermiteSpline.ControlPoints = controlPoints; //_selectedHermiteSpline.Derivations = derivations; //_canvasUtilities.TotalRefreshHermiteSplineInCanvas(_selectedHermiteSpline, canvas1, _engine); //_canvasUtilities.RemoveInCanvas(canvas1, _selectedHermiteSpline.LinesOfSpline); //_canvasUtilities.RemoveInCanvas(canvas1, _selectedHermiteSpline.DerivationEllipses); //_canvasUtilities.RemoveInCanvas(canvas1, _selectedHermiteSpline.DragEllipses); //_hermiteSplineList.Remove(_selectedHermiteSpline); var spline = _engine.InteractiveHermiteSpline(_selectedHermiteSpline.Knots.ToArray(), _selectedHermiteSpline.ControlPoints.ToArray(), _selectedHermiteSpline.Derivations.ToArray()); _hermiteSplineList.Add(spline); } else if (_selectedSpline is ClampedSpline) { } else if (_selectedSpline is GlobalBSpline) { } } break; // hybanie s objektami case 1: var elements = VisualTreeHelper.FindElementsInHostCoordinates(e.GetPosition(null), (UIElement)sender) as List <UIElement>; for (int i = 0; i < elements.Count; i++) { if (elements[i] is Ellipse) { _selectedEllipse = elements[i]; for (int j = 0; j < _bSplineList.Count; j++) { _selectedBSpline = _bSplineList[j]; _selectedSpline = _selectedBSpline; _changedPointIndex = 0; //if (_selectedBSpline.FunctionValues == null) //{ var controlPointsCount = _selectedBSpline.ControlPoints.Count(); while (_changedPointIndex < controlPointsCount) { if (_selectedEllipse.Equals(_selectedBSpline.DragEllipses[_changedPointIndex])) { haha.Text += " CP: " + _changedPointIndex + " "; //_changedKnotPos = _changedPointIndex + 1; if (_changedPointIndex == 0) { _leftEllipseX = -1; _rightEllipseX = (double)_selectedBSpline.DragEllipses[_changedPointIndex + 1].GetValue(Canvas.LeftProperty); } else if (_changedPointIndex == _selectedBSpline.DragEllipses.Count - 1) { _leftEllipseX = (double)_selectedBSpline.DragEllipses[_changedPointIndex - 1].GetValue(Canvas.LeftProperty); _rightEllipseX = TransformCoordinates.WorldAreaToPlotAreaX(_selectedBSpline.Knots[_changedPointIndex + 2] - DEFAULT_REDRAWING_PRECISION, _plotArea, _worldArea); } else { _leftEllipseX = (double)_selectedBSpline.DragEllipses[_changedPointIndex - 1].GetValue(Canvas.LeftProperty); _rightEllipseX = (double)_selectedBSpline.DragEllipses[_changedPointIndex + 1].GetValue(Canvas.LeftProperty); } SELECTED_ITEM_TYPE = SelectedDragItem.BSplineEllipse; _isMoving = true; _changedKnotPos = _changedPointIndex + 1; // _selectedSpline = _redrawedBSpline; haha.Text += " Knot: " + _changedKnotPos + " "; //goto DRAG; // preskocime nasledujuci for-cyklus _engine.DrawPrecision = RedrawingPrecision; _selectedEllipse.CaptureMouse(); return; } _changedPointIndex++; } //} //else //{ } for (int j = 0; j < _globalBSplineList.Count; j++) { _selectedGlobalBSpline = _globalBSplineList[j]; _selectedSpline = _selectedGlobalBSpline; _changedPointIndex = 0; var redrawedGlobalBSplineCount = _selectedGlobalBSpline.ControlPoints.Count(); if (_selectedEllipse.Equals(_selectedGlobalBSpline.LeftDerivationEllipse)) { SELECTED_ITEM_TYPE = SelectedDragItem.GBSplineLeftDerEllipse; _isMoving = true; _changedKnotPos = _changedPointIndex; _engine.DrawPrecision = RedrawingPrecision; _selectedEllipse.CaptureMouse(); return; } else if (_selectedEllipse.Equals(_selectedGlobalBSpline.RightDerivationEllipse)) { SELECTED_ITEM_TYPE = SelectedDragItem.GBSplineRightDerEllipse; _isMoving = true; _changedKnotPos = _changedPointIndex; _engine.DrawPrecision = RedrawingPrecision; _selectedEllipse.CaptureMouse(); return; } else { while (_changedPointIndex < _selectedGlobalBSpline.FunctionValues.Count()) { if (_selectedEllipse.Equals(_selectedGlobalBSpline.DragEllipses[_changedPointIndex])) { //haha.Text += " CP: " + _changedPointIndex + " "; SELECTED_ITEM_TYPE = SelectedDragItem.GBSplineEllipse; // _selectedSpline = _redrawedBSpline; // haha.Text += " Knot: " + _changedKnotPos + " "; // goto DRAG; // preskocime nasledujuci for-cyklus _isMoving = true; _changedKnotPos = _changedPointIndex; _engine.DrawPrecision = RedrawingPrecision; _selectedEllipse.CaptureMouse(); return; } _changedPointIndex++; } } } for (int j = 0; j < _clampedSplineList.Count; j++) { _selectedClampedSpline = _clampedSplineList[j]; _selectedSpline = _selectedClampedSpline; int redrawedCSplineCount = _selectedClampedSpline.ControlPoints.Count(); _changedPointIndex = 0; if (_selectedEllipse.Equals(_selectedClampedSpline.LeftDerivationEllipse)) { SELECTED_ITEM_TYPE = SelectedDragItem.CSplineLeftDerEllipse; _isMoving = true; //_selectedSpline = _redrawedHermiteSpline; // goto DRAG; _engine.DrawPrecision = RedrawingPrecision; _selectedEllipse.CaptureMouse(); return; } else if (_selectedEllipse.Equals(_selectedClampedSpline.RightDerivationEllipse)) { SELECTED_ITEM_TYPE = SelectedDragItem.CSplineRightDerEllipse; _isMoving = true; //_selectedSpline = _redrawedHermiteSpline; // goto DRAG; _engine.DrawPrecision = RedrawingPrecision; _selectedEllipse.CaptureMouse(); return; } else { while (_changedPointIndex < redrawedCSplineCount) { if (_selectedEllipse.Equals(_selectedClampedSpline.DragEllipses[_changedPointIndex])) { //haha.Text += _changedPointIndex + " "; SELECTED_ITEM_TYPE = SelectedDragItem.CSplineEllipse; _isMoving = true; //_selectedSpline = _redrawedHermiteSpline; // goto DRAG; _engine.DrawPrecision = RedrawingPrecision; _selectedEllipse.CaptureMouse(); return; } _changedPointIndex++; // } } } } for (int j = 0; j < _hermiteSplineList.Count; j++) { _selectedHermiteSpline = _hermiteSplineList[j]; _selectedSpline = _selectedHermiteSpline; int redrawedHSplineControlPointsCount = _selectedHermiteSpline.ControlPoints.Count(); _changedPointIndex = 0; while (_changedPointIndex < redrawedHSplineControlPointsCount) { if (_selectedEllipse.Equals(_selectedHermiteSpline.DragEllipses[_changedPointIndex])) { haha.Text += _changedPointIndex + " "; if (_changedPointIndex == 0) { _leftEllipseX = -1; _rightEllipseX = (double)_selectedHermiteSpline.DragEllipses[_changedPointIndex + 1].GetValue(Canvas.LeftProperty); } else if (_changedPointIndex == redrawedHSplineControlPointsCount - 1) { _leftEllipseX = (double)_selectedHermiteSpline.DragEllipses[_changedPointIndex - 1].GetValue(Canvas.LeftProperty); _rightEllipseX = -1; } else { _leftEllipseX = (double)_selectedHermiteSpline.DragEllipses[_changedPointIndex - 1].GetValue(Canvas.LeftProperty); _rightEllipseX = (double)_selectedHermiteSpline.DragEllipses[_changedPointIndex + 1].GetValue(Canvas.LeftProperty); } SELECTED_ITEM_TYPE = SelectedDragItem.HSplineEllipse; _isMoving = true; //_selectedSpline = _redrawedHermiteSpline; // goto DRAG; _engine.DrawPrecision = RedrawingPrecision; _selectedEllipse.CaptureMouse(); return; } else if (_selectedEllipse.Equals(_selectedHermiteSpline.DerivationEllipses[_changedPointIndex])) { SELECTED_ITEM_TYPE = SelectedDragItem.HSplineDerEllipse; _isMoving = true; _engine.DrawPrecision = RedrawingPrecision; _selectedEllipse.CaptureMouse(); return; } _changedPointIndex++; // } } } //DRAG: //_selectedEllipse.CaptureMouse(); } } break; } }