One 、 Preface

The project involves the drawing of fetal heart rate graph curve , Recently, the project also needs to add the drawing function of ECG curve and blood sample curve . Today, let's share the drawing method of ECG curve ;

Two 、 Text

1、 The fetal heart rate curve is drawn by DrawingVisual To achieve , I also use the same method to realize the ECG curve here , Only the data of the two curves are different . The ECG data server sends a packet to the client every second , There are about 100 ECG data in a packet , Those who have seen ECG should know , The effect of ECG is drawn at a constant speed , Instead of drawing a hundred points at once ; In the project, the data is stored in the data buffer , Then push data to the drawing end through the thread , The thread will dynamically control the speed of data according to the existing data amount in the buffer ; In the example here, I will directly demonstrate how to implement... By pushing data regularly ;

2、 New project , Add a class inheritance FrameworkElement, Then the corresponding data receiving and drawing functions are added , All the codes are posted directly here , The specific details have been written before when drawing the high-performance curve , For those unclear, please refer to the previous ;( In fact, it is used for drawing part Canvas It can also be realized , use DrawingVisual In fact, one data is pushed every time , The entire view has been redrawn , I use this because I want to support autoscale )

public class EcgDrawingVisual : FrameworkElement
{
private readonly List<Visual> visuals = new List<Visual>();
private DrawingVisual Layer; private Pen ecg_pen = new Pen(Brushes.Orange, 1.5); private int?[] ecg_points = new int?[2000]; private int currentStart = 0; private double y_offset = 0; private int ecg_max = 60;
private int ecg_min = -25; public EcgDrawingVisual()
{
ecg_pen.Freeze(); Layer = new DrawingVisual();
visuals.Add(Layer);
} public void SetupData(int ecg)
{
ecg_points[currentStart] = ecg;
for (int i = 1; i <= 20; i++)
{
ecg_points[currentStart + i] = null;
} currentStart++;
if (currentStart >= RenderSize.Width / 2)
{
currentStart = 0;
} DrawEcgLine();
InvalidateVisual();
} private void DrawEcgLine()
{
var scale = RenderSize.Height / (ecg_max - ecg_min);
y_offset = ecg_min * -scale; DrawingContext dc = Layer.RenderOpen();
Matrix mat = new Matrix();
mat.ScaleAt(1, -1, 0, RenderSize.Height / 2);
dc.PushTransform(new MatrixTransform(mat)); for (int i = 0, left = 0; left < RenderSize.Width; i++, left += 2)
{
if (ecg_points[i] == null || ecg_points[i + 1] == null) continue;
dc.DrawLine(ecg_pen, new Point(left, ecg_points[i].Value * scale + y_offset), new Point(left + 2, ecg_points[i + 1].Value * scale + y_offset));
} dc.Pop();
dc.Close();
} protected override int VisualChildrenCount => visuals.Count;
protected override Visual GetVisualChild(int index)
{
return visuals[index];
} protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
{
base.OnRenderSizeChanged(sizeInfo);
} protected override void OnRender(DrawingContext drawingContext)
{
drawingContext.DrawRectangle(Brushes.White, null, new Rect(0, 0, RenderSize.Width, RenderSize.Height));
base.OnRender(drawingContext);
}
}

3、 Add this control to the main interface , Then add the corresponding thread to push data in the background , Here I push a data to the drawing end every ten milliseconds .

public partial class MainWindow : Window
{
private List<int> points = new List<int>() { 4, 4, 3, -1, -2, -2, -2, -2, -2, -2, -2, -2, -4, -3, 25, 37, 8, -7, -5, -3, -3, -3, -3, -3, -3, -3, -3, -2, -2, -2, -1, -1, 3, 5, 8, 9, 9, 10, 9, 7, 5, 1, -1, -4, -4, -4, -4, -4, -4, -4, -3, -3, -3, -3, -3, -3, -3, -3, -3, -2, -2, -2, -2, -2, -2, -1, 1, 3 };
private bool flag = true;
private int currentIndex = 0; public MainWindow()
{
InitializeComponent(); new Thread(() =>
{
while (flag)
{
Thread.Sleep(10);
this.Dispatcher.BeginInvoke(new Action(() =>
{
if (currentIndex == points.Count) currentIndex = 0;
ecgDrawingVisual.SetupData(points[currentIndex]);
currentIndex++;
}));
}
}).Start();
} protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
flag = false;
}
}

4、 Final effect

WPF Development essay collection - More articles on ECG curve drawing

  1. WPF Graph control curve drawing and moving

    Purpose : Draw a simple and lightweight curve view Two . Realization effect : 1, Draw a standard baseline 2, Drag 3、 ... and . Use control 1,Canvas 2,Ellipse XAML Code : <Canvas Background=&quo ...

  2. A good workman does his work well , You must sharpen your tools first And WPF piece : Efficient with development track WPF Tools and techniques for development

    Previous article < A good workman does his work well , You must sharpen your tools first .VS2013 Total strategy ( install , skill , Shortcut key , plug-in unit )!> See many friends reply and support , Thank you very much , Especially some oil sprays that beat bricks , Thank you for your criticism , Benefit a lot . My first job was W ...

  3. WPF Developed lottery program ( A good example of hand training ) Source code attached

    Preface WPF yes .NET The latest interface development library , The development interface is very flexible ! But learning WPF It's also very difficult . At the invitation of a friend , Write a small program . The program is small , Five zang organs ,WPF A glimpse of the flexibility of development . It's a good reference for beginners , ...

  4. WPF Developed lottery program ( A good example of hand training )

    Preface WPF yes .NET The latest interface development library , The development interface is very flexible ! But learning WPF It's also very difficult . At the invitation of a friend , Write a small program . The program is small , Five zang organs ,WPF A glimpse of the flexibility of development . It's a good reference for beginners , ...

  5. iOS Use Bezier curve to draw path

    Use Bezier curve to draw path Most of the time , The border of the control we used in the development is rectangular , Or make some rounded corners , Is to make the corners of the rectangle look more smooth . But what if we want an irregular shape ? Some people say , It's called UI Sister do , It's not only easy , just so so ...

  6. wpf Develop desktop software records

    My development environment is win7,vs2013,sql2012, use wpf Developed a very simple desktop software , use Installshield Make the installation package , The installation package contains .framework4.5, Test normal on your computer , Think very ...

  7. ROC Curve drawing

    ROC Curve drawing Personal understanding :1.ROC The curve must be entered for continuous values , By selecting different thresholds, smooth and continuous ROC curve , So it is usually applied to Saliency Algorithm evaluation , Because you can choose 0~255 Any value in the threshold ...

  8. WPF Develop time trace diary

       I haven't written anything for a long time , A new year, a new beginning . I have long wanted to develop a diary software, not only for my own use , You can also use it for free , The most important thing is to recognize yourself , self-taught WPF since , It doesn't feel very good ,WPF There is a little bit less information about , Lord ...

  9. [ Re posting ]MATLAB Curve drawing and color type

    The method of signal source generation source :http://www.2cto.com/kf/201401/270494.html  matlab Of checkerboard explain ,GOOD! source :http://www.chi ...

  10. dried food -- Wechat public platform client debugging tool - First try WPF Development

    This tool can be used by any developer who develops wechat public platform , Although it's used by itself WPF(C#) Developed , But it's not affected by the language of the service you want to debug . I have been developing wechat public platform before , Client debugging is a must , It's been used all the time ...

Random recommendation

  1. MapReduce Word count

    Recently in to see google That classic MapReduce The paper , The Chinese version can refer to... Recommended by Meng Yan mapreduce Chinese version Chinese translation It is mentioned in the paper that ,MapReduce Our programming model is : The calculation uses an input key/value ...

  2. thorough ThreadLocal One of

    I think many friends are right ThreadLocal No stranger , Today, let's discuss ThreadLocal How to use it and how to realize it . First , This article first talks about the right ThreadLocal The understanding of the , And then according to ThreadLocal Class source code ...

  3. Network subsystem 55_ip The agreement was pieced together _ Join in ipq

    //ip Slice into the right ipq structure // Call path :ip_defrag->ip_frag_queue // Treatment process : // 1. Being released ipq, Don't deal with newly added pieces (ipq Being released by last ...

  4. Psychos in a Line

    Codeforces Round #189 (Div. 1) B:http://codeforces.com/problemset/problem/319/B The question : each ROUND If someone's number is greater than ...

  5. Newton method and quasi Newton method ,DFP Law ,BFGS Law ,L-BFGS Law

    Newton method Consider the following unconstrained minimization problem : $$\min_{x} f(x)$$ among $x\in R^N$, And suppose $f(x)$ Is a convex function , Second order differentiability . The current point is marked as $x_k$, The best points are recorded as $x^*$. The gradient descent method uses ...

  6. Nginx+keepalive Other LAN hosts ping vip no

    There are two high availability server server1  192.168.11.10 server2  192.168.11.11 vip :192.168.11.12 Good configuration keepalive After the server1 ...

  7. How to be in vmware esxi Opening up in China VNC Functions and ports realize remote management Full article

    VMWare esxi Opening up in China VNC Functions and ports realize remote management Full article I have read relevant articles on several forums , The overall writing is incomplete . Now the resources of all parties are compiled into a complete version . The details are as follows ! ( The picture is from 51CTO) step 1.  modify ESXi The host ...

  8. 11 Zabbix Item Type Zabbix Calculated Computational Item type

    Click on the return : self-taught Zabbix The way Click on the return : self-taught Zabbix4.0 The way Click on the return : self-taught zabbix highlights 11 Zabbix Item Type Zabbix Calculated Computational Item type Calculation type ...

  9. unity Find which objects in the scene the script is referenced by

    Right click the script you want to find : All objects that reference the script have been displayed in the scene

  10. [TJOI2018] The quiz

    subject We find that we need to maximize the minimum , Basically two points Then we divide a value in two, and we delete all values less than or equal to this value , The question now becomes how to use \(n+1\) Paths cover this picture This is not the minimum path coverage So I forgot how to cover the minimum path ...