A method, device and medium for drawing electrocardiogram waveform based on GPU shader
Through the GPU shader-based electrocardiogram waveform drawing method, the problem of sharp puncture of the extreme point of the electrocardiogram waveform is solved. The combined drawing method of rectangle and triangle is adopted to achieve an approximate circular transition effect and improve the diagnostic accuracy.
Patent Information
- Application Number
- CN202411782842.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-06
- Publication Date
- 2025-03-21
- Estimated Expiration
- 2044-12-06
AI Technical Summary
When drawing medical electrocardiogram waveforms, when the current and last few data values fluctuate by orders of magnitude, the traditional method will cause the extreme value points to be too sharp and seriously deviate from the voltage value, causing the doctor to misdiagnose.
Using the electrocardiogram waveform drawing method based on the GPU shader, two adjacent data in the electrocardiogram data set are used as line segment groups, and the line width d/2 is extended along the normal vector of the line segment group to form a rectangle, and the rectangle is colored through the GPU shader. For the inflection point, calculate that the circle with the inflection point as the center of the circle and d/2 as the radius is uniformly split into n sections, and n triangles are constructed to approximately circular transitions.
The problem of sharp puncture of extreme points in traditional electrocardiogram waveform drawing is solved, and the accuracy of doctors' diagnosis is improved through the approximate circular transition effect.
Smart Images

Figure CN119257609B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of electrocardiogram waveform drawing, and in particular to an electrocardiogram waveform drawing method, device and medium based on a GPU shader. Background Art
[0002] The basic primitives for GPU drawing are: point, line, triangle. For ordinary 1-pixel-width lines, we can directly use "line" as the basic primitive; however, for lines with "width", the lines are actually treated as "rectangles", but the basic primitives do not have "rectangles". Since "rectangles" can be regarded as two triangles spliced together, such as Figure 1 As shown, when the GPU draws a line (or a continuous polyline) with "width", it uses "triangle" as the basic primitive and implements it using the principle of stitching triangles. For example, if we want to draw a polyline segment composed of 3 points (the 3 points are P0, P1, and P2 in sequence) and the line width is d, the principle is to first calculate the angle bisector generated by the two lines before and after a certain point, and then extend the vertical normal vectors in the two directions of the angle bisector by d / 2 units to form two "rectangles". Finally, each rectangle is composed of 2 triangles, as shown in Figure 2 This approach is generally not a big problem when dealing with data fluctuations that are not drastic. However, when drawing medical ECG waveforms, when the values of the first and last data fluctuate by an order of magnitude (dramatic fluctuations), a certain extreme point will be very "sharp" and pierce, which seriously deviates from the voltage value represented by the point, causing doctors to misdiagnose. The reasons for this are as follows: Figure 3 The mathematical illustration shown is: , . Figure 4 This is an example of an ECG waveform that appears in an actual project. It can be seen that the extreme point marked by the circle is convex into a line segment. The actual extreme point is much larger than the actual voltage absolute value, which seriously affects the diagnosis of the ECG doctor. Summary of the invention
[0003] In order to solve the above problems, the present invention proposes a method, device and medium for drawing ECG waveform based on GPU shader.
[0004] The specific plan is as follows:
[0005] A method for drawing an electrocardiogram waveform based on a GPU shader comprises the following steps:
[0006] S1: Take two adjacent data in the ECG data set as a line segment group, and take each data except the first and last two data as an inflection point;
[0007] S2: for each line segment group, according to the width d of the line in the electrocardiogram to be drawn, each data contained in the line segment group is extended by a distance d / 2 in two directions of the normal vector of the line segment composed of two data in the line segment group, to obtain four vertices of a rectangle with a length equal to the length of the line segment and a width of d;
[0008] S3: According to the four vertices of the rectangle corresponding to each line segment group, each rectangle is shaded by the GPU shader;
[0009] S4: for each inflection point, according to the coordinates of the inflection point, calculate the coordinates of n segmentation points after a circle with the inflection point as the center and d / 2 as the radius is evenly divided into n segments;
[0010] S5: Based on the inflection point and each segmentation point, n triangles are constructed, and three vertices in each triangle include the inflection point and two adjacent segmentation points;
[0011] S6: According to the coordinates of the three vertices of each triangle, the n triangles are shaded by the GPU shader at each inflection point.
[0012] Furthermore, n is 20.
[0013] A GPU shader-based ECG waveform drawing terminal device comprises a processor, a memory, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the method described above in the embodiment of the present invention are implemented.
[0014] A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method described above in an embodiment of the present invention are implemented.
[0015] The present invention adopts the above technical solution to solve the problem of sharp punctures in traditional ECG waveforms, and innovatively adopts an "approximately circular" transition effect to improve the accuracy of doctors' diagnosis. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 The figure shows a schematic diagram of a GPU drawing a rectangle.
[0017] Figure 2 Shown is a schematic diagram of a GPU drawing a line with width.
[0018] Figure 3 Shown is a schematic diagram of the extreme points of the ECG waveform.
[0019] Figure 4 Shown is a schematic diagram of the extreme points in the actual ECG waveform.
[0020] Figure 5Shown is a flow chart of a method according to a first embodiment of the present invention.
[0021] Figure 6 Shown is a schematic diagram of rectangles corresponding to each line segment in this embodiment.
[0022] Figure 7 Shown is a schematic diagram of an ECG waveform after line widening processing in this embodiment.
[0023] Figure 8 Shown is a schematic diagram of an actual ECG waveform in this embodiment. DETAILED DESCRIPTION
[0024] To further illustrate various embodiments, the present invention provides drawings. These drawings are part of the disclosure of the present invention, which are mainly used to illustrate the embodiments and can be used in conjunction with the relevant descriptions in the specification to explain the operating principles of the embodiments. With reference to these contents, ordinary technicians in this field should be able to understand other possible implementations and advantages of the present invention.
[0025] The present invention will now be further described with reference to the accompanying drawings and specific implementation methods.
[0026] Embodiment 1:
[0027] The embodiment of the present invention provides a method for drawing an ECG waveform based on a GPU shader, such as Figure 5 As shown, the method comprises the following steps:
[0028] S1: Take two adjacent data in the ECG data set as a line segment group, and take each data except the first and last two data as an inflection point.
[0029] S2: For each line segment group, according to the width d of the lines in the electrocardiogram to be drawn, each data contained in the line segment group is extended by a distance of d / 2 in both directions of the normal vector of the line segment composed of two data in the line segment group, to obtain four vertices of a rectangle with a length of the line segment and a width of d.
[0030] The width d needs to be set in advance.
[0031] In this embodiment, the points corresponding to the two data in the line segment group are used as the endpoints of the line segment, such as Figure 6 In the figure, a and b are the two endpoints of a line segment ab. Since the normal vector of line segment ab has two directions (such as the directions of the normal vector at point a include a→p1 and a→p2, and the directions of the normal vector at point b include b→p3 and b→p4), by extending each endpoint along the two directions of the normal vector by a distance of d / 2, the two extended line segments together form a side of the rectangle (such as sides p1p2 and p3p4).
[0032] According to the coordinates of the two endpoints and the width d, the coordinates of the four vertices of the rectangle can be calculated through existing mathematical theory formulas, such as:
[0033] Assume v is the vector of line segment ab, obviously, v=ba.
[0034] Assuming v1 is the normal vector of ab, then the unit expression of extending d / 2 in the two directions of the normal vector is: v1= * normalize(v) * , where normalize represents the normalized vector.
[0035] The four vertices p1, p2, p3, and p4 of the rectangle can be calculated respectively by the normal vector v1:
[0036] p1 = a + v1;
[0037] p2 = a - v1;
[0038] p3 = a - v1 + v;
[0039] p4 = a + v1 + v.
[0040] S3: According to the four vertices of the rectangle corresponding to each line segment group, each rectangle is shaded by a GPU shader.
[0041] It should be noted that, since the basic graphics primitives drawn by the GPU do not include rectangles, the existing method can be used to split the rectangle into two triangles for drawing and then coloring.
[0042] S4: For each inflection point, according to the coordinates of the inflection point, calculate the coordinates of n segmentation points after a circle with the inflection point as the center and d / 2 as the radius is evenly divided into n segments.
[0043] The splitting in this embodiment is uniform splitting, that is, the lengths of the n arcs obtained by splitting are equal, and the size of the sectors enclosed by each arc and the center of the circle is the same.
[0044] The size of n can be set by those skilled in the art according to actual needs. In this embodiment, n is set to 20.
[0045] According to the coordinates of the center of the circle, the radius (d / 2) and the number of splits (n), the coordinates of the n split points can be calculated using the existing mathematical theory formula. The specific formula is as follows:
[0046] cx + * , y = cy + *
[0047] Among them, cx represents the x-axis coordinate corresponding to the center of the circle, and cy represents the y-axis coordinate corresponding to the center of the circle. It represents the angle between the line connecting the dividing point and the center of the circle and the positive direction of the x-axis. (x, y) represents the coordinates of the dividing point.
[0048] S5: Based on the inflection point and each segmentation point, n triangles are constructed, and the three vertices in each triangle include the inflection point and two adjacent segmentation points.
[0049] After splicing the above n triangles, we get a regular n-gon with the inflection point as the center. When n is larger, the regular n-gon is closer to a circle.
[0050] S6: According to the coordinates of the three vertices of each triangle, the n triangles are shaded by the GPU shader at each inflection point.
[0051] The principle of coloring n triangles in this embodiment is as follows: after obtaining the coordinates of n segmentation points, it is necessary to construct a triangle with every two segmentation points and the center of the circle. Each triangle requires the center of the circle to participate once. We assume that these n points are recorded in turn as an array points[n] = [p 0 , p 1 , ... , p n-1 ], the center of the circle is recorded as: , then the points used to construct the triangle are: , ,... , , To draw n triangles, we need n*3 points. It can be seen that each of the n vertices calculated above needs to be reused once, and then the center of the circle is reused n times. Now let's assume that the sequence of any point in these n*3 points is recorded as , The value range is [0, n*3), excluding n*3, and the center (end) of the circle is recorded as An array of n points Let any point in be p. Then The mathematical relationship with point p is as follows:
[0052]
[0053] This embodiment uses circular arcs to replace sharp corners when processing inflection points. Considering that circles are not included in the basic graphics primitives drawn by the GPU, an approximate circle segmentation processing method is adopted to replace the circle by surrounding it with multiple triangles in order to draw the circle.
[0054] like Figure 7The figure shows the ECG waveform after line widening obtained by the method of this embodiment (the line width is increased to facilitate observation of details). It can be seen that at the connection point (inflection point) of the two straight lines, although the implementation principle adopts the approximate circle segmentation processing method, due to the multi-sampling anti-aliasing MSAA and the limit of human eye resolution, the actual operating effect of this approximate circle segmentation idea is no different from a circle.
[0055] pass Figure 8 It can be seen from the actual ECG waveform obtained by the method of this embodiment that the extreme points therein no longer have sharp punctures.
[0056] Embodiment 2:
[0057] The present invention also provides an ECG waveform drawing terminal device based on a GPU shader, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps in the above-mentioned method embodiment of the first embodiment of the present invention when executing the computer program.
[0058] Further, as an executable solution, the ECG waveform drawing terminal device based on GPU shader can be a computing device such as a desktop computer, a notebook, a PDA, and a cloud server. The ECG waveform drawing terminal device based on GPU shader can include, but is not limited to, a processor and a memory. Those skilled in the art can understand that the composition structure of the ECG waveform drawing terminal device based on GPU shader is only an example of the ECG waveform drawing terminal device based on GPU shader, and does not constitute a limitation on the ECG waveform drawing terminal device based on GPU shader. It can include more or less components than the above, or combine certain components, or different components. For example, the ECG waveform drawing terminal device based on GPU shader can also include input and output devices, network access devices, buses, etc., and the embodiments of the present invention do not limit this.
[0059] Further, as an executable solution, the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, etc. The general-purpose processor may be a microprocessor or any conventional processor, etc. The processor is the control center of the GPU shader-based ECG waveform drawing terminal device, and uses various interfaces and lines to connect various parts of the entire GPU shader-based ECG waveform drawing terminal device.
[0060] The memory can be used to store the computer program and / or module, and the processor realizes various functions of the ECG waveform drawing terminal device based on GPU shader by running or executing the computer program and / or module stored in the memory and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system and an application required for at least one function; the data storage area can store data created according to the use of the mobile phone, etc. In addition, the memory can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart MediaCard, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0061] The present invention also provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above method in the embodiment of the present invention are implemented.
[0062] If the module / unit integrated in the GPU shader-based ECG waveform drawing terminal device is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory) and software distribution medium, etc.
[0063] Although the present invention has been specifically shown and described in conjunction with the preferred embodiments, it should be understood by those skilled in the art that various changes may be made to the present invention in form and details without departing from the spirit and scope of the present invention as defined by the appended claims, all of which are within the scope of protection of the present invention.
Claims
1. A method for drawing ECG waveforms based on GPU shaders, used for drawing ECG waveforms with sharp puncture problems, characterized in that: The following steps are involved: S1: Take two adjacent data in the ECG data set as a data group, and take each data except the first and last two data as an inflection point; S2: for each data group consisting of two data forming a line segment, according to the width d of the line in the electrocardiogram to be drawn, each data contained in the data group is extended by a distance d / 2 in two directions of the normal vector of the line segment formed by the two data in the data group, to obtain four vertices of a rectangle with a length equal to the length of the line segment and a width of d; S3: coloring each rectangle through a GPU shader according to the four vertices of the rectangle corresponding to each data group; S4: for each inflection point, according to the coordinates of the inflection point, calculate the coordinates of n segmentation points after a circle with the inflection point as the center and d / 2 as the radius is evenly divided into n segments; S5: Based on the inflection point and each segmentation point, n triangles are constructed, and three vertices in each triangle include the inflection point and two adjacent segmentation points; S6: According to the coordinates of the three vertices of each triangle, the n triangles are shaded by the GPU shader at each inflection point.
2. The method for drawing ECG waveforms based on GPU shader according to claim 1, characterized in that: n is 20.
3. An ECG waveform drawing terminal device based on GPU shader, characterized in that: The method comprises a processor, a memory, and a computer program stored in the memory and running on the processor, wherein the processor implements the steps of the method according to any one of claims 1 to 2 when executing the computer program.
4. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method as claimed in any one of claims 1 to 2 are implemented.
Citation Information
Patent Citations
Map rendering method and device, storage medium, and electronic device
CN109544658A
Curve generation method and system, computer equipment and storage medium
CN115082592A
Waveform drawing method and device, equipment and storage medium
CN117456044A