A distortion-free drawing method for multi-linewidth line segments for flat-screen displays
The method addresses distortion in multi-line width line segments by selecting a main axis and interpolating pixel center points to achieve high-quality, effective anti-aliasing, and reduces cache space usage by avoiding redundant drawing points.
Patent Information
- Application Number
- CN202210501117.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-10
- Publication Date
- 2024-12-27
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing methods for drawing multi-line width line segments in head-up displays result in distortion, particularly for oblique lines with floating-point endpoints, and fail to provide effective anti-aliasing.
A method involving selecting a main axis based on the line segment's slope, determining a scanning window, and using a uniformly distributed grid algorithm to generate sampling points, judging their position within the line segment, and interpolating pixel center points for anti-aliasing to achieve distortion-free rendering.
Enables distortion-free rendering of multi-line width line segments with floating-point endpoints, improves display quality, and reduces cache space usage by avoiding redundant drawing points.
Smart Images

Figure CN114913265B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of graphic display technology, and in particular to a method for rendering multi-line width line segments without distortion for a head-up display. Background Art
[0002] Line segments are one of the most basic elements of computer graphics. In many display systems, line segments of arbitrary line widths need to be drawn. Common methods for drawing multi-line width line segments are DDA algorithm, Bresenham algorithm, and Wu anti-aliasing algorithm. These methods are simple and convenient to implement, but the oblique line segments are presented as diamonds instead of rectangles, and these algorithms do not support the case where the starting point and end point are floating point numbers. How to quickly and easily draw distortion-free multi-line width line segments has become an important research topic. Summary of the invention
[0003] In view of the deficiencies in the prior art, the present invention provides a method for drawing multi-line width line segments without distortion for a head-up display, which can solve the problem that multi-line width oblique line segments are presented in a diamond shape. The method is applicable to drawing line segments of arbitrary line width whose endpoints are floating point numbers without distortion and has low hardware requirements.
[0004] To achieve the above object, the present invention adopts the following technical solutions:
[0005] A method for rendering multiple line width segments without distortion for a head-up display, the method comprising the following steps:
[0006] S1, select the main axis according to the slope of the line segment, determine the four sides of the line segment and the scanning window;
[0007] S2, scan each pixel point one by one in the determined scanning window, adopt a uniformly distributed grid algorithm, generate n sampling points for each pixel point, judge whether the sampling point is inside the line segment through the intersection of the horizontal scanning line or the vertical scanning line passing through the sampling point and the four sides of the line segment, record the number of sampling points inside the line segment as mask, and then interpolate the pixel center point to obtain color information, calculate the weight of the transparency of each pixel point weight = mask / n according to the value of mask, calculate the weight of transparency according to multiple sampling points, assign RGB to the pixel point according to the color information obtained by interpolation, and combine the transparency weight to achieve anti-aliasing effect, and complete the drawing of distortion-free multi-line width line segments.
[0008] To optimize the above technical solutions, the specific measures taken also include:
[0009] Furthermore, in step S1, the process of selecting the main axis according to the slope of the line segment and determining the four sides of the line segment and the scanning window includes the following steps:
[0010] S11, let the starting point and end point of the line segment be P0(x0,y0) and P1(x1,y1), and P0 be on the left side of P1;
[0011] S12, according to the slope of line segment P0P1 Select the main axis, the line width is w, the four sides of the line segment are L1, L2, L3, L4, L3, L4 are perpendicular to P0P1, L1, L2 are parallel to P0P1; the analytical expression of L1 is y=k(x-x0)+y0+b; the analytical expression of L2 is y=k(x-x0)+y0-b; the analytical expression of L3 is y=k′(x-x0)+y0; the analytical expression of L4 is y=k′(x-x1)+y1;
[0012] S13, the calculated starting coordinates of the scanning window area are set as The area end coordinates of the scan window are set to Indicates rounding down. Indicates rounding up.
[0013] Furthermore, in step S2, the process of determining whether the sampling point is inside the line segment by the intersection of the horizontal scanning line or the vertical scanning line passing through the sampling point and the four sides of the line segment includes the following steps:
[0014] S201, let the rectangle to be drawn be P 0′ P 1′ P 2′ P 3′ ;
[0015] S202, select any sampling point P si (x si ,y si ), the corresponding vertical scanning line x = x si The intersection points with L1, L2, L3, and L4 are P L1 , P L2 , P L3 , P L4 , click P L1 The vertical coordinate y L1 = k(x si -x0)+y0+b, point P L2 The vertical coordinate y L2 = k(x si -x0)+y0-b, point P L3 The vertical coordinate y L3 = k′(x si -x0)+y0, point P L4 The vertical coordinate y L4 = k′(x si -x1)+y1;
[0016] S203, by comparing y si With the vertical scan line x=x si The intersection point P with the four boundaries of the rectangle L1, L2, L3, L4 L1 , P L2 , P L3 , P L4 The size of the ordinate is used to determine whether the sampling point is inside the rectangle.
[0017] Furthermore, in step S203, the sampling point P si The condition inside the line segment is y si ≥y L2 and y si ≥y L3 andy si ≤y L1 and y si ≤y L4 .
[0018] Furthermore, in step S2, the process of interpolating the pixel center point to obtain color information includes the following steps:
[0019] S211, record any pixel (x s ,y s ) corresponds to the coordinates of the pixel center point P is (x s +0.5,y s +0.5), the ratio of the projection of PP0 on P0P1 to P0P1 is t, and the angle between PP0 and P0P1 is θ;
[0020] S212 is calculated according to the following formula: After simplification,
[0021] S213, the attribute of the starting point P0 is recorded as f0, and the attribute of the end point P1 is recorded as f1, then the attribute f of the pixel point is obtained by interpolation calculation: f=(1-t)·f0+t·f1.
[0022] The beneficial effects of the present invention are:
[0023] First, the method for rendering multiple line width segments without distortion for HUD of the present invention can realize rendering of line segments without distortion of any line width, supports rendering of line segments whose endpoints are floating point numbers, has good display effect, and is highly practical.
[0024] Secondly, the method for drawing multi-line width line segments without distortion for HUD of the present invention solves the problem that multi-line width oblique line segments are presented as diamonds instead of rectangles, optimizes the display effect, and is more in line with the actual presentation of graphics.
[0025] Thirdly, the method for drawing multiple line width segments without distortion for HUD of the present invention does not generate repeated drawing points when drawing multiple line width segments, thereby reducing the occupation of cache space and enhancing the graphics processing capability. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 Schematic diagram of the principle of judging whether a sampling point is inside a multi-line width line segment;
[0027] Figure 2 It is a schematic diagram of the calculation principle of the analytical expression of the four sides of a rectangle;
[0028] Figure 3 Schematic diagram of the calculation principle of pixel attributes;
[0029] Figure 4 The figures are simulation display effect diagrams of multi-line width line segments with different line widths and slopes drawn by the Wu anti-aliasing algorithm and the method of the present invention respectively; wherein, Figure 4 (a) Draw the simulation display effect diagram for Wu anti-aliasing algorithm of multi-line width line segments with different line widths and slopes; Figure 4 (b) is a simulation display effect diagram of drawing multi-line width line segments with different line widths and slopes according to the method of the present invention. DETAILED DESCRIPTION
[0030] The present invention will now be described in further detail with reference to the accompanying drawings.
[0031] It should be noted that the terms such as "upper", "lower", "left", "right", "front", "back", etc. cited in the invention are only for the convenience of description and are not used to limit the scope of implementation of the present invention. Changes or adjustments in their relative relationships should be regarded as the scope of implementation of the present invention without substantially changing the technical content.
[0032] The idea of the present invention is to improve the existing anti-aliasing drawing method based on the principle of multiple sampling. The main axis is selected according to the slope, and the sampling point is judged whether it is inside the line segment through the intersection of the horizontal / vertical scanning line and the four sides of the line segment. Then the pixel center point is interpolated to obtain color information, and the transparency weight is calculated according to multiple sampling points to achieve anti-aliasing and draw distortion-free multi-line width line segments.
[0033] Figure 1 A schematic diagram for determining whether a sampling point is inside a multi-line width segment. The starting and ending coordinates of the segment are P0(x0,y0) and P1(x1,y1), and P0 is on the left side of P1. Select the main axis and line width as w. The actual rectangle to be drawn is denoted as P 0′ P 1′ P 2′ P 3′ , let the coordinates of a sampling point be P si (xsi ,y si ), by comparing y si With the vertical scan line x=x si The intersection point P with the four boundaries of the rectangle L1, L2, L3, L4L4 L1 , P L2 , P L3 , P L4 The size of the ordinate is used to determine whether the sampling point is inside the rectangle, and the weight of the sampling point inside the rectangle is obtained.
[0034] Figure 2 This is a schematic diagram for calculating the analytical expression of the four sides of a rectangle.
[0035] Step 1: The slope of line segment P0P1 is L3 and L4 are perpendicular to P0P1. Let the slope of L3 and L4 be k′. Then L3 passes through point P0, so the analytical expression of L3 is y=k′(x-x0)+y0. L4 passes through point P1, so the analytical expression of L4 is y=k′(x-x1)+y1. Vertical scanning line x=x si The intersection point with L3 and L4 is P L3 , P L4 , thus we get point P L3 The vertical coordinate y L3 = k′(x si -x0)+y0, point P L4 The vertical coordinate y L4 = k′(x si -x1)+y1.
[0036] Step 2: L1 and L2 are parallel to the line segment P0P1, and their slope is k. By using the similarity of triangles, calculate the intercept difference b of L1 and L2 relative to the line segment P0P1. By using the similarity of triangles, we get Calculated The analytical expression of L1 is y=k(x-x0)+y0+b, and the analytical expression of L2 is y=k(x-x0)+y0-b. si The intersection point with L1 and L2 is P L1 , P L2 , thus we get point P L1 The vertical coordinate y L1 = k(x si -x0)+y0+b, point P L2 The vertical coordinate y L2 = k(x si -x0)+y0-b.
[0037] Step 3: Set the sampling point P si (x si,y si ) si and the calculated y L1 ,y L2 ,y L3 ,y L4 The size of the sampling point P is compared si The condition inside the line segment is y si ≥y L2 and y si ≥y L3 and y si ≤y L1 and y si ≤y L4 , thereby calculating the proportional weight of the sampling point inside the line segment. The weight is the transparency of the pixel point, which makes the edge points darker and achieves the anti-aliasing effect.
[0038] Figure 3 The following is a schematic diagram of the calculation of pixel attributes. The attributes of each pixel are obtained by interpolating the pixel center point, the starting point, and the end point of the pixel. s ,y s ), then the coordinates of the pixel center point P are (x s +0.5,y s +0.5). Let the ratio of the projection of PP0 on P0P1 to P0P1 be t, and the angle between PP0 and P0P1 be θ, then After simplification, Let the attribute of the starting point P0 be f0, and the attribute of the end point P1 be f1. Then the attribute f of the pixel point can be obtained by interpolation calculation: f=(1-t)·f0+t·f1.
[0039] This embodiment presets several sets of multi-line width drawing parameters with different line widths and different slopes. Figure 4 (a) is the simulation display effect diagram of multi-line width line segments with different line widths and slopes drawn by Wu anti-aliasing algorithm. Figure 4(b) is a simulation display effect diagram of multi-line width line segments with different line widths and slopes drawn by the method of the present invention; the top picture is an enlarged view of the line segment endpoints. It can be found that the Wu anti-aliasing algorithm achieves the anti-aliasing effect of the line segment by adding pixels with a transparency of not 1 directly above and below the line segment rather than in the direction perpendicular to the line segment. For line segments with a slope of not 0, if the anti-aliasing algorithm used is the Wu anti-aliasing algorithm, the final display effect of the line segment will be a rhombus state instead of a rectangle, and the anti-aliasing effect will not be applied to the endpoints of the line segment. In addition, for line segments with floating-point endpoints, the Wu anti-aliasing algorithm will round the floating-point part, so that the actual display position is different from the theoretical display position. The method of the present invention adopts a multi-sampling algorithm and determines whether the sampling point is inside the line segment through the function analytical expression of the four sides of the line segment. In this way, there is no need to round the floating-point endpoints to determine the weight of the pixel transparency, so that the problem of the line segment presentation being a rhombus will not occur, and the problem of no anti-aliasing effect at the endpoints is also solved. The optimization effect brought about by the method of the present invention can be more intuitively observed through the comparison of the following figures.
[0040] By comparison, it can be seen that the display effect of the method of the present invention is better than that of the display effect drawn by the Wu anti-aliasing algorithm, and the problem of the oblique line segment being presented in a diamond shape is solved. Anti-aliasing is performed at both the starting point and the end point, and the input endpoint is allowed to be a floating point number, so the drawing method is more extensive.
[0041] The above are only preferred embodiments of the present invention, and the protection scope of the present invention is not limited to the above embodiments. All technical solutions under the concept of the present invention belong to the protection scope of the present invention. It should be pointed out that for ordinary technicians in this technical field, some improvements and modifications without departing from the principle of the present invention should be regarded as the protection scope of the present invention.
Claims
1. A method for rendering multi-line width segments without distortion for a head-up display, characterized in that: The drawing method comprises the following steps: S1, select the main axis according to the slope of the line segment, determine the four sides of the line segment and the scanning window; S2, scan each pixel point one by one in the determined scanning window, adopt a uniformly distributed grid algorithm, generate n sampling points for each pixel point, judge whether the sampling point is inside the line segment through the intersection of the horizontal scanning line or the vertical scanning line passing through the sampling point and the four sides of the line segment, record the number of sampling points inside the line segment as mask, then interpolate the pixel center point to obtain color information, calculate the weight of the transparency of each pixel point weight = mask / n according to the value of mask, calculate the weight of transparency according to multiple sampling points, assign RGB to the pixel point according to the color information obtained by interpolation, and achieve anti-aliasing effect in combination with the weight of transparency to complete the drawing of distortion-free multi-line width line segments; In step S1, the process of selecting the main axis according to the slope of the line segment and determining the four sides of the line segment and the scanning window includes the following steps: S11, let the starting point and end point of the line segment be P0(x0,y0) and P1(x1,y1), and P0 be on the left side of P1; S12, according to the slope of line segment P0P1 Select the main axis, the line width is w, the four sides of the line segment are L1, L2, L3, L4, L3, L4 are perpendicular to P0P1, L1, L2 are parallel to P0P1; the analytical expression of L1 is y=k(x-x0)+y0+b; the analytical expression of L2 is y=k(x-x0)+y0-b; the analytical expression of L3 is y=k′(x-x0)+y0; the analytical expression of L4 is y=k′(x-x1)+y1; S13, the calculated starting coordinates of the scanning window area are set as The end coordinates of the scanning window are set to Indicates rounding down. Indicates rounding up; In step S2, the process of determining whether the sampling point is inside the line segment by the intersection of the horizontal scanning line or the vertical scanning line passing through the sampling point and the four sides of the line segment includes the following steps: S201, let the rectangle to be drawn be P 0′ P 1′ P 2′ P 3′ ; S202, select any sampling point P si (x si ,y si ), the corresponding vertical scanning line x = x si The intersection points with L1, L2, L3, and L4 are P L1 , P L2 , P L3 , P L4 , click P L1 The vertical coordinate y L1 = k(x si -x0)+y0+b, point P L2 The y-coordinate L2 = k(x si -x0)+y0-b, point P L3 The y-coordinate L3 = k′(x si -x0)+y0, point P L4 The vertical coordinate y L4 = k′(x si -x1)+y1; S203, by comparing y si With the vertical scan line x=x si The intersection point P with the four boundaries of the rectangle L1, L2, L3, L4 L1 , P L2 , P L3 , P L4 The size of the ordinate is used to determine whether the sampling point is inside the rectangle.
2. The method for rendering multiple line width segments without distortion for a head-up display according to claim 1, characterized in that: In step S203, the sampling point P si The condition inside the line segment is y si ≥y L2 and y si ≥y L3 and y si ≤y L1 and y si ≤y L4 .
3. The method for rendering multiple line width segments without distortion for a head-up display according to claim 1, characterized in that: In step S2, the process of interpolating the pixel center point to obtain color information includes the following steps: S211, record any pixel (x s ,y s ) corresponds to the coordinates of the pixel center point P (x s +0.5,y s +0.5), the ratio of the projection of PP0 on P0P1 to P0P1 is t, and the angle between PP0 and P0P1 is θ; S212 is calculated according to the following formula: Multiply the numerator and denominator together |P1P0| and we get After simplification, S213, the attribute of the starting point P0 is recorded as f0, and the attribute of the end point P1 is recorded as f1, then the attribute f of the pixel point is obtained by interpolation calculation: f=(1-t)·f0+t·f1.