public PointsAndPeaks FindPeaks(List<ECGData> points, int lead, bool findPeaks = true) { PointsAndPeaks result = new PointsAndPeaks(); result.Peaks = new List<ECGAnalyzer.Peak>(); result.Points = new List<double>(); for (int i = 0; i < points.Count; i++) { double v = 0; Random rand = new Random(); v = points[i].Lead2.FilteredValue; result.Points.Add(v); if (findPeaks) { List<ECGAnalyzer.Peak> peaks = _analyzer.Update(v); if (peaks != null && peaks.Count > 0) foreach (var p in peaks) result.Peaks.Add(new ECGAnalyzer.Peak(p.Type, p.Tic - points.Count + i, p.GlobalTic, p.Voltage)); } } return result; }
void AddPoints(PointsAndPeaks pointsAndPeaks) { if (!_isInit) { _isInit = true; Init(); ClearImage(); } var values = pointsAndPeaks.Points; var peaks = pointsAndPeaks.Peaks; int count = values == null ? 0 : values.Count(); Label.Text = count.ToString(); double wholeStep = StepPerPoint * count; // StepPerBeat; int windowWidth = (int)Math.Round(VG.ActualWidth); int delta = (int)Math.Round(_currentX + wholeStep - windowWidth); if (count > 0) { double _start = _currentX; double dx = wholeStep / count; if (delta > 0) { int j = (int)((wholeStep - delta) / dx); int[] points = new int[j * 2 + 4]; AddStartPoint(points); FillPoints(points, 2, 0, j, values, dx); double x = points[j * 2] + dx - windowWidth; double converted = ConvertValue(values[j]); double y = (converted - points[j * 2 + 1]) / dx * x + points[j * 2 + 1]; points[j * 2 + 2] = windowWidth; points[j * 2 + 3] = (int)Math.Round(y); DrawLines(points); ClearImage(); if (AutoShift) { Max = (_maxY + _minY) / 2 + 1; Min = (_maxY + _minY) / 2 - 1; _maxY = _minY = values[j]; } _currentX = 0; points = new int[(values.Count - j + 1) * 2]; AddStartPoint(points); FillPoints(points, 2, j, values.Count - j, values, dx); DrawLines(points); _currentX = delta; } else { int[] points = new int[values.Count * 2 + 2]; AddStartPoint(points); if (points[0] == 0) _maxY = _minY = values[0]; FillPoints(points, 2, 0, values.Count, values, dx); DrawLines(points); _currentX = _start + wholeStep; } DrawPicks(peaks, dx, windowWidth); } else { int[] points = new int[4]; AddStartPoint(points); if (delta > 0) { points[2] = windowWidth; points[3] = _currentY; DrawLines(points); ClearImage(); points[0] = 0; points[2] = delta; DrawLines(points); _currentX = delta; } else { points[2] = (int)Math.Round(_currentX + wholeStep); points[3] = _currentY; DrawLines(points); _currentX = _currentX + wholeStep; } } OldClipRect.Rect = new Rect(_currentX, 0, VG.ActualWidth, VG.ActualHeight); }