CN117726774A - Triangle rasterization method and device based on line generation algorithm and related equipment - Google Patents
Triangle rasterization method and device based on line generation algorithm and related equipment Download PDFInfo
- Publication number
- CN117726774A CN117726774A CN202410173857.7A CN202410173857A CN117726774A CN 117726774 A CN117726774 A CN 117726774A CN 202410173857 A CN202410173857 A CN 202410173857A CN 117726774 A CN117726774 A CN 117726774A
- Authority
- CN
- China
- Prior art keywords
- triangle
- grid
- grid cell
- generation algorithm
- coordinates
- 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.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 64
- 230000009466 transformation Effects 0.000 claims abstract description 10
- 238000004590 computer program Methods 0.000 claims description 19
- 238000003384 imaging method Methods 0.000 claims description 17
- 238000012545 processing Methods 0.000 abstract description 21
- 238000004088 simulation Methods 0.000 abstract description 16
- 238000012805 post-processing Methods 0.000 abstract description 9
- 238000007667 floating Methods 0.000 abstract description 8
- 238000009877 rendering Methods 0.000 abstract description 7
- 238000010586 diagram Methods 0.000 description 14
- 230000011218 segmentation Effects 0.000 description 5
- 230000006870 function Effects 0.000 description 4
- 230000008569 process Effects 0.000 description 4
- 238000009499 grossing Methods 0.000 description 3
- 230000009286 beneficial effect Effects 0.000 description 2
- 238000013461 design Methods 0.000 description 2
- 238000005516 engineering process Methods 0.000 description 2
- 239000000835 fiber Substances 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 230000003287 optical effect Effects 0.000 description 2
- 238000004806 packaging method and process Methods 0.000 description 2
- 230000003190 augmentative effect Effects 0.000 description 1
- 238000006243 chemical reaction Methods 0.000 description 1
- 239000003086 colorant Substances 0.000 description 1
- 238000004891 communication Methods 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 230000018109 developmental process Effects 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 239000004744 fabric Substances 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 238000012546 transfer Methods 0.000 description 1
- 230000001131 transforming effect Effects 0.000 description 1
- 238000012800 visualization Methods 0.000 description 1
Abstract
The invention provides a triangle rasterization method and device based on a line generation algorithm and related equipment. The method comprises the following steps: and 1, establishing a three-dimensional model, and meshing the three-dimensional model. And 2, obtaining the triangle to be rasterized through view transformation. Step 3, judging whether one side of the obtained triangle to be rasterized is parallel to the x direction, if so, entering the next step; if not, the acquired triangle to be rasterized is segmented into two triangles with one side parallel to the x direction, and then the next step is carried out. And 4, processing triangles with one side parallel to the x direction by using a line generation algorithm. Step 5, repeating step 4 until the grid cells inside the triangle are completely filled. According to the invention, an lead-in generation algorithm replaces floating point operation in the original algorithm through integer operation, so that the rendering efficiency of a post-processing display interface in multi-physical-field core industrial simulation processing platform software is improved.
Description
Technical Field
The invention relates to the field of computer graphics processing, in particular to a triangle rasterization method and device based on a line generation algorithm and related equipment.
Background
Rasterization is a process in computer graphics that maps continuous, geometrically defined graphical objects (e.g., triangles, lines, etc.) to discrete pixels or primitives (minimum display units on a screen). This process is a critical step from the abstract representation of the graph to the image that is ultimately displayed on the screen. In graphics, a screen may be abstracted into a two-dimensional array, where each element in the two-dimensional array is a pixel.
Triangle rasterization is a common and important technique in computer graphics because triangles are the most basic geometric primitives and can constitute more complex graphics. Triangle rasterization plays an important role in various fields, including: computer game development, computer animation, virtual Reality (VR) and Augmented Reality (AR), engineering and scientific visualization, and medical image processing. Before triangle rasterization, a three-dimensional model needs to be built according to the entity of the required simulation. Since the screen is two-dimensional, a method must be found to project these three-dimensional models onto the two-dimensional screen so that we can see and interact, triangle rasterization being a key step in this process. Specifically, the three-dimensional model is mesh-dissected in a three-dimensional space to be divided into a number of triangles. For example, in a method for performing numerical simulation smoothing on a triangular mesh disclosed in chinese patent CN116977598B, a method is described in which a three-dimensional structure is mesh-divided into a plurality of triangles to form a triangular mesh, and the numerical simulation smoothing is performed on the triangular mesh. The technical scheme provided by the invention enables the result display to be more in line with the actual scene of solving, and effectively solves the problem of data distortion generated in the process of smoothing the unit value of the existing post-processing result view. Each triangle after meshing has a set of three-dimensional coordinates representing its position in three-dimensional space. These coordinates are typically relative to a coordinate system, such as a world coordinate system or a model coordinate system. In order to project a three-dimensional model onto a two-dimensional screen, a view transformation is required, which converts the three-dimensional coordinates into two-dimensional view coordinates. In two-dimensional view coordinates, the cropping operation will remove portions that are not within the screen viewport. Once the view transformation and clipping is performed, the rasterization stage follows. In the rasterization stage, the three-dimensional model is converted into grid cells (e.g., pixels), i.e., points on the screen.
The traditional triangle rasterization firstly obtains the slopes of the left and right sides of the triangle, then rasterizes each row of pixels through a scanning line algorithm, and then obtains the positions of the starting point and the end point of the next row of pixels through floating point number addition. However, performing floating point addition under a Central Processing Unit (CPU) can face performance bottlenecks, especially where large numbers of pixels are handled, where the grid is dense. In particular, in some grid-intensive scenarios, the computational effort may increase significantly, which may reduce the smoothness of the post-processing interface, especially in real-time graphics rendering, such as games or simulators. One solution is to develop a triangle rasterization method based on an image processing unit (GPU). For example, chinese patent CN109598669B discloses a triangle rasterization scanning system facing GPU, which integrates an initialization unit, a Y-axis stepping unit and an X-axis scanning unit, so as to implement triangle rasterization scanning of GPU, and thus implement conversion from system architecture document to RTL. Although, parallelism and dedicated hardware of an image processing unit (GPU) may provide significant advantages in terms of floating point operations. However, the application scenario of the image processing unit (GPU) is also limited.
In the multi-physical-field core industrial simulation processing platform software, various hardware compatibility problems need to be considered in the post-processing display interface, so that the display function of the finite element simulation result is completely based on CPU hardware, and the GPU is not suitable for the multi-physical-field core industrial simulation processing platform software. If triangle rasterization processing is desired in the multi-physical field core industrial simulation processing platform software, a CPU-based processing scheme is still required. Therefore, it is important to design a new triangle rasterization technical scheme capable of improving the rendering efficiency of the post-processing display interface in the multi-physical-field core industrial simulation processing platform software.
Disclosure of Invention
In order to solve the problems in the prior art, the technical scheme provided by the invention is as follows: a triangle rasterization method, a triangle rasterization device and a related device based on a line generation algorithm are provided. The line generation algorithm is, among other things, cloth Lei Senhan m line segment generation algorithm (Bresenham's line algorithm). According to the invention, an lead-in generation algorithm replaces floating point operation in the original algorithm through integer operation, so that floating point addition is avoided being executed under a Central Processing Unit (CPU), the rendering efficiency of a post-processing display interface in multi-physical-field core industrial simulation processing platform software is improved, and the performance under the CPU is improved.
The invention provides a triangle rasterization method based on a line generation algorithm, which comprises the following steps:
step 1, a three-dimensional model is established according to a real structure to be simulated, grid subdivision is carried out on the three-dimensional model in a three-dimensional space so as to divide the three-dimensional model into a plurality of triangles, and each triangle is provided with a group of three-dimensional coordinates so as to represent the position of the triangle in the three-dimensional space;
step 2, projecting the three-dimensional model which is segmented into a plurality of triangles to a grating imaging device through view transformation to obtain a plurality of triangles to be rasterized, wherein the view transformation is to convert three-dimensional coordinates into two-dimensional view coordinates;
step 3, judging whether one side of each triangle to be rasterized is parallel to the x direction or not respectively, if so, entering the next step, if not, cutting the triangle into two triangles with one side parallel to the x direction, and entering the next step;
step 4, for a triangle with one side parallel to the x direction, simultaneously solving the next grid unit of the current grid unit on two hypotenuses of the triangle by using a line generation algorithm until the coordinates of the next grid unit in the y direction are different from the coordinates of the last grid unit in the y direction, so as to respectively acquire two grid units with the same coordinates in the y direction on the two hypotenuses of the triangle, filling the two grid units and all grid units in the middle of the two grid units, and taking the two grid units as the current grid units of the two hypotenuses respectively and entering the next step;
step 5, repeating the step 4 until the grid cells inside the triangle with one side parallel to the x direction are completely filled in the step 4;
the triangle rasterization method based on the line generation algorithm is used for forming a grid cell set corresponding to all triangles to be rasterized on a raster imaging device, the raster imaging device is divided into a plurality of same grid cells, a two-dimensional view coordinate system is established on the raster imaging device, the x direction is the direction of an x axis in the two-dimensional view coordinate system, and the y direction is the direction of a y axis in the two-dimensional view coordinate system.
In one embodiment, the step 4 includes:
the three vertexes of a triangle with one side parallel to the x axis are respectively P1, P2 and P3, the sides P1P2 and P1P3 are respectively two sloping sides L, R, the sloping side L takes P1 as a starting point and P2 as an end point, the sloping side R takes P1 as a starting point and P3 as an end point, and the initial value of the current grid unit is taken as the starting point P1;
simultaneously solving the next grid cell of the current grid cell on the two hypotenuses L, R of the triangle by using a line generating algorithm;
if the height of the coordinates of the next grid cell on the oblique side L in the y direction is larger than the height of the coordinates of the next grid cell on the oblique side R in the y direction, continuing to acquire the next grid cell on the oblique side L by using a line generating algorithm until the height of the coordinates of the next grid cell on the oblique side L in the y direction is equal to the height of the coordinates of the next grid cell on the oblique side R in the y direction, filling the two grid cells on the two oblique sides L, R and all grid cells among the two grid cells, taking the two grid cells as current grid cells of the two oblique sides respectively, and entering the next step;
if the height of the coordinates of the next grid cell on the oblique side L in the y direction is smaller than the height of the coordinates of the next grid cell on the oblique side R in the y direction, continuing to acquire the next grid cell on the oblique side R by using a line generating algorithm until the height of the coordinates of the next grid cell on the oblique side R in the y direction is equal to the height of the coordinates of the next grid cell on the oblique side L in the y direction, filling the two grid cells on the two oblique sides L, R and all grid cells among the two grid cells, taking the two grid cells as current grid cells of the two oblique sides respectively, and entering the next step;
if the height of the coordinates of the next grid cell on the hypotenuse L in the y direction is equal to the height of the coordinates of the next grid cell on the hypotenuse R in the y direction, the two grid cells on the two hypotenuses L, R and all grid cells in between are filled, and the two grid cells are respectively taken as the current grid cells of the two hypotenuses and enter the next step.
In one embodiment, the step 5 includes: step 4 is repeated to simultaneously find the next grid cell of the current grid cell on both hypotenuses L, R of the triangle using a line generation algorithm until the end point of both hypotenuses L, R is scanned and the grid cell inside the triangle is completely filled.
In one embodiment, in the step 4, the method for simultaneously obtaining the next grid cell of the current grid cell on two hypotenuses of the triangle by using a line generation algorithm includes:
taking two vertexes on the bevel edge as a starting point and a terminal point respectively, enabling the initial value of e to be-dx, enabling dx to be the distance between the next grid unit and the current grid unit in the x direction, and enabling the initial value of the current grid unit to be the starting point of the bevel edge;
scanning from a starting point of the hypotenuse using a line generation algorithm to find a next grid cell to the current grid cell, the finding the next grid cell to the current grid cell comprising:
stepping the current grid cell P by one unit in the x direction, and updating e=e+2xdy, wherein dy is the distance between the next grid cell and the current grid cell in the y direction;
judging whether e is greater than or equal to 0, if e is greater than or equal to 0, the coordinate of the next grid unit in the y direction is the coordinate of the current grid unit in the y direction by one unit, updating e=e-2 x dx at the same time, and if e is less than 0, the coordinate of the next grid unit in the y direction is the coordinate of the current grid unit in the y direction.
In one embodiment, the grid cells are pixels.
In one embodiment, the triangle rasterization method based on the line generation algorithm is applied to an electronic device.
In one embodiment, the triangle rasterization method based on the line generation algorithm is applied in chip packaging.
The invention also provides a triangle rasterization device based on the line generation algorithm, which comprises a memory and a processor;
the memory is used for storing a computer program;
the processor is configured to implement a triangle rasterization method based on a line generation algorithm as described above when executing the computer program.
The invention also proposes a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements a triangle rasterization method based on a line generation algorithm as described above.
The invention also proposes a computer program product comprising a computer program which, when executed by a processor, implements a triangle rasterization method based on a line generation algorithm as described above.
The triangle rasterization method based on the line generation algorithm and the related equipment have the beneficial effects that: a line generation algorithm is introduced into a triangle rasterization algorithm, floating point operation in the original algorithm is replaced by integer operation, and rendering efficiency of a post-processing display interface in multi-physical-field core industrial simulation processing platform software is improved.
Drawings
FIG. 1 is a flow chart of a triangle rasterization method based on a line generation algorithm according to an embodiment of the present invention.
Fig. 2 is a schematic diagram illustrating a triangle to be rasterized without one side parallel to the x-direction in a triangle rasterization method based on a line generation algorithm according to an embodiment of the present invention.
Fig. 3a, 3b and 3c are schematic diagrams of a triangle rasterization method based on a line generation algorithm according to an embodiment of the present invention applied to a triangle embodiment having one side parallel to the x-direction.
Fig. 4 is a schematic diagram of an embodiment of a triangle rasterization method based on a line generation algorithm applied to an electronic device according to an embodiment of the present invention.
Fig. 5a, fig. 5b, fig. 5c, fig. 5d, fig. 5e, fig. 5f, fig. 5g are schematic diagrams of a triangle rasterization method based on a line generation algorithm according to an embodiment of the present invention applied to each slice layer two-dimensional geometric model of an electronic device embodiment.
Fig. 6a, fig. 6b, fig. 6c, fig. 6d, fig. 6e, fig. 6f, fig. 6g are schematic diagrams of a triangle rasterization method based on a line generation algorithm according to an embodiment of the present invention applied to each split layer mesh subdivision of an electronic device embodiment.
Fig. 7 is a schematic diagram of mesh division of a three-dimensional model of an embodiment of an electronic device to which a triangle rasterization method based on a line generation algorithm according to an embodiment of the present invention is applied.
Fig. 8 is a schematic diagram of a triangle rasterization method based on a line generation algorithm applied to a chip package embodiment according to an embodiment of the present invention.
Fig. 9a, 9b, 9c, and 9d are schematic diagrams of a triangle rasterization method based on a line generation algorithm applied to each sliced layer two-dimensional geometric model of a chip package according to an embodiment of the present invention.
Fig. 10a, 10b, 10c, and 10d are schematic diagrams of a triangle rasterization method based on a line generation algorithm applied to each split layer mesh division of a chip package embodiment according to an embodiment of the present invention.
FIG. 11 is a diagram illustrating a meshing of a three-dimensional model of a chip package using a line-generating algorithm-based triangle rasterization method in accordance with one embodiment of the present invention.
FIG. 12 is a thermal simulation diagram of triangle rasterization using a triangle rasterization method based on a line generation algorithm in accordance with one embodiment of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the drawings and examples, in order to make the objects, technical solutions and advantages of the present invention more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the invention.
As shown in fig. 1, the present invention proposes a triangle rasterization method based on a line generation algorithm, including:
step 1, a three-dimensional model is established according to a real structure to be simulated, grid subdivision is carried out on the three-dimensional model in a three-dimensional space so as to divide the three-dimensional model into a plurality of triangles, and each triangle is provided with a group of three-dimensional coordinates so as to represent the position of the triangle in the three-dimensional space.
And 2, projecting the three-dimensional model which is segmented into a plurality of triangles to a grating imaging device through view transformation to obtain a plurality of triangles to be rasterized. Wherein the view transformation converts the three-dimensional coordinates into two-dimensional view coordinates.
Step 3, judging whether one side of each obtained triangle to be rasterized is parallel to the x direction or not respectively, if so, entering the next step; if not, the triangle is split into two triangles with one side parallel to the x-direction (see fig. 2), and the next step is entered.
And 4, for a triangle with one side parallel to the x direction, simultaneously solving the next grid unit of the current grid unit on two hypotenuses of the triangle by using a line generation algorithm until the coordinates of the next grid unit in the y direction are different from the coordinates of the last grid unit in the y direction, so as to acquire two grid units with the same coordinates in the y direction on the two hypotenuses of the triangle respectively, and filling the two grid units and all grid units in the middle of the two grid units, as shown in fig. 3a, 3b and 3c. The two grid cells are respectively used as current grid cells with two oblique sides and enter the next step.
Step 5, repeat step 4 until the grid cells inside triangles with one side parallel to the x-direction are completely filled in step 4, see fig. 3c.
The method comprises the steps of dividing a grating imaging device into a plurality of same grid cells, establishing a two-dimensional view coordinate system on the grating imaging device, wherein the x direction is the direction of an x axis in the two-dimensional view coordinate system, the y direction is the direction of a y axis in the two-dimensional view coordinate system, and the triangle rasterization method based on a line generation algorithm is used for forming a grid cell set corresponding to each triangle to be rasterized on the grating imaging device.
Further, step 4 includes:
as shown in fig. 3a, three vertices of a triangle with one side parallel to the x-axis are P1, P2, and P3, two oblique sides L, R are respectively provided on the side P1P2 and the side P1P3, the oblique side L takes P1 as a starting point and P2 as an ending point, the oblique side R takes P1 as a starting point and P3 as an ending point, and the initial value of the current grid cell is taken as the starting point P1.
The next grid cell to the current grid cell on both hypotenuses L, R of the triangle is simultaneously found using a line generation algorithm.
If the height of the coordinates of the next grid cell on the hypotenuse L in the y direction is greater than the height of the coordinates of the next grid cell on the hypotenuse R in the y direction, the next grid cell continues to be acquired on the hypotenuse L using the line generating algorithm until the height of the coordinates of the next grid cell on the hypotenuse L in the y direction is equal to the height of the coordinates of the next grid cell on the hypotenuse R in the y direction, the two grid cells on the two hypotenuses L, R and all the grid cells in between the two grid cells are filled, and the two grid cells are respectively taken as the current grid cells of the two hypotenuses and enter the next step.
If the height of the coordinates of the next grid cell on the hypotenuse L in the y direction is smaller than the height of the coordinates of the next grid cell on the hypotenuse R in the y direction, the next grid cell is continuously acquired on the hypotenuse R using the line generating algorithm until the height of the coordinates of the next grid cell on the hypotenuse R in the y direction is equal to the height of the coordinates of the next grid cell on the hypotenuse L in the y direction, the two grid cells on the two hypotenuses L, R and all the grid cells in between the two grid cells are filled, and the two grid cells are respectively taken as the current grid cells of the two hypotenuses and enter the next step.
If the height of the coordinate of the next grid cell on the oblique side L in the y direction is equal to the height of the coordinate of the next grid cell on the oblique side R in the y direction, the two grid cells on the two oblique sides L, R and all grid cells in between the two grid cells are filled. And the two grid cells are respectively used as current grid cells with two oblique sides and enter the next step.
For example, as shown in fig. 3b, the starting point P1 is the current grid cell of each of the hypotenuses L, R, the height of the coordinates of the next grid cell P11 of the hypotenuse L in the y direction is smaller than the height of the coordinates of the next grid cell P12 of the hypotenuse R in the y direction, and then the next grid cell P13 is obtained on the hypotenuse R by continuing to use the line generating algorithm. At this time, the height of the coordinates of the next grid cell P11 on the oblique side L in the y direction is equal to the height of the coordinates of the next grid cell P13 on the oblique side R in the y direction, and the two grid cells P11, P13 on the two oblique sides L, R and all grid cells in the middle of the two grid cells are filled. And the two grid cells P11 and P13 are respectively used as the current grid cells of the two sloping sides L, R and enter the next step.
And 4, scanning and converting the left hypotenuse and the right hypotenuse of the triangle by using a line generation algorithm, selecting a later point for iteration each time, and generating a transverse line when the two points are at the same height. The pseudo code of the above steps is as follows:
FuncDrawTriangle(point p1, point p2, point p3)
Get l by p1,p2
Get r by p1,p3
pl = pr = p1
While pl not equal p2
If pl’s height equal pr’s height
Generate line to pl and pr
Use Bresenham get next scan point pl in l line
Use Bresenham get next scan point pr in r line
Else if pl’s height>pr’s height
Use Bresenham get next scan point pl in l line
Else
Use Bresenham get next scan point pr in r line
deriving to other types of triangles only requires splitting the triangle and appropriately transforming the direction of the recursion.
Still further, in step 4, a method for simultaneously obtaining the next grid cell of the current grid cell on the two hypotenuses of the triangle using a line generation algorithm includes:
and respectively taking the two vertexes on the bevel as a starting point and a finishing point. Let e have an initial value of-dx, dx is the distance between the next grid cell and the current grid cell in the x direction, and let the initial value of the current grid cell be the starting point of the hypotenuse.
Scanning from a starting point of the hypotenuse using a line generation algorithm to find a next grid cell to the current grid cell, the finding the next grid cell to the current grid cell comprising:
stepping the current grid cell P by one unit in the x direction, and updating e=e+2xdy, wherein dy is the distance between the next grid cell and the current grid cell in the y direction;
and judging whether e is more than or equal to 0. If e is greater than or equal to 0, the coordinates of the next grid cell in the y direction are the current grid cell stepped by one unit in the y direction, and e=e-2 x dx is updated. If e is less than 0, the coordinates of the next grid cell in the y direction are the coordinates of the current grid cell in the y direction.
As described above, the raster imaging apparatus is divided into several identical grid cells. It should be appreciated that in one particular embodiment, the x-axis and the y-axis in a two-dimensional view coordinate system established on the raster imaging apparatus are each parallel to two adjacent edges of a grid cell. One unit is the width of one grid cell in the x-direction or the y-direction.
The principle of the line generation algorithm is that in a straight line with a slope between 0 and 1, x increases by 1 (one unit) at a time, then y has the two possibilities of increasing by 1 (one unit) or remaining unchanged. How to choose between the two becomes a key point of the algorithm. The pseudo code of the above steps is as follows:
Func(point p1, point p2)
Get dx and dy by p1,p2.
e = -dx
p = p1
For i = 0:dx
// p is result point
p add x direction 1
e = e + 2*dy
If e>0
p add y direction 1
e = e - 2*dy
further, step 5 includes: step 4 is repeated to simultaneously find the next grid cell to the current grid cell on both hypotenuses L, R of the triangle using a line generation algorithm until the end points of both hypotenuses L, R are scanned to fill the entire triangle.
In one embodiment, the slope of the two hypotenuses is between 0 and 1.
In one embodiment, the raster imaging device is a screen.
In one embodiment, the grid cells are pixels.
The triangle rasterization method based on the line generation algorithm has the application scene of multi-physical-field core industrial simulation processing platform software, and one exemplary application scene is the improvement of rendering efficiency of a post-processing display interface in the multi-physical-field core industrial simulation processing platform software (CPU environment).
The triangle rasterization method based on the line generation algorithm in an embodiment of the present invention is applied to the electronic device embodiment as follows:
step 1, as shown in fig. 4, a three-dimensional model of the electronic device is built, and an XY axis plane is taken as a slicing plane, and is sliced into a plurality of slicing layers along the Z axis direction. And (3) performing intersection operation on the boundary curved surface of the three-dimensional model of the electronic equipment and each segmentation layer to obtain a two-dimensional model of each segmentation layer shown in fig. 5a, 5b, 5c, 5d, 5e, 5f and 5 g. The two-dimensional model of each cut layer is subjected to grid segmentation and is discretized into a plurality of triangle sets, see fig. 6a, 6b, 6c, 6d, 6e, 6f and 6g. The mesh subdivision schematic diagram of the multi-layer layered geometric model shown in fig. 7, namely the 2.5D geometric model, can be obtained by sequentially stacking the segmentation layers according to the space positions.
In step 2, to display a set of triangles on a raster imaging device (e.g., a screen), it is necessary to color pixels falling inside the triangles. Firstly, a three-dimensional model which is segmented into a plurality of triangles is projected onto a grating imaging device through view transformation to obtain a plurality of triangles to be rasterized.
And 3, judging whether the triangle to be rasterized is a triangle with one side parallel to the x direction or not respectively. If the triangle to be rasterized is a triangle with one side parallel to the x-direction, the next step is directly entered. If the triangle to be rasterized cannot find one side parallel to the x direction, then the triangle is split into two triangles with one side parallel to the x direction, and then the next step is carried out.
Taking a triangle to be rasterized, for which the base parallel to the x-direction is not found (see fig. 2), the three vertices of the triangle are P1, P2, P3, respectively. No side of the triangle P1P2P3 is parallel to the x-direction. Therefore, the triangle is divided into two triangles with one side parallel to the x-direction by the straight line L0, the straight line L0 passes through the point P2 and intersects the side P1P3 at the point P4, and the two triangles with one side parallel to the x-direction are the triangle P1P2P4 and the triangle P2P3P4, respectively. Next, step 4 is performed on the triangles P1P2P4 and P2P3P4, respectively.
Step 4, taking triangle P1P2P4 as an example. The side P2P4 is parallel to the x-direction, so the sides P1P2 and P1P4 are two oblique sides L, R. The bevel edge L takes P1 as a starting point, P2 as an end point, and the bevel edge R takes P1 as a starting point and P3 as an end point. Let the initial values of the current grid cells of both hypotenuses L, R be the start point P1.
The next grid cell to the current grid cell on both hypotenuses of the triangle is simultaneously found using a line generation algorithm. Specifically, the step of simultaneously finding the next mesh unit of the current mesh unit on the two hypotenuses of the triangle using a line generation algorithm includes: let e be-dx, which is the distance in x-direction between the next grid cell and the current grid cell. Scanning from the starting point of the hypotenuse using a line generation algorithm to find the next grid cell to the current grid cell: the current grid cell is stepped by one unit in the x-direction, and e=e+2xdy is updated as the distance between the next grid cell and the current grid cell in the y-direction. Judging whether e is greater than or equal to 0, if e is greater than or equal to 0, the coordinate of the next grid unit in the y direction is that the current grid unit steps by one unit in the y direction, and updating e=e-2 x dx; if e is less than 0, the coordinates of the next grid cell in the y direction are the coordinates of the current grid cell in the y direction.
If the height of the coordinates of the next grid cell on the oblique side L in the y direction is larger than the height of the coordinates of the next grid cell on the oblique side R in the y direction, continuing to acquire the next grid cell on the oblique side L by using a line generating algorithm until the height of the coordinates of the next grid cell on the oblique side L in the y direction is equal to the height of the coordinates of the next grid cell on the oblique side R in the y direction, filling the two grid cells on the two oblique sides L, R and all grid cells among the two grid cells, taking the two grid cells as current grid cells of the two oblique sides respectively, and entering the next step;
if the height of the coordinates of the next grid cell on the oblique side L in the y direction is smaller than the height of the coordinates of the next grid cell on the oblique side R in the y direction, continuing to acquire the next grid cell on the oblique side R by using a line generating algorithm until the height of the coordinates of the next grid cell on the oblique side R in the y direction is equal to the height of the coordinates of the next grid cell on the oblique side L in the y direction, filling the two grid cells on the two oblique sides L, R and all grid cells among the two grid cells, taking the two grid cells as current grid cells of the two oblique sides respectively, and entering the next step;
if the height of the coordinates of the next grid cell on the hypotenuse L in the y direction is equal to the height of the coordinates of the next grid cell on the hypotenuse R in the y direction, the two grid cells on the two hypotenuses L, R and all grid cells in between are filled, and the two grid cells are respectively taken as the current grid cells of the two hypotenuses and enter the next step.
Step 5, repeat step 4, use the line generation algorithm to find the next grid cell of the current grid cell on both hypotenuses L, R of the triangle at the same time, until scanning to the end points P2 and P3 of both hypotenuses L, R, to fill the entire triangle. Wherein the hypotenuse loop iterates dx a pair from the start point to the end point.
In addition, the triangle rasterization method based on the line generation algorithm can be applied to the field of chips. Step 1, as shown in fig. 8, a three-dimensional model of the chip package is built, or an XY axis plane is taken as a dicing plane, and the chip package is diced into a plurality of dicing layers along the z axis direction. And (3) performing intersection operation on the boundary curved surface of the chip packaging three-dimensional model and each slicing layer to obtain a two-dimensional model of each slicing layer shown in fig. 9a, 9b, 9c and 9 d. The two-dimensional model of each slicing layer is subjected to grid slicing and is discretized into a plurality of triangle sets, see fig. 10a, 10b, 10c and 10d. The mesh subdivision schematic diagram of the multi-layer layered geometric model shown in fig. 11, namely the 2.5D geometric model, can be obtained by sequentially stacking the segmentation layers according to the space positions. Steps 2 to 5 are consistent with the embodiments of the electronic device described above.
Fig. 12 is a thermal simulation diagram of a triangle rasterization method based on a line generation algorithm applied to an electronic device or a chip package according to an embodiment of the present invention, where different colors represent different temperatures. It should be appreciated that the triangle rasterization method based on the line generation algorithm does not affect the triangle rasterization effect, but significantly increases the processing speed of triangle rasterization.
The invention also provides a triangle rasterization device based on the line generation algorithm, which comprises a memory and a processor. The memory is used for storing a computer program. The processor is configured to implement the triangle rasterization method based on the line generation algorithm as described above when executing the computer program.
The invention also proposes a computer readable medium having a computer program stored thereon. The computer program, when executed by a processor, implements a triangle rasterization method based on a line generation algorithm as described above.
The invention also proposes a computer program product comprising a computer program. The computer program, when executed by a processor, implements a triangle rasterization method based on a line generation algorithm as described above.
The triangle rasterization method based on the line generation algorithm and the related equipment have the beneficial effects that: a line generation algorithm is introduced into a triangle rasterization algorithm, floating point operation in the original algorithm is replaced by integer operation, and rendering efficiency of a post-processing display interface in multi-physical-field core industrial simulation processing platform software is improved.
Those of skill would further appreciate that the various illustrative logical blocks, modules, circuits, and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both. To clearly illustrate this interchangeability of hardware and software, various illustrative components, blocks, modules, circuits, and steps have been described above generally in terms of their functionality. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the overall system. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
The various illustrative logical modules, and circuits described in connection with the embodiments disclosed herein may be implemented or performed with a general purpose processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components, or any combination thereof designed to perform the functions described herein. A general purpose processor may be a microprocessor, but in the alternative, the processor may be any conventional processor, controller, microcontroller, or state machine. A processor may also be implemented as a combination of computing devices, e.g., a combination of a DSP and a microprocessor, a plurality of microprocessors, one or more microprocessors in conjunction with a DSP core, or any other such configuration.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. A software module may reside in RAM memory, flash memory, ROM memory, EPROM memory, EEPROM memory, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art. An exemplary storage medium is coupled to the processor such the processor can read information from, and write information to, the storage medium. In the alternative, the storage medium may be integral to the processor. The processor and the storage medium may reside in an ASIC. The ASIC may reside in a user terminal. In the alternative, the processor and the storage medium may reside as discrete components in a user terminal.
In one or more exemplary embodiments, the functions described may be implemented in hardware, software, firmware, or any combination thereof. If implemented in software as a computer program product, the functions may be stored on or transmitted over as one or more instructions or code on a computer-readable medium. Computer-readable media includes both computer storage media and communication media including any medium that facilitates transfer of a computer program from one place to another. A storage media may be any available media that can be accessed by a computer. By way of example, and not limitation, such computer-readable media can comprise RAM, ROM, EEPROM, CD-ROM or other optical disk storage, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer. Any connection is properly termed a computer-readable medium. For example, if the software is transmitted from a web site, server, or other remote source using a coaxial cable, fiber optic cable, twisted pair, digital Subscriber Line (DSL), or wireless technologies such as infrared, radio, and microwave, then the coaxial cable, fiber optic cable, twisted pair, DSL, or wireless technologies such as infrared, radio, and microwave are included in the definition of medium. Disk (disk) and disc (disk) as used herein include Compact Disc (CD), laser disc, optical disc, digital Versatile Disc (DVD), floppy disk and blu-ray disc where disks (disk) usually reproduce data magnetically, while discs (disk) reproduce data optically with lasers. Combinations of the above should also be included within the scope of computer-readable media.
The above embodiments are merely further illustrative of the present invention and are not intended to limit the present invention in any way, and various other embodiments are possible. Various modifications and variations may be made by those skilled in the art in light of the present disclosure without departing from the spirit and scope of the present disclosure, and such modifications and variations are intended to fall within the scope of the present disclosure.
Claims (10)
1. A method for triangle rasterization based on a line generation algorithm, comprising:
step 1, a three-dimensional model is established according to a real structure to be simulated, grid subdivision is carried out on the three-dimensional model in a three-dimensional space so as to divide the three-dimensional model into a plurality of triangles, and each triangle is provided with a group of three-dimensional coordinates so as to represent the position of the triangle in the three-dimensional space;
step 2, projecting the three-dimensional model which is segmented into a plurality of triangles to a grating imaging device through view transformation to obtain a plurality of triangles to be rasterized, wherein the view transformation is to convert three-dimensional coordinates into two-dimensional view coordinates;
step 3, judging whether one side of each triangle to be rasterized is parallel to the x direction or not respectively, if so, entering the next step, if not, cutting the triangle into two triangles with one side parallel to the x direction, and entering the next step;
step 4, for a triangle with one side parallel to the x direction, simultaneously solving the next grid unit of the current grid unit on two hypotenuses of the triangle by using a line generation algorithm until the coordinates of the next grid unit in the y direction are different from the coordinates of the last grid unit in the y direction, so as to respectively acquire two grid units with the same coordinates in the y direction on the two hypotenuses of the triangle, filling the two grid units and all grid units in the middle of the two grid units, and taking the two grid units as the current grid units of the two hypotenuses respectively and entering the next step;
step 5, repeating the step 4 until the grid cells inside the triangle with one side parallel to the x direction are completely filled in the step 4;
the triangle rasterization method based on the line generation algorithm is used for forming a grid cell set corresponding to all triangles to be rasterized on a raster imaging device, the raster imaging device is divided into a plurality of same grid cells, a two-dimensional view coordinate system is established on the raster imaging device, the x direction is the direction of an x axis in the two-dimensional view coordinate system, and the y direction is the direction of a y axis in the two-dimensional view coordinate system.
2. The method of triangle rasterization based on a line generation algorithm of claim 1, wherein said step 4 comprises:
the three vertexes of a triangle with one side parallel to the x axis are respectively P1, P2 and P3, the sides P1P2 and P1P3 are respectively two sloping sides L, R, the sloping side L takes P1 as a starting point and P2 as an end point, the sloping side R takes P1 as a starting point and P3 as an end point, and the initial value of the current grid unit is taken as the starting point P1;
simultaneously solving the next grid cell of the current grid cell on the two hypotenuses L, R of the triangle by using a line generating algorithm;
if the height of the coordinates of the next grid cell on the oblique side L in the y direction is larger than the height of the coordinates of the next grid cell on the oblique side R in the y direction, continuing to acquire the next grid cell on the oblique side L by using a line generating algorithm until the height of the coordinates of the next grid cell on the oblique side L in the y direction is equal to the height of the coordinates of the next grid cell on the oblique side R in the y direction, filling the two grid cells on the two oblique sides L, R and all grid cells among the two grid cells, taking the two grid cells as current grid cells of the two oblique sides respectively, and entering the next step;
if the height of the coordinates of the next grid cell on the oblique side L in the y direction is smaller than the height of the coordinates of the next grid cell on the oblique side R in the y direction, continuing to acquire the next grid cell on the oblique side R by using a line generating algorithm until the height of the coordinates of the next grid cell on the oblique side R in the y direction is equal to the height of the coordinates of the next grid cell on the oblique side L in the y direction, filling the two grid cells on the two oblique sides L, R and all grid cells among the two grid cells, taking the two grid cells as current grid cells of the two oblique sides respectively, and entering the next step;
if the height of the coordinates of the next grid cell on the hypotenuse L in the y direction is equal to the height of the coordinates of the next grid cell on the hypotenuse R in the y direction, the two grid cells on the two hypotenuses L, R and all grid cells in between are filled, and the two grid cells are respectively taken as the current grid cells of the two hypotenuses and enter the next step.
3. The method of triangle rasterization based on the line generation algorithm of claim 2, wherein said step 5 comprises: step 4 is repeated to simultaneously find the next grid cell of the current grid cell on both hypotenuses L, R of the triangle using a line generation algorithm until the end point of both hypotenuses L, R is scanned and the grid cell inside the triangle is completely filled.
4. The method for rasterizing a triangle based on a line generating algorithm according to claim 1, wherein in the step 4, the method for simultaneously determining the next grid cell of the current grid cells on the two hypotenuses of the triangle using the line generating algorithm comprises:
taking two vertexes on the bevel edge as a starting point and a terminal point respectively, enabling the initial value of e to be-dx, enabling dx to be the distance between the next grid unit and the current grid unit in the x direction, and enabling the initial value of the current grid unit to be the starting point of the bevel edge;
scanning from a starting point of the hypotenuse using a line generation algorithm to find a next grid cell to the current grid cell, the finding the next grid cell to the current grid cell comprising:
stepping the current grid cell P by one unit in the x direction, and updating e=e+2xdy, wherein dy is the distance between the next grid cell and the current grid cell in the y direction;
judging whether e is greater than or equal to 0, if e is greater than or equal to 0, the coordinate of the next grid unit in the y direction is the coordinate of the current grid unit in the y direction by one unit, updating e=e-2 x dx at the same time, and if e is less than 0, the coordinate of the next grid unit in the y direction is the coordinate of the current grid unit in the y direction.
5. The line generation algorithm-based triangle rasterization method of claim 1, wherein said grid cells are pixels.
6. The line generation algorithm-based triangle rasterization method of any one of claims 1 to 5, wherein the line generation algorithm-based triangle rasterization method is applied in an electronic device.
7. The line generation algorithm based triangle rasterization method of any one of claims 1 to 5, wherein the line generation algorithm based triangle rasterization method is applied in a chip package.
8. A triangle rasterization apparatus based on a line generation algorithm, comprising a memory and a processor;
the memory is used for storing a computer program;
the processor for implementing a triangle rasterization method based on a line generation algorithm as claimed in any one of claims 1 to 7 when executing the computer program.
9. A computer readable medium having a computer program stored thereon, which, when executed by a processor, implements a triangle rasterization method based on a line generation algorithm as claimed in any one of claims 1 to 7.
10. A computer program product comprising a computer program which, when executed by a processor, implements a triangle rasterization method based on a line generation algorithm as claimed in any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202410173857.7A CN117726774B (en) | 2024-02-07 | 2024-02-07 | Triangle rasterization method and device based on line generation algorithm and related equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202410173857.7A CN117726774B (en) | 2024-02-07 | 2024-02-07 | Triangle rasterization method and device based on line generation algorithm and related equipment |
Publications (2)
Publication Number | Publication Date |
---|---|
CN117726774A true CN117726774A (en) | 2024-03-19 |
CN117726774B CN117726774B (en) | 2024-04-30 |
Family
ID=90207337
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202410173857.7A Active CN117726774B (en) | 2024-02-07 | 2024-02-07 | Triangle rasterization method and device based on line generation algorithm and related equipment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN117726774B (en) |
Citations (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5673379A (en) * | 1995-03-20 | 1997-09-30 | Hewlett-Packard Company | Scan line generator for area fill of extensible polygons |
US20060132495A1 (en) * | 2004-12-21 | 2006-06-22 | Anderson Michael H | 2D/3D line rendering using 3D rasterization algorithms |
WO2007002592A2 (en) * | 2005-06-23 | 2007-01-04 | Mental Images Gmbh | Image synthesis by rank-1 lattices |
CN103236058A (en) * | 2013-04-25 | 2013-08-07 | 内蒙古科技大学 | Method for obtaining volume of interest of four-dimensional heart image |
WO2016116045A1 (en) * | 2015-01-21 | 2016-07-28 | 高德软件有限公司 | Method and apparatus for generating digital terrain model data of electronic maps |
CN109598669A (en) * | 2018-11-14 | 2019-04-09 | 西安翔腾微电子科技有限公司 | A kind of triangle rasterization Scan Architecture towards GPU |
US20200184705A1 (en) * | 2018-12-06 | 2020-06-11 | Cesium GS, Inc. | System and Method For Transferring Surface Information From Massive Meshes to Simplified Meshes Using Voxels |
CN115953290A (en) * | 2022-12-23 | 2023-04-11 | 东北大学 | Scene voxelization method based on GPU (graphics processing Unit) rasterizer |
CN116977598A (en) * | 2023-09-22 | 2023-10-31 | 芯瑞微(上海)电子科技有限公司 | Triangular mesh numerical simulation smoothing method |
CN117078890A (en) * | 2023-10-13 | 2023-11-17 | 芯瑞微(上海)电子科技有限公司 | Three-dimensional geometric model mesh subdivision method, system, device and computer readable medium |
-
2024
- 2024-02-07 CN CN202410173857.7A patent/CN117726774B/en active Active
Patent Citations (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5673379A (en) * | 1995-03-20 | 1997-09-30 | Hewlett-Packard Company | Scan line generator for area fill of extensible polygons |
US20060132495A1 (en) * | 2004-12-21 | 2006-06-22 | Anderson Michael H | 2D/3D line rendering using 3D rasterization algorithms |
WO2007002592A2 (en) * | 2005-06-23 | 2007-01-04 | Mental Images Gmbh | Image synthesis by rank-1 lattices |
CN103236058A (en) * | 2013-04-25 | 2013-08-07 | 内蒙古科技大学 | Method for obtaining volume of interest of four-dimensional heart image |
WO2016116045A1 (en) * | 2015-01-21 | 2016-07-28 | 高德软件有限公司 | Method and apparatus for generating digital terrain model data of electronic maps |
CN109598669A (en) * | 2018-11-14 | 2019-04-09 | 西安翔腾微电子科技有限公司 | A kind of triangle rasterization Scan Architecture towards GPU |
US20200184705A1 (en) * | 2018-12-06 | 2020-06-11 | Cesium GS, Inc. | System and Method For Transferring Surface Information From Massive Meshes to Simplified Meshes Using Voxels |
CN115953290A (en) * | 2022-12-23 | 2023-04-11 | 东北大学 | Scene voxelization method based on GPU (graphics processing Unit) rasterizer |
CN116977598A (en) * | 2023-09-22 | 2023-10-31 | 芯瑞微(上海)电子科技有限公司 | Triangular mesh numerical simulation smoothing method |
CN117078890A (en) * | 2023-10-13 | 2023-11-17 | 芯瑞微(上海)电子科技有限公司 | Three-dimensional geometric model mesh subdivision method, system, device and computer readable medium |
Non-Patent Citations (2)
Title |
---|
张文明;刘彬;徐刚;: "三维实体网格自适应划分算法", 机械工程学报, no. 11, 15 November 2009 (2009-11-15), pages 272 - 276 * |
聂;田泽;马城城;: "一种并行扫描的三角形光栅化算法设计与实现", 信息通信, no. 03, 15 March 2016 (2016-03-15), pages 73 - 74 * |
Also Published As
Publication number | Publication date |
---|---|
CN117726774B (en) | 2024-04-30 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
KR100889602B1 (en) | Apparatus and method of ray-triangle collision detection for ray-tracing | |
US6717599B1 (en) | Method, system, and computer program product for implementing derivative operators with graphics hardware | |
US8310480B2 (en) | Method, medium, and system for compressing and decoding mesh data in three-dimensional mesh model | |
US8059119B2 (en) | Method for detecting border tiles or border pixels of a primitive for tile-based rendering | |
CN113178014A (en) | Scene model rendering method and device, electronic equipment and storage medium | |
JP2001052194A (en) | Reconfiguration for curved surface | |
KR20080090671A (en) | Apparatus and method for mapping textures to object model | |
JP2010512582A (en) | Computer graphic shadow volume with hierarchical occlusion culling | |
JP2015535978A (en) | Computer graphics method for rendering a three-dimensional scene | |
JP2005352657A (en) | Device, method, and program for drawing processing | |
EP1860614A1 (en) | 3-Dimensional Graphics Processing Method, Medium and Apparatus Performing Perspective Correction | |
JP2005100176A (en) | Image processor and its method | |
US11087511B1 (en) | Automated vectorization of a raster image using a gradient mesh with arbitrary topology | |
JP3892016B2 (en) | Image processing apparatus and image processing method | |
US6774897B2 (en) | Apparatus and method for drawing three dimensional graphics by converting two dimensional polygon data to three dimensional polygon data | |
CN117726774B (en) | Triangle rasterization method and device based on line generation algorithm and related equipment | |
CN111724313B (en) | Shadow map generation method and device | |
US10347034B2 (en) | Out-of-core point rendering with dynamic shapes | |
US6831642B2 (en) | Method and system for forming an object proxy | |
KR100984335B1 (en) | A method for removing cracks using gpu in quad-tree based terrain rendering | |
US20030231180A1 (en) | Image processing apparatus and method of same | |
KR20140103407A (en) | Method for terrain rendering using bimodal vertex splitting | |
KR100551132B1 (en) | method for filtering of triangle strip in rendering system of view-dependency Level Of Detail based | |
KR101228118B1 (en) | Method for constructing a Kd-tree based on polygon importance | |
CN102074004A (en) | Method and device for determining type of barrier of spatial entity |
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 | ||
GR01 | Patent grant |