A Visualization Method for Processed Surface Quality Based on GPU and Mesh Search Algorithm

By combining GPU and mesh search algorithms with the Phong lighting model, high-precision visualization of machined surface quality is achieved, overcoming the shortcomings of existing methods in terms of efficiency, accuracy, and adaptability. It is suitable for real-time visualization analysis of complex parts and cutting tools.

CN121544778BActive Publication Date: 2026-05-05SHANGHAI JIAOTONG UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SHANGHAI JIAOTONG UNIV
Filing Date
2026-01-21
Publication Date
2026-05-05

AI Technical Summary

Technical Problem

Existing methods for evaluating the quality of machined surfaces are inadequate in terms of efficiency, accuracy, and adaptability. They are unable to achieve highly realistic and interactive micro-morphological rendering and cannot effectively assess complex textures and micro-structural features.

Method used

A GPU-based and mesh search algorithm is adopted to achieve efficient rendering and lighting calculation of point cloud data through 3D mesh partitioning, 3×3×3 local neighborhood search and GPU parallel computing, and surface quality visualization is achieved by combining the Phong lighting model.

Benefits of technology

It achieves high-precision real-time reconstruction of complex textures and microstructure features, supports efficient visualization of industrial parts, and is applicable to milled parts and tools of arbitrary geometry, improving the efficiency and accuracy of surface quality inspection and process optimization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121544778B_ABST
    Figure CN121544778B_ABST
Patent Text Reader

Abstract

This invention discloses a method for visualizing the surface quality of machined parts based on GPU and mesh search algorithms, belonging to the field of machining technology. The method includes acquiring tool point cloud data and discretizing it to construct a three-dimensional mesh structure surrounding the point cloud; linearizing the three-dimensional mesh data into a one-dimensional array and packaging it; creating four types of structured GPU computing buffers to achieve batch data transmission; utilizing GPU shader programs to achieve parallel data access and fast local neighborhood queries; completing high-precision real-time reconstruction of fragment surface normal vectors through neighborhood search and signed projection distance calculation; and outputting realistic rendering results based on an optimized Phong lighting model. This invention leverages the advantages of GPU parallel computing to accurately reproduce complex textures, microstructures, and special curved surfaces, making it suitable for surface quality inspection, wear assessment, and process optimization of milled parts and tools.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of machining technology, and in particular to a method for visualizing the quality of machined surfaces based on GPU and mesh search algorithms. Background Technology

[0002] In precision machining processes such as milling and grinding, the surface quality directly affects the service performance and lifespan of parts. Therefore, accurate assessment and visualization of surface morphology are of great significance. This is especially true for parts with complex profiles and high-quality surface requirements, such as aero-engine blades and precision molds. Not only are surface integrity standards stringent, but machining deviations can lead to the scrapping of the entire part, resulting in significant economic losses. Therefore, effective prediction and visualization analysis of surface quality during the machining process planning stage plays a crucial role in optimizing process parameters and controlling surface condition.

[0003] Currently, mainstream methods for evaluating the quality of machined surfaces have two limitations: First, traditional evaluation systems based on two-dimensional contours or statistical parameters are difficult to fully characterize the three-dimensional surface morphology with complex textures, anisotropy, and microstructure features, and lack an intuitive reflection of the real morphology; Second, existing visualization methods mostly rely on discrete point clouds or simplified geometric models, which cannot achieve highly realistic and interactive micromorphological rendering, thus limiting their in-depth application in process optimization and defect detection. Summary of the Invention

[0004] The purpose of this invention is to provide a method for visualizing the surface quality of machined parts based on GPU and mesh search algorithms. This method enables high-precision three-dimensional morphology rendering and visual evaluation of the surface of milled parts with arbitrary geometric shapes, providing a general solution for achieving realistic reproduction and in-depth analysis of the surface quality of machined parts.

[0005] To achieve the above objectives, this invention provides a method for visualizing the quality of machined surfaces based on GPU and mesh search algorithms, comprising the following steps:

[0006] S1. Acquire tool point cloud data, perform file reading and discretization processing, divide the point cloud space into a uniform three-dimensional mesh structure, and assign each point and its normal vector to the corresponding mesh cell.

[0007] S2. Perform 3D to 1D linearization mapping and data packaging on the point cloud data;

[0008] S3. Create a GPU computing buffer and transfer the data packaged on the CPU to the GPU memory in batches.

[0009] S4. Parallel data access and fast querying are achieved through GPU shader programs;

[0010] S5. Construct a mesh-accelerated nearest neighbor search algorithm for high-precision real-time reconstruction of point cloud surface normals within the fragment shader, and reconstruct accurate surface normals for each rendered fragment in parallel within the GPU shader program.

[0011] S6. Optimize the Phong lighting model for real-time coloring of point cloud surfaces. The final surface color output is synthesized by the linear superposition of three physical components: ambient light, diffuse light, and specular light.

[0012] Preferably, S1 specifically includes the following steps:

[0013] S11. Extract the coordinates of the tool point cloud data, including the three-dimensional spatial coordinates of each point and its corresponding surface normal vector;

[0014] S12. Traverse all data points, calculate the axial boundaries of the point cloud in three-dimensional space, determine its minimum boundary coordinates and maximum boundary coordinates, and then define a cube bounding box that can completely enclose all point clouds.

[0015] S13. Based on the user-preset mesh granularity parameters, the cube bounding box is uniformly divided into a series of regular 3D mesh units in 3D space. The physical size of each mesh unit is obtained by dividing the total size of the cube bounding box by the number of meshes in each direction. The formula for calculating the physical size of the mesh unit in the X direction is:

[0016] BoxSizeX = (Xmax) Xmin) / GridSizeX (1);

[0017] Where BoxSizeX represents the length of a single grid cell in the X direction; Xmax and Xmin represent the maximum and minimum coordinate values ​​of the cube's bounding box in the X direction; and GridSizeX represents the number of grid cells in the X direction.

[0018] S14. Calculate the dimensions in each direction according to formula (1), and set the spatial origin of the grid system as the minimum boundary coordinate;

[0019] S15. After the partitioning is completed, the system constructs a three-dimensional mesh container PointsBox to store the coordinates of points falling into each mesh cell, and at the same time constructs a parallel three-dimensional normal vector container NormalsBox to store the corresponding normal vectors.

[0020] Preferably, in S2, to adapt to the linear memory model of the GPU, the three-dimensional mesh structure is converted into a compact one-dimensional array format, specifically including the following steps:

[0021] S21. Convert each 3D mesh cell into a continuous 1D index GridIndex. The conversion formula is as follows:

[0022] (2);

[0023] Wherein, GridIndex represents the number corresponding to the conversion of a 3D mesh into a 1D mesh, x, y, z represent the mesh numbers in the three dimensions, and GridSizeX, GridSizeY, GridSizeZ represent the number of meshes in the x, y, and z directions, respectively.

[0024] S22. Traverse all grid cells one by one, and store all the point coordinate data stored in each cell into a one-dimensional point coordinate array FlatPointArray, and at the same time store all the corresponding normal vector data into a one-dimensional normal vector array FlatNormalArray.

[0025] S23. Simultaneously construct a key point index buffer PointIndexBuffer, which is a one-dimensional array with a length equal to the total number of grids. The value stored at each position GridIndex represents the starting position of the point data contained in the corresponding grid cell in the one-dimensional point coordinate array. This structure provides an important mapping relationship for the GPU to quickly locate point data in any grid.

[0026] Preferably, in S3, the GPU compute buffer includes four structured compute buffers:

[0027] PointBuffer: This buffer is bound to a packed one-dimensional point coordinate array and is used to store the three-dimensional spatial position information of all points;

[0028] Normal Buffer: This buffer is bound to a packed one-dimensional normal vector array and is used to store the three-dimensional normal vector information corresponding to all points;

[0029] GridInfoBuffer: This buffer stores a structure that defines the global parameters of the grid system, including the grid origin GridOrigin, the number of grids in each dimension, the physical size of the grid cells BoxSize, and the total number of point clouds TotalPoints;

[0030] PointIndexBuffer: This buffer stores an array of point index mapping relationships, enabling fast location of point cloud data from grid index;

[0031] Four structured computation buffers use the ComputeBuffer interface provided by the Unity engine to transfer pre-packaged data from the CPU to the GPU memory in a batch at once; this avoids the huge performance overhead and communication latency caused by point-by-point transmission in traditional methods, and improves the transmission efficiency of large-scale point cloud data.

[0032] Preferably, in S4, the specific process is as follows: In the GPU shader program, the four structured computation buffers in S3 are accessed in parallel and efficiently through the StructuredBuffer interface; when a point in world space needs to be rendered, the shader uses the mesh index calculation which is the opposite of formula (2) to quickly determine the mesh cell where the point is located; with the starting position recorded in the point index buffer, the shader immediately locates the point cloud data of the mesh cell in the one-dimensional array, and drastically narrows the search range from the global point cloud to the local neighborhood.

[0033] Preferably, step S5 specifically includes the following steps:

[0034] S51. Determine the world space location of the fragment and its corresponding mesh cell: When the fragment shader is executed, each fragment carries its three-dimensional coordinate information in world space. The GetGridCell function is called to convert the world coordinates to the mesh coordinate system. Specifically, the local coordinates are obtained by subtracting the mesh origin coordinates GridOrigin from the fragment world coordinates. Then, each component of the local coordinates is divided by the physical size BoxSize of the mesh cell, and a floor operation is performed to obtain the index coordinates of the three-dimensional mesh cell to which the fragment belongs. This step is the key to discretizing the continuous spatial query into an accurate mesh index.

[0035] S52. Perform a local search based on a 3×3×3 neighborhood: Use a 3×3×3 cube neighborhood centered on the current grid cell as the search range, limiting the search range from the entire point cloud dataset to a maximum of 27 adjacent grid cells, reducing computational complexity; The shader program uses a three-level nested loop structure to traverse the current cell and all its adjacent cells offset by ±1 units in each of the X, Y, and Z directions, generating a total of 27 candidate grid cell coordinates;

[0036] S53. Quickly locate point cloud data and calculate projection distance within candidate grid cells: For each candidate grid cell, call the GetPointBoxIndex function to convert its three-dimensional cell coordinates into the corresponding one-dimensional index according to formula (2); query the point index buffer pointIndexBuffer to obtain the start and end indices of the point data stored in the cell in the point coordinate buffer PointBuffer, accurately locate and traverse all stored points in the cell;

[0037] Signed projection distance is used as the criterion for measuring the proximity of fragments to the point cloud surface. The specific calculation method is as follows: starting from the current world space position of the fragment, projection is performed along the opposite direction of the current normal vector towards the local surface where the candidate point is located. The formula for calculating the distance value dist is:

[0038] dist=dot((fragment position) (Candidate point position, current normal vector) PointRadius (3);

[0039] PointRadius is a preset point radius parameter used to correct surface reconstruction deviations caused by the sparsity of the point cloud data itself; this distance value is a signed value, which can effectively distinguish whether the fragment is located on the front or back of the point.

[0040] S54. Select the best neighboring point and assign its normal vector: Traverse all candidate points within all 27 candidate mesh cells, continuously track and record the minimum projection distance value minDist and its corresponding candidate point index; when the entire local search is completed, retrieve the normal vector corresponding to the candidate point with the minimum projection distance from the normal vector buffer NormalBuffer, and assign it as the final surface normal vector finalNormal of the current fragment; this mechanism ensures that each fragment can obtain accurate orientation information from the nearest and most relevant surface point.

[0041] Preferably, step S6 specifically includes the following steps:

[0042] S61. Perform dynamic consistency correction of normal vector direction: Check and correct the direction consistency of the reconstructed surface normal vectors to ensure the correctness of the lighting calculation. The specific method is to construct a branchless correction algorithm based on symbolic function simulation. Its core operation is defined by the formula:

[0043] normal =(step(0.0,dot(normal,eyeDir)) 2.0 1.0) (4);

[0044] The built-in `step` function checks if the dot product of the normal vector and the viewing direction `eyeDir` is greater than or equal to 0. If the dot product is non-negative, `step` returns 1, and then... The linear transformation from 2.0 to 1.0 has a multiplier factor of +1, and the normal vector direction remains unchanged. If the dot product is negative, step returns to 0, the multiplier factor becomes -1, and the normal vector direction is automatically reversed. This process avoids flow control instructions, ensuring the execution efficiency of the GPU shader unit.

[0045] S62. Calculate the three components of the Phong lighting model and perform linear superposition. The three components include the ambient light component, the diffuse reflection component, and the specular reflection component.

[0046] S63. Perform legality verification and constraint on the color output range: A component limitation algorithm is used to process the final color. The components of the three RGB color channels after synthesis are compared with the upper limit value of 1.0, and the minimum value is taken. The expression is:

[0047] finalColor=float3(min(result.r,1.0),min(result.g,1.0),min(result.b,1.0)) (5);

[0048] This step ensures that the color values ​​output to the screen frame buffer are always within the legal and correctly interpretable range of [0,1], guaranteeing the color accuracy and visual stability of the final rendered image.

[0049] Preferably, in S62, the calculation method for the three components is as follows:

[0050] Ambient light component calculation: Used to simulate global indirect lighting in a scene, providing a base brightness for surfaces and preventing completely backlit areas from falling into pure black; the calculation process is as follows: a fixed coefficient, set to 0.2, is directly multiplied by the base color of the object's surface, i.e., ambient = 0.2. col; This component is independent of the direction of light and the angle of view;

[0051] Diffuse reflection component calculation: Following Lambert's cosine law, it is used to simulate the uniform scattering phenomenon of light on a rough surface; the intensity depends on the cosine of the angle between the surface normal vector and the incident light direction; to simplify the calculation, the light direction lightDir adopts -rayDirection, which is opposite to the viewing direction; during the calculation, first calculate the dot product ndotl of the normal vector and the light direction, and then use the max function to clamp it within the non-negative range of [0,1]. Finally, multiply it by the base color to obtain the diffuse reflection light, i.e., diffuse=max(dot(normal,lightDir),0.0). col;

[0052] Specular reflection component calculation: used to simulate specular flares on smooth surfaces, enhancing the texture of objects; the calculation process is as follows: based on the incident light direction and the surface normal vector, the ideal reflection direction r of the light is calculated using the reflect function; the cosine value rdotv of the angle between this reflection direction and the viewing direction v is calculated, and the max function is used to ensure that it is non-negative; finally, this cosine value is raised to a higher power, called the gloss index, which is set to 32, and then multiplied by a specular intensity parameter set to 0.15, and the specular color to obtain the specular reflected light, i.e., specular=pow(max(dot(r,v),0.0),32.0). float3(1.0) 0.15; the higher the gloss index, the more concentrated and sharp the highlight areas.

[0053] The three components are linearly superimposed to obtain the initial composite color:

[0054] result=ambient+diffuse+specular.

[0055] Therefore, this invention adopts the above-mentioned visualization method for machining surface quality based on GPU and mesh search algorithm. Through three-dimensional mesh division, 3×3×3 local neighborhood search and GPU parallel computing architecture, the complexity of point cloud search is optimized from the traditional O(N) to almost O(1). At the same time, a large number of pixels' normal vector reconstruction and lighting calculation are performed synchronously in the fragment shader, giving full play to the advantages of GPU parallelism. The mesh-accelerated nearest neighbor search algorithm realizes high-precision real-time reconstruction of point cloud surface normal vectors, which can accurately restore the three-dimensional micro-geometric features of machining surfaces with complex textures, microstructures, anisotropic features or sharp edges, grooves, free-form surfaces, etc. Combined with the optimized Phong lighting model, it realistically presents the gloss and material texture of industrial parts. This method is applicable to milling parts of arbitrary geometry and milling tools with cutting edge shapes. Through the GPU computing buffer, batch point cloud data transmission from CPU to GPU is realized, avoiding the delay and overhead of point-by-point transmission. It supports real-time interactive analysis and provides an intuitive and efficient general visualization tool for surface quality inspection, tool wear assessment and process optimization in the field of precision machining, solving the shortcomings of traditional methods in terms of efficiency, accuracy, memory usage and adaptability.

[0056] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description

[0057] Figure 1 This is a technical flowchart of an embodiment of the present invention;

[0058] Figure 2 This is a flowchart of point cloud information transmission according to an embodiment of the present invention;

[0059] Figure 3 This is a flowchart of point cloud surface normal vector reconstruction according to an embodiment of the present invention;

[0060] Figure 4 This is a flowchart of the real-time rendering process of the lighting model according to an embodiment of the present invention. Detailed Implementation

[0061] The technical solution of the present invention will be further described below with reference to the accompanying drawings and embodiments.

[0062] Unless otherwise defined, the technical or scientific terms used in this invention shall have the ordinary meaning understood by one of ordinary skill in the art to which this invention pertains. The terms "first," "second," and similar terms used in this invention do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Terms such as "comprising" or "including" mean that the element or object preceding the word encompasses the elements or objects listed following the word and their equivalents, without excluding other elements or objects. Terms such as "connected" or "linked" are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. Terms such as "upper," "lower," "left," and "right" are used only to indicate relative positional relationships; when the absolute position of the described object changes, the relative positional relationship may also change accordingly.

[0063] Example 1

[0064] This invention provides a method for visualizing the surface quality of machined surfaces based on GPU and mesh search algorithms. The technical process is as follows: Figure 1 As shown, it includes the following steps:

[0065] S1. Acquire tool point cloud data, perform file reading and discretization processing, divide the point cloud space into a uniform three-dimensional mesh structure, and assign each point and its normal vector to the corresponding mesh cell; specifically including the following steps:

[0066] S11. Extract the coordinates of the tool point cloud data, including the three-dimensional spatial coordinates (X,Y,Z) of each point and its corresponding surface normal vector (NX,NY,NZ).

[0067] S12. Traverse all data points, calculate the axial boundaries of the point cloud in three-dimensional space, determine its minimum boundary coordinates (Xmin, Ymin, Zmin) and maximum boundary coordinates (Xmax, Ymax, Zmax), and then define a cube bounding box that can completely enclose all point clouds.

[0068] S13. Based on the user-preset mesh granularity parameters (GridSizeX, GridSizeY, GridSizeZ), the bounding box of the cube is uniformly divided into a series of regular three-dimensional mesh units in three-dimensional space. The physical size (BoxSizeX, BoxSizeY, BoxSizeZ) of each mesh unit is obtained by dividing the total size of the bounding box of the cube by the number of meshes in each direction. The formula for calculating the physical size of the mesh unit in the X direction is:

[0069] BoxSizeX = (Xmax) Xmin) / GridSizeX (1);

[0070] Where BoxSizeX represents the length of a single grid cell in the X direction; Xmax and Xmin represent the maximum and minimum coordinate values ​​of the cube's bounding box in the X direction; and GridSizeX represents the number of grid cells in the X direction.

[0071] S14. Calculate the dimensions in each direction according to formula (1), and set the spatial origin of the grid system, GridOrigin, as the minimum boundary coordinates (Xmin, Ymin, Zmin).

[0072] S15. After the partitioning is completed, the system constructs a three-dimensional mesh container PointsBox to store the coordinates of points falling into each mesh cell, and at the same time constructs a parallel three-dimensional normal vector container NormalsBox to store the corresponding normal vectors.

[0073] S2. Perform 3D-to-1D linearization mapping and data packaging on the point cloud data; to adapt to the linear memory model of the GPU, convert the 3D mesh structure into a compact 1D array format, specifically including the following steps:

[0074] S21. Convert each 3D mesh cell into a continuous 1D index GridIndex. The conversion formula is as follows:

[0075] (2);

[0076] Wherein, GridIndex represents the number corresponding to the conversion of a 3D mesh into a 1D mesh, x, y, z represent the mesh numbers in the three dimensions, and GridSizeX, GridSizeY, GridSizeZ represent the number of meshes in the x, y, and z directions, respectively.

[0077] S22. Traverse all grid cells one by one, and store all the point coordinate data stored in each cell into a one-dimensional point coordinate array FlatPointArray, and at the same time store all the corresponding normal vector data into a one-dimensional normal vector array FlatNormalArray.

[0078] S23. Simultaneously construct a key point index buffer PointIndexBuffer, which is a one-dimensional array with a length equal to the total number of grids. The value stored at each position GridIndex represents the starting position of the point data contained in the corresponding grid cell in the one-dimensional point coordinate array. This structure provides an important mapping relationship for the GPU to quickly locate point data in any grid.

[0079] S3. Create a GPU compute buffer to transfer the packaged data from the CPU to the GPU memory in batches; the GPU compute buffer includes four structured compute buffers: ComputeBuffer

[0080] PointBuffer: This buffer is bound to a packed one-dimensional point coordinate array and is used to store the three-dimensional spatial position information of all points;

[0081] Normal Buffer: This buffer is bound to a packed one-dimensional normal vector array and is used to store the three-dimensional normal vector information corresponding to all points;

[0082] GridInfoBuffer: This buffer stores a structure that defines the global parameters of the grid system, including the grid origin GridOrigin, the number of grids in each dimension (GridSizeX, GridSizeY, GridSizeZ), the physical size of the grid cells BoxSize, and the total number of points in the cloud TotalPoints.

[0083] PointIndexBuffer: This buffer stores an array of point index mapping relationships, enabling fast location of point cloud data from grid index;

[0084] Four structured computation buffers, through the ComputeBuffer interface provided by the Unity engine, transfer pre-packaged data from the CPU to the GPU memory in a single batch. This avoids the significant performance overhead and communication latency caused by point-by-point transmission in traditional methods, improving the transmission efficiency of large-scale point cloud data. The point cloud information transmission process is as follows: Figure 2 As shown.

[0085] The transmission method described in this embodiment optimizes the time complexity of point cloud search and access from O(N) of traditional methods to nearly O(1) through data preprocessing, regularized mesh partitioning, compact one-dimensional array packing, and batch GPU buffer transmission. This not only reduces computational overhead but also fully leverages the parallel computing power and high-speed memory bandwidth of GPUs, laying the foundation for real-time, high-quality rendering of large-scale, high-precision tool point cloud data. It is particularly suitable for the precise visualization analysis and industrial inspection needs of complex tool geometry.

[0086] S4. Parallel data access and fast query are achieved through the GPU shader program. The specific process is as follows: In the GPU shader program Shader, the four structured calculation buffers in S3 are accessed in parallel and efficiently through the StructuredBuffer interface. When a point in the world space needs to be rendered, the shader uses the grid index calculation which is the opposite of formula (2) to quickly determine the grid cell where the point is located. Based on the starting position recorded in the point index buffer, the shader immediately locates the point cloud data of the grid cell in the one-dimensional array, and drastically narrows the search range from the global point cloud to the local neighborhood.

[0087] S5. Construct a mesh-accelerated nearest neighbor search algorithm for high-precision real-time reconstruction of point cloud surface normals within the fragment shader. This algorithm reconstructs accurate surface normals for each rendered fragment in parallel within the GPU shader program. The point cloud surface normal reconstruction process is as follows: Figure 3 As shown, the specific steps include:

[0088] S51. Determine the world space location of the fragment and its corresponding mesh cell: When the fragment shader is executed, each fragment carries its three-dimensional coordinate information in world space. The GetGridCell function is called to convert the world coordinates to the mesh coordinate system. Specifically, the local coordinates are obtained by subtracting the mesh origin coordinates GridOrigin from the fragment world coordinates. Then, each component of the local coordinates is divided by the physical size BoxSize of the mesh cell, and a floor operation is performed to obtain the index coordinates of the three-dimensional mesh cell to which the fragment belongs. This step is the key to discretizing the continuous spatial query into an accurate mesh index.

[0089] S52. Perform a local search based on a 3×3×3 neighborhood: Use a 3×3×3 cube neighborhood centered on the current grid cell as the search range, limiting the search range from the entire point cloud dataset to a maximum of 27 adjacent grid cells, reducing computational complexity; The shader program uses a three-level nested loop structure to traverse the current cell and all its adjacent cells offset by ±1 units in each of the X, Y, and Z directions, generating a total of 27 candidate grid cell coordinates;

[0090] S53. Quickly locate point cloud data and calculate projection distance within candidate grid cells: For each candidate grid cell, call the GetPointBoxIndex function to convert its three-dimensional cell coordinates into the corresponding one-dimensional index according to formula (2); query the point index buffer pointIndexBuffer to obtain the start and end indices of the point data stored in the cell in the point coordinate buffer PointBuffer, accurately locate and traverse all stored points in the cell;

[0091] Signed projection distance is used as the criterion for measuring the proximity of fragments to the point cloud surface. The specific calculation method is as follows: starting from the current world space position of the fragment, projection is performed along the opposite direction of the current normal vector towards the local surface where the candidate point is located. The formula for calculating the distance value dist is:

[0092] dist=dot((fragment position) (Candidate point position, current normal vector) PointRadius (3);

[0093] PointRadius is a preset point radius parameter used to correct surface reconstruction deviations caused by the sparsity of the point cloud data itself; this distance value is a signed value, which can effectively distinguish whether the fragment is located on the front or back of the point.

[0094] S54. Select the best neighboring point and assign its normal vector: Traverse all candidate points within all 27 candidate mesh cells, continuously track and record the minimum projection distance value minDist and its corresponding candidate point index; when the entire local search is completed, retrieve the normal vector corresponding to the candidate point with the minimum projection distance from the normal vector buffer NormalBuffer, and assign it as the final surface normal vector finalNormal of the current fragment; this mechanism ensures that each fragment can obtain accurate orientation information from the nearest and most relevant surface point.

[0095] This reconstruction method combines spatial grid indexing with a local neighborhood search strategy, optimizing the time complexity of the traditional brute-force search algorithm from O(N) to a near-constant O(1) level. Executed in parallel within the GPU fragment shader, this method can simultaneously process normal vector reconstruction tasks involving millions of pixels, achieving extreme computational efficiency. By adjusting the mesh size, a flexible trade-off can be struck between the original density of the point cloud data and the visual smoothness of the final reconstructed surface, making it particularly suitable for real-time, high-quality rendering and visualization analysis of complex tool geometries, such as those with sharp edges, grooves, and freeform surfaces.

[0096] S6. Optimize the Phong lighting model for real-time point cloud surface shading. The final surface color output is synthesized through the linear superposition of three physical components: ambient light, diffuse light, and specular light. The workflow is as follows: Figure 4 As shown, the specific steps include:

[0097] S61. Perform dynamic consistency correction of normal vector direction: Check and correct the direction consistency of the reconstructed surface normal vectors to ensure the correctness of the lighting calculation. The specific method is to construct a branchless correction algorithm based on symbolic function simulation. Its core operation is defined by the formula:

[0098] (4);

[0099] The built-in `step` function checks if the dot product of the normal vector and the viewing direction `eyeDir` is greater than or equal to 0. If the dot product is non-negative, `step` returns 1, and then... The linear transformation from 2.0 to 1.0 has a multiplier factor of +1, and the normal vector direction remains unchanged. If the dot product is negative, step returns to 0, the multiplier factor becomes -1, and the normal vector direction is automatically reversed. This process avoids flow control instructions, ensuring the execution efficiency of the GPU shader unit.

[0100] S62. Calculate and linearly superimpose the three components of the Phong lighting model, including the ambient light component, diffuse reflection component, and specular reflection component. The calculation methods for the three components are as follows:

[0101] Ambient light component calculation: Used to simulate global indirect lighting in a scene, providing a base brightness for surfaces and preventing completely backlit areas from falling into pure black; the calculation process is as follows: a fixed coefficient, set to 0.2, is directly multiplied by the base color of the object's surface, i.e., ambient = 0.2. col; This component is independent of the direction of light and the angle of view;

[0102] Diffuse reflection component calculation: Following Lambert's cosine law, it is used to simulate the uniform scattering of light on a rough surface; the intensity depends on the cosine of the angle between the surface normal vector and the incident light direction; to simplify the calculation, the light direction `lightDir` is set to `-rayDirection`, which is opposite to the viewing direction. During calculation, the dot product of the normal vector and the light direction `ndotl` is first calculated, and then constrained to the non-negative range [0,1] using the `max` function. Finally, it is multiplied by the base color to obtain the diffuse reflection light, i.e., `diffuse=max(dot(normal,lightDir),0.0)`. col;

[0103] Specular reflection component calculation: used to simulate specular flares on smooth surfaces, enhancing the texture of objects; the calculation process is as follows: based on the incident light direction and the surface normal vector, the ideal reflection direction r of the light is calculated using the reflect function; the cosine value rdotv of the angle between this reflection direction and the viewing direction v is calculated, and the max function is used to ensure that it is non-negative; finally, this cosine value is raised to a higher power, called the gloss index, which is set to 32, and then multiplied by a specular intensity parameter set to 0.15, and the specular color to obtain the specular reflected light, i.e., specular=pow(max(dot(r,v),0.0),32.0). float3(1.0) 0.15; the higher the gloss index, the more concentrated and sharp the highlight areas.

[0104] The three components are linearly superimposed to obtain the initial composite color:

[0105] result=ambient+diffuse+specular.

[0106] S63. Perform legality verification and constraint on the color output range: A component limitation algorithm is used to process the final color. The components of the three RGB color channels after synthesis are compared with the upper limit value of 1.0, and the minimum value is taken. The expression is:

[0107] (5);

[0108] This step ensures that the color values ​​output to the screen frame buffer are always within the legal and correctly interpretable range of [0,1], guaranteeing the color accuracy and visual stability of the final rendered image.

[0109] This lighting rendering method achieves an excellent balance between visual realism and real-time performance through GPU-friendly modifications and parameter optimizations of the classic Phong model. Specifically, the branchless normal vector correction strategy significantly improves GPU parallel efficiency, while the carefully tuned lighting parameters work together to accurately reproduce the gloss characteristics and material texture of industrial parts such as metal cutting tools, meeting the stringent requirements of real-time, high-quality visualization analysis of complex tool geometries in industrial inspection.

[0110] Therefore, this invention adopts the above-mentioned visualization method for machining surface quality based on GPU and mesh search algorithm. Through three-dimensional mesh division, 3×3×3 local neighborhood search and GPU parallel computing architecture, the complexity of point cloud search is optimized from the traditional O(N) to almost O(1). At the same time, a large number of pixels' normal vector reconstruction and lighting calculation are performed synchronously in the fragment shader, giving full play to the advantages of GPU parallelism. The mesh-accelerated nearest neighbor search algorithm realizes high-precision real-time reconstruction of point cloud surface normal vectors, which can accurately restore the three-dimensional micro-geometric features of machining surfaces with complex textures, microstructures, anisotropic features or sharp edges, grooves, free-form surfaces, etc. Combined with the optimized Phong lighting model, it realistically presents the gloss and material texture of industrial parts. This method is applicable to milling parts of arbitrary geometry and milling tools with cutting edge shapes. Through the GPU computing buffer, batch point cloud data transmission from CPU to GPU is realized, avoiding the delay and overhead of point-by-point transmission. It supports real-time interactive analysis and provides an intuitive and efficient general visualization tool for surface quality inspection, tool wear assessment and process optimization in the field of precision machining, solving the shortcomings of traditional methods in terms of efficiency, accuracy, memory usage and adaptability.

[0111] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit them. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the technical solutions of the present invention, and these modifications or equivalent substitutions cannot cause the modified technical solutions to deviate from the spirit and scope of the technical solutions of the present invention.

Claims

1. A method for visualizing the quality of machined surfaces based on GPU and mesh search algorithms, characterized in that, Includes the following steps: S1. Acquire tool point cloud data, perform file reading and discretization processing, divide the point cloud space into a uniform three-dimensional mesh structure, and assign each point and its normal vector to the corresponding mesh cell. S2. Perform 3D to 1D linearization mapping and data packaging on the point cloud data; S3. Create a GPU computing buffer and transfer the data packaged on the CPU to the GPU memory in batches. S4. Parallel data access and fast querying are achieved through GPU shader programs; S5. Construct a mesh-accelerated nearest neighbor search algorithm for high-precision real-time reconstruction of point cloud surface normals within the fragment shader, and reconstruct accurate surface normals for each rendered fragment in parallel within the GPU shader program. S6. Optimize the Phong lighting model for real-time coloring of point cloud surfaces. The final surface color output is synthesized by the linear superposition of three physical components: ambient light, diffuse light, and specular light.

2. The method for visualizing the surface quality of a machined surface based on GPU and mesh search algorithm according to claim 1, characterized in that, S1 specifically includes the following steps: S11. Extract the coordinates of the tool point cloud data, including the three-dimensional spatial coordinates of each point and its corresponding surface normal vector; S12. Traverse all data points, calculate the axial boundaries of the point cloud in three-dimensional space, determine its minimum boundary coordinates and maximum boundary coordinates, and then define a cube bounding box that can completely enclose all point clouds. S13. Based on the user-preset mesh granularity parameters, the cube bounding box is uniformly divided into a series of regular 3D mesh units in 3D space. The physical size of each mesh unit is obtained by dividing the total size of the cube bounding box by the number of meshes in each direction. The formula for calculating the physical size of the mesh unit in the X direction is: BoxSizeX=(Xmax Xmin) / GridSizeX (1); Where BoxSizeX represents the length of a single grid cell in the X direction; Xmax and Xmin represent the maximum and minimum coordinate values ​​of the cube's bounding box in the X direction; and GridSizeX represents the number of grid cells in the X direction. S14. Calculate the dimensions in each direction according to formula (1), and set the spatial origin of the grid system as the minimum boundary coordinate; S15. After the partitioning is completed, the system constructs a three-dimensional mesh container PointsBox to store the coordinates of points falling into each mesh cell, and at the same time constructs a parallel three-dimensional normal vector container NormalsBox to store the corresponding normal vectors.

3. The method for visualizing the surface quality of a machined surface based on GPU and mesh search algorithms according to claim 2, characterized in that, In S2, to adapt to the linear memory model of the GPU, the three-dimensional mesh structure is converted into a compact one-dimensional array format, specifically including the following steps: S21. Convert each 3D mesh cell into a continuous 1D index GridIndex. The conversion formula is as follows: (2); Wherein, GridIndex represents the number corresponding to the conversion of a 3D mesh into a 1D mesh, x, y, z represent the mesh numbers in the three dimensions, and GridSizeX, GridSizeY, GridSizeZ represent the number of meshes in the x, y, and z directions, respectively. S22. Traverse all grid cells one by one, and store all the point coordinate data stored in each cell into a one-dimensional point coordinate array FlatPointArray, and at the same time store all the corresponding normal vector data into a one-dimensional normal vector array FlatNormalArray. S23. Simultaneously construct a key point index buffer PointIndexBuffer, which is a one-dimensional array with a length equal to the total number of grids. The value stored at each position GridIndex represents the starting position of the point data contained in the corresponding grid cell in the one-dimensional point coordinate array. This structure provides an important mapping relationship for the GPU to quickly locate point data in any grid.

4. The method for visualizing the surface quality of a machined surface based on GPU and mesh search algorithm according to claim 3, characterized in that, In S3, the GPU compute buffer includes four structured compute buffers: PointBuffer: This buffer is bound to a packed one-dimensional point coordinate array and is used to store the three-dimensional spatial position information of all points; Normal Buffer: This buffer is bound to a packed one-dimensional normal vector array and is used to store the three-dimensional normal vector information corresponding to all points; GridInfoBuffer: This buffer stores a structure that defines the global parameters of the grid system, including the grid origin GridOrigin, the number of grids in each dimension, the physical size of the grid cells BoxSize, and the total number of point clouds TotalPoints; PointIndexBuffer: This buffer stores an array of point index mapping relationships, enabling fast location of point cloud data from grid index; Four structured computation buffers use the ComputeBuffer interface provided by the Unity engine to transfer pre-packaged data from the CPU to the GPU memory in a batch at once; this avoids the huge performance overhead and communication latency caused by point-by-point transmission in traditional methods, and improves the transmission efficiency of large-scale point cloud data.

5. The method for visualizing the surface quality of a machined surface based on GPU and mesh search algorithm according to claim 4, characterized in that, In S4, the specific process is as follows: In the GPU shader program, the four structured computation buffers in S3 are accessed in parallel and efficiently through the StructuredBuffer interface; when a point in the world space needs to be rendered, the shader uses the mesh index calculation which is the opposite of formula (2) to quickly determine the mesh cell where the point is located; with the starting position recorded in the point index buffer, the shader immediately locates the point cloud data of the mesh cell in the one-dimensional array, and drastically narrows the search range from the global point cloud to the local neighborhood.

6. The method for visualizing the surface quality of a machined surface based on GPU and mesh search algorithm according to claim 5, characterized in that, S5 specifically includes the following steps: S51. Determine the world space location of the fragment and its corresponding mesh cell: When the fragment shader is executed, each fragment carries its three-dimensional coordinate information in world space. The GetGridCell function is called to convert the world coordinates to the mesh coordinate system. Specifically, the local coordinates are obtained by subtracting the mesh origin coordinates GridOrigin from the fragment world coordinates. Then, each component of the local coordinates is divided by the physical size BoxSize of the mesh cell, and a floor operation is performed to obtain the index coordinates of the three-dimensional mesh cell to which the fragment belongs. This step is the key to discretizing the continuous spatial query into an accurate mesh index. S52. Perform a local search based on a 3×3×3 neighborhood: Use a 3×3×3 cube neighborhood centered on the current grid cell as the search range, limiting the search range from the entire point cloud dataset to a maximum of 27 adjacent grid cells, reducing computational complexity; The shader program uses a three-level nested loop structure to traverse the current cell and all its adjacent cells offset by ±1 units in each of the X, Y, and Z directions, generating a total of 27 candidate grid cell coordinates; S53. Quickly locate point cloud data and calculate projection distance within candidate grid cells: For each candidate grid cell, call the GetPointBoxIndex function to convert its three-dimensional cell coordinates into the corresponding one-dimensional index according to formula (2); query the point index buffer pointIndexBuffer to obtain the start and end indices of the point data stored in the cell in the point coordinate buffer PointBuffer, accurately locate and traverse all stored points in the cell; Signed projection distance is used as the criterion for measuring the proximity of fragments to the point cloud surface. The specific calculation method is as follows: starting from the current world space position of the fragment, projection is performed along the opposite direction of the current normal vector towards the local surface where the candidate point is located. The formula for calculating the distance value dist is: dist=dot((fragment position) (Candidate point position, current normal vector) PointRadius (3); PointRadius is a preset point radius parameter used to correct surface reconstruction deviations caused by the sparsity of the point cloud data itself; this distance value is a signed value, which can effectively distinguish whether the fragment is located on the front or back of the point. S54. Select the best neighboring point and assign its normal vector: Traverse all candidate points within all 27 candidate mesh cells, continuously track and record the minimum projection distance value minDist and its corresponding candidate point index; when the entire local search is completed, retrieve the normal vector corresponding to the candidate point with the minimum projection distance from the normal vector buffer NormalBuffer, and assign it as the final surface normal vector finalNormal of the current fragment; this mechanism ensures that each fragment can obtain accurate orientation information from the nearest and most relevant surface point.

7. The method for visualizing the surface quality of a machined surface based on GPU and mesh search algorithm according to claim 6, characterized in that, S6 specifically includes the following steps: S61. Perform dynamic consistency correction of normal vector direction: Check and correct the direction consistency of the reconstructed surface normal vectors to ensure the correctness of the lighting calculation. The specific method is to construct a branchless correction algorithm based on symbolic function simulation. Its core operation is defined by the formula: (4); The built-in `step` function checks if the dot product of the normal vector and the viewing direction `eyeDir` is greater than or equal to 0. If the dot product is non-negative, `step` returns 1, and then... The linear transformation from 2.0 to 1.0 has a multiplier factor of +1, and the normal vector direction remains unchanged. If the dot product is negative, step returns to 0, the multiplier factor becomes -1, and the normal vector direction is automatically reversed. This process avoids flow control instructions, ensuring the execution efficiency of the GPU shader unit. S62. Calculate the three components of the Phong lighting model and perform linear superposition. The three components include the ambient light component, the diffuse reflection component, and the specular reflection component. S63. Perform legality verification and constraint on the color output range: A component limitation algorithm is used to process the final color. The components of the three RGB color channels after synthesis are compared with the upper limit value of 1.0, and the minimum value is taken. The expression is: (5); This step ensures that the color values ​​output to the screen frame buffer are always within the legal and correctly interpretable range of [0,1], guaranteeing the color accuracy and visual stability of the final rendered image.

8. The method for visualizing the surface quality of a machined surface based on GPU and mesh search algorithm according to claim 7, characterized in that, In S62, the calculation methods for the three components are as follows: Ambient light component calculation: Used to simulate global indirect lighting in a scene, providing a base brightness for surfaces and preventing completely backlit areas from falling into pure black; the calculation process is as follows: a fixed coefficient, set to 0.2, is directly multiplied by the base color of the object's surface, i.e., ambient = 0.

2. col; This component is independent of the direction of light and the angle of view; Diffuse reflection component calculation: follows Lambert's cosine law and is used to simulate the uniform scattering of light on a rough surface; The intensity depends on the cosine of the angle between the surface normal vector and the incident light direction. To simplify the calculation, the light direction `lightDir` is set to `-rayDirection`, which is opposite to the line-of-sight direction. The calculation first calculates the dot product of the normal vector and the light direction `ndotl`, then uses the `max` function to constrain it within the non-negative range of [0,1]. Finally, it is multiplied by the base color to obtain the diffuse light, i.e., `diffuse=max(dot(normal,lightDir),0.0)`. col; Specular reflection component calculation: used to simulate specular flares on smooth surfaces, enhancing the texture of objects; The calculation process is as follows: Based on the incident light direction and the surface normal vector, the ideal reflection direction r of the light is calculated using the reflect function; the cosine value rdotv of the angle between this reflection direction and the viewing direction v is calculated, and the max function is used to ensure that it is non-negative; finally, this cosine value is raised to a higher power, called the gloss index, which is set to 32, and then multiplied by a specular intensity parameter set to 0.15 and the specular color to obtain the specular reflected light, i.e., specular=pow(max(dot(r,v),0.0),32.0). float3(1.0) 0.15; the higher the gloss index, the more concentrated and sharp the highlight areas. The three components are linearly superimposed to obtain the initial composite color: result=ambient+diffuse+specular.

Citation Information

Patent Citations

  • High-dimensional data visual rendering method, system and device and storage medium

    CN118606396A

  • Three-dimensional scene loading and rendering method for deep sea three-dimensional environment deduction

    CN119991921A