Graph filling method, system and equipment based on OpenGL SC
Through the OpenGL SC-based graphics filling method, a virtual scan line is generated and its intersection point with the figure to be filled is calculated, which solves the stack overflow problem that the injection filling algorithm may cause when processing large areas, and achieves more stable and efficient graphics rendering.
Patent Information
- Application Number
- CN202510077790.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-17
- Publication Date
- 2025-05-16
AI Technical Summary
Existing injection fill algorithms can cause stack overflow when dealing with large areas, especially in embedded systems or safety-critical areas, where such instability is unacceptable.
Using the OpenGL SC-based graph filling method, recursive calls and pixel-level traversal are avoided by generating a virtual scan line and calculating its intersection with the figure to be filled.
It effectively avoids the risk of stack overflow, improves the stability and performance of graphics rendering, and is suitable for graphics rendering needs in security-critical areas.
Smart Images

Figure CN120014108A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing, and in particular to a graphics filling method, system and device based on OpenGL SC. Background Art
[0002] Graphics filling is a basic technology in computer graphics, which refers to the process of filling the internal area of a closed figure with a specified color or pattern. It is widely used in graphics rendering, image processing, geographic information systems, game development and other fields. For example, in graphical interface design, graphics filling is used to draw interface elements such as buttons and icons; in game development, it is used to fill the colors of objects such as characters and scenes; in geographic information systems, it is used to draw map areas. Efficient and accurate graphics filling algorithms can significantly improve the quality and performance of graphics rendering, and are one of the indispensable core technologies in computer graphics.
[0003] At present, commonly used graphics filling algorithms include injection filling algorithms. The injection filling algorithm starts from an internal point and expands outwards through recursion or iteration to fill all connected pixels with the target color. Although the algorithm is simple to understand and easy to implement, it has obvious disadvantages: the injection filling algorithm usually relies on recursive calls, which may cause stack overflow when processing large areas. Especially in embedded systems or safety-critical fields (such as avionics and automotive electronics), this instability is unacceptable. Summary of the invention
[0004] In order to solve the above problems, the present invention provides a graphics filling method, system and device based on OpenGL SC.
[0005] The first aspect of the present invention discloses a graphics filling method based on OpenGL SC, comprising:
[0006] Receive a graphic filling request, wherein the graphic filling request includes a target color and coordinates of all feature vertices of the graphic to be filled;
[0007] Calculating the target slope according to the coordinates of all the feature vertices;
[0008] According to the target slope, a plurality of virtual scan lines of preset width are generated to cover the figure to be filled;
[0009] Calculating the intersection points of each of the scan lines and the figure to be filled, and determining each of the scan line segments related to the figure to be filled;
[0010] Based on the OpenGL SC interface, the target color is filled into each scan line segment to complete the filling of the graphics to be filled.
[0011] Furthermore, the step of calculating the target slope according to the coordinates of all the feature vertices includes:
[0012] According to the coordinates of all the feature vertices, a rotating caliper algorithm is used to calculate the minimum circumscribed rectangle of the figure to be filled;
[0013] The slope of the long side of the minimum circumscribed rectangle is calculated to obtain a target slope.
[0014] Furthermore, the step of generating a plurality of virtual scan lines of preset widths according to the target slope includes:
[0015] Based on the target slope, calculating the minimum boundary coordinates and the maximum boundary coordinates of the figure to be filled;
[0016] Generate a virtual line segment from the minimum boundary coordinate to the maximum boundary coordinate to obtain a calibration line segment;
[0017] For each pixel point in the calibration line segment, a scan line of a preset width intersecting the pixel point is generated according to the target slope.
[0018] Furthermore, the graphic filling request also includes an angle difference between each feature vertex and its adjacent feature vertex; wherein the angle difference represents the arc of a line between the feature vertex and its adjacent feature vertex;
[0019] And, the step of calculating the intersection points of each of the scan lines and the figure to be filled includes:
[0020] Determining the line segment type of each edge of the figure to be filled according to the angle difference;
[0021] For each of these scan lines:
[0022] According to the line segment type of each edge, the intersection point of the edge and the scan line is calculated, and the characteristic vertices are filtered out to obtain the intersection point of the scan line and the figure to be filled.
[0023] Furthermore, the step of determining the line segment type of each edge of the to-be-filled figure according to the angle difference includes:
[0024] Determine whether each angle difference is a preset straight line angle difference:
[0025] If yes, determine that the line segment type of the edge of the to-be-filled figure corresponding to the two characteristic vertices corresponding to the angle difference is a straight line segment;
[0026] If not, it is determined that the line segment type of the edge of the to-be-filled figure corresponding to the two characteristic vertices corresponding to the angle difference is an arc line segment.
[0027] Furthermore, when the line segment type is a straight line segment, the step of calculating the intersection of each edge with the scan line according to the line segment type of the edge includes:
[0028] Based on the coordinates of the two feature vertices corresponding to the edge, the intersection point of the edge and the scan line is calculated according to the linear interpolation method.
[0029] Furthermore, when the line segment type is an arc line segment, the step of calculating the intersection of each edge with the scan line according to the line segment type of the edge includes:
[0030] According to the coordinates of the two characteristic vertices corresponding to the edge and the angle difference, an arc equation is constructed, so as to determine the arc segment connecting the two characteristic vertices as an edge of the figure to be filled;
[0031] The intersection point of the circular arc segment and the scan line is calculated based on the circular arc interpolation method.
[0032] Furthermore, based on the OpenGL SC interface, the step of filling the target color into each scan line segment includes:
[0033] For each of the scan lines:
[0034] Sort all the corresponding intersection points according to their coordinates;
[0035] The intersection points are connected based on the OpenGL SC interface and using the target color in a step of two.
[0036] The second aspect of the present invention discloses a graphics filling system based on OpenGL SC, comprising:
[0037] A receiving module, configured to receive a graphic filling request, wherein the graphic filling request includes a target color and coordinates of all feature vertices of the graphic to be filled;
[0038] A first calculation module, used for calculating a target slope according to the coordinates of all the feature vertices;
[0039] A generating module, used for generating a plurality of virtual scanning lines of preset width according to the target slope, so as to cover the figure to be filled;
[0040] A second calculation module, used for calculating the intersection points of each of the scan lines and the figure to be filled, and determining each scan line segment related to the figure to be filled;
[0041] The filling module is used to fill the target color into each scan line segment based on the OpenGL SC interface to complete the filling of the graphic to be filled.
[0042] The third aspect of the present invention discloses an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and is characterized in that when the processor executes the computer program, it implements the steps of any OpenGL SC-based graphics filling method disclosed in the first aspect of the present invention.
[0043] The present invention provides a graphics filling method based on OpenGL SC, which avoids recursive calls and pixel-level traversal by generating virtual scan lines and calculating the intersection points between them and the graphics to be filled, and has significant beneficial effects. The present invention adopts a scan line filling algorithm, does not require recursive calls, fundamentally avoids the risk of stack overflow, and is suitable for graphics rendering requirements in safety-critical fields (such as avionics and automotive electronics). BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0045] Figure 1 It is a flowchart of a graphics filling method based on OpenGL SC disclosed in an embodiment of the present invention;
[0046] Figure 2 It is a structural schematic diagram of a graphics filling system based on OpenGL SC disclosed in an embodiment of the present invention;
[0047] Figure 3 It is a schematic diagram of the structure of an electronic device disclosed in an embodiment of the present invention. DETAILED DESCRIPTION
[0048] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0049] The terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, device, or product end that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units that are not listed, or may optionally include other steps or units inherent to these processes, methods, devices, or product ends.
[0050] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0051] See also Figure 1 As shown, Figure 1 FIG. 1 is a flow chart of a method for filling graphics based on OpenGL SC disclosed in an embodiment of the present invention. Figure 1 As shown, the graphics filling method based on OpenGL SC may include the following operations:
[0052] S101, receiving a graphic filling request, wherein the graphic filling request includes a target color and coordinates of all feature vertices of a graphic to be filled;
[0053] In this optional embodiment, the graphic filling request can be in JSON format, XML format, or any other structured format, which is not limited in the embodiment of the present invention. All feature vertex coordinates are arranged in order to form a closed graphic to be filled. The graphic to be filled can be any closed shape, such as a triangle, rectangle, polygon, circle, irregular shape, etc., which is not limited in the embodiment of the present invention.
[0054] S102, calculating a target slope according to the coordinates of all the feature vertices;
[0055] In an optional embodiment, the step of calculating the target slope according to the coordinates of all the feature vertices includes:
[0056] According to the coordinates of all the feature vertices, a rotating caliper algorithm is used to calculate the minimum circumscribed rectangle of the figure to be filled;
[0057] The slope of the long side of the minimum circumscribed rectangle is calculated to obtain a target slope.
[0058] In this optional embodiment, the rotating caliper algorithm is an algorithm for solving plane geometry problems. Its basic idea is to find the required geometric structure by continuously rotating a caliper. Here, the caliper refers to a minimum convex polygon that can completely cover the figure to be filled. The required result can be obtained by continuously rotating the caliper and updating its characteristic vertex coordinates until a certain condition is met.
[0059] The minimum enclosing rectangle is a rectangle that can completely contain the figure to be filled and has the smallest area. It can be regarded as a special caliper, that is, a convex polygon with only four characteristic vertices. For any plane figure, its minimum enclosing rectangle can be found. The sides of this rectangle are parallel to certain specific directions of the figure to be filled, so it can be obtained by rotating the caliper.
[0060] When solving the minimum enclosing rectangle, it is necessary to determine the long side of the minimum enclosing rectangle. The so-called long side refers to the two longer parallel sides of the minimum enclosing rectangle. The slope of the long side refers to the tangent value of the angle between these two sides and the horizontal direction. The slope reflects the degree of inclination of the long side. The larger the slope, the larger the angle between the long side and the horizontal direction, and the higher the inclination of the side; the smaller the slope, the closer the long side is to the horizontal direction, and the lower the inclination.
[0061] In order to calculate the slope of the long side, we first need to find the minimum enclosing rectangle by rotating the caliper algorithm. Specifically, we need to continuously rotate the initial caliper and update the coordinates of its feature vertices until all the feature vertices of the figure to be filled are covered. During the rotation process, the area of the current caliper should be recorded. When the caliper area can no longer be reduced by rotation, the minimum enclosing rectangle is obtained. At this time, the four feature vertices that make up the minimum enclosing rectangle can be extracted and the two long sides can be determined according to their coordinates. Then, the coordinates of the points on these two long sides can be used to calculate their slopes. Generally, the side with the larger slope is selected as the target slope. This process can be completed with only basic coordinate calculations and angle calculations.
[0062] It can be seen that this optional embodiment calculates the minimum enclosing rectangle of the figure to be filled based on the coordinates of all feature vertices using the rotating caliper algorithm, and calculates the long side slope of the minimum enclosing rectangle to obtain the target slope. This can effectively evaluate the shape and direction of the figure to be filled, thereby generating a more suitable scan line based on the target slope, thereby improving the filling efficiency and accuracy of the figure.
[0063] S103, generating a plurality of virtual scan lines of preset width according to the target slope to cover the figure to be filled;
[0064] In an optional embodiment, the step of generating a plurality of virtual scan lines of preset widths according to the target slope includes:
[0065] Based on the target slope, calculating the minimum boundary coordinates and the maximum boundary coordinates of the figure to be filled;
[0066] Generate a virtual line segment from the minimum boundary coordinate to the maximum boundary coordinate to obtain a calibration line segment;
[0067] For each pixel point in the calibration line segment, a scan line of a preset width intersecting the pixel point is generated according to the target slope.
[0068] In this optional embodiment, the minimum boundary coordinate refers to the minimum coordinate of the figure to be filled on the target slope, and the maximum boundary coordinate refers to the maximum coordinate of the figure to be filled on the target slope. The preset width refers to a width of one pixel.
[0069] The minimum boundary coordinate and the maximum boundary coordinate define the boundary of the figure to be filled in the target slope direction. Map all feature vertex coordinates of the figure to be filled to the target slope direction and then select the one with the smallest value as the minimum boundary coordinate and the one with the largest value as the maximum boundary coordinate.
[0070] For each pixel on the calibration line segment, a straight line that intersects it is generated according to the target slope. The width of this straight line is one pixel. In this way, a series of parallel and equal-width scan lines can be obtained, and these scan lines cover the entire length of the calibration line segment. Since the calibration line segment covers the range of the figure in the direction of the target slope, the generated scan lines also cover the entire figure to be filled.
[0071] It can be seen that this optional embodiment uses the target slope information to simplify the complex graphic filling problem into an orderly scan line generation problem. This processing method has a clear idea, is easy to implement, and has high computational efficiency and controllability.
[0072] S104, calculating the intersection points of each of the scan lines and the figure to be filled, and determining each of the scan line segments related to the figure to be filled;
[0073] In an optional embodiment, the graphic filling request further includes an angle difference between each feature vertex and its adjacent feature vertex; wherein the angle difference represents the arc of a line between the feature vertex and its adjacent feature vertex;
[0074] And, the step of calculating the intersection points of each of the scan lines and the figure to be filled includes:
[0075] Determining the line segment type of each edge of the figure to be filled according to the angle difference;
[0076] For each of these scan lines:
[0077] According to the line segment type of each edge, the intersection point of the edge and the scan line is calculated, and the characteristic vertices are filtered out to obtain the intersection point of the scan line and the figure to be filled.
[0078] In this optional embodiment, the characteristic vertices are the endpoints of the boundary of the figure to be filled. Although they belong to the outline of the figure to be filled, they are not the areas that need to be filled.
[0079] It can be seen that this optional embodiment can accurately obtain the real intersection point of the scan line and the figure to be filled by distinguishing the line segment types and using different intersection calculation methods. This not only improves the filling accuracy but also avoids the filling error caused by using a unified linear calculation method.
[0080] In an optional embodiment, the step of determining the line segment type of each edge of the to-be-filled figure according to the angle difference includes:
[0081] Determine whether each angle difference is a preset straight line angle difference:
[0082] If yes, determine that the line segment type of the edge of the to-be-filled figure corresponding to the two characteristic vertices corresponding to the angle difference is a straight line segment;
[0083] If not, it is determined that the line segment type of the edge of the to-be-filled figure corresponding to the two characteristic vertices corresponding to the angle difference is an arc line segment.
[0084] In this optional embodiment, the angle difference includes an angle information. When the angle information is a straight line angle difference, it means that the line segments corresponding to the two feature vertices corresponding to the angle difference in the edge of the figure to be filled are straight line segments. In this embodiment, the straight line angle difference is 0.
[0085] In an optional embodiment, when the line segment type is a straight line segment, the step of calculating the intersection of each edge with the scan line according to the line segment type of the edge includes:
[0086] Based on the coordinates of the two feature vertices corresponding to the edge, the intersection point of the edge and the scan line is calculated according to the linear interpolation method.
[0087] In this optional embodiment, linear interpolation is a method of estimating the value of a point anywhere between two known points given two known points. It assumes that the value of any point between two known points can be approximated by a weighted average of the values of the two known points. Linear interpolation is widely used in computer graphics, numerical analysis, signal processing, and other fields to make smooth transitions between discrete data points or estimate intermediate values.
[0088] It can be seen that this optional embodiment makes full use of the existing feature vertex coordinate information and avoids complex geometric operations. It is an efficient and practical means of intersection calculation. It strikes a good balance between calculation accuracy and efficiency, and provides important support for quickly and accurately determining the filling interval.
[0089] In an optional embodiment, when the line segment type is an arc line segment, the step of calculating the intersection of each edge with the scan line according to the line segment type of the edge includes:
[0090] According to the coordinates of the two characteristic vertices corresponding to the edge and the angle difference, an arc equation is constructed, so as to determine the arc segment connecting the two characteristic vertices as an edge of the figure to be filled;
[0091] The intersection point of the circular arc segment and the scan line is calculated based on the circular arc interpolation method.
[0092] In this optional embodiment, the angle difference includes an angle information and a direction information, the angle information represents the center angle of the arc between a feature vertex and its adjacent feature vertex, and the direction information represents whether the adjacent feature vertex is in the clockwise or counterclockwise direction of the feature vertex.
[0093] The arc equation is a mathematical expression used to describe an arc on a plane. It defines the relationship between the coordinates of any point on the arc and the coordinates of the center of the arc, the arc radius, and the central angle of the arc. The arc equation can be used to determine the position of any point on the arc, or to determine whether a point is on the arc.
[0094] The midpoint of the two feature vertices is obtained according to their coordinates, and then the offset of the center of the circle relative to the midpoint is calculated according to the direction information and the degree of the center angle. The coordinates of the midpoint and the offset are added to obtain the coordinates of the center of the circle. How to construct an arc equation based on the coordinates of the center of the circle is common knowledge in the art and will not be described in detail in the present invention.
[0095] It can be seen that this optional embodiment shows how to use the arc equation and arc interpolation method to calculate the intersection when the edge of the figure to be filled is a circular arc segment. This method uses the geometric properties of the arc and achieves efficient and accurate intersection location through mathematical calculation, providing reliable data support for subsequent figure filling.
[0096] S105 . Based on the OpenGL SC interface, fill each scan line segment with the target color to complete the filling of the graphic to be filled.
[0097] In an optional embodiment, based on the OpenGL SC interface, the step of filling the target color into each scan line segment includes:
[0098] For each of the scan lines:
[0099] Sort all the corresponding intersection points according to their coordinates;
[0100] The intersection points are connected using the target color based on the OpenGL SC interface with a step size of two.
[0101] In this optional embodiment, the calculated intersections of the scan lines and the figure to be filled need to be sorted, in order to determine the order in which the scan lines pass through the figure to be filled, and thus determine which parts should be filled. If the scan lines are horizontal, they can be sorted according to the x-coordinates of the intersections; if the scan lines are vertical, they can be sorted according to the y-coordinates of the intersections.
[0102] For example: the scan line is horizontal, the coordinates of the intersections of the figure to be filled and a scan line are (2, 10), (5, 10), (6, 10), (8, 10) and (9, 10), and the intersections are sorted according to the x coordinate, and the results are: (2, 10), (5, 10), (6, 10), (8, 10), (9, 10). With a step of two, based on the OpenGL SC interface, using the target color, the intersections are connected. Corresponding to this example, the first line segment will be connected with feature vertices (2, 10) and (5, 10), and the second line segment will be connected with feature vertices (6, 10) and (8, 10).
[0103] It can be seen that this optional embodiment can efficiently complete the filling of graphics of arbitrary shapes by introducing the concept of virtual scan lines and using the OpenGL SC interface for color filling in an innovative way. Compared with traditional pixel-based or polygon-based filling methods, this method is more clever, has higher filling efficiency, and has a smoother and more natural filling effect.
[0104] See also Figure 2 As shown, Figure 2 Schematic diagram of a graphics filling system based on OpenGL SC disclosed in an embodiment of the present invention. Figure 2 As shown, the graphic filling system includes:
[0105] A receiving module 201 is used to receive a graphic filling request, wherein the graphic filling request includes a target color and coordinates of all feature vertices of the graphic to be filled;
[0106] A first calculation module 202, used to calculate a target slope according to the coordinates of all the feature vertices;
[0107] A generating module 203, configured to generate a plurality of virtual scan lines of preset widths according to the target slope to cover the figure to be filled;
[0108] A second calculation module 204, used to calculate the intersection points of each of the scan lines and the figure to be filled, and determine each scan line segment related to the figure to be filled;
[0109] The filling module 205 is used to fill the target color into each scan line segment based on the OpenGL SC interface to complete the filling of the graphic to be filled.
[0110] For the specific definition of the graphics filling system based on OpenGL SC, please refer to the definition of the graphics filling method based on OpenGL SC above, which will not be repeated here. Each module in the above-mentioned graphics filling system based on OpenGL SC can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the electronic device in hardware format, or can be stored in the memory of the electronic device in software format, so that the processor can call the corresponding operations of each of the above modules.
[0111] It should be noted that, in order to highlight the innovative part of the present invention, the present embodiment does not introduce modules that are not closely related to solving the technical problem proposed by the present invention, but this does not mean that there are no other modules in the present embodiment.
[0112] like Figure 3 As shown, the electronic device 1 provided by the present invention may include a memory 12, a processor 13 and a bus, and may also include a computer program stored in the memory 12 and executable on the processor 13, such as a graphics filling program based on OpenGLSC.
[0113] Among them, the memory 12 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, mobile hard disk, multimedia card, card-type memory (for example: SD or DX memory, etc.), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 12 can be an internal storage unit of the electronic device 1, such as a mobile hard disk of the electronic device 1. In other embodiments, the memory 12 can also be an external storage device of the electronic device 1, such as a plug-in mobile hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device 1. Further, the memory 12 can also include both an internal storage unit of the electronic device 1 and an external storage device. The memory 12 can not only be used to store application software and various types of data installed in the electronic device 1, such as graphics filling code based on OpenGL SC, etc., but also can be used to temporarily store data that has been output or is to be output.
[0114] In some embodiments, the processor 13 may be composed of an integrated circuit, for example, a single packaged integrated circuit, or a plurality of packaged integrated circuits with the same or different functions, including one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and combinations of various control chips. The processor 13 is the control core (Control Unit) of the electronic device 1, and uses various interfaces and lines to connect various components of the entire electronic device 1, and executes or executes programs or modules (such as graphics filling programs based on OpenGL SC, etc.) stored in the memory 12, and calls data stored in the memory 12 to execute various functions of the electronic device 1 and process data.
[0115] The processor 13 executes the operating system and various installed application programs of the electronic device 1. The processor 13 executes the application programs to implement the steps in the above-mentioned OpenGL SC-based graphics filling method.
[0116] Exemplarily, the computer program may be divided into one or more modules, which are stored in the memory 12 and executed by the processor 13 to complete the present application. The one or more modules may be a series of computer program instruction segments capable of completing specific functions, which are used to describe the execution process of the computer program in the electronic device 1. For example, the computer program may be divided into a receiving module 201, a first calculation module 202, a generation module 203, a second calculation module 204, and a filling module 205.
[0117] The above-mentioned integrated unit implemented in the form of a software function module can be stored in a computer-readable storage medium, and the storage medium can be non-volatile or volatile. The above-mentioned software function module is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a computer device, or a network device, etc.) or a processor to perform part of the functions of the graphics filling method based on OpenGL SC described in various embodiments of the present application.
[0118] In summary, the method, system and device for filling graphics based on OpenGL SC disclosed in the present invention avoid recursive calls and pixel-level traversal by generating virtual scan lines and calculating their intersections with the graphics to be filled, and have significant beneficial effects. The present invention adopts a scan line filling algorithm without recursive calls, fundamentally avoids the risk of stack overflow, and is suitable for graphics rendering requirements in safety-critical fields (such as avionics and automotive electronics). Therefore, the present invention effectively overcomes various shortcomings in the prior art and has a high industrial utilization value.
[0119] The above embodiments are merely illustrative of the principles and effects of the present invention, and are not intended to limit the present invention. Anyone familiar with the art may modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by a person of ordinary skill in the art without departing from the spirit and technical concept disclosed by the present invention shall still be covered by the claims of the present invention.
Claims
1. A graphics filling method based on OpenGL SC, characterized in that: The graphics filling method comprises: Receive a graphic filling request, wherein the graphic filling request includes a target color and coordinates of all feature vertices of the graphic to be filled; Calculating the target slope according to the coordinates of all the feature vertices; According to the target slope, a plurality of virtual scan lines of preset width are generated to cover the figure to be filled; Calculating the intersection points of each of the scan lines and the figure to be filled, and determining each of the scan line segments related to the figure to be filled; Based on the OpenGL SC interface, the target color is filled into each scan line segment to complete the filling of the graphics to be filled.
2. The OpenGL SC-based graphics filling method according to claim 1, characterized in that: According to the coordinates of all the feature vertices, the step of calculating the target slope includes: According to the coordinates of all the feature vertices, a rotating caliper algorithm is used to calculate the minimum circumscribed rectangle of the figure to be filled; The slope of the long side of the minimum circumscribed rectangle is calculated to obtain a target slope.
3. The OpenGL SC-based graphics filling method according to claim 1, characterized in that: The step of generating a plurality of virtual scan lines of preset widths according to the target slope comprises: Based on the target slope, calculating the minimum boundary coordinates and the maximum boundary coordinates of the figure to be filled; Generate a virtual line segment from the minimum boundary coordinate to the maximum boundary coordinate to obtain a calibration line segment; For each pixel point in the calibration line segment, a scan line of a preset width intersecting the pixel point is generated according to the target slope.
4. The OpenGL SC-based graphics filling method according to claim 1, characterized in that: The graphic filling request also includes an angle difference between each feature vertex and its adjacent feature vertex; wherein the angle difference represents the arc of the line between the feature vertex and its adjacent feature vertex; And, the step of calculating the intersection points of each of the scan lines and the figure to be filled includes: Determining the line segment type of each edge of the figure to be filled according to the angle difference; For each of these scan lines: According to the line segment type of each edge, the intersection point of the edge and the scan line is calculated, and the characteristic vertices are filtered out to obtain the intersection point of the scan line and the figure to be filled.
5. The OpenGL SC-based graphics filling method according to claim 4, characterized in that: The step of determining the line segment type of each edge of the to-be-filled figure according to the angle difference comprises: Determine whether each angle difference is a preset straight line angle difference: If yes, determine that the line segment type of the edge of the to-be-filled figure corresponding to the two characteristic vertices corresponding to the angle difference is a straight line segment; If not, it is determined that the line segment type of the edge of the to-be-filled figure corresponding to the two characteristic vertices corresponding to the angle difference is an arc line segment.
6. The OpenGL SC-based graphics filling method according to claim 4, characterized in that: When the line segment type is a straight line segment, the steps of calculating the intersection of each edge with the scan line according to the line segment type of the edge include: Based on the coordinates of the two feature vertices corresponding to the edge, the intersection point of the edge and the scan line is calculated according to the linear interpolation method.
7. The OpenGL SC-based graphics filling method according to claim 4, characterized in that: When the line segment type is an arc line segment, the steps of calculating the intersection point of each edge with the scan line according to the line segment type of the edge include: According to the coordinates of the two characteristic vertices corresponding to the edge and the angle difference, an arc equation is constructed, so as to determine the arc segment connecting the two characteristic vertices as an edge of the figure to be filled; The intersection point of the circular arc segment and the scan line is calculated based on the circular arc interpolation method.
8. The OpenGL SC-based graphics filling method according to claim 1, characterized in that: Based on the OpenGL SC interface, the steps of filling the target color into each scan line segment include: For each of the scan lines: Sort all the corresponding intersection points according to their coordinates; The intersection points are connected based on the OpenGL SC interface and using the target color in a step of two.
9. A graphics filling system based on OpenGL SC, characterized in that: The graphic filling system comprises: A receiving module, configured to receive a graphic filling request, wherein the graphic filling request includes a target color and coordinates of all feature vertices of the graphic to be filled; A first calculation module, used for calculating a target slope according to the coordinates of all the feature vertices; A generating module, used for generating a plurality of virtual scanning lines of preset width according to the target slope, so as to cover the figure to be filled; A second calculation module, used for calculating the intersection points of each of the scan lines and the figure to be filled, and determining each scan line segment related to the figure to be filled; The filling module is used to fill the target color into each scan line segment based on the OpenGL SC interface to complete the filling of the graphic to be filled.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the OpenGL SC-based graphics filling method as claimed in any one of claims 1 to 8 are implemented.