Method, device and equipment for three-dimensional terrain clipping based on texture mapping

CN117152329BActive Publication Date: 2026-09-15SHAANXI XINXIANG INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310742435.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-06-21
Publication Date
2026-09-15
Estimated Expiration
2043-06-21

AI Technical Summary

Technical Problem

[0009]本发明的目的在于提供一种基于纹理映射的三维引擎地形裁剪方法,以解决上述背景技术中提出的现有的Cesium三维GIS平台的裁剪方法不能够裁剪地表及地下的任意地形,不能同时对多个裁剪区域进行裁剪,仅支持凸多边形的地形裁剪的问题

Benefits of technology

[0079](1) The three-dimensional terrain clipping method based on the present invention solves the problem of clipping multiple regions at the same time and solves the problem that concave polygons cannot be clipped, which facilitates the intuitive and flexible display of underground model data in project engineering management.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117152329B_ABST
    Figure CN117152329B_ABST
Patent Text Reader

Abstract

The present application relates to a kind of texture mapping-based three-dimensional terrain clipping method, device and equipment, belong to three-dimensional platform terrain display technical field, by obtaining polygon region according to attribute judgment display or hide, utilize the all points of polygon region to construct a minimum enclosing rectangle, utilize boundary sphere theory to add polygon to unloading set or display set, rewrite the function getShaderProgram of Cesium engine and function endUpdate;The clipping region in display set is mapped to canvas to form clipping texture, dynamically update the variable of color source script createFS in function getShaderProgram, complete polygon three-dimensional terrain clipping;The present application can simultaneously clip multiple arbitrary polygons, and different terrain is quickly and accurately clipped by the arbitrary polygon region surrounded by construction site model data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of 3D platform terrain display technology, specifically to a 3D terrain clipping method, apparatus, device, and readable storage medium based on texture mapping. Background Technology

[0002] Currently, during the development of underground construction projects, it is necessary to trim the terrain to ensure that hidden underground works can be displayed intuitively. For example, a subway line typically includes multiple stations, and the model data for the vast majority of these stations are underground, constituting hidden works. If the underground model data is not displayed intuitively, users will not be able to see the underground station works once they locate the station.

[0003] Currently, due to limitations in its interface, the Cesium 3D GIS platform only allows for one clipping region globally, and this region can only be created once. When setting a new clipping region, the previous one is overwritten, and it only supports convex polygon terrain clipping. However, the Cesium 3D GIS platform loads model data from multiple stations, and these station model data require local terrain clipping underground. This means clipping multiple terrain regions, and the clipped regions can be any polygon, whether convex or concave.

[0004] In summary, the existing cropping methods of the Cesium 3D GIS platform have the following problems when dealing with underground concealed engineering projects:

[0005] (1) The Cesium 3D GIS platform supports terrain clipping. The clipping area can only be set to the Earth. The clipping area can only be set globally and can only be set once.

[0006] (2) Multiple cropping areas cannot be cropped simultaneously;

[0007] (3) Only supports terrain clipping of convex polygons.

[0008] Therefore, the existing cropping methods of the Cesium 3D GIS platform are clearly unsuitable for underground concealed engineering construction. In light of this, there is an urgent need to design a method capable of cropping arbitrary surface and underground terrain, supporting simultaneous cropping of multiple areas, and also supporting arbitrary polygon cropping. Summary of the Invention

[0009] The purpose of this invention is to provide a 3D engine terrain clipping method based on texture mapping, in order to solve the problems mentioned in the background art that the existing clipping method of the Cesium 3D GIS platform cannot clip arbitrary terrain on the surface and underground, cannot clip multiple clipping areas at the same time, and only supports terrain clipping of convex polygons.

[0010] To achieve the above objectives, the present invention provides the following technical solution:

[0011] A 3D terrain clipping method based on texture mapping includes the following steps:

[0012] (1) Obtain the polygon region, add the polygon region to the clipping region interface, determine the display attribute of the polygon region, if the polygon region is hidden, add the clipping data to the hidden collection; if the polygon region is displayed, proceed to the next step.

[0013] (2) Further determine whether each point of the polygon region is within the display area. If each point is not within the display area, the unloading condition is met, and the polygon region is added to the unloading set. If any one or more points are within the display area, proceed to the next step.

[0014] (3) Construct a minimum enclosing rectangle using all points of the polygonal region, and calculate the minimum boundary sphere using this rectangle;

[0015] (4) Calculate and determine the geometric error value of the minimum boundary sphere observation distance and the geometric error value of the minimum boundary sphere, and add the polygon region to the unload set or the display set;

[0016] (5) Rewrite the Cesium engine functions getShaderProgram and endUpdate;

[0017] (6) The clipping region in the display set is mapped to the canvas to form a clipping texture. The variable of the color source script createFS in the function getShaderProgram is dynamically updated to complete the polygon 3D terrain clipping.

[0018] Further, the unloading condition in step (2) is: the visible distance of the polygonal region exceeds the preset maximum error or each vertex of the polygonal region is not within the display area.

[0019] Further specifying, step (4) specifically includes:

[0020] (4.1) Calculate the geometric error value E1 of the observation distance of the minimum boundary sphere based on the distance D between the center of the minimum boundary sphere and the virtual camera;

[0021] E1 = D / E0,

[0022] Where E1 is the geometric error value of the minimum boundary sphere observation distance, and E0 is the screen space error value;

[0023] (4.2) Calculate the geometric error value of the minimum boundary sphere;

[0024]

[0025] Where E2 is the geometric error value of the minimum boundary sphere; V is the volume of the minimum boundary sphere; and d is the diameter of the boundary sphere.

[0026] (4.3) Determine the geometric error values ​​E1 and E2 of the minimum boundary sphere observation distance. If E1 > E2, the unloading condition is met, and the polygon region is added to the unloading set. If E1 ≤ E2, the polygon region is added to the display set.

[0027] Further specifying, step (5) includes:

[0028] (5.1) Rewrite the Cesium engine function getShaderProgram

[0029] (5.1.1) Define a global variable setGlobeFS with an initial value of 0;

[0030] (5.1.2) Determine if the function oldGetShaderProgram of the Cesium engine exists. If it does not exist, assign the original function getShaderProgram in the Cesium engine to the function oldGetShaderProgram and rewrite the function getShaderProgram. If it exists, do nothing.

[0031] (5.1.3) Determine if the global variable setGlobeFS is 0. If it is, obtain the data source set of the fragment shader, modify the content with index 1 in the data source set to the system script xh_fsShader, add the custom shader source script createFS after it, and adjust the global variable setGlobeFS to 1. If not, do not do anything.

[0032] (5.1.4) Call the original function oldGetShaderProgram and return, completing the rewriting of the function getShaderProgram;

[0033] (5.2) Rewrite the Cesium engine function endUpdate

[0034] (5.2.1) Define the initial value of the global variable

[0035] Whether to prune the variable m_xh_enabled = 0

[0036] The clipping range variable m_xh_flatten_extent = (0, 0, 0, 0)

[0037] Clipping matrix variables

[0038] The clipping texture variable m_xh_flatten_texture = null;

[0039] (5.2.2) Determine if the function oldEndUpdate exists. If it does not exist, assign the original function endUpdate to the function oldEndUpdate. If it exists, do nothing.

[0040] (5.2.3) Rewrite the function endUpdate, call the original function oldEndUpdate, obtain the system variable _uniformMaps collection, and determine whether the system variable _uniformMaps collection is empty. If it is not empty, iterate through each element in the system variable _uniformMaps collection and implement the corresponding clipping function xh_enabled, clipping range function xh_flatten_extent, clipping matrix function xh_flatten_mat, and clipping texture function xh_flatten_texture for each element. If the system variable _uniformMaps collection is empty, no processing is performed.

[0041] Specifically:

[0042] The implementation of the pruning function `xh_enabled`: returns whether the variable `m_xh_enabled` is pruned.

[0043] The implementation of the clipping extent function xh_flatten_extent: returns the clipping extent variable m_xh_flatten_extent.

[0044] The implementation of the clipping matrix function xh_flatten_mat: obtain the view matrix from the parameters of the function endUpdate rewritten in step (4.3.1.7), calculate the product of the view matrix and the clipping matrix variable m_xh_flatten_mat, calculate the inverse matrix of the product, and return the current inverse matrix;

[0045] The implementation of the clipping texture function xh_flatten_texture: It checks whether the clipping texture variable m_xh_flatten_texture is empty. If it is, it returns the system default texture; otherwise, it returns the clipping texture variable m_xh_flatten_texture.

[0046] (5.2.4) Set whether to prune the variable m_xh_enabled to 1, and complete the rewriting of the function endUpdate.

[0047] To further define, the specific operation of adding the custom shading source script createFS in (5.1.3) is as follows:

[0048] Get the function to enable clipping (xh_enabled), the function to set the clipping range (xh_flatten_extent), the function to set the clipping matrix (xh_flatten_mat), and the function to set the clipping texture (xh_flatten_texture);

[0049] If the clipping function xh_enabled is false, the system script xh_fsShader is called to render normally and the process ends; if the clipping function xh_enabled is true, a variable ep of type vec4 with a w value of 1 is constructed using any coordinate point of type vec3, and the product of the clipping matrix function xh_flatten_mat and the variable ep is calculated to obtain the coordinates vt of any point within the clipping region.

[0050] The coordinates vt are scaled down by a factor of vt.w. If the x-value of vt is greater than the z-value of the clipping matrix function xh_flatten_mat, or the x-value of vt is less than 0, or the y-value of vt is greater than the w-value of the clipping matrix function xh_flatten_mat, or the y-value of vt is less than 0, then the system script xh_fsShader is invoked for normal rendering, and the process ends. Otherwise, the uv coordinates of the point are obtained by dividing the xy-value of vt by the zw-value of the clipping range function xh_flatten_extent.

[0051] The color of the point is calculated using the clipping texture function xh_flatten_texture and the uv coordinates. If the r value of the color is less than 1, the system script xh_fsShader is called to render normally and the process ends; otherwise, the point is not rendered.

[0052] Further specifying, step (6) specifically includes:

[0053] (6.1) Set the high dynamic range rendering property of the scene to true;

[0054] (6.2) Calculate the minimum latitude and longitude cmin, maximum latitude and longitude cmax, width, height and minimum height of the merged polygon by displaying each polygon region in the clip set;

[0055] (6.3) Set the mapping width and height, calculate the ratio rate of the polygon's width to its height. If the ratio is greater than 1, adjust the mapping width; if it is less than or equal to 1, adjust the mapping height.

[0056] (6.4) Create a canvas and set its properties;

[0057] (6.5) will convert all polygon clipping regions in the display collection clip according to the set ratio and draw them on the 2D rendering context of the canvas to form clipping textures;

[0058] (6.6) Create a new texture object, assign values ​​to the texture object parameters context and source, and dynamically update the variable of the color source script createFS in the function getShaderProgram;

[0059] Assign the newly created texture object to the clipping texture variable m_xh_flatten_texture;

[0060] (6.7) Calculate the minimum latitude and longitude c1 of the bounding rectangle by merging the minimum latitude and longitude values ​​cmin and the minimum height minHeight of the polygons. Calculate the maximum latitude and longitude c2 of the bounding rectangle by merging the maximum latitude and longitude values ​​cmax and the minimum height minHeight of the polygons. Obtain the vertical coordinate system matrix of c1 perpendicular to the current ground surface, which is the clipping matrix variable m_xh_flatten_mat. Calculate the inverse matrix ienu of the north matrix. Calculate the product of the inverse matrix ienu of the north matrix and c2. Assign the x-value of the product of the inverse matrix ienu of the north matrix and c2 to the z-value of the clipping texture variable m_xh_flatten_extent, and assign the y-value of the product of the inverse matrix ienu of the north matrix and c2 to the w-value of the clipping range variable m_xh_flatten_extent, thus completing the polygon 3D terrain clipping.

[0061] Further specifying, the specific steps for setting the canvas properties in step (6.4) are as follows:

[0062] The width is the adjusted mapped width;

[0063] The height is the adjusted mapped height;

[0064] The position is in fixed function mode;

[0065] The style property has a right value of 0px, a top value of 75px, and a z-index of 10000;

[0066] Get the 2D rendering context of the canvas, set the fill color to red, the border color to red, and the line width to 1.

[0067] The present invention provides a three-dimensional terrain clipping device, comprising:

[0068] The polygon acquisition module is used to acquire polygon regions and add them to the clipping region interface.

[0069] The processing module is used to determine the display status of the polygon region acquired by the polygon acquisition module, and to determine whether each point of the polygon region is within the display area and whether the unloading condition is met; and to construct a minimum bounding rectangle using all the points of the polygon region, calculate the minimum boundary sphere through the rectangle, determine the geometric error value corresponding to the observation distance of the minimum boundary sphere from the virtual camera and the geometric error value of the minimum boundary sphere, and add the polygon region to the unloading set or the display set.

[0070] The display module is used to display the polygon region if the display attribute is set to display and every point of the polygon region is within the display area.

[0071] The hidden module is used to hide the polygonal region if the display attribute is set to hidden.

[0072] The mapping module is used to map the clipping regions in the display set onto the canvas to form clipping textures, dynamically update the variables in the color source script createFS in the getShaderProgram function, and complete the polygonal 3D terrain clipping.

[0073] A computer device according to the present invention includes:

[0074] Memory, used to store computer programs;

[0075] A processor is used to implement the steps of the texture mapping-based 3D terrain clipping method described above when executing the computer program.

[0076] The present invention provides a readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the texture mapping-based three-dimensional terrain clipping method described above.

[0077] This invention provides a three-dimensional terrain clipping method, apparatus, device, and readable storage medium based on texture mapping. By filtering and hiding polygonal regions, a minimum bounding box is constructed. The Cesium plugin is further developed to set clipping textures and dynamically update variables of the rewritten function to perform regional rendering of the clipping area. This enables the simultaneous clipping of any number of polygons. It is a method that can clip multiple arbitrary polygons simultaneously, and can quickly and accurately clip different terrains using arbitrary polygonal regions enclosed by construction site model data.

[0078] Compared with the prior art, the beneficial effects of the present invention are:

[0079] (1) The three-dimensional terrain clipping method based on the present invention solves the problem of clipping multiple regions at the same time and solves the problem that concave polygons cannot be clipped, which facilitates the intuitive and flexible display of underground model data in project engineering management.

[0080] (2) The texture mapping three-dimensional terrain clipping method based on the present invention is extended to parametric terrain clipping. The terrain clipping parameter elements are designed by parametric design, and the set of polygon points is clipped. It has fewer operations, faster speed and higher accuracy, and can quickly and accurately locate the model, which solves the application defects of the existing Cesium three-dimensional GIS platform. Attached Figure Description

[0081] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0082] Figure 1 This is a global cutting process diagram of the present invention;

[0083] Figure 2 A cropped image of a multi-regional arbitrary polygon terrain viewed from the sky at an angle.

[0084] Figure 3 This is a cropped image of a multi-regional arbitrary polygon terrain viewed from below at an angle.

[0085] Figure 4 A cropped image of a convex polygon terrain viewed from the sky at an angle.

[0086] Figure 5 A cropped image of a convex polygonal terrain viewed from below at an angle to the sky.

[0087] Figure 6 A cropped image of a concave polygonal terrain viewed from the sky at an angle.

[0088] Figure 7 A cropped image of a concave polygonal terrain viewed from below at an angle to the sky;

[0089] Figure 8 This is a schematic diagram of the three-dimensional terrain clipping device. Detailed Implementation

[0090] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.

[0091] This invention is based on the Cesium 3D GIS platform and is designed to address the shortcomings of the existing Cesium 3D GIS platform, such as the inability to clip multiple clipping regions simultaneously and the fact that clipping regions can only be set globally and only once. The technical solutions in the embodiments of this invention will be clearly and completely described below with reference to the accompanying drawings.

[0092] Example 1

[0093] Please see Figures 1-3 The embodiment provided by this invention: a 3D engine terrain clipping method based on texture mapping, showing the effect of clipping arbitrary polygon terrain in multiple regions, can be achieved through the following steps:

[0094] (1) Obtain the polygon region (polygon), add the polygon region (polygon) to the clipping region interface, determine the show property of the polygon region (polygon), if the polygon region (polygon) is hidden, add the clipping data to the hidden collection unclip; if the polygon region (polygon) is shown, proceed to the next step.

[0095] (2) Further determine whether each point of the polygon region is within the display area. If each point is not within the display area, the unloading condition is met, that is, if the visible distance of the polygon region exceeds the preset maximum error or each vertex of the polygon region is not within the display area, then add it to the unload collection unloadclip; if any one or more points are within the display area, then proceed to the next step.

[0096] (3) Construct a minimum enclosing rectangle using all the points of the polygon region, and calculate the minimum boundary sphere using this rectangle;

[0097] (4) Calculate and determine the geometric error value corresponding to the observation distance of the minimum boundary ball distance virtual camera and the geometric error value of the minimum boundary ball, and add the polygon region polygon to the unload collection unloadclip or the display collection clip;

[0098] (4.1) Calculate the geometric error value E1 of the observation distance of the minimum boundary sphere based on the distance D between the center of the minimum boundary sphere and the virtual camera;

[0099] E1 = D / E0,

[0100] Where E1 is the geometric error value of the minimum boundary sphere observation distance, and E0 is the screen space error value;

[0101] (4.2) Calculate the geometric error value of the minimum boundary sphere;

[0102]

[0103] Where E2 is the geometric error value of the minimum boundary sphere; V is the volume of the minimum boundary sphere; and d is the diameter of the boundary sphere.

[0104] (4.3) Determine the geometric error values ​​E1 and E2 of the minimum boundary ball observation distance. If E1 > E2, the unloading condition is met, and the polygon region is added to the unloaded set unloadclip. If E1 ≤ E2, the polygon region is added to the display set clip.

[0105] (5) Rewrite the Cesium engine functions getShaderProgram and endUpdate;

[0106] (5.1) Rewrite the Cesium engine function getShaderProgram

[0107] (5.1.1) Define a global variable setGlobeFS with an initial value of 0;

[0108] (5.1.2) Determine if the function oldGetShaderProgram of the Cesium engine exists. If it does not exist, assign the original function getShaderProgram in the Cesium engine to the function oldGetShaderProgram and rewrite the function getShaderProgram. If it exists, do nothing.

[0109] (5.1.3) Determine if the global variable setGlobeFS is 0. If it is, obtain the data source set of the fragment shader, modify the content with index 1 in the data source set to the script xh_fsShader, add the custom shader source script createFS after it, and adjust the global variable setGlobeFS to 1. If not, do not do anything.

[0110] To further explain, the specific steps for adding the custom shader source script `createFS` are as follows:

[0111] Get the function to enable clipping (xh_enabled), the function to set the clipping range (xh_flatten_extent), the function to set the clipping matrix (xh_flatten_mat), and the function to set the clipping texture (xh_flatten_texture);

[0112] If the clipping function xh_enabled is false, the system script xh_fsShader is called to render normally and the process ends; if the clipping function xh_enabled is true, a variable ep of type vec4 with a w value of 1 is constructed using any coordinate point of type vec3, and the product of the clipping matrix function xh_flatten_mat and the variable ep is calculated to obtain the coordinates vt of any point within the clipping region.

[0113] Shrink the coordinates vt by a factor of vt.w for further analysis:

[0114] If the x-value of coordinate vt is greater than the z-value of the clipping matrix function xh_flatten_mat, the system script xh_fsShader is called to render normally and the process ends.

[0115] Alternatively, if the x-value of coordinate vt is less than 0, the system script xh_fsShader will be invoked for normal rendering, and the process will end.

[0116] Alternatively, if the y-value of coordinate vt is greater than the w-value of the clipping matrix, the system script xh_fsShader will be invoked for normal rendering, and the process will end.

[0117] Alternatively, if the y-value of coordinate vt is less than 0, the system script xh_fsShader will be invoked for normal rendering, and the process will end.

[0118] Conversely, for any of the above cases, the uv coordinates of the point are obtained by dividing the xy value of the coordinate vt by the zw value of the clipping range function xh_flatten_extent.

[0119] The color of the point is calculated using the clipping texture function xh_flatten_texture and the uv coordinates. If the r value of color is less than 1, the system script xh_fsShader is called to render normally and the process ends; otherwise, the point is not rendered.

[0120] (5.1.4) Call the original function oldGetShaderProgram and return, completing the rewriting of the function getShaderProgram;

[0121] (5.2) Rewrite the Cesium engine function endUpdate

[0122] (5.2.1) Define the initial value of the global variable

[0123] Whether to prune the variable m_xh_enabled = 0

[0124] The clipping range variable m_xh_flatten_extent = (0, 0, 0, 0)

[0125] Clipping matrix variables

[0126] The clipping texture variable m_xh_flatten_texture = null;

[0127] (5.2.2) Determine if the function oldEndUpdate exists. If it does not exist, assign the original function endUpdate to the function oldEndUpdate. If it exists, do nothing.

[0128] (5.2.3) Rewrite the function endUpdate, call the original function oldEndUpdate, obtain the system variable _uniformMaps collection, and determine whether the system variable _uniformMaps collection is empty. If it is not empty, iterate through each element in the system variable _uniformMaps collection and implement the corresponding clipping function xh_enabled, clipping range function xh_flatten_extent, clipping matrix function xh_flatten_mat, and clipping texture function xh_flatten_texture for each element; if the system variable _uniformMaps collection is empty, no processing is performed.

[0129] Specifically:

[0130] The implementation of the `xh_enabled` function to determine whether to prune: returns `m_xh_enabled`.

[0131] The implementation of the clipping range function xh_flatten_extent: returns m_xh_flatten_extent

[0132] The implementation of the clipping matrix function xh_flatten_mat: obtain the view matrix from the parameters of the function endUpdate rewritten in step (4.3.1.7), calculate the product of the view matrix and the clipping matrix function m_xh_flatten_mat, calculate the inverse matrix of the product, and return the current inverse matrix;

[0133] The implementation of the clipping texture function xh_flatten_texture: It checks whether the clipping texture variable m_xh_flatten_texture is empty. If it is, it returns the system default texture; otherwise, it returns the clipping texture variable m_xh_flatten_texture.

[0134] (5.2.4) Set whether to prune the variable m_xh_enabled to 1, and complete the rewriting of the function endUpdate.

[0135] 6) Map the clipping region in the display collection clip to the canvas to form a clipping texture, dynamically update the variable of the color source script createFS in the function getShaderProgram, and complete the polygon 3D terrain clipping.

[0136] (6.1) Set the high dynamic range rendering property of the scene to true;

[0137] (6.2) Calculate the minimum latitude and longitude of the merged polygon, the maximum latitude and longitude of the polygon, the width of the polygon, the height of the merged polygon, and the minimum height of the polygon by displaying each polygon region in the clip set.

[0138] (6.3) Set the mapping width and height, calculate the ratio rate of the polygon's width to its height. If the ratio is greater than 1, adjust the mapping width (the specific calculation is to divide the set mapping width by the rate). If it is less than or equal to 1, adjust the mapping height (the specific calculation is to divide the set mapping height by the rate).

[0139] (6.4) Create a canvas, set the canvas properties, namely the width is the adjusted mapped width, the height is the adjusted mapped height, the position is in fixed function mode, the style properties are 0px for the right and 75px for the top, and z-index is 10000. Get the 2D rendering context of the canvas, set the fill color to red, the border color to red, and the line width to 1.

[0140] (6.5) will convert all polygon clipping regions in the display collection clip according to the set ratio and draw them on the 2D rendering context of the canvas to form clipping textures;

[0141] x = (lon - cmin.x) / ilon) * width

[0142] y=(1-(lat-cmin.y) / ilat)*height

[0143] Where Lon is the longitude of the polygon's vertices; ilon = cmax.x - cmin.x;

[0144] lat is the latitude of the polygon's vertices; ilat = cmax.y - cmin.y;

[0145] cmin.x is the x-axis coordinate of the minimum latitude and longitude of the polygon, and cmax.x is the x-axis coordinate of the maximum latitude and longitude of the polygon.

[0146] cmin.y is the y-axis coordinate of the minimum latitude and longitude of the polygon, and cmax.y is the y-axis coordinate of the maximum latitude and longitude of the polygon.

[0147] (6.6) Create a new texture object, assign values ​​to the texture object parameters context and source, and dynamically update the variable of the color source script createFS in the function getShaderProgram;

[0148] Context=viewer.scene.context

[0149] Source = canvas

[0150] Assign the newly created texture object to the clipping texture variable m_xh_flatten_texture;

[0151] (6.7) Calculate the minimum latitude and longitude c1 of the bounding rectangle using the minimum latitude and longitude values ​​cmin and the minimum height of the polygon minHeight. Calculate the maximum latitude and longitude c2 of the bounding rectangle using the maximum latitude and longitude values ​​cmax and the minimum height of the polygon minHeight. Obtain the vertical coordinate system matrix of c1 perpendicular to the current ground surface, denoted as m_xh_flatten_mat. Calculate the inverse matrix ienu of the north matrix. Calculate the product of the inverse matrix ienu and c2. Assign the x-value of the product of the inverse matrix ienu and c2 to the z-value of the clipping range variable m_xh_flatten_extent, and assign the y-value of the product to the w-value of the clipping range variable m_xh_flatten_extent to complete the polygon 3D terrain clipping.

[0152] Example 2

[0153] Please see Figure 4 , 5This invention provides a 3D engine terrain clipping method based on texture mapping, specifically for convex polygon terrain clipping effect examples. This embodiment is based on Embodiment 1, but differs from Embodiment 1 in that: in step (1), the convex polygon region is obtained, added to the clipping region interface, and the display attribute of the convex polygon region is determined. If the convex polygon region is hidden, the clipping data is added to the hidden set; if the convex polygon region is displayed, the next step is performed; all other operations are the same as in Embodiment 1.

[0154] Example 3

[0155] Please see Figure 6 , 7 This invention provides an embodiment of a 3D engine terrain clipping method based on texture mapping, specifically for clipping concave polygon terrain. This embodiment is based on Embodiment 1, but differs from Embodiment 1 in that:

[0156] In step (1), the concave polygon region is obtained and added to the clipping region interface. The display attribute of the concave polygon region is determined. If the concave polygon region is hidden, the clipping data is added to the hidden collection. If the concave polygon region is displayed, the next step is performed. All other operations are the same as in Example 1.

[0157] This invention employs the same clipping steps for concave and convex polygons, enabling the clipping of arbitrary polygons, including those within multiple clipping regions. It overcomes the limitations of the Cesium 3D GIS platform, such as its inability to simultaneously clip multiple regions and the limitation that clipping regions can only be set globally and only once. By filtering polygon regions through hiding and showing, constructing a minimum bounding box, and further developing the Cesium plugin to set clipping textures and dynamically update variables in the rewritten function, the invention performs regional rendering of the clipping region, thereby achieving the goal of simultaneously clipping any number of polygons.

[0158] The present invention also provides a three-dimensional terrain clipping device capable of implementing the above embodiments 1 to 3. The three-dimensional terrain clipping device described below corresponds to the above-described texture mapping-based three-dimensional terrain clipping method.

[0159] Figure 8 As shown in the figure, the three-dimensional terrain clipping device of the present invention includes:

[0160] The polygon acquisition module is used to acquire polygon regions and add the polygon regions to the clipping region interface;

[0161] The processing module is used to determine the display status of the polygon region (polygon) acquired by the polygon acquisition module, and to determine whether each point of the polygon region (polygon) is within the display area and whether the unloading condition is met; and to construct a minimum bounding rectangle using all the points of the polygon region (polygon), calculate the minimum boundary sphere using this rectangle, determine the geometric error value corresponding to the observation distance of the minimum boundary sphere from the virtual camera and the geometric error value of the minimum boundary sphere, and add the polygon region (polygon) to the unloading set unloadclip or the display set clip;

[0162] The display module is used to display the polygon region if the display property is set to the display state and every point of the polygon region is within the display area.

[0163] The hidden module is used to hide the polygon region when the show attribute is set to hidden.

[0164] The mapping module is used to map the clipping region in the display collection clip to the canvas to form a clipping texture, dynamically update the variables of the color source script createFS in the function getShaderProgram, and complete the polygon 3D terrain clipping.

[0165] It should be noted that the apparatus provided in this embodiment of the invention can implement all the method steps implemented in the above method embodiment and can achieve the same technical effect. Therefore, the parts and beneficial effects that are the same as those in the method embodiment will not be described in detail here.

[0166] The present invention also provides a computer device comprising:

[0167] Memory, used to store computer programs;

[0168] A processor is used to implement the steps of the texture mapping-based 3D terrain clipping method described above when executing the computer program.

[0169] Furthermore, the logical instructions in the aforementioned memory can be implemented as software functional units and sold or used as independent products, and can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, is essentially embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0170] Furthermore, the present invention also provides a readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the texture mapping-based three-dimensional terrain clipping method described above.

[0171] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.

Claims

1. A three-dimensional terrain clipping method based on texture mapping, characterized in that, Includes the following steps: (1) Obtain the polygon region, add the polygon region to the clipping region interface, determine the display attribute of the polygon region, and if the polygon region is hidden, add the clipping data to the hidden collection. If the polygonal region is displayed, proceed to the next step; (2) Further determine whether each point of the polygon region is within the display area. If each point is not within the display area, the unloading condition is met, and the polygon region is added to the unloading set. If any one or more points are within the display area, proceed to the next step; (3) Construct a minimum enclosing rectangle using all points of the polygonal region, and calculate the minimum boundary sphere using this rectangle; (4) Calculate and determine the geometric error value of the minimum boundary sphere observation distance and the geometric error value of the minimum boundary sphere, and add the polygon region to the unload set or the display set; (5) Rewrite the Cesium engine functions getShaderProgram and endUpdate; specifically: (5.1) Rewrite the Cesium engine function getShaderProgram; (5.1.1) Define a global variable setGlobeFS with an initial value of 0; (5.1.2) Determine if the function oldGetShaderProgram of the Cesium engine exists. If it does not exist, assign the original function getShaderProgram in the Cesium engine to the function oldGetShaderProgram and rewrite the function getShaderProgram. If it exists, do nothing. (5.1.3) Determine if the value of the global variable setGlobeFS is 0. If it is, obtain the data source set of the fragment shader, modify the content with index 1 in the data source set to the system script xh_fsShader, add the custom shader source script createFS after it, and adjust the value of the global variable setGlobeFS to 1; if not, do not do anything. (5.1.4) Call the original function oldGetShaderProgram and return, completing the rewriting of the function getShaderProgram; (5.2) Rewrite the Cesium engine function endUpdate; (5.2.1) Define the initial values ​​for global variables; Whether to prune the variable m_xh_enabled=0 The clipping range variable m_xh_flatten_extent = (0, 0, 0, 0) Clipping matrix variable m_xh_flatten_mat= , The clipping texture variable m_xh_flatten_texture is set to null. (5.2.2) Determine if the function oldEndUpdate exists. If it does not exist, assign the original function endUpdate to the function oldEndUpdate. If it exists, do nothing. (5.2.3) Rewrite the function endUpdate, call the original function oldEndUpdate, get the system variable _uniformMaps collection, and check whether the system variable _uniformMaps collection is empty. If it is not empty, iterate through each element in the system variable _uniformMaps collection and implement the corresponding clipping function xh_enabled, clipping range function xh_flatten_extent, clipping matrix function xh_flatten_mat, and clipping texture function xh_flatten_texture for each element. If the system variable _uniformMaps collection is empty, no processing is performed. (5.2.4) Set whether to prune the variable m_xh_enabled to 1, and complete the rewriting of the function endUpdate; (6) The clipping region in the display set is mapped to the canvas to form a clipping texture. The variable of the color source script createFS in the function getShaderProgram is dynamically updated to complete the polygon 3D terrain clipping.

2. The three-dimensional terrain clipping method based on texture mapping according to claim 1, characterized in that, The unloading condition in step (2) is: the visible distance of the polygonal region exceeds the preset maximum error or each vertex of the polygonal region is not in the display area.

3. The three-dimensional terrain clipping method based on texture mapping according to claim 1, characterized in that, Step (4) specifically involves: (4.1) Based on the distance between the center of the smallest boundary sphere and the virtual camera D Calculate the geometric error value of the minimum boundary sphere observation distance. E 1; E 1= D / E 0, Where E1 is the geometric error value of the minimum boundary sphere observation distance. E 0 represents the screen space error value; (4.2) Calculate the geometric error value of the minimum boundary sphere; in, E 2 represents the geometric error value of the minimum boundary sphere; V Let be the volume of the smallest boundary sphere; d Let be the diameter of the boundary sphere; (4.3) Determine the geometric error value of the observation distance of the minimum boundary sphere E 1 and the geometric error value of the minimum boundary sphere E 2. Size, if E 1> E 2. If the unloading condition is met, the polygonal region is added to the unloading set; if E 1≤ E 2. Then add the polygonal region to the display set.

4. The three-dimensional terrain clipping method based on texture mapping according to claim 1, characterized in that, In step (5.2.3): The implementation of the pruning function `xh_enabled`: returns whether the variable `m_xh_enabled` is pruned. The implementation of the clipping extent function xh_flatten_extent: returns the clipping extent variable m_xh_flatten_extent. The implementation of the clipping matrix function xh_flatten_mat: obtain the view matrix from the parameters of the function endUpdate rewritten in step (4.3.1.7), calculate the product of the view matrix and the clipping matrix variable m_xh_flatten_mat, calculate the inverse matrix of the product, and return the current inverse matrix; The implementation of the clipping texture function xh_flatten_texture: It checks whether the clipping texture variable m_xh_flatten_texture is empty. If it is, it returns the system default texture; otherwise, it returns the clipping texture variable m_xh_flatten_texture.

5. The three-dimensional terrain clipping method based on texture mapping according to claim 4, characterized in that, The specific operation of adding the custom shading source script createFS in (5.1.3) is as follows: Get the function to enable clipping (xh_enabled), the function to set the clipping range (xh_flatten_extent), the function to set the clipping matrix (xh_flatten_mat), and the function to set the clipping texture (xh_flatten_texture); If the clipping function xh_enabled is false, the system script xh_fsShader is called to render normally and the process ends; if the clipping function xh_enabled is true, a variable ep of type vec4 with a w value of 1 is constructed using any coordinate point of type vec3, and the product of the clipping matrix function xh_flatten_mat and the variable ep is calculated to obtain the coordinates vt of any point within the clipping region. The coordinates vt are scaled down by a factor of vt.w. If the x-value of vt is greater than the z-value of the clipping matrix function xh_flatten_mat, or the x-value of vt is less than 0, or the y-value of vt is greater than the w-value of the clipping matrix function xh_flatten_mat, or the y-value of vt is less than 0, then the system script xh_fsShader is invoked for normal rendering, and the process ends. Otherwise, the uv coordinates of the point are obtained by dividing the xy-value of vt by the zw-value of the clipping range function xh_flatten_extent. The color of the point is calculated using the clipping texture function xh_flatten_texture and the uv coordinates. If the r value of the color is less than 1, the system script xh_fsShader is called to render normally and the process ends; otherwise, the point is not rendered.

6. The three-dimensional terrain clipping method based on texture mapping according to claim 1, characterized in that, The specific steps (6) are as follows: (6.1) Set the high dynamic range rendering property of the scene to true; (6.2) Calculate the minimum latitude and longitude cmin, maximum latitude and longitude cmax, width, height and minimum height minHeight of the merged polygon by displaying each polygon region in the clip set; (6.3) Set the mapping width and height, calculate the ratio rate of the polygon's width to its height. If the ratio is greater than 1, adjust the mapping width; if it is less than or equal to 1, adjust the mapping height. (6.4) Create a canvas and set its properties; (6.5) All polygon clipping regions in the display collection clip will be converted according to the set ratio and drawn on the 2D rendering context of the canvas to form clipping textures; (6.6) Create a new texture object, assign values ​​to the texture object parameters context and source, and dynamically update the variable of the color source script createFS in the function getShaderProgram; Assign the newly created texture object to the clipping texture variable m_xh_flatten_texture; (6.7) Calculate the minimum latitude and longitude c1 of the bounding rectangle by merging the minimum latitude and longitude values ​​cmin and the minimum height minHeight of the polygons. Calculate the maximum latitude and longitude c2 of the bounding rectangle by merging the maximum latitude and longitude values ​​cmax and the minimum height minHeight of the polygons. Obtain the vertical coordinate system matrix of c1 that is perpendicular to the current ground surface, which is the clipping matrix variable m_xh_flatten_mat. Calculate the inverse matrix ienu of the north matrix. Calculate the product of the inverse matrix ienu of the north matrix and c2. Assign the x value of the product of the inverse matrix ienu of the north matrix and c2 to the z value of the clipping texture variable m_xh_flatten_extent. Assign the y value of the product of the inverse matrix ienu of the north matrix and c2 to the w value of the clipping range variable m_xh_flatten_extent to complete the polygon 3D terrain clipping.

7. The three-dimensional terrain clipping method based on texture mapping according to claim 6, characterized in that, The specific steps for setting the canvas properties in step (6.4) are as follows: The width is the adjusted mapped width; The height is the adjusted mapped height; The position is in fixed function mode; The style property has a right value of 0 pixels, a top value of 75 pixels, and a z-index of 10000. Get the 2D rendering context of the canvas, set the fill color to red, the border color to red, and the line width to 1.

8. A three-dimensional terrain clipping device, characterized in that, The method for 3D terrain clipping based on texture mapping as described in claim 1 includes: The polygon acquisition module is used to acquire polygon regions and add them to the clipping region interface. The processing module is used to determine the display status of the polygon region acquired by the polygon acquisition module, and to determine whether each point of the polygon region is within the display area and whether the unloading condition is met; and to construct a minimum bounding rectangle using all the points of the polygon region, calculate the minimum boundary sphere through the rectangle, determine the geometric error value corresponding to the observation distance of the minimum boundary sphere from the virtual camera and the geometric error value of the minimum boundary sphere, and add the polygon region to the unloading set or the display set. The display module is used to display the polygon region if the display attribute is set to display and every point of the polygon region is within the display area. The hidden module is used to hide the polygonal region if the display attribute is set to hidden. The mapping module is used to map the clipping regions in the display set onto the canvas to form clipping textures, dynamically update the variables in the color source script createFS in the getShaderProgram function, and complete the polygonal 3D terrain clipping.

9. A computer device, characterized in that, include: Memory, used to store computer programs; A processor, configured to implement the steps of the texture mapping-based three-dimensional terrain clipping method as described in any one of claims 1 to 7 when executing the computer program.

10. A readable storage medium, characterized in that, The readable storage medium stores a computer program that, when executed by a processor, implements the steps of the texture mapping-based three-dimensional terrain clipping method as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Real-time terrain modification method based on height map elevation

    CN111260780A

  • Three-dimensional terrain cutting method, device and equipment and readable storage medium

    CN115131513A