A method for generating high-quality isosurface mesh in real time, the method is capable of being applied to 3D scene reconstruction and executed by a real-time graphics system, the method comprises the following steps:
- (1) constructing equivalent edges of each triangle in a case of a Marching Cubes (MC) algorithm, wherein the equivalent edges represent a distribution of edges where vertices of each triangle are located, and when the distribution changes, a relative position relationship among three edges of each triangle also changes;
- (2) inputting voxel data of a certain 3D model and setting an isosurface value;
- (3) evenly dividing the voxel data into individual cube cells, and marking each cell vertex with a sign according to a size relationship between a value at the cell vertex and the isosurface value, wherein when the value at the cell vertex is greater than the isosurface value, marking the cell vertex with a positive sign, and when the value at the cell vertex is less than the isosurface value, marking the cell vertex with a negative sign;
- or, when the value at the cell vertex is greater than the isosurface value, marking the cell vertex with the negative sign, and when the value at the cell vertex is less than the isosurface value, marking the cell vertex with the positive sign;
- (4) according to the signs marked in step (3), determining a case to which a current cell belongs by comparing with the case in the MC algorithm;
- (5) after the case is determined, generating an index according to vertex index rules of the MC algorithm, and querying an active edge table in the MC algorithm to obtain a set of edges where the isosurface intersects the current cube cell, and obtaining the equivalent edges configuration of each triangle in the current cell according to step (1), wherein the vertex index rules of the MC algorithm comprise 256 two-dimensional arrays representing 256 configurations of the current cube cell, and the active edge table comprises hexadecimal data of an active edge of the current cube cell;
- (6) evaluating quality performance of the equivalent edges corresponding to the triangle;
- (7) using a connectivity modification method in remeshing technology to eliminate the equivalent edge with the worst quality performance, wherein the connectivity modification method comprises:
- under a condition of ensuring that the vertices of each triangle are unchanged, modifying a connection relationship between vertices so as to modify a composition of each edge of the triangle;
- (8) inserting new vertices in the cell to construct new equivalent edges with regard to the worst equivalent edge which cannot be eliminated in step (7);
- (9) moving the active edge to make the active edge more perpendicular to the isosurface to improve the quality of the equivalent edges of the triangle, wherein the step (9) comprises the following sub-steps:
- (9.1) determining the gradient direction from two end points of each active edge of the cube cell to the isosurface and the vertical direction of the gradient direction;
- (9.2) taking one end point of the active edge as a starting point, drawing an extension line along the vertical direction of the gradient direction from the starting point to the isosurface, taking another end point of the active edge as a starting point, and drawing an extension line along the gradient direction from the starting point to the isosurface;
- similarly, exchanging the two end points and drawing extension lines to obtain another intersection point the two intersection points and the two end points forming a quadrilateral, and taking midpoints of two edges parallel to the gradient direction in the quadrilateral as end points of a new active edge;
- (10) selecting a next cube cell and repeating steps (4)-(10) until all cube cells divided in step (3) are traversed;
- (11) splicing, according to a distribution of the cube cells obtained by evenly dividing the voxel data, all cube cells together in such a manner that triangle vertices on the edges of adjacent cube cells coincide;
- (12) moving the triangle vertices shared by no less than 6 triangles on an edge of the cube cell to a midpoint of the edge to obtain a final mesh output, wherein the triangles is capable of being distributed in multiple cube cells, a displacement distance is modulated by a gain function, and a parameter of the gain function is set to be 0.5, and wherein the gain function is constructed for the cube cells and is configured to move the triangle vertices shared by no less than 6 triangles on the edge of the cube cell;
- and
- (13) rendering the isosurface of the certain 3D model based on the final mesh output, and displaying rendering results on a display device to achieve real-reconstruction of a 3D scene.