public void UpdateLine(Core.Curve.ICurve curve) { m_Stopwatch.Restart(); foreach (var cpc in _curvesWithPointControls[curve]) { cpc.UpdateControlTangents(); } m_Stopwatch.Stop(); m_Stopwatch.Restart(); var path = _curvesWithPaths[curve]; PathGeometry myPathGeometry = new PathGeometry(); PathFigure pathFigure2 = new PathFigure(); const int SAMPLE_STEP = 1; int steps = (int)this.ActualWidth / SAMPLE_STEP; Point[] polyLinePointArray = new Point[steps]; for (int i = 0; i < steps; i++) { double u = xToU(i * SAMPLE_STEP); double v = curve.GetSampledValue(u); polyLinePointArray[i] = new Point(i * SAMPLE_STEP, vToY(v)); } if (steps == 0) { return; } pathFigure2.StartPoint = polyLinePointArray[0]; PolyLineSegment myPolyLineSegment = new PolyLineSegment(); myPolyLineSegment.Points = new PointCollection(polyLinePointArray); pathFigure2.Segments.Add(myPolyLineSegment); myPathGeometry.Figures.Add(pathFigure2); path.Data = myPathGeometry; m_Stopwatch.Stop(); }
private void RebuildCurve(Core.Curve.ICurve curve) { if (!_updatingCurveEnabled) { return; } // Keep original selection var selectedKeys = new List <Tuple <ICurve, double> >(); foreach (var e in _SelectionHandler.SelectedElements) { var cpc = e as CurvePointControl; if (cpc == null) { continue; } selectedKeys.Add(new Tuple <ICurve, double>(cpc.Curve, cpc.U)); } //_SelectionHandler.Clear(); if (!_curvesWithPointControls.ContainsKey(curve)) { _curvesWithPointControls[curve] = new List <CurvePointControl>(); } var curvePointControls = _curvesWithPointControls[curve]; int cepIndex = 0; bool reusingControls = true; foreach (var pair in curve.GetPoints()) { double u = pair.Key; var vDefinition = pair.Value; // Reuse existing control if (reusingControls && cepIndex < curvePointControls.Count) { var reusedPointControl = curvePointControls[cepIndex]; reusedPointControl.U = u; reusedPointControl.InitFromVDefinition(vDefinition); reusedPointControl.Curve = curve; reusedPointControl.IsSelected = false; // Was it selected? foreach (var curveTime in selectedKeys) { if (reusedPointControl.Curve == curveTime.Item1 && reusedPointControl.U == curveTime.Item2) { reusedPointControl.IsSelected = true; _SelectionHandler.AddElement(reusedPointControl); break; } } cepIndex++; } else { reusingControls = false; CurvePointControl newPointControl; // Reuse from pool... if (_pointControlRecyclePool.Count > 0) { newPointControl = _pointControlRecyclePool[0]; _pointControlRecyclePool.RemoveAt(0); newPointControl.U = u; newPointControl.InitFromVDefinition(vDefinition); newPointControl.Curve = curve; newPointControl.IsSelected = false; } // Create new control else { newPointControl = new CurvePointControl(u, vDefinition, curve, this); newPointControl.U = u; } _curvesWithPointControls[curve].Add(newPointControl); XCurvePointCanvas.Children.Add(newPointControl); } } // Move obsolete control points to pool if (reusingControls) { List <CurvePointControl> obsoletePoints = new List <CurvePointControl>(); while (cepIndex < _curvesWithPointControls[curve].Count) { var obsoletePointControl = curvePointControls[cepIndex]; _pointControlRecyclePool.Add(obsoletePointControl); XCurvePointCanvas.Children.Remove(obsoletePointControl); obsoletePoints.Add(obsoletePointControl); cepIndex++; } foreach (var removeThis in obsoletePoints) { curvePointControls.Remove(removeThis); } } // Update curve line (Path) if (_curvesWithPaths.ContainsKey(curve)) { XCurveLineCanvas.Children.Remove(_curvesWithPaths[curve]); } var newPath = new Path(); newPath.Stroke = Brushes.DarkGray; newPath.StrokeThickness = 1; _curvesWithPaths[curve] = newPath; XCurveLineCanvas.Children.Add(newPath); UpdateCurveHighlight(); UpdateLine(curve); }
private void ViewAllKeys(bool KeeyURange = false) { double minU = double.PositiveInfinity; double maxU = double.NegativeInfinity; double minV = double.PositiveInfinity; double maxV = double.NegativeInfinity; int numPoints = 0; if (_SelectionHandler.SelectedElements.Count == 0) { foreach (var pair in _curvesWithPaths) { Core.Curve.ICurve curve = pair.Key; foreach (var pair2 in curve.GetPoints()) { numPoints++; double u = pair2.Key; var vDef = pair2.Value; minU = Math.Min(minU, u); maxU = Math.Max(maxU, u); minV = Math.Min(minV, vDef.Value); maxV = Math.Max(maxV, vDef.Value); } } } else { foreach (var element in _SelectionHandler.SelectedElements) { var cpc = element as CurvePointControl; if (cpc != null) { numPoints++; minU = Math.Min(minU, cpc.U); maxU = Math.Max(maxU, cpc.U); minV = Math.Min(minV, cpc.m_vdef.Value); maxV = Math.Max(maxV, cpc.m_vdef.Value); } } } if (numPoints == 0) { minV = -3; maxV = +3; minU = -2; maxU = 10; } double scaleV = ActualHeight / (maxV - minV); if (minV != maxV) { MinV = minV - CURVE_VALUE_PADDING * (maxV - minV); MaxV = maxV + CURVE_VALUE_PADDING * (maxV - minV); } else { MinV = minV - 1.0; MaxV = maxV + 1.0; } if (!KeeyURange) { if (maxU != minU) { UScale = (ActualWidth) / ((maxU - minU) * (1 + 2 * CURVE_VALUE_PADDING)); UOffset = minU - CURVE_VALUE_PADDING * (maxU - minU); } else { UOffset = 0.5 * (minU + maxU); } } UpdateCurveLinesAndEditBox(); }
private void CurveChangedHandler(object o, EventArgs e) { Core.Curve.ICurve curve = o as Core.Curve.ICurve; RebuildCurve(curve); }