/// <summary> /// 根据偏差移动绘图区 /// </summary> /// <param name="offect"></param> /// <returns></returns> public bool MoveDrawLinesAndPoints(Point offset) { if (Math.Pow(offset.X, 2) + Math.Pow(offset.Y, 2) < 3 * 3) { return(false); } centerOffect.Vect1 += offset.X; centerOffect.Vect2 += offset.Y; VectorChart2 offectValue = GetOffectValue(centerOffect); if (xExtremeValue.Vect1 + offectValue.Vect1 <= ScaleLimt.Vect1 || xExtremeValue.Vect2 + offectValue.Vect1 >= ScaleLimt.Vect2 || yExtremeValue.Vect1 + offectValue.Vect2 <= ScaleLimt.Vect3 || yExtremeValue.Vect2 + offectValue.Vect2 >= ScaleLimt.Vect4) { centerOffect.Vect1 -= offset.X; centerOffect.Vect2 -= offset.Y; return(false); } Point curp = new Point(Canvas.GetLeft(DrawLineAndPoint), Draw.Height - Canvas.GetBottom(DrawLineAndPoint)); curp.X += offset.X; curp.Y += offset.Y; Canvas.SetLeft(DrawLineAndPoint, curp.X); Canvas.SetBottom(DrawLineAndPoint, Draw.Height - curp.Y); AdjustLines(); return(true); }
protected void AppendData(VectorChart2 selectedData) { if (SourceData.Count > 0) { this.AppendData(this.GenerateDrawData(selectedData), brush, 1, 1); } }
public void OnPassValues(object sender, PassValuesEventArgs e) { SelectedData = e.vect; if (this.SelectedData.Vect1 != SelectedData.Vect2) { this.AppendData(); } //NOTICE: values are passed here }
/// <summary> /// 调整曲线 刻度(直接修改) /// </summary> protected void AdjustLines() { if (!(xTip.Count >= 1 && yTip.Count >= 1)) { return; } double xeveryone = (xExtremeValue.Vect2 - xExtremeValue.Vect1) / (xTip.Count - 1); double yeveryone = (yExtremeValue.Vect2 - yExtremeValue.Vect1) / (yTip.Count - 1); if (Draw.Width > 0) { double xSize = xExtremeValue.Vect2 - xExtremeValue.Vect1; //everyDisForPiexl.Vect1 = xSize / Draw.Width; if (everyDisForPiexl.Vect1 < 1) { everyDisForPiexl.Vect1 = 1; } //XSkipOffset = Draw.Width/20; } if (Draw.Height > 0) { double ySize = yExtremeValue.Vect2 - yExtremeValue.Vect1; // everyDisForPiexl.Vect2 = ySize / Draw.Height; if (everyDisForPiexl.Vect2 < 1) { everyDisForPiexl.Vect2 = 1; } //YSkipOffset = Draw.Height/20; } double cur = 0; ///计算偏移量 VectorChart2 offect = GetOffectValue(centerOffect); foreach (var item in xTip) { //item.Text = (cur * everyDisForPiexl.Vect1 + offect.Vect1).ToString("0.00"); //item.Text = (((int)item.GetValue(Canvas.LeftProperty) - origPoint.X) * everyDisForPiexl.Vect1 + offect.Vect1).ToString("0.0"); cur++; } cur = 0; foreach (var item in yTip) { //item.Text = (cur * everyDisForPiexl.Vect2 + offect.Vect2).ToString("0.00"); //item.Text = (((int)item.GetValue(Canvas.BottomProperty) - origPoint.Y) * everyDisForPiexl.Vect2 + offect.Vect2).ToString("0.0"); cur++; } }
private List <Point> GenerateDrawData(VectorChart2 selectedData) { if (filteredData.Count > 0) { filteredData.Clear(); } int begin = (int)this.SelectedData.Vect1; int end = (int)this.SelectedData.Vect2; int length = (end - begin) / 256; float min = 0, max = 0; float frequency; //MFCC mfcc = new MFCC(); float[][] results = new float[length][]; MFCC mfcc = new MFCC(44100, 512, 512, 0, 4000, 24, 12); float[] frames = new float[512]; for (int i = begin; i <= end - 512; i += 256) { for (int j = 0; j < 512; j++) { frames[j] = (float)this.SourceData[i + j]; } float[] r = mfcc.ProcessFrame(frames); //min = r.Min(); //max = r.Max(); //rMin = rMin < min ? rMin : min; //rMax = rMax > max ? rMax : max; results[i / 256] = r; for (int j = 0; j < 256; j++) { frequency = results[i][j]; if (frequency < FrequencyMax) { filteredData.Add(new Point(i, j)); } } } return(filteredData); }
///// <summary> ///// 渲染事件 ///// </summary> ///// <param name="drawingContext"></param> //protected override void OnRender(DrawingContext drawingContext) //{ // base.OnRender(drawingContext); //} /// <summary> /// 加载事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MyChart_Loaded(object sender, RoutedEventArgs e) { var layer = AdornerLayer.GetAdornerLayer(DrawLineAndPoint); //foreach (UIElement ui in DrawLineAndPoint.Children) layer.Add(new ResizeAdorner(ResizableRect)); this.xExtremeValue.Vect1 = 0; this.xExtremeValue.Vect2 = SourceData.Count; this.yExtremeValue.Vect1 = SourceData.Min(); this.yExtremeValue.Vect2 = SourceData.Max(); double xx = this.xExtremeValue.Vect2 - this.xExtremeValue.Vect1; double yy = this.yExtremeValue.Vect2 - this.yExtremeValue.Vect1 + 50000; this.everyDisForPiexl = new VectorChart2(xx / DrawLineAndPoint.Width, yy / DrawLineAndPoint.Height); Point p = ResizableRect.TranslatePoint(o, DrawLineAndPoint); SelectedData.Vect1 = p.X * this.everyDisForPiexl.Vect1; SelectedData.Vect2 = (p.X + this.ResizableRect.Width) * this.everyDisForPiexl.Vect1; this.AppendData(SourceData); }
private List <Point> GenerateDrawData(VectorChart2 selectedData) { this.xExtremeValue.Vect1 = SelectedData.Vect1; this.xExtremeValue.Vect2 = SelectedData.Vect2; this.everyDisForPiexl.Vect1 = (this.xExtremeValue.Vect2 - this.xExtremeValue.Vect1) / DrawLineAndPoint.Width; this.everyDisForPiexl.Vect2 = (this.yExtremeValue.Vect2 - this.yExtremeValue.Vect1) / DrawLineAndPoint.Height; if (filteredData.Count > 0) { filteredData.Clear(); } int offset = (int)(this.everyDisForPiexl.Vect1 / 2); offset = offset > 1 ? offset : 1; for (int i = (int)SelectedData.Vect1; i < SelectedData.Vect2; i += offset) { filteredData.Add(new Point(i, SourceData[i])); } //int start = (int)(SelectedData.Vect1); //int end =(int)(SelectedData.Vect2); //int datacount = end-start + 1; //double sum = 0; //int count = 0; //double everage = 0; //for (int i = start; i <= end; i++) //{ // count++; // sum += SourceData[i]; // if (i > 0 && i % offset == 0) // { // everage = sum / count; // count = 0; // sum = 0; // filteredData.Add(new Point(i, everage)); // everage = 0; // } //} return(filteredData); }
/// <summary> /// 鼠标滚轮事件 /// </summary> /// <param name="e"></param> protected override void OnMouseWheel(MouseWheelEventArgs e) { base.OnMouseWheel(e); VectorChart2 curPDraw = (VectorChart2)e.GetPosition(Draw); VectorChart2 curPLinesAndPoint = (VectorChart2)e.GetPosition(DrawLineAndPoint); double delta = 1; if (e.Delta >= 120) { delta = 1.2; } else if (e.Delta <= -120) { delta = (double)5 / (double)6; } if (IsXZoom) { DrawLineAndPoint.Width *= delta; curPDraw.Vect1 *= delta; curPLinesAndPoint.Vect1 *= delta; } if (IsYZoom) { DrawLineAndPoint.Height *= delta; curPDraw.Vect2 *= delta; curPLinesAndPoint.Vect2 *= delta; } currentLinesScale.Vect4 *= delta; //Canvas.SetLeft(DrawLineAndPoint, curPDraw.Vect1 - curPLinesAndPoint.Vect1); //Canvas.SetBottom(DrawLineAndPoint, -(DrawArea.Vect2 - (curPLinesAndPoint.Vect2 - curPDraw.Vect2))); ///调整刻度 AdjustLines(); AdjustLinesAndPoints(); }
public PassValuesEventArgs(VectorChart2 v) { vect = v; }
/// <summary> /// 根据具体的值获取应该的偏移量 /// </summary> /// <param name="offectValue"></param> /// <returns></returns> protected VectorChart2 GetOffectPoint(VectorChart2 offectValue) { return(new VectorChart2(offectValue.Vect1 / everyDisForPiexl.Vect1, offectValue.Vect2 / everyDisForPiexl.Vect2)); }
/// <summary> /// 获取偏移量 /// </summary> /// <returns></returns> protected VectorChart2 GetOffectValue(VectorChart2 offectValue) { return(new VectorChart2(-offectValue.Vect1 * everyDisForPiexl.Vect1, offectValue.Vect2 * everyDisForPiexl.Vect2)); }