private async Task AlgorithmAsync(VibrationChannelToken token) { double sampleFre = token.VData.SampleFre; if (token.VData.Trigger == TriggerType.Angle) { sampleFre = token.VData.RPM * token.VData.TeethNumber / 60; } int samplePoint = token.VData.SamplePoint; double rpm = token.VData.RPM; var input = token.VData.Waveform; if (filterCheckBox.IsChecked == true) { input = await Task.Run(() => { return(viewModel.Filter(input, samplePoint, sampleFre, rpm)); }); } if (envelopeCheckBox.IsChecked == true) { input = await Task.Run(() => { return(Algorithm.Instance.Envelope(input, samplePoint)); }); } else if (tffCheckBox.IsChecked == true) { input = await Task.Run(() => { return(Algorithm.Instance.TFF(input, samplePoint, sampleFre)); }); } else if (cepstrumCheckBox.IsChecked == true) { input = await Task.Run(() => { return(Algorithm.Instance.Cepstrum(input, samplePoint)); }); } int length = (int)(samplePoint / 2.56) + 1; token.VData.PowerSpectrum = Algorithm.Instance.PowerSpectrumAction(input, sampleFre, samplePoint, dbCheckBox.IsChecked.Value).Take(length).ToArray(); }
private async Task AlgorithmAsync(VibrationChannelToken token) { double sampleFre = token.VData.SampleFre; if (token.VData.Trigger == TriggerType.Angle) { sampleFre = token.VData.RPM * token.VData.TeethNumber / 60; } int samplePoint = token.VData.SamplePoint; double rpm = token.VData.RPM; var input = token.VData.Waveform; if (filterCheckBox.IsChecked == true) { input = await Task.Run(() => { return(viewModel.Filter(input, samplePoint, sampleFre, rpm)); }); } if (envelopeCheckBox.IsChecked == true) { input = await Task.Run(() => { return(Algorithm.Instance.Envelope(input, samplePoint)); }); } else if (tffCheckBox.IsChecked == true) { input = await Task.Run(() => { return(Algorithm.Instance.TFF(input, samplePoint, sampleFre)); }); } else if (cepstrumCheckBox.IsChecked == true) { input = await Task.Run(() => { return(Algorithm.Instance.Cepstrum(input, samplePoint)); }); } token.VData.FilterWaveform = input; }
private void UpdateCursorResult() { m_chart.BeginUpdate(); LineSeriesCursor cursor = m_chart.ViewXY.LineSeriesCursors[0]; AnnotationXY cursorValueDisplay = m_chart.ViewXY.Annotations[0]; float fTargetYCoord = m_chart.ViewXY.GetMarginsRect().Bottom; double dY; m_chart.ViewXY.YAxes[0].CoordToValue(fTargetYCoord, out dY); cursorValueDisplay.TargetAxisValues.X = cursor.ValueAtXAxis; cursorValueDisplay.TargetAxisValues.Y = dY; StringBuilder sb = new StringBuilder(); int iSeriesNumber = 1; string strValue = ""; bool bLabelVisible = false; int seriesCount = m_chart.ViewXY.PointLineSeries.Count; for (int i = 0; i < seriesCount; i++) { var series = m_chart.ViewXY.PointLineSeries[i]; strValue = iSeriesNumber + ":"; VibrationChannelToken token = series.Tag as VibrationChannelToken; if (token.VData != null) { bool bResolvedOK = false; double yValue = 0; bResolvedOK = SolveValueAccurate(series, cursor.ValueAtXAxis, out yValue); if (bResolvedOK) { bLabelVisible = true; //strValue = string.Format(strChannelStringFormat, iSeriesNumber, Math.Round(yValue, 2), unit); strValue += Math.Round(yValue, 2) + "(" + token.VData.Unit + ")"; } else { //strValue = string.Format(strChannelStringFormat, iSeriesNumber, "---", "Unit"); strValue += "---" + "(Unit)"; } } sb.AppendLine(strValue); iSeriesNumber++; } sb.AppendLine("频率: " + cursor.ValueAtXAxis.ToString("0.00") + "Hz"); //Set text cursorValueDisplay.Text = sb.ToString().Trim(); cursorValueDisplay.Visible = bLabelVisible; //Allow chart rendering m_chart.EndUpdate(); }
private async Task AlgorithmAsync(VibrationChannelToken token) { double sampleFre = token.VData.SampleFre; if (token.VData.Trigger == TriggerType.Angle) { sampleFre = token.VData.RPM * token.VData.TeethNumber / 60; } int samplePoint = token.VData.SamplePoint; double rpm = token.VData.RPM; var input = token.VData.Waveform; if (filterCheckBox.IsChecked == true) { input = await Task.Run(() => { return(viewModel.Filter(input, samplePoint, sampleFre, rpm)); }); } if (envelopeCheckBox.IsChecked == true) { input = await Task.Run(() => { return(Algorithm.Instance.Envelope(input, samplePoint)); }); } else if (tffCheckBox.IsChecked == true) { input = await Task.Run(() => { return(Algorithm.Instance.TFF(input, samplePoint, sampleFre)); }); } else if (cepstrumCheckBox.IsChecked == true) { input = await Task.Run(() => { return(Algorithm.Instance.Cepstrum(input, samplePoint)); }); } var output = Algorithm.Instance.FFT2AndPhaseAction(input, samplePoint); double frequencyInterval = sampleFre / samplePoint; int length = (int)(samplePoint / 2.56) + 1; if (token.VData.Frequency == null || token.VData.Frequency.Length != length) { token.VData.Frequency = new double[length]; } for (int i = 0; i < length; i++) { token.VData.Frequency[i] = frequencyInterval * i; } token.VData.Amplitude = output[0].Take(length).ToArray(); token.VData.Phase = output[1].Take(length).ToArray(); }
private void OnChannelAdded(ChannelToken token) { try { if (viewModel == null || !(token is VibrationChannelToken)) { return; } m_chart.BeginUpdate(); VibrationChannelToken vToken = token as VibrationChannelToken; AxisY axisY = new AxisY(m_chart.ViewXY); axisY.Tag = vToken; axisY.Title.Visible = false; axisY.AxisThickness = 2; axisY.AxisColor = Color.FromArgb(100, 135, 205, 238); m_chart.ViewXY.YAxes.Add(axisY); int count = m_chart.ViewXY.PointLineSeries.Count; while (count > 15) { count -= 15; } Color color = DefaultColors.SeriesForBlackBackgroundWPF[count]; PointLineSeries series = new PointLineSeries(m_chart.ViewXY, m_chart.ViewXY.XAxes[0], axisY); series.MouseInteraction = false; series.LineStyle.Color = color; series.LineStyle.AntiAliasing = LineAntialias.None; series.LineStyle.Width = 1; series.Tag = vToken; series.Title.Text = vToken.Channel.Name + vToken.Channel.MSSN; series.Title.Font = new WPFFont(System.Drawing.FontFamily.GenericSansSerif, 10f, System.Drawing.FontStyle.Bold); series.Title.Color = ChartTools.CalcGradient(Colors.White, Colors.White, 50); series.Title.HorizontalAlign = AlignmentHorizontal.Left; series.Title.VerticalAlign = AlignmentVertical.Top; series.Title.MoveByMouse = false; series.Title.MouseInteraction = false; series.Title.Offset = new PointIntXY(5, 5); series.Title.Visible = true; if (m_chart.ViewXY.Annotations.Count == 0) { CreateCalloutAnnotation(); CreateFAAnnotation(); } //Update Annotation AnnotationXY annotation = m_chart.ViewXY.Annotations[1]; string[] branches = annotation.Text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); StringBuilder sb = new StringBuilder(); for (int i = 0; i < branches.Length; i++) { sb.AppendLine(branches[i]); } string freText = "F"; string ampText = "A"; if (vToken.VData != null) { int length = vToken.VData.FFTLength; SeriesPoint[] points = new SeriesPoint[length]; SeriesPoint[] phasePoints = new SeriesPoint[length]; for (int i = 0; i < length; i++) { points[i] = new SeriesPoint(vToken.VData.Frequency[i], vToken.VData.PowerSpectrum[i]); phasePoints[i] = new SeriesPoint(vToken.VData.Frequency[i], vToken.VData.Phase[i]); } series.Points = points; var fftValuesDict = vToken.VData.PowerSpectrum.Select((s, i) => new { Key = i, Value = s }).OrderByDescending(o => o.Value).Take(6); foreach (var item in fftValuesDict) { freText += string.Format("{0,6}|", vToken.VData.Frequency[item.Key].ToString("0.00")); ampText += string.Format("{0,6}|", item.Value.ToString("0.00")); } } sb.AppendLine(freText); sb.AppendLine(ampText); annotation.Text = sb.ToString(); m_chart.ViewXY.PointLineSeries.Add(series); m_chart.ViewXY.Annotations[0].AssignYAxisIndex = -1; m_chart.ViewXY.Annotations[0].AssignYAxisIndex = 0; m_chart.ViewXY.FitView(); m_chart.EndUpdate(); } catch (Exception ex) { m_chart.EndUpdate(); EventAggregatorService.Instance.EventAggregator.GetEvent <ThrowExceptionEvent>().Publish(Tuple.Create <string, Exception>("数据回放-功率谱-添加通道", ex)); } }
private void OnChannelAdded(ChannelToken token) { try { if (viewModel == null || !(token is VibrationChannelToken)) { return; } m_chart.BeginUpdate(); VibrationChannelToken vToken = token as VibrationChannelToken; AxisY axisY = new AxisY(m_chart.ViewXY); axisY.Tag = vToken; axisY.Title.Visible = false; axisY.AxisThickness = 2; axisY.AxisColor = Color.FromArgb(100, 135, 205, 238); m_chart.ViewXY.YAxes.Add(axisY); if (m_chart.ViewXY.Annotations.Count == 0) { CreateAnnotation(); } AnnotationXY annotation = m_chart.ViewXY.Annotations[0]; int count = m_chart.ViewXY.SampleDataSeries.Count; while (count > 15) { count -= 15; } Color color = DefaultColors.SeriesForBlackBackgroundWPF[count]; SampleDataSeries series = new SampleDataSeries(m_chart.ViewXY, m_chart.ViewXY.XAxes[0], axisY); series.SampleFormat = SampleFormat.DoubleFloat; series.MouseInteraction = false; series.LineStyle.Color = color; series.LineStyle.AntiAliasing = LineAntialias.None; series.LineStyle.Width = 1; series.Tag = vToken; series.Title.Text = vToken.Channel.Name + vToken.Channel.MSSN; series.Title.Font = new WPFFont(System.Drawing.FontFamily.GenericSansSerif, 10f, System.Drawing.FontStyle.Bold); series.Title.Color = ChartTools.CalcGradient(Colors.White, Colors.White, 50); series.Title.HorizontalAlign = AlignmentHorizontal.Left; series.Title.VerticalAlign = AlignmentVertical.Top; series.Title.MoveByMouse = false; series.Title.MouseInteraction = false; series.Title.Offset = new PointIntXY(5, 5); series.Title.Visible = true; //Update Annotation StringBuilder sb = new StringBuilder(); string[] branches = annotation.Text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < branches.Length; i++) { sb.AppendLine(branches[i]); } string text = string.Format("{0}:", m_chart.ViewXY.YAxes.Count); if (vToken.VData != null) { series.SamplesDouble = vToken.VData.Waveform; axisY.Title.Text += "\r\n" + " (" + vToken.VData.Unit + ")"; text = string.Format("{0,6}|{1,6}|{2,6}|{3,7}|{4,6}|{5,9}|{6,9}|{7,9}|{8,9}|{9,9}|{10,9}", vToken.VData.AMS.ToString("0.00"), vToken.VData.PeakValue.ToString("0.00"), vToken.VData.PeakPeakValue.ToString("0.00"), vToken.VData.Slope.ToString("0.00"), vToken.VData.Kurtosis.ToString("0.00"), vToken.VData.KurtosisValue.ToString("0.00"), vToken.VData.WaveIndex.ToString("0.00"), vToken.VData.PeakIndex.ToString("0.00"), vToken.VData.ImpulsionIndex.ToString("0.00"), vToken.VData.RootAmplitude.ToString("0.00"), vToken.VData.ToleranceIndex.ToString("0.00")); } sb.Append(text); annotation.Text = sb.ToString().Trim(); m_chart.ViewXY.SampleDataSeries.Add(series); m_chart.ViewXY.FitView(); m_chart.EndUpdate(); } catch (Exception ex) { m_chart.EndUpdate(); EventAggregatorService.Instance.EventAggregator.GetEvent <ThrowExceptionEvent>().Publish(Tuple.Create <string, Exception>("数据回放-时域-添加通道", ex)); } }
private void UpdateCursorResult(double xValue) { try { m_chart.BeginUpdate(); List <VibrationChannelToken> channelList = new List <VibrationChannelToken>(); AnnotationXY cursorValueDisplay = m_chart.ViewXY.Annotations[0]; float fTargetYCoord = m_chart.ViewXY.GetMarginsRect().Bottom; double dY; m_chart.ViewXY.YAxes[0].CoordToValue(fTargetYCoord, out dY); cursorValueDisplay.TargetAxisValues.X = xValue; cursorValueDisplay.TargetAxisValues.Y = dY; StringBuilder sb = new StringBuilder(); int iSeriesNumber = 1; string strChannelStringFormat = "{0}: {1}({2})"; string strValue = ""; bool bLabelVisible = false; foreach (PointLineSeries series in m_chart.ViewXY.PointLineSeries) { strValue = ""; int index = GetNearestIndex(series, xValue); bLabelVisible = true; if (series.Tag is VibrationChannelToken) { VibrationChannelToken token = series.Tag as VibrationChannelToken; token.CurrentIndex = index; channelList.Add(token); if (index != -1) { VInfoTableAMSContract contract = token.DataContracts[index]; //. series.Points[index].Tag as VInfoTableAMSContract; string unit = string.Empty; switch (contract.Unit) { case 0: unit = "m/s2"; break; case 1: unit = "mm/s"; break; case 2: unit = "mm"; break; } strValue = string.Format("{0}: {1}({2})|{3}", token.Channel.Name + token.Channel.MSSN, Math.Round(contract.Value, 3), unit, Math.Round(contract.RPM ?? 0.0, 3)); } else { strValue = string.Format(strChannelStringFormat, token.Channel.Name + token.Channel.MSSN, "---", "Unit"); } } else if (series.Tag is AnalogChannelToken) { AnalogChannelToken token = series.Tag as AnalogChannelToken; if (index != -1) { AnInfoTableAMSContract contract = token.DataContracts[index]; //series.Points[index].Tag as AnInfoTableAMSContract; string unit = string.Empty; switch (contract.Unit) { case 3: unit = "℃"; break; case 4: unit = "Pa"; break; case 5: unit = "RPM"; break; } strValue = string.Format(strChannelStringFormat, token.Channel.Name + token.Channel.MSSN, Math.Round(contract.Value, 3), unit); } else { strValue = string.Format(strChannelStringFormat, token.Channel.Name + token.Channel.MSSN, "---", "Unit"); } } else if (series.Tag is DivFreChannelToken) { DivFreChannelToken token = series.Tag as DivFreChannelToken; if (index != -1) { DivFreTableFreContract contract = token.DataContracts[index]; string unit = string.Empty; switch (contract.Unit) { case 0: unit = "分频-m/s2"; break; case 1: unit = "分频-mm/s"; break; case 2: unit = "分频-mm"; break; } strValue = string.Format(strChannelStringFormat, token.Channel.FreDescription, Math.Round(contract.FreMV, 3), unit); } else { strValue = string.Format(strChannelStringFormat, token.Channel.FreDescription, "---", "Unit"); } } sb.AppendLine(strValue); // series.Title.Text = strValue; iSeriesNumber++; } sb.AppendLine("Time: " + m_chart.ViewXY.XAxes[0].TimeString(xValue, "yyyy/MM/dd HH:mm:ss")); //Set text cursorValueDisplay.Text = sb.ToString().Trim(); cursorValueDisplay.Visible = bLabelVisible; //Allow chart rendering m_chart.EndUpdate(); if (channelList.Count > 0) { viewModel.RaiseTrackChanged(channelList); } } catch (Exception ex) { EventAggregatorService.Instance.EventAggregator.GetEvent <ThrowExceptionEvent>().Publish(Tuple.Create <string, Exception>("数据回放-通频趋势-Track", ex)); m_chart.EndUpdate(); } }