CN114913265A - Multi-line wide line segment distortion-free drawing method for flat display - Google Patents
Multi-line wide line segment distortion-free drawing method for flat display Download PDFInfo
- Publication number
- CN114913265A CN114913265A CN202210501117.2A CN202210501117A CN114913265A CN 114913265 A CN114913265 A CN 114913265A CN 202210501117 A CN202210501117 A CN 202210501117A CN 114913265 A CN114913265 A CN 114913265A
- Authority
- CN
- China
- Prior art keywords
- line
- line segment
- point
- points
- pixel
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T11/00—2D [Two Dimensional] image generation
- G06T11/20—Drawing from basic elements, e.g. lines or circles
- G06T11/203—Drawing of straight lines or curves
Landscapes
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Image Generation (AREA)
Abstract
The invention discloses a flat display-oriented multi-line wide line segment distortion-free drawing method, which comprises the following steps: s1, selecting a main shaft according to the slope of the line segment, and determining four edges of the line segment and a scanning window; s2, scanning pixel points one by one in a determined scanning window, generating n sampling points for each pixel point, judging whether the sampling points are in the line segment or not through the intersection points of the transverse scanning line or the longitudinal scanning line passing through the sampling points and the four sides of the line segment, interpolating the pixel center points to obtain color information, calculating the weight of transparency according to multiple sampling points, and drawing a non-distorted multi-line width line segment by combining the weight. The invention can solve the problem that the presentation mode is diamond when drawing the multi-line wide inclined line segment, is suitable for the distortion-free drawing method of any line width line segment with the end point as the floating point number, and has low requirement on hardware.
Description
Technical Field
The invention relates to the technical field of graphic display, in particular to a flat display-oriented multi-line wide line segment distortion-free drawing method.
Background
A line segment is one of the most basic elements constituting computer graphics, and a line segment of an arbitrary line width needs to be drawn in many display systems. The DDA algorithm, Bresenham algorithm and Wu anti-aliasing algorithm are adopted as common drawing methods of the multi-line-width line segments. The methods are simple and convenient to implement, but the oblique line segment has the phenomenon that the presentation mode is a diamond shape instead of a rectangle, and the algorithms do not support the condition that the starting point and the end point are floating point numbers. How to draw the distortion-free multi-line-width line segment quickly and simply becomes important research content.
Disclosure of Invention
Aiming at the defects in the prior art, the invention provides a flat display-oriented multi-line wide line segment distortion-free drawing method, which can solve the problem that the presentation mode is diamond when drawing multi-line wide oblique line segments, is suitable for the distortion-free drawing method of any line width line segment with an end point as a floating point number, and has low requirement on hardware.
In order to achieve the purpose, the invention adopts the following technical scheme:
a flat-display-oriented multi-line-width segment distortion-free drawing method comprises the following steps:
s1, selecting a main shaft according to the slope of the line segment, and determining four edges of the line segment and a scanning window;
s2, scanning pixel points one by one in a determined scanning window, adopting a uniformly distributed grid algorithm, generating n sampling points for each pixel point, judging whether the sampling points are in the line segment or not through the intersection points of a transverse scanning line or a longitudinal scanning line which passes through the sampling points and the four sides of the line segment, recording the number of the sampling points in the line segment as mask, interpolating the pixel center points to obtain color information, calculating the weight of the transparency of each pixel point as mask/n according to the value of the mask, calculating the weight of the transparency according to multiple sampling points, assigning values to RGB of the pixel points according to the color information obtained by interpolation, realizing the anti-aliasing effect by combining the weight of the transparency, and finishing the drawing of a distortion-free multi-line width line segment.
In order to optimize the technical scheme, the specific measures adopted further comprise:
further, in step S1, the process of selecting the principal axis according to the slope of the line segment and determining the four edges of the line segment and the scanning window includes the following steps:
s11, let the coordinates of the start and end points of the line segment be P 0 (x 0 ,y 0 ),P 1 (x 1 ,y 1 ) And P is 0 At P 1 Left side;
s12, according to the line segment P 0 P 1 Slope of (2)Selecting a main shaft with a line width of w and four edges of the line segment of L respectively 1 、L 2 、L 3 、L 4 ,L 3 、L 4 And P 0 P 1 Perpendicular, L 1 、L 2 And P 0 P 1 Parallel connection; l is 1 Has an analytical formula of y ═ k (x-x) 0 )+y 0 +b;L 2 Has an analytical formula of y ═ k (x-x) 0 )+y 0 -b;L 3 Has an analytical formula of y ═ k' (x-x) 0 )+y 0 ;L 4 Has an analytical formula of y ═ k' (x-x) 1 )+y 1 ;
S13, setting the area initial coordinate of the scanning window by calculationThe region end coordinate of the scanning window is set asMeaning that the rounding is done down,indicating rounding up.
Further, 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, recording a rectangle to be drawn as P 0′ P 1′ P 2′ P 3′ ;
S202, selecting any sampling point P si (x si ,y si ) The corresponding longitudinal scanning line x ═ x si And L 1 、L 2 、L 3 、L 4 Respectively, are P L1 、P L2 、P L3 、P L4 Point P L1 Ordinate y of L1 =k(x si -x 0 )+y 0 + b, point P L2 Ordinate y of L2 =k(x si -x 0 )+y 0 B, point P L3 Ordinate y of L3 =k′(x si -x 0 )+y 0 Point P L4 Ordinate y of L4 =k′(x si -x 1 )+y 1 ;
S203, by comparing y si And the longitudinal scanning line x ═ x si Four boundaries L with rectangle 1 、L 2 、L 3 、L 4 Point of intersection P L1 、P L2 、P L3 、P L4 The size of the ordinate to determine whether the sample point is inside the rectangle.
Further, in step S203, a 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 。
Further, in step S2, the process of interpolating the pixel center points to obtain the color information includes the following steps:
s211, recording any pixel (x) s ,y s ) The coordinate of the corresponding pixel center point P is (x) s +0.5,y s +0.5), notePP 0 At P 0 P 1 Projection and P on 0 P 1 Has a ratio of t, PP 0 And P 0 P 1 The included angle between the two is theta;
s212, the calculation is carried out according to the following formula:after simplification, the product is obtained
S213, recording the point P 0 Has an attribute of f 0 End point P 1 Has an attribute of f 1 If so, the attribute f of the pixel point is obtained by interpolation calculation: f ═ 1-t · f 0 +t·f 1 。
The invention has the beneficial effects that:
first, the multi-line width line segment undistorted drawing method for the flat display can achieve undistorted drawing of any line width line segment, supports drawing of line segments with floating point numbers as end points, and is good in display effect and strong in practicability.
Secondly, the undistorted drawing method of the multi-line width line segment facing the flat display solves the problem that the presentation mode of the multi-line width oblique line segment is a diamond shape instead of a rectangle, optimizes the display effect and better fits the actual presentation mode of the graph.
Thirdly, the flat display-oriented multi-line width line segment non-distortion drawing method does not generate repeated drawing points when drawing the multi-line width line segment, reduces the occupation of the cache space and enhances the graphic processing capacity.
Drawings
FIG. 1 is a schematic diagram of a principle of determining whether a sampling point is inside a multi-line wide segment;
FIG. 2 is a schematic diagram of the calculation principle of four-edge analytic expressions of a rectangle;
FIG. 3 is a schematic diagram illustrating the principle of calculating pixel attributes;
FIG. 4 is a diagram of simulation display effect of multi-line width segments with different line widths and slopes, which are respectively drawn by the Wu antialiasing algorithm and the method of the present invention; wherein, fig. 4(a) is a simulation display effect graph drawn by a multi-line width line section Wu antialiasing algorithm with different line widths and slopes; fig. 4(b) is a simulation display effect diagram for drawing a multi-line width line segment with different line widths and slopes according to the method of the present invention.
Detailed Description
The present invention will now be described in further detail with reference to the accompanying drawings.
It should be noted that the terms "upper", "lower", "left", "right", "front", "back", etc. used in the present invention are for clarity of description only, and are not intended to limit the scope of the present invention, and the relative relationship between the terms and the terms is not limited by the technical contents of the essential changes.
The idea of the invention is to improve the existing anti-aliasing drawing method based on the multisampling principle, select a main shaft according to the slope, judge whether a sampling point is in the interior of a line segment or not through the intersection points of a horizontal/longitudinal scanning line and four sides of the line segment, interpolate a pixel central point to obtain color information, calculate the weight of transparency according to multiple sampling points to realize anti-aliasing, and draw a non-distorted multi-line width line segment.
Fig. 1 is a schematic diagram of determining whether a sampling point is inside a multi-linewidth segment. The coordinates of the starting point and the end point of the line segment are respectively P 0 (x 0 ,y 0 ),P 1 (x 1 ,y 1 ) And P is 0 At P 1 Left side. According to the slopeSelecting a main shaft with the line width of w. The rectangle actually needed to be drawn is denoted as P 0′ P 1′ P 2′ P 3′ Let a coordinate of a sampling point be P si (x si ,y si ) By comparison of y si And the longitudinal scanning line x ═ x si Four boundaries L with rectangle 1 、L 2 、L 3 、L 4 L 4 Point of intersection P L1 、P L2 、P L3 、P L4 Judging whether the sampling point is in the rectangle or not according to the size of the ordinate, and obtaining the proportion weight of the sampling point in the rectangle.
FIG. 2 is a schematic diagram of the calculation of four-edge analytic expressions of a rectangle.
Step 1: line segment P 0 P 1 Has a slope ofL 3 、L 4 And P 0 P 1 Perpendicular to, note L 3 、L 4 Has a slope of k', thenL 3 Passing through point P 0 Therefore L is 3 Has an analytical formula of y ═ k' (x-x) 0 )+y 0 。L 4 Passing through point P 1 Therefore L is 4 Has an analytical formula of y ═ k' (x-x) 1 )+y 1 . Longitudinal scanning line x ═ x si And L 3 、L 4 Has a point of intersection of P L3 、P L4 Thereby obtaining a point P L3 Ordinate y of L3 =k′(x si -x 0 )+y 0 Point P L4 Ordinate y of L4 =k′(x si -x 1 )+y 1 。
Step 2: l is 1 、L 2 And line segment P 0 P 1 Parallel, the slope is k. Calculating L by similarity of triangles 1 、L 2 Relative to line segment P 0 P 1 The intercept difference b of (a). From the similarity of trianglesIs calculated to obtainThereby obtaining L 1 Has an analytical formula of (x-x) where y is k 0 )+y 0 +b,L 2 Has an analytical formula of y ═ k (x-x) 0 )+y 0 -b. Longitudinal scanning line x ═ x si And L 1 、L 2 Has a point of intersection of P L1 、P L2 Thereby obtaining a point P L1 Ordinate y of L1 =k(x si -x 0 )+y 0 + b, point P L2 Ordinate y of L2 =k(x si -x 0 )+y 0 -b。
And step 3: sample point P si (x si ,y si ) Ordinate y of si And calculated y L1 、y L2 、y L3 、y L4 Is compared with the magnitude of (B), sample 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 And calculating the proportion weight of the sampling point in the line segment, wherein the weight is the transparency of the pixel point, so that the edge point is darker, and the anti-aliasing effect is achieved.
Fig. 3 is a schematic diagram of calculating pixel point attributes, where the attribute of each pixel point is obtained by interpolating a pixel center point of the pixel point with a start point and an end point. Noting that a certain pixel point coordinate is (x) s ,y s ) Then the coordinate of the pixel center point P is (x) s +0.5,y s +0.5). Note PP 0 At P 0 P 1 Projection and P of 0 P 1 Has a ratio of t, PP 0 And P 0 P 1 The included angle between is theta, then After simplification, the product is obtainedStarting point P 0 Has an attribute of f 0 End point P 1 Has an attribute of f 1 If the attribute f of the pixel is calculated by interpolation, the obtained f is (1-t) f 0 +t·f 1 。
In this embodiment, several sets of multi-line width drawing parameters with different line widths and different slopes are preset, fig. 4(a) is a multi-line width line segment simulation display effect graph with different line widths and slopes drawn by the Wu antialiasing algorithm, and fig. 4(b) is a multi-line width line segment simulation display effect graph with different line widths and slopes drawn by using the method of the present invention; the top picture is an enlarged view of the line segment end points. It can be found that the Wu antialiasing algorithm realizes the antialiasing effect of the line segment by adding the pixel points with the transparency not being 1 directly above and below the line segment instead of in the direction perpendicular to the line segment, and for the line segment with the slope not being 0, if the antialiasing algorithm adopted by the line segment is the Wu antialiasing algorithm, the final display effect of the line segment is in a diamond state instead of a rectangle, and the antialiasing effect cannot be applied to the end point of the line segment. In addition, for a line segment with a floating point number as an end point, the Wu antialiasing algorithm performs rounding operation on the floating point part, so that the actual display position is different from the theoretical display position. The method adopts a multi-sampling algorithm and judges whether the sampling point is in the line segment or not through the function analytic expression of the four sides of the line segment, and in such a way, the integer operation of the floating point number end point is not needed, the weight of the transparency of the pixel point is determined, so that the problem that the line segment is in a rhombic presentation mode is avoided, and the problem that the anti-aliasing effect is not generated at the end point is also solved. The optimization effect brought by the method can be more intuitively observed through comparison of the following figures.
The comparison shows that the display effect of the method is better than that of the Wu antialiasing algorithm, the problem that the oblique line section is presented in a diamond mode is solved, antialiasing processing is performed at the starting point and the end point, the condition that the input end point is a floating point number is allowed, and the drawing method is wide.
The above is only a preferred embodiment of the present invention, and the protection scope of the present invention is not limited to the above-mentioned embodiments, and all technical solutions belonging to the idea of the present invention belong to the protection scope of the present invention. It should be noted that modifications and embellishments within the scope of the invention may be made by those skilled in the art without departing from the principle of the invention.
Claims (5)
1. A flat-display-oriented multi-line-width segment distortion-free drawing method is characterized by comprising the following steps:
s1, selecting a main shaft according to the slope of the line segment, and determining four edges of the line segment and a scanning window;
s2, scanning pixel points one by one in a determined scanning window, adopting a uniformly distributed grid algorithm, generating n sampling points for each pixel point, judging whether the sampling points are in the line segment or not through the intersection points of a transverse scanning line or a longitudinal scanning line which passes through the sampling points and the four sides of the line segment, recording the number of the sampling points in the line segment as mask, interpolating the pixel center points to obtain color information, calculating the weight of the transparency of each pixel point as mask/n according to the value of the mask, calculating the weight of the transparency according to multiple sampling points, assigning values to RGB of the pixel points according to the color information obtained by interpolation, realizing the anti-aliasing effect by combining the weight of the transparency, and finishing the drawing of a distortion-free multi-line width line segment.
2. The method for undistorted rendering of multi-line-width line segments oriented to flat display of claim 1, wherein in step S1, the process of selecting the principal axis according to the slope of the line segment and determining the four edges of the line segment and the scanning window comprises the following steps:
s11, let the coordinates of the start and end points of the line segment be P 0 (x 0 ,y 0 ),P 1 (x 1 ,y 1 ) And P is 0 At P 1 Left side;
s12, according to the line segment P 0 P 1 Slope of (2)Selecting a main shaft with a line width of w and four edges of the line segment of L respectively 1 、L 2 、L 3 、L 4 ,L 3 、L 4 And P 0 P 1 Perpendicular, L 1 、L 2 And P 0 P 1 Parallel; l is a radical of an alcohol 1 Has an analytical formula of y ═ k (x-x) 0 )+y 0 +b;L 2 Has an analytical formula of y ═ k (x-x) 0 )+y 0 -b;L 3 Has an analytical formula of y ═ k' (x-x) 0 )+y 0 ;L 4 Has an analytical formula of (x) k' (x-x) 1 )+y 1 ;
3. The method for drawing the multi-line-width line segment without distortion for flat display according to claim 2, wherein the step of judging whether the sampling point is inside the line segment by the intersection point of the horizontal scanning line or the vertical scanning line passing through the sampling point and the four sides of the line segment in the step S2 comprises the following steps:
s201, recording a rectangle to be drawn as P 0′ P 1′ P 2′ P 3′ ;
S202, selecting any sampling point P si (x si ,y si ) The corresponding longitudinal scanning line x ═ x si And L 1 、L 2 、L 3 、L 4 Respectively, are P L1 、P L2 、P L3 、P L4 Point P L1 Ordinate y of L1 =k(x si -x 0 )+y 0 + b, point P L2 Ordinate y of L2 =k(x si -x 0 )+y 0 B, point P L3 Ordinate y of L3 =k′(x si -x 0 )+y 0 Point P L4 Ordinate y of L4 =k′(x si -x 1 )+y 1 ;
S203, by comparing y si And the longitudinal scanning line x ═ x si Four boundaries L with rectangle 1 、L 2 、L 3 、L 4 Point of intersection P L1 、P L2 、P L3 、P L4 The size of the ordinate to determine whether the sample point is inside the rectangle.
4. The method for drawing multiple line-width line segments without distortion according to claim 1, wherein in step S203, a sampling point P is selected 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 。
5. The method for undistorted rendering of multi-line-width line segments oriented to flat display of claim 3, wherein in step S2, the process of interpolating the pixel center points to obtain color information comprises the following steps:
s211, recording any pixel (x) s ,y s ) The coordinate of the corresponding pixel center point P is (x) s +0.5,y s +0.5), note PP 0 At P 0 P 1 Projection and P on 0 P 1 Has a ratio of t, PP 0 And P 0 P 1 The included angle between the two is theta;
s212, the calculation is carried out according to the following formula:multiplication of numerator and denominatorAfter simplification, the product is obtained
S213, recording the point P 0 Has an attribute of f 0 End point P 1 Has an attribute of f 1 If so, the attribute f of the pixel point is obtained by interpolation calculation: f ═ 1-t · f 0 +t·f 1 。
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210501117.2A CN114913265A (en) | 2022-05-10 | 2022-05-10 | Multi-line wide line segment distortion-free drawing method for flat display |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210501117.2A CN114913265A (en) | 2022-05-10 | 2022-05-10 | Multi-line wide line segment distortion-free drawing method for flat display |
Publications (1)
Publication Number | Publication Date |
---|---|
CN114913265A true CN114913265A (en) | 2022-08-16 |
Family
ID=82767024
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210501117.2A Pending CN114913265A (en) | 2022-05-10 | 2022-05-10 | Multi-line wide line segment distortion-free drawing method for flat display |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114913265A (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115205422A (en) * | 2022-09-14 | 2022-10-18 | 南京航空航天大学 | Multi-line-width line segment end point anti-aliasing processing method and system |
CN115661298A (en) * | 2022-12-15 | 2023-01-31 | 南京航空航天大学 | Area division drawing method for distortion-free triangle |
-
2022
- 2022-05-10 CN CN202210501117.2A patent/CN114913265A/en active Pending
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115205422A (en) * | 2022-09-14 | 2022-10-18 | 南京航空航天大学 | Multi-line-width line segment end point anti-aliasing processing method and system |
CN115661298A (en) * | 2022-12-15 | 2023-01-31 | 南京航空航天大学 | Area division drawing method for distortion-free triangle |
CN115661298B (en) * | 2022-12-15 | 2023-04-07 | 南京航空航天大学 | Area division drawing method for distortion-free triangle |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN114913265A (en) | Multi-line wide line segment distortion-free drawing method for flat display | |
US11361405B2 (en) | Dynamic spread anti-aliasing | |
US5544294A (en) | Method for generating a subpixel mask for computer graphics system and apparatus thereof | |
US9153068B2 (en) | Clipless time and lens bounds for improved sample test efficiency in image rendering | |
US7764292B2 (en) | Three dimensional graphics processing apparatus, image display apparatus, three dimensional graphics processing method, control program and computer-readable recording medium | |
US8520007B2 (en) | Graphic drawing device and graphic drawing method | |
EP1958162B1 (en) | Vector graphics anti-aliasing | |
JP2003271987A (en) | Method of determining percentage of pixel covered by primitive | |
JPH04222074A (en) | Inclination computing method for texture map | |
JPH06274641A (en) | Anti-aliasing straight line display device | |
US7679620B2 (en) | Image processing using saltating samples | |
WO2017024443A1 (en) | High efficiency parallel vector data visualization method | |
JP3507057B2 (en) | Triangle polygon drawing apparatus and triangle polygon drawing method | |
CN111260750B (en) | Processing method and device for openFL drawing vector graphics and electronic equipment | |
US7221372B2 (en) | Method of analyzing and modifying a footprint | |
JP2957511B2 (en) | Graphic processing unit | |
JP3898864B2 (en) | Image conversion method, image processing apparatus, and image display apparatus | |
Wu et al. | Correct resolution rendering of trimmed spline surfaces | |
US6570562B1 (en) | Method for drawing patterned lines in a system supporting off-screen graphics | |
KR20120069134A (en) | Apparatus and method for enhancing aliasing in two dimension | |
US20100141649A1 (en) | Drawing device | |
CN115601472B (en) | Undistorted black edge drawing method based on expansion corrosion algorithm | |
JP3493745B2 (en) | Drawing device | |
US11288788B2 (en) | Anti-aliasing for distance field graphics rendering | |
US20030187891A1 (en) | Scaling method by using dual point slope control (DPSC) |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |