Method and device for dynamic flattening of local area of three-dimensional scene based on flattened polygon
Through the dynamic flattening method of local areas of three-dimensional scenes based on flattened polygons, the problem in the existing technology that flattening low-quality models requires professional operations and is irreversible is solved. Flattening and dynamic adjustment on any inclined surface are realized, providing efficient 3D model repair solution.
Patent Information
- Application Number
- CN202110200278.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-02-23
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2041-02-23
AI Technical Summary
Existing 3D model repair software requires professional operations when flattening low-quality models, and the operation is irreversible, causing the virtual scene to be inconsistent with the actual scene, and can only be flattened on the horizontal plane, which cannot adapt to the needs of complex scenes.
A dynamic flattening method for local areas of a three-dimensional scene based on flattening polygons is adopted. By defining flattening polygons, creating flattening cameras, generating depth maps, and performing vertex shader processing in the GPU, flattening of arbitrary slopes is achieved, allowing users to Interactively view and adjust flattening effects.
It achieves a low-cost, highly interactive flattening effect without modifying the three-dimensional model. It can flatten on any inclined plane, avoiding the problem of physical damage to the model quality, and providing the convenience of dynamic adjustment.
Smart Images

Figure CN112927352B
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of spatial information, and in particular relates to a method and device for dynamically flattening a local area of a three-dimensional scene based on flattened polygons. Background Art
[0002] The 3D model is an important data foundation for 3D visualization. Its accuracy is closely related to the visualization effect of the 3D scene. A fine model can improve the quality of 3D visualization, while the existence of a low-quality model will hinder the perception and even affect the application effect. Fine models are generally produced by manual modeling or lidar modeling, but due to the high production cost, fine modeling methods are generally only used for key targets. Oblique photography is a full-factor 3D modeling method with low production cost and fast production speed. It can achieve batch 3D reconstruction of large scenes including geometric structures and textures. However, due to the limitations of current technology, the modeling effect of small and scattered targets such as trees and electric poles is poor, which easily leads to the generation of a large number of low-quality models.
[0003] Professional modeling software can be used to remove low-quality models to improve the visualization effect. The removal operation is essentially a secondary modeling of the original model, and data (such as texture images) need to be re-collected to achieve 3D reconstruction of the removed area. At present, some modeling software such as MeshMixer and wish3D provide a local flattening function for the model. Without the need to re-collect data, low-quality models (such as trees) can be directly flattened to the ground, indirectly achieving the requirement of removing low-quality models. However, this method has the following problems: (1) Flattening requires professional user operation and professional modeling software support. In addition to increasing the extra workload, it is basically not feasible for ordinary users. (2) Modeling software flattening is essentially a physical destruction of the 3D model, turning the "1-N" problem reflecting the quality of the model into a "0-1" problem reflecting the existence of the model, resulting in new inconsistencies between the virtual scene and the actual scene. Since its operation is irreversible, it is unacceptable in some applications. Summary of the invention
[0004] Purpose of the invention: The present invention proposes a method and device for dynamic flattening of a local area of a three-dimensional scene based on flattened polygons. The method and device have low restrictions on the flattened area and are not limited to horizontal planes. They can be any inclined plane and have strong interactivity. The actual flattening effect can be easily viewed and dynamically adjusted.
[0005] Technical solution: The present invention proposes a method for dynamically flattening a local area of a three-dimensional scene based on flattened polygons, which specifically includes the following steps:
[0006] (1) Defining a flattening polygon in the user coordinate system to determine a flattening area: defining a flattening polygon according to the target to be flattened, so that the flattening polygon closely fits the flattening area of the target to be flattened;
[0007] (2) Create a flattened camera based on the flattened polygon, and set the observation matrix, projection matrix, and viewport matrix;
[0008] (3) Generate a flattened polygon depth map using a flattening camera;
[0009] (4) The observation matrix, projection matrix and flattened polygon depth map of the flattened camera are passed to the GPU programmable pipeline;
[0010] (5) In the vertex shader of the GPU, the inclusion relationship between the flattened polygon and the vertex is determined, and the vertices that are inside the flattened polygon and higher than the flattened polygon are shifted and flattened.
[0011] Furthermore, the step (2) comprises the following steps:
[0012] (21) Calculate the flattened polygon bounding box: the flattened polygon bounding box is the smallest axis-aligned cube containing all vertices of the flattened polygon, wherein the upper bottom surface Z value bTop is equal to the maximum value of all vertex Z values, and the lower bottom surface Z value bBottom is equal to the minimum value of all vertex Z values, and correct bTop = max(bTop, bBottom + f), wherein f is any value greater than 0;
[0013] (22) Setting the flattened camera observation matrix: Determine the straight line L by flattening the upper and lower bottom centers of the polygonal bounding box, select any spatial point on L that is higher than the bounding box as the origin O of the observation coordinate system, define the X, Y, and Z axes of the observation coordinate system to be consistent with the X, Y, and Z axes of the user coordinate system, respectively, establish the observation coordinate system, and set the flattened camera observation matrix according to the observation coordinate system;
[0014] (23) Setting the projection matrix of the flattened camera: setting the flattened polygonal bounding box as the observation space of the flattened camera, and then setting the projection matrix of the flattened camera according to the orthogonal projection type and the observation space of the flattened camera;
[0015] (24) Setting the viewport matrix of the flattening camera: Setting the viewport width W and height H of the flattening camera, where W and H are both greater than 0; setting the viewport matrix of the flattening camera according to the viewport width and height.
[0016] Furthermore, the step (3) comprises the following steps:
[0017] (31) Decomposing the flattened polygon into triangulated meshes;
[0018] (32) Output the flattened polygon depth map: turn off the color cache, turn on the depth cache, input the decomposed triangulated network into the GPU, and generate the flattened polygon depth map.
[0019] Furthermore, the step (5) comprises the following steps:
[0020] (51) In the vertex shader, according to the viewing matrix and projection matrix of the flattened camera, the vertex coordinates V0(x0, y0, z0) in the user coordinate system are transformed into the texture space of the flattened camera, and the transformed coordinates are set as V1(x1, y1, z1).
[0021] (52) If both x1 and y1 are within the range of [0, 1], sample the depth map of the flattened polygon using the coordinates (x1, y1) to obtain the depth value z2. If z2 < 1.0, inverse-transform the coordinates (x1, y1, z2) into the user coordinate system according to the viewing matrix and projection matrix of the flattened camera to obtain the coordinates (x3, y3, z3): If z3 < z0, then this vertex needs to be flattened, and modify the z value of V0 to z3; otherwise, keep V0 unchanged.
[0022] (53) Use V0 to participate in the normal rendering process.
[0023] Based on the same inventive concept, the present invention also provides a three-dimensional scene local area dynamic flattening device based on a flattened polygon, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the computer program is loaded into the processor, it implements the three-dimensional scene local area dynamic flattening method based on a flattened polygon described above.
[0024] Advantageous effects: Compared with the prior art, the advantageous effects of the present invention are as follows: Compared with the traditional flattening method that requires modifying the model file, the present invention does not require modifying the three-dimensional model, and has strong interactivity, allowing for convenient viewing of the actual flattening effect and dynamic adjustment; at the same time, the present invention has lower restrictions on the flattened area, not limited to the horizontal plane, but can be any inclined plane, and can define the flattened area using an imprecise coplanar spatial polygon according to user needs. Brief Description of the Drawings
[0025] Figure 1 is a flowchart of the present invention;
[0026] Figure 2 is a visualization effect diagram before the pole is flattened;
[0027] Figure 3 is an interactive definition of the flattened polygon diagram;
[0028] Figure 4 is a schematic diagram of the flattened camera setting;
[0029] Figure 5 is a visualization effect diagram after the pole is flattened. Detailed Embodiment
[0030] The present invention will be further described in detail below with reference to the accompanying drawings.
[0031] The present invention provides a method for dynamically flattening a local area of a three-dimensional scene based on a flattened bounding sphere. Figure 1 As shown, the specific steps include:
[0032] Step 1: Define a flattening polygon in the user coordinate system to determine the flattening area: Define a flattening polygon according to the target to be flattened, so that the flattening polygon fits closely to the flattening area of the target to be flattened.
[0033] Figure 2 This is a visualization of the pole before it is flattened. Figure 3 As shown, the screen coordinates of the vertices of the flattened polygon are obtained by taking points on the screen. The flattened polygon is required to fit the flattened area of the target to be flattened. The flattened area is the reference surface to which the model is to be flattened, which is generally consistent with the ground. The flattened polygon is a user-defined spatial polygon that approximates the flattened area. Then, with the help of the viewport matrix, projection matrix, and view matrix under the rendering camera viewpoint, the screen coordinates are transformed into the user coordinate system. In the 3D rendering engine library OpenGL, this can be achieved using the gluUnProject function.
[0034] Step 2: Create a flattened camera based on the flattened polygon, and set the observation matrix, projection matrix, and viewport matrix.
[0035] (2.1) Calculate the flattened polygonal bounding box: Figure 4 As shown in the figure, the bounding box of the flattened polygon is the smallest axis-aligned cube containing all the vertices of the flattened polygon, where the upper bottom surface Z value bTop is equal to the maximum value of all the vertex Z values, and the lower bottom surface Z value bBottom is equal to the minimum value of all the vertex Z values. To avoid the upper and lower bottom surfaces being coplanar and causing the bounding box to fail, bTop=max(bTop,bBottom+f) is corrected, where f is the adjustment factor, which is any value greater than 0. Since the flattened polygon is close to horizontal, if the adjustment factor f=1, the final bTop=bBottom+1.
[0036] (2.2) Set the flattened camera observation matrix: Figure 4 As shown, the straight line L is determined by flattening the upper and lower bottom centers of the polygonal bounding box, and any spatial point on L that is higher than the bounding box is selected as the origin O of the observation coordinate system. The X, Y, and Z axes of the observation coordinate system are defined to be consistent with the X, Y, and Z axes of the user coordinate system, respectively, and the observation coordinate system is established. The flattened camera observation matrix is set according to the observation coordinate system. In the 3D rendering engine library OpenGL, the gluLookAt function can be used to automatically set the observation matrix according to the observation coordinate system information.
[0037] (2.3) Set the flattened camera projection matrix: Set the bounding box of the flattened polygon as the viewing space of the flattened camera, and then set the projection matrix of the flattened camera according to the type of orthographic projection and the viewing space of the flattened camera. In the 3D rendering engine library OpenGL, the gluOtho function can be used to automatically set the orthographic projection matrix according to the viewing space.
[0038] (2.4) Set the flattened camera viewport matrix: Set the viewport width W and height H of the flattened camera, where both W and H are required to be greater than 0, and the actual width and height of the window can be directly used as the values; set the viewport matrix of the flattened camera according to the viewport width and height. In the 3D rendering engine library OpenGL, the glViewport function can be used to automatically set the viewport matrix.
[0039] Step 3: Generate the depth map of the flattened polygon using the flattened camera.
[0040] Decompose the flattened polygon into a triangular mesh; Output the depth map of the flattened polygon: Turn off the color buffer and turn on the depth buffer, input the decomposed triangular mesh into the GPU, and generate the depth map of the flattened polygon based on the FBO technology.
[0041] Step 4: Pass the viewing matrix, projection matrix of the flattened camera, and the depth map of the flattened polygon into the GPU programmable pipeline.
[0042] Step 5: In the vertex shader of the GPU, determine the inclusion relationship between the flattened polygon and the vertex, and shift and flatten the vertices that are inside the flattened polygon and higher than the flattened polygon.
[0043] (5.1) Normally render the 3D scene. In the vertex shader, convert the vertex coordinates V0(x0, y0, z0) to the texture space of the flattened camera according to the flattened camera view matrix Mview, projection matrix Mproject, and viewport matrix Mviewport. Here, the total transformation matrix M = Mview * Mproject * Mviewport can be set, and V0 is transformed and normalized using the M matrix to obtain the transformed coordinates V1(x1, y1, z1).
[0044] (5.2) If both x1 and y1 are within the range of [0, 1], sample the depth map of the flattened polygon with the coordinates (x1, y1) to obtain the depth value z2. If z2 < 1.0, it indicates that the projection of this point on the XY plane is covered by the flattened polygon. Transform the coordinates (x1, y1, z2) using the inverse matrix of the M matrix to obtain the transformed z coordinate z3(x3, y3, z3): If z3 < z0, this vertex needs to be flattened, and modify the z value of V0 to z3; otherwise, this vertex does not need to be flattened, and V0 remains unchanged.
[0045] (5.3) Use V0 to participate in the normal rendering process. The final effect is as follows Figure 5 shown.
[0046] The present invention also provides a device for dynamically flattening a local area of a three-dimensional scene based on flattened polygons, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the computer program is loaded into the processor, the method for dynamically flattening a local area of a three-dimensional scene based on flattened polygons is implemented.
Claims
1. A method for dynamic flattening of a local area of a three-dimensional scene based on flattened polygons, characterized in that: It includes the following steps: (1) Define a flattening polygon in the user coordinate system to determine the flattening area: Define a flattening polygon according to the target to be flattened, so that the flattening polygon closely fits the flattening area of the target to be flattened; (2) Create a flattening camera according to the flattening polygon, and set the view matrix, projection matrix and viewport matrix; (3) Use the flattening camera to generate a depth map of the flattening polygon; (4) Pass the view matrix, projection matrix of the flattening camera and the depth map of the flattening polygon into the GPU programmable pipeline; (5) In the vertex shader of the GPU, judge the inclusion relationship between the flattening polygon and the vertex, and shift and flatten the vertex located inside the flattening polygon and higher than the flattening polygon; The step (2) includes the following steps: (21) Calculate the bounding box of the flattening polygon: The bounding box of the flattening polygon is the smallest axis-aligned cube containing all vertices of the flattening polygon, where the Z value bTop of the upper bottom surface is equal to the maximum value of the Z values of all vertices, and the Z value bBottom of the lower bottom surface is equal to the minimum value of the Z values of all vertices. Modify bTop = max(bTop, bBottom + f), where f is any value greater than 0; (22) Set the view matrix of the flattening camera: Determine the straight line L through the centers of the upper and lower bottom surfaces of the bounding box of the flattening polygon, select any spatial point above the bounding box on L as the origin O of the view coordinate system, define that the X, Y and Z axes of the view coordinate system are respectively consistent with the X, Y and Z axes of the user coordinate system, establish the view coordinate system, and set the view matrix of the flattening camera according to the view coordinate system; (23) Set the projection matrix of the flattening camera: Set the bounding box of the flattening polygon as the viewing space of the flattening camera, and then set the projection matrix of the flattening camera according to the type of orthographic projection and the viewing space of the flattening camera; (24) Set the viewport matrix of the flattening camera: Set the viewport width W and height H of the flattening camera, where both W and H are greater than 0; Set the viewport matrix of the flattening camera according to the viewport width and height; The step (3) includes the following steps: (31) Decompose the flattening polygon into a triangular mesh; (32) Output the depth map of the flattening polygon: Turn off the color buffer and turn on the depth buffer, input the decomposed triangular mesh into the GPU, and generate the depth map of the flattening polygon; The step (5) includes the following steps: (51) In the vertex shader, transform the vertex coordinates V0(x0, y0, z0) in the user coordinate system to the texture space of the flattening camera according to the view matrix and projection matrix of the flattening camera, and set the transformed coordinates as V1(x1, y1, z1); (52) If both x1 and y1 are within the range of [0, 1], sample the depth map of the flattening polygon with the coordinates (x1, y1) to obtain the depth value z2. If z2 < 1.0, inverse-transform the coordinates (x1, y1, z2) to the user coordinate system according to the view matrix and projection matrix of the flattening camera to obtain the coordinates (x3, y3, z3): If z3 < z0, the vertex needs to be flattened, and modify the z value of V0 to z3; otherwise, keep V0 unchanged; (53) Use V0 to participate in the normal rendering process.
2. A device for dynamically flattening a local area of a three-dimensional scene based on flattened polygons, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the computer program is loaded into a processor, the method for dynamic flattening of a local area of a three-dimensional scene based on flattened polygons according to claim 1 is implemented.
Citation Information
Patent Citations
Topographical flattening method for three-dimensional scenes
CN107845136A
