A method and device for real-time mapping of a three-dimensional model by a laser beam
The laser beam is simulated by parallel surface light sources and combined with frame buffering and depth buffering algorithms, real-time mapping of three-dimensional models is achieved, solving the problems of large amount of calculation and incomplete simulation effects in the prior art, and providing efficient information on the irradiation intensity distribution of triangular surface sheets.
Patent Information
- Application Number
- CN202210749044.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-28
- Publication Date
- 2025-05-13
- Estimated Expiration
- 2042-06-28
AI Technical Summary
In the real-time mapping of laser beams to three-dimensional models, the prior art cannot effectively simulate the beam oblique incident effect, and the calculation amount is large, so it is impossible to accurately obtain the vertex, normal and irradiation intensity distribution information of the triangle face sheet.
The parallel surface light source is used to simulate the laser beam, and the light source texture image is obtained through frame buffering technology. The texture mapping technology and depth buffering algorithm are used to calculate the irradiation intensity of the triangle surface sheet in real time, cut the obstructed surface sheet, and output the final irradiance value.
Real-time mapping of three-dimensional models is realized, and the irradiation intensity distribution information of the triangular face sheet can be accurately obtained, which reduces the graphics hardware and modeling requirements, and is suitable for the fields of optical scattering cross-section calculation and laser illumination, identification and detection.
Smart Images

Figure CN115205492B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of high-power laser application, and in particular relates to a method and a device for real-time mapping of a three-dimensional model by a laser beam. Background Art
[0002] Whether it is the calculation of the optical scattering cross section of a high-precision complex target (i.e. a target with a complex three-dimensional model) or the simulation of the real-time mapping effect between the light spot and the target in the field of laser illumination and identification detection, the real-time mapping calculation of the three-dimensional model using a laser beam is a crucial issue.
[0003] The real-time mapping calculation of laser beam to three-dimensional model is to use surface light source to simulate the effect of laser beam projected onto three-dimensional model in real time, and obtain the irradiation intensity distribution information on the triangular facets constituting the three-dimensional model.
[0004] At present, there are two ways to realize the calculation of laser beam projection on complex targets: 1) Using Z-Buffer (depth buffer) and image fusion technology, the spot image and the target brightness image are data-fused to simulate the real-time projection effect of the light beam on the complex target. This method can meet the real-time calculation requirements, but it cannot simulate the projection effect when the light beam is obliquely incident, and cannot obtain the vertices of the illuminated triangular facets on the complex target and the irradiation intensity distribution information; 2) Using ray tracing technology to simulate the surface light source with a very fine grid of parallel light, calculate the intersection of each ray with the triangular facets that constitute the three-dimensional model, and calculate the angle between the normal of the triangular facet and the ray and the area of the intersection plane, so as to calculate the irradiation intensity distribution information on the three-dimensional model. This method can simulate the oblique incidence effect of the light beam, but it has a large amount of calculation, requires the surface light source grid to match the illuminated three-dimensional model grid, has high requirements for three-dimensional model modeling, and cannot obtain the vertices, normals and irradiation intensity distribution information of the illuminated triangular facets on the three-dimensional model. Summary of the invention
[0005] In order to solve the deficiencies in the prior art, the present application proposes a method and device for real-time mapping of a three-dimensional model by a laser beam.
[0006] In a first aspect, the present application proposes a method for real-time mapping of a three-dimensional model by a laser beam, comprising the following steps:
[0007] Step S1: read the 3D model using the 3D model reading and writing plug-in;
[0008] Step S2: establishing a beam source data structure, using a parallel surface light source to simulate a laser beam to illuminate the three-dimensional model in a light source space coordinate system, to obtain illumination data;
[0009] Step S3: Rendering the illumination data into the graphics card memory to obtain a light source texture image;
[0010] Step S4: restoring the light source texture image to the world coordinate system, and mapping it to the surface of the three-dimensional model to obtain the irradiance result on the triangular facet, where the triangular facet is located on the surface of the three-dimensional model;
[0011] Step S5: trimming the blocked triangular facets in the three-dimensional model to obtain the radiation intensity results on the trimmed triangular facets;
[0012] Step S6: restoring and mapping the irradiance intensity result on the clipped triangular facets to the three-dimensional model in the world coordinate system to obtain the final irradiance value of the triangular facets on the three-dimensional model;
[0013] Step S7: output and save the final irradiance value of all triangular facets on the three-dimensional model, wherein the final irradiance value includes the components, vertices, normal information of the triangular facets of the irradiated three-dimensional model and the irradiance intensity distribution information on the triangular facets.
[0014] The light source texture image is obtained by using frame buffer technology, and the specific steps include:
[0015] Step S3.1: saving the illumination data to a texture image in the graphics card memory by means of a frame buffer object;
[0016] Step S3.2: Use the open graphics library shading language to complete the acquisition of pixel values of the light source texture image to obtain the light source texture image.
[0017] The irradiance intensity result on the triangular facet is obtained by using texture mapping technology, including the following steps:
[0018] Step S4.1: sampling light source texture image data values by texture coordinate mapping, wherein the texture coordinates refer to the mapping of the light source texture image to the surface of the three-dimensional model;
[0019] Step S4.2: taking the average of the irradiance values of T points around the texture coordinate as the irradiance intensity result on the triangle patch.
[0020] The method of adopting texture coordinate mapping to sample light source texture image data values comprises the following steps:
[0021] Step S4.1.1: Assuming that a point P on the three-dimensional model in the local coordinate system of the scene is known, the mapping point P' of point P in the light source space coordinate system is obtained by the following formula:
[0022] P′=M lightP *M lightV *M world *P
[0023] Among them, M world Represents the transformation matrix that transforms point P to the world coordinate system, MlightV Represents the observation matrix of the light source virtual camera, M lightP Represents the projection matrix of the light source virtual camera, and the P' result value (x, y) ranges from [-1, 1];
[0024] Step S4.1.2: Determine P' x or P' y Is the value of less than -1 or greater than 1? If so, discard it directly. If not, go to step S4.1.3, where (x, y) corresponds to the normalized coordinate point (P' in the illumination data. x ,P' y );
[0025] Step S4.1.3: Set (P' x ,P' y ) is renormalized to the interval [0,1], and the normalized (P' x ,P' y ) as texture coordinates to map the sampled light source texture image data value.
[0026] The clipping of the blocked triangles in the three-dimensional model is completed by using a depth cache algorithm. The value (x, y) of the mapping point P' obtained corresponds to the texture coordinate value of the illumination data, and the z value of the point P' represents the vertical distance between the point P in the world coordinate system and the light source plane. The specific steps are:
[0027] Step S5.1: Compare the z value of point P' with the distance value stored in the illumination data;
[0028] Step S5.2: If the absolute value of the difference between the two is less than or equal to the first threshold, it means that the point P on the three-dimensional model is the same point as the point of the illumination data;
[0029] Step S5.3: If the absolute value of the difference between the two is greater than the first threshold, it means that the point P on the three-dimensional model is not the same as the point of the illumination data, and point P is removed.
[0030] The final irradiance value of the triangular facets on the three-dimensional model is obtained by simultaneously irradiating the three-dimensional model with an ambient light source and a normalized laser beam light source.
[0031] The output and storage of the final irradiance values of all triangular facets on the three-dimensional model includes the following steps:
[0032] Step S7.1: reading the light source texture image from the graphics processor memory into the system central processor memory;
[0033] Step S7.2: traverse each triangle of the three-dimensional model and the vertex data on the triangle, set the irradiance value corresponding to the vertex blocked by other triangles to zero, and set the vertex not blocked by other triangles to the value corresponding to the vertex texture;
[0034] Step S7.3: Save the final irradiance values of all triangular facets on the three-dimensional model into a file.
[0035] The light source texture image is read from the graphics processor memory to the system central processor memory, and the specific steps include:
[0036] Step S7.1.1: Project any vertex A of the triangle into the light source space coordinate system to obtain a two-dimensional coordinate A' and a depth value d;
[0037] Step S7.1.2: Compare the value range of A' with the resolution of the light source texture. If the value range of A' is greater than the resolution of the light source texture, discard vertex A; otherwise, do not discard vertex A.
[0038] Step S7.1.3: Obtain the distance value c between vertex A and the nearest point on the model according to the illumination data result;
[0039] Step S7.1.4: Determine whether the face normal of the triangle where vertex A is located is on the same side as the light source direction. If so, discard vertex A; otherwise, do not discard vertex A.
[0040] Step S7.1.5: Determine whether the absolute value of the difference between the distance value c and the depth value d is less than or equal to a second threshold value. If so, retain vertex A; if not, discard vertex A.
[0041] The laser beam includes multiple laser beams or a single laser beam. When multiple laser beams are used, multiple light source texture images and corresponding multiple fragment shader variable values are established and calculated separately in the graphics processor; when a single laser beam is used, a single light source texture image is established.
[0042] In the second aspect, the present application proposes a device for real-time mapping of a three-dimensional model by a laser beam, comprising a three-dimensional model reading unit, a three-dimensional model irradiation unit, a lighting data rendering unit, a light source texture image mapping unit, a triangle patch cutting unit, a triangle patch information restoration mapping unit, and a triangle patch information storage unit, wherein each unit is connected in sequence;
[0043] The 3D model reading unit is used to read the 3D model using the 3D model reading and writing plug-in;
[0044] The three-dimensional model irradiation unit is used to establish a beam source data structure, and in the light source space coordinate system, use a parallel surface light source to simulate a laser beam to irradiate the three-dimensional model to obtain illumination data;
[0045] The illumination data rendering unit is used to render the illumination data into the graphics card memory to obtain a light source texture image;
[0046] The light source texture image mapping unit is used to restore the light source texture image to the world coordinate system and map it to the surface of the three-dimensional model to obtain the irradiance intensity result on the triangular facet, and the triangular facet is located on the surface of the three-dimensional model;
[0047] The triangle patch cutting unit is used to cut the blocked triangle patches in the three-dimensional model and obtain the irradiance intensity result on the cut triangle patches;
[0048] The triangle patch information restoration and mapping unit is used to restore and map the irradiance intensity result on the clipped triangle patch to the three-dimensional model in the world coordinate system to obtain the final irradiance value of the triangle patch on the three-dimensional model;
[0049] The triangle patch information storage unit is used to output and store the final irradiance value of all triangle patches on the three-dimensional model, wherein the final irradiance value includes the components, vertices, normal information of the triangle patches of the irradiated three-dimensional model and the irradiance intensity distribution information on the triangle patches.
[0050] Beneficial technical effects:
[0051] The present application proposes a method and device for real-time mapping of a laser beam to a three-dimensional model, which can obtain in real time the components, vertices, normal information and irradiation intensity distribution information on the triangular facets of the irradiated three-dimensional model, and can simulate in real time the accumulated irradiation intensity distribution information of multiple surface light sources on the three-dimensional model, and has the advantages of low requirements on graphics hardware, low requirements on the modeling level of the three-dimensional model, wide versatility and strong universality, which are specifically embodied in:
[0052] Applicable to uniform light source or non-uniform surface light source;
[0053] The laser wavefront can be annular, rectangular or any shape;
[0054] Support real-time update of 3D model and beam position and posture;
[0055] Supports 3D models with more than 100,000 vertices, and the frame rate of drawing light mapping results of a single model is no less than 30Hz;
[0056] Support multiple parts of a 3D model or multiple 3D models;
[0057] Adapt to ive, ogb or 3ds format files exported from 3DS MAX;
[0058] Supports the use of C++ language, and supports domestic Kylin and Windows operating systems;
[0059] It can be applied to the calculation of optical scattering cross sections of complex targets and is practical in the fields of laser illumination and identification detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings in the following description are only used to explain the concept of the present application.
[0061] Figure 1 A flowchart of a method for real-time mapping of a three-dimensional model by a laser beam according to an embodiment of the present application;
[0062] Figure 2 This is a schematic diagram of an orthogonal projection of a laser beam simulating a parallel plane light source irradiating the three-dimensional model according to an embodiment of the present application;
[0063] Figure 3 This is a simulation diagram of the effect of a parallel plane light source illuminating a three-dimensional model according to an embodiment of the present application;
[0064] Figure 4 A schematic diagram of multi-point projection of a cross section of a complex 3D model according to an embodiment of the present application;
[0065] Figure 5 When the refresh frame rate of the embodiment of the present application is 20 Hz per second, two beams of light calculate and display the result graph of the complex three-dimensional model in real time;
[0066] Figure 6 This is a display diagram of the interactive results of real-time mapping of a complex three-dimensional model by two beams of light (directional rectangular non-uniform surface light sources) in an embodiment of the present application;
[0067] Figure 7 This is a principle block diagram of a device for real-time mapping of a three-dimensional model by a laser beam according to an embodiment of the present application. DETAILED DESCRIPTION
[0068] The present application is further described below in conjunction with the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solution of the present application, and cannot be used to limit the protection scope of the present application.
[0069] This application proposes a method that can be applied to the optical scattering cross section of complex targets and has a reference role in the fields of laser illumination and identification detection.
[0070] To ensure better results, this application preferably uses a graphics card that supports OpenGL3.2 / GLSL3.2 and above and supports the Transform Feedback feature. It preferably uses four shaders, namely the vertex shader of the emission source perspective, the fragment shader of the emission source perspective, the vertex shader of the main scene perspective, and the fragment shader of the main scene perspective, to map the three-dimensional model in real time.
[0071] In order to overcome the shortcomings and defects of the prior art, the present application proposes a method for real-time mapping of a three-dimensional model by a laser beam, such as Figure 1 As shown, the steps are as follows:
[0072] Step S1: read the 3D model using the 3D model reading and writing plug-in;
[0073] This method uses an OSG (Open Scene Graph, open source 3D engine) 3D model reading and writing plug-in to read in the 3D model, and the 3D model can be in different formats.
[0074] Step S2: Establishing a beam source data structure, using a parallel surface light source to simulate a laser beam to illuminate the three-dimensional model in a light source space coordinate system to obtain illumination data.
[0075] When the laser beam approaches the 3D model target (i.e., the enclosing sphere of the 3D model target), the laser beam can be assumed to be parallel light, and the laser light source can be simulated by a surface light source. The enclosing sphere of the 3D model target means that such a value is needed in the calculation to determine whether the laser beam reaches the vicinity of the 3D model target. Because the laser has a divergence angle, it is similar to a truncated cone with a small radius at the bottom surface of the emission end and a large radius at the bottom surface of the arrival end. Assuming that the modeling center of the 3D model target is at the geometric center of the 3D model target, with the farthest distance from the vertex of the 3D model target to the modeling center as the radius, a sphere can be constructed. This sphere can just enclose the 3D model target. This sphere is called the enclosing sphere of the 3D model target. The laser beam has a relatively small divergence angle, similar to the upper and lower bottom surfaces of a truncated cone. When it reaches the target after a certain transmission distance, because the target size is limited, it can be assumed that the laser beam after the enclosing sphere no longer diverges, but is transmitted in parallel; the light source reaching the target can be represented by a surface, such as the bottom surface of the truncated cone. Because the light source is non-uniform, it is necessary to use a grid to represent the light source information, and use the size of the array and rectangle to represent the light source information.
[0076] Therefore, this embodiment uses a rectangle with a certain direction to describe the shape of the surface light source, and a two-dimensional array describes the two-dimensional distribution of the light source. The data structure of the illumination matrix is shown in Table 1:
[0077] Table 1 Light source input and output conventions
[0078]
[0079]
[0080] The position, rotation, and size of the entire parallel surface light source in space can be adjusted through lightPos, lightDir, lightUp, and lightSize.
[0081] The two-dimensional distribution of the light source is a 256x256-dimensional float (single-precision floating-point) type array matrix (this can be modified according to actual needs). Each number represents the irradiance intensity at the location of the two-dimensional distribution matrix of the light source. Therefore, set lightDataW and lightDataH to 256, and pass 256x256 float-type irradiance intensity values to lightData.
[0082] lightSpaceImage is the rendering result of the illuminated 3D model in the light source space coordinate system. In order to obtain the final irradiance value of the 3D model triangle patch, we need to take the result out of the GPU (Graphics Processing Unit), restore it to the world coordinate system, and map it to the 3D model surface, so as to obtain the irradiance intensity result on the 3D model surface triangle patch.
[0083] In addition, in order to meet the needs of setting multiple light source data, lightID is used to distinguish the attribute values of each light source.
[0084] In this embodiment, the light source plane is regarded as a camera object in the real-time graphics scene, so the laser beam is equivalent to an orthogonal projection type camera, and a parallel surface light source is used to simulate the orthogonal projection schematic diagram of the laser beam irradiating the three-dimensional model, as shown in FIG. Figure 2 shown.
[0085] In the software implementation, in order to obtain the lighting result map, that is, the lighting data, it is necessary to set up a light source virtual camera and set the lighting matrix of the light source virtual camera, including the projection matrix (that is, the orthogonal projection volume matrix) and the observation matrix, and render the scene seen in the light source virtual camera into the lighting result data array.
[0086] The projection matrix is constructed according to the light source lightSize parameter and lightMaxAttenuation parameter in Table 1. The projection matrix is set to:
[0087]
[0088] Where left is -lightSize.x*0.5, bottom is -lightSize.y*0.5, right is lightSize.x*0.5, top is lightSize.y*0.5. near is set to 0, and far is set to lightMaxAttenuation.
[0089] The observation matrix M of the light source virtual camera lightV Set to:
[0090]
[0091] Here up is lightUp in the above table, dir is lightDir, pos is lightPos, and right is the result of the cross product of dir and up.
[0092] At this time, the rendering result of the light source virtual camera is as follows Figure 3 It records the scene image rendered with the light source virtual camera as the main perspective. If the image is directly mapped to the light source virtual camera screen of the world coordinate system, as shown in the large picture, it is equivalent to recording the information of the intersection point closest to the light source plane after the parallel light rays emitted from the light source plane are projected onto the 3D model.
[0093] Step S3: Rendering the illumination data into the graphics card memory to obtain a light source texture image;
[0094] Specifically, by means of FBO (Frame Buffer Object), with each surface light source illumination matrix as the observer, the 3D model is rendered in the light source space coordinate system and the rendering result image is recorded in the graphics card memory, that is, the illumination data of the 3D model is saved in a texture image in the graphics card memory, and the light source texture image of the 3D model is obtained. The illumination data of the 3D model is the light source perspective rendering result image. The resolution of the light source texture image is set to 1024x1024. The larger the value, the higher the algorithm accuracy. In the actual process, the actual carrying capacity of the graphics hardware also needs to be considered.
[0095] This embodiment is specifically implemented through the following steps:
[0096] Step S3.1: saving the illumination data to a texture image in the graphics card memory by means of a frame buffer object;
[0097] Step S3.2: Use the open graphics library shading language to complete the acquisition of pixel values of the light source texture image to obtain the light source texture image.
[0098] In order to improve the calculation accuracy, this embodiment sets the pixel format of the light source texture image to GL_FLOAT, and the internal storage format of the texture is set to GL_RGBA32F_ARB, that is, 32-bit floating point numbers are used to save the result data.
[0099] This embodiment uses OpenGL (Open Graphics Library) shading language to complete the pixel value acquisition of the light source texture image, specifically using the lighting space fragment shader for processing. The core code is as follows:
[0100] vec2 lightUV=vec2(gl_FragCoord.x / lightDataSize.x,
[0101] gl_FragCoord.y / lightDataSize.y);
[0102] vec4 lightColor=texture(lightDataTexture,lightUV);
[0103] gl_FragColor=vec4(lightColor.xyz,gl_FragCoord.z / gl_FragCoord.w);
[0104] Here, lightUV represents the starting point of a ray on the light source plane, and lightDataTexture comes from the lightData parameter that stores the data intensity of the parallel light source. Therefore, lightColor records the light intensity value corresponding to the current ray, and gl_FragCoord.z represents the data depth value of the light source space. According to the Z-Buffer principle, it saves the distance value between the ray and the nearest intersection point on the model. Save lightColor and the distance value together in the result image, that is, save them in lightSpaceImage.
[0105] Step S4: restoring the light source texture image to the world coordinate system, and mapping it to the surface of the three-dimensional model to obtain the irradiance result on the triangular facet, where the triangular facet is located on the surface of the three-dimensional model;
[0106] The lighting data obtained from the light source space rendering is valid primitive data, which is actually the primitive position on the model that can receive lighting. The lighting data in lightSpaceImage is restored to the world coordinate system and mapped to the 3D model surface to obtain the irradiance intensity result on the triangular facets of the 3D model surface.
[0107] Therefore, the method of this application first assumes that a point P on the three-dimensional model in the local coordinate system of the scene is known, then the mapping point P' of point P in the light source space coordinate system is obtained by the following formula:
[0108] P'=M lightP *M lightV *M world *P
[0109] Among them, M world Represents the transformation matrix that transforms point P to the world coordinate system, M lightV Represents the observation matrix of the light source virtual camera, M lightP Represents the projection matrix of the light source virtual camera. The P' result value (x, y) corresponds to the normalized coordinate point in the lightSpaceImage image, that is, the light source texture image obtained. The normalized coordinate point in the lightSpaceImage image is represented by (P' x ,P' y ) indicates that the value range is [-1,1];
[0110] The above scene local coordinate system can be understood by referring to the following example: if the center of the earth is assumed to be the world coordinate system, then it can be assumed that there is a building complex at a certain point on the earth's spherical surface, and that the building complex has a coordinate origin. The geometric center of one of the rooms is the scene local coordinate system of the entire building complex. In order to illuminate the building complex, a lamp is needed. This lamp can only illuminate a part of the building complex. The vertex brightness calculation of this part of the building complex needs to be calculated based on the coordinate system of the lamp, which is called the light source space coordinate system. It can be seen that the scene local coordinate system and the light source space coordinate system are both part of the world coordinate system. The scene local coordinate system and the light source space coordinate system are different coordinate systems generated according to different reference systems for different calculation purposes.
[0111] At this time, the situation can be judged as follows, if P' x or P' y If the value of is less than -1 or greater than 1, it means that the current point on the 3D model cannot be mapped to the light source plane and can be discarded directly. x ,P' y ) is renormalized to the interval [0,1] and then used as the texture coordinate to sample the texel value in the lightSpaceImage texture. The result is the irradiance value of the nearest intersection point between the ray at that point on the light source plane and the model.
[0112] The specific implementation steps of this embodiment are as follows:
[0113] Step S4.1: sampling light source texture image data values by texture coordinate mapping, wherein the texture coordinates refer to the mapping of the light source texture image to the surface of the three-dimensional model;
[0114] Step S4.1.1: Assuming that a point P on the three-dimensional model in the local coordinate system of the scene is known, the mapping point P' of point P in the light source space coordinate system is obtained by the following formula:
[0115] P'=M lightP *M lightV *M world *P
[0116] Among them, M world Represents the transformation matrix that transforms point P to the world coordinate system, M lightV Represents the observation matrix of the light source virtual camera, M lightP Represents the projection matrix of the light source virtual camera, and the P' result value (x, y) ranges from [-1, 1];
[0117] Step S4.1.2: Determine P' x or P' y Is the value of less than -1 or greater than 1? If so, discard it directly. If not, go to step S4.1.3, where (x, y) corresponds to the normalized coordinate point (P' in the illumination data. x ,P' y );
[0118] Step S4.1.3: Set (P' x ,P' y ) is renormalized to the interval [0,1], and the normalized (P' x ,P' y ) as texture coordinates to map the sampled light source texture image data value.
[0119] Step S4.2: taking the average of the irradiance values of T points around the texture coordinate as the irradiance intensity result on the triangle patch.
[0120] The method for calculating the irradiance intensity result on the triangular facet in the present application is to use the texture coordinate mapping to sample the texture image data value in the texture, which actually utilizes the OpenGL texture interpolation algorithm, thereby avoiding the problem of missing faces caused by the mismatch between the modeling subdivision and the light line array subdivision in the ray tracing algorithm (such as the spherical model, the triangular facets at both ends of the sphere are very fine, and it is almost impossible to obtain the correct calculation result by using ray tracing intersection). At the same time, the mean filtering method is adopted to take the average of the irradiance values of T points near the texture coordinates as the final calculation result. In this embodiment, T is taken as 16, so that the algorithm result is smoother.
[0121] Step S5: Clipping the blocked triangular facets in the three-dimensional model to obtain the radiation intensity results on the clipped triangular facets.
[0122] For a point P on the model, it has only one projection point on the light source plane, namely P'; however, there may be more than one point on the model whose projection point calculation result is P'. Figure 4 The figure shows a multi-point projection diagram of a complex 3D model cross section. There are at least 4 points on its surface that can be projected onto point P' on the light source plane, but obviously only P0 will actually receive the light source radiation (without considering transmission), and the other points are blocked. For each pixel on the screen, the depth buffer will record the distance information between the object in the scene and the viewpoint at this pixel. Using the Z-Buffer principle, this algorithm judges and handles this situation in the shading language.
[0123] The (x, y) value of point P' obtained in step S4 corresponds to the texture coordinate value of the image rendered from the light source perspective; and its z value represents the vertical distance between point P in the local coordinates and the light source plane. This feature can be used to compare P'.z with the distance value stored in lightSpaceImage: if the two are very close, it means that point P on the current model is exactly the same point rendered from the light source virtual camera perspective, that is, the model surface point that should receive irradiation. If P'.z is significantly larger than the distance value recorded in lightSpaceImage, then this point must be blocked by other triangles and can be ignored.
[0124] This embodiment uses the Z-Buffer algorithm to perform triangle face clipping, and the specific steps are as follows:
[0125] Step S5.1: Compare the z value of point P' with the distance value stored in the illumination data;
[0126] Step S5.2: If the absolute value of the difference between the two is less than or equal to the first threshold, it means that the point P on the three-dimensional model is the same point as the point of the illumination data. In this embodiment, the first threshold is set to 1.0e-5, that is, 1 times 10 to the negative fifth power, which is 0.00001;
[0127] Step S5.3: If the absolute value of the difference between the two is greater than the first threshold, it means that the point P on the three-dimensional model is not the same as the point of the illumination data, and point P is removed.
[0128] Step S6: restoring and mapping the irradiance intensity result on the clipped triangular facets to the three-dimensional model in the world coordinate system to obtain the final irradiance value of the triangular facets on the three-dimensional model;
[0129] This embodiment uses OpenGL shading language to implement step S5 and step S6, that is, the above process is processed by a model space fragment shader. The specific code fragment is as follows:
[0130]
[0131] Where lightSpacePos is the point P' obtained by matrix concatenation, and lightTexture is the texture corresponding to the lightSpaceImage obtained by FBO rendering. The result returned by the code snippet is the final irradiance value received by the current fragment, which may be the value recorded in lightSpaceImage or directly 0 (indicating that no irradiance is received).
[0132] Step S7: output and save the final irradiance value of all triangular facets on the three-dimensional model, wherein the final irradiance value includes the components, vertices, normal information of the triangular facets of the irradiated three-dimensional model and the irradiance intensity distribution information on the triangular facets.
[0133] The lightSpaceImage image data records the texture image of the light source irradiated on the surface of the 3D model. However, through the GLSL (Graphics Library Shader Language) shading language, only the irradiated form of the 3D model under the current viewing angle can be rendered, that is, only the image result after the light source is mapped to the 3D model can be obtained, that is, the rendering effect that can be seen in the scene, and the irradiance value on each triangle of the final model cannot be truly output. Therefore, the output of the irradiance value is completed on the CPU (Central Processing Unit) side.
[0134] First, the lightSpaceImage image data needs to be read from the GPU video memory to the system CPU memory through the ReadPixels method, and the data of each triangle face and each vertex on the triangle face of the 3D model needs to be collected for traversal.
[0135] Read the light texture image from the GPU video memory to the system CPU memory:
[0136] (1) Project vertex A into the light source space coordinate system to obtain a two-dimensional coordinate A' and a depth value (distance value) d. The value range of A' should not exceed the resolution of lightSpaceImage, that is, the interval range of [0,1024]. If it exceeds this range, it means that the point A is outside the illumination range and can be directly discarded (set its illumination result to the default value).
[0137] (2) Get the floating-point value of the corresponding position from the memory data of lightSpaceImage, that is, the distance c between the light source ray at that position and the nearest point on the model, assuming that the parallel surface light source is composed of lightDataW*lightDataH rays.
[0138] (3) If the face normal of the triangle where the current point is located is on the same side as the light source direction, that is, the dot product of the normal and the light source direction vector is greater than 0, then the point should be discarded in advance (it is facing away from the light source, and its lighting result is set to the default value).
[0139] (4) If the distance value c is close to d, it can be considered that the current vertex is the closest point receiving the radiation of the light source, and the current brightness value / color value of the light source point is the color value of this point on the model, that is, the irradiance value.
[0140] This embodiment is implemented by the following steps:
[0141] Step S7.1: reading the light source texture image from the graphics processor memory into the system central processor memory;
[0142] Step S7.1.1: Project any vertex A of the triangle into the light source space coordinate system to obtain a two-dimensional coordinate A' and a depth value d;
[0143] Step S7.1.2: Compare the value range of A' with the resolution of the light source texture. If the value range of A' is greater than the resolution of the light source texture, discard vertex A; otherwise, do not discard vertex A.
[0144] Step S7.1.3: Obtain the distance value c between vertex A and the nearest point on the model according to the illumination data result;
[0145] Step S7.1.4: Determine whether the face normal of the triangle where vertex A is located is on the same side as the light source direction. If so, discard vertex A; otherwise, do not discard vertex A.
[0146] Step S7.1.5: Determine whether the absolute value of the difference between the distance value c and the depth value d is less than or equal to a second threshold value. If so, retain vertex A; if not, discard vertex A. In this embodiment, the second threshold value is set to 1.0e-3, that is, 1 times 10 to the negative power of 3, which is 0.001.
[0147] Step S7.2: traverse each triangle of the three-dimensional model and the vertex data on the triangle, set the irradiance value corresponding to the vertex blocked by other triangles to zero, and set the vertex not blocked by other triangles to the value corresponding to the vertex texture;
[0148] Step S7.3: Save the final irradiance values of all triangular facets on the three-dimensional model into a file.
[0149] Using OSG's FaceData class, we traverse all the faces of the model and set the irradiance values corresponding to the vertices that are beyond the range of the light source texture image and blocked by other faces to zero, otherwise it is set to the value corresponding to the texture at that point, and save the vertex information, normal information and irradiance value corresponding to the triangular face into a file.
[0150] The final irradiance value of the triangular facets on the three-dimensional model is obtained by simultaneously irradiating the three-dimensional model with an ambient light source and a normalized laser beam light source.
[0151] The laser beam includes multiple laser beams or a single laser beam. When multiple laser beams are used, multiple light source texture images and corresponding multiple fragment shader variable values are established and calculated separately in the graphics processor; when a single laser beam is used, a single light source texture image is established.
[0152] During the specific implementation of the method of this application, the effects are shown as follows:
[0153] Figure 5 It shows the results of real-time calculation and display of a complex three-dimensional model by two beams of light when the refresh frame rate is 20 Hz per second;
[0154] Figure 6 The interactive display of the results of real-time mapping of a complex three-dimensional model by two beams of light with non-zero irradiance values taken from the vertex coordinates of a triangular patch and a directed rectangular non-uniform surface light source is shown.
[0155] Table 2 records the content of a frame result after real-time mapping of a rectangular surface light source with a certain direction and a complex three-dimensional model, including the component name, the coordinates of the three vertices of the triangular patch, the patch normal vector, and the irradiance intensity distribution information on the patch;
[0156] Table 2
[0157] Part Name Point 1 - X coordinate Point 1 - Y coordinate Point 1 - Z coordinate Point 2 - X coordinate Point 2 - Y coordinate Point 2 - Z coordinate Point 3 - X coordinate Point 8 - Y coordinate Point 3 - Z coordinates Normal X Normal Y Normal Z energy Cylinder001-GEODE -0.174312 -2.03125 1.99239 -0.174312 -1.95312 1.99239 -0.20945 -1.95312 1.98776 -0.130529 0 0.991444 142931 Cylindet001-GEODE -0.290537 -1.95312 1.97709 -0.233776 -2.03125 1.98456 -0.20945 -1.95312 1.98776 -0.130527 4.65E-07 0.991445 142931 Cylinder001-GEODE -0.249318 -1.91406 1.98251 -0.290537 -1.95312 1.97709 -0.20945 -1.95312 1.98776 -0.130527 -7.29E-07 0.991445 142931 Cylinder001-GEODE -0.298645 -2.42187 1.97602 -0.347297 -2.34375 1.96962 -0.347297 -2.42187 1.96962 -0.130528 0 0.991445 73282.8 Cylinder001-GEODE -0.347297 -2.34375 1.96962 -0.36859 -2.42187 1.9649 -0.347297 -2.42187 1.96962 -0.216443 0 0.976295 13282.8 Cylinder001-GEODE -0.347297 -1.64062 1.96962 -0.373913 -1.64062 1.96371 -0.347297 -1.7i875 1.96962 -0.21644 0 0.976296 59168.8 Cylinder001-GEODE -0.373913 -1.64062 1.96371 -0.400529 -1.71875 1.95781 -0.347297 -1.71875 1.96962 -0.21644 0 0.976296 59168.8 Cylinder001-GEODE -0.22837 -1.71875 1.98527 -0.309457 -1.64062 1.9746 -0.347297 -1.71875 1.96962 -0.130526 -1.04E-06 0.991445 59168.8 Cylinder001-GEODE -0.46973 -2.42187 1.94247 -0.389883 -2.5 1.96017 -0.36859 -2.42187 1.9649 -0.21644 5.03E-07 0.976296 3239.8 Cylinder001-GEODE -0.421822 -2.34375 1.95309 -0.46973 -2.42187 1.94247 -0.36859 -2.42187 1.9649 -0.21644 2.80E-07 0.976296 53239.8 Cylinder001-GEODE -9.30E-07 -2.03125 2 -9.30E-07 -1.95312 2 -0.0354079 -1.95312 1.99845 -0.0436161 0 0.999048 45310.5 Cylinder001-GEODE -0.117116 -1.95312 1.99489 -0.0599205 -2.03125 1.99738 -0.0354079 -1.95312 1.99845 -0.0436192 -3.03E-07 0.999048 45310.5 Cylinder001-GEODE -0.0755813 -1.91406 1.9967 -0.117116 -1.95312 1.99489 -0.0354079 -1.95312 1.99845 -0.0436192 1.17E-06 0.999048 45310.5 Cylinder001-GEODE -0.212153 -2.26562 1.98741 -0.282428 -2.1875 1.97816 -0.314863 -2.26562 1.97389 -0.130525 2.88E-08 0.991445 9079.3 Cylinder001-GEODE -0.249993 -2.34375 1.98243 -0.212153 -2.26562 1.98741 -0.314863 -2.26562 1.97389 -0.130525 -7.19E-09 0.991445 39079.3 Cylinder001-GEODE -0.443114 -1.5625 1.94837 -0.480377 -1.64062 1.94011 -0.373913 -1.64062 1.96371 -0.21644 2.66E-07 0.976296 38321.5 Cylinder001-GEODE -0.0755813 -1.91406 1.9967 -0.0354079 -1.95312 1.99845 -0.0231517 -1.91406 1.99899 -0.0436203 4.26E-08 0.999048 36055.1 Cylinder001-GEODE -0.0354079 -1.95312 1.99845 -9.30E-07 -1.95312 2 -0.0231517 -1.91406 1.99899 -0.0436161 -1.29E-06 0.999048 6055.1 Cylinder001-GEODE -0.347297 -1.71875 1.96962 -0.309457 -1.64062 1.9746 -0.347297 -1.64062 1.96962 -0.130528 0 0.991445 35695.3 Cylinder001-GEODE -0.347297 -1.5625 1.96962 -0.373913 -1.64062 1.96371 -0.347297 -1.64062 1.96962 -0.21644 0 0.976296 35695.3
[0158] The above examples illustrate that the method of the present application can obtain in real time the components, vertices, normal information and radiation intensity distribution information on the triangular facets of the illuminated three-dimensional model, and can simulate in real time the beneficial effects of accumulating radiation intensity distribution information of multiple surface light sources on the three-dimensional model, and has the advantages of wide versatility and strong universality.
[0159] In the second aspect, the present application proposes a device for real-time mapping of a three-dimensional model by a laser beam, such as Figure 7 As shown, it includes a 3D model reading unit, a 3D model irradiation unit, a lighting data rendering unit, a light source texture image mapping unit, a triangle patch cutting unit, a triangle patch information restoration mapping unit, and a triangle patch information storage unit, and each unit is connected in sequence;
[0160] The 3D model reading unit is used to read the 3D model using the 3D model reading and writing plug-in;
[0161] The three-dimensional model irradiation unit is used to establish a beam source data structure, and in the light source space coordinate system, use a parallel surface light source to simulate a laser beam to irradiate the three-dimensional model to obtain illumination data;
[0162] The illumination data rendering unit is used to render the illumination data into the graphics card memory to obtain a light source texture image;
[0163] The light source texture image mapping unit is used to restore the light source texture image to the world coordinate system and map it to the surface of the three-dimensional model to obtain the irradiance intensity result on the triangular facet, and the triangular facet is located on the surface of the three-dimensional model;
[0164] The triangle patch cutting unit is used to cut the blocked triangle patches in the three-dimensional model and obtain the irradiance intensity result on the cut triangle patches;
[0165] The triangle patch information restoration and mapping unit is used to restore and map the irradiance intensity result on the clipped triangle patch to the three-dimensional model in the world coordinate system to obtain the final irradiance value of the triangle patch on the three-dimensional model;
[0166] The triangle patch information storage unit is used to output and store the final irradiance value of all triangle patches on the three-dimensional model, wherein the final irradiance value includes the components, vertices, normal information of the triangle patches of the irradiated three-dimensional model and the irradiance intensity distribution information on the triangle patches.
[0167] The applicant of the present invention has made a detailed explanation and description of the implementation examples of the present invention in conjunction with the drawings in the specification. However, those skilled in the art should understand that the above implementation examples are only preferred implementation schemes of the present invention, and the detailed description is only to help readers better understand the spirit of the present invention, but not to limit the scope of protection of the present invention. On the contrary, any improvements or modifications based on the inventive spirit of the present invention should fall within the scope of protection of the present invention.
Claims
1. A method for real-time mapping of a three-dimensional model by a laser beam, characterized in that: The steps include: Step S1: read the 3D model using the 3D model reading and writing plug-in; Step S2: establishing a beam source data structure, using a parallel surface light source to simulate a laser beam to illuminate the three-dimensional model in a light source space coordinate system, to obtain illumination data; Step S3: Rendering the illumination data into the graphics card memory to obtain a light source texture image; Step S4: restoring the light source texture image to the world coordinate system, and mapping it to the surface of the three-dimensional model to obtain the irradiance result on the triangular facet, where the triangular facet is located on the surface of the three-dimensional model; Step S5: trimming the blocked triangular facets in the three-dimensional model to obtain the radiation intensity result on the trimmed triangular facets; Step S6: restoring and mapping the irradiance intensity result on the clipped triangular facets to the three-dimensional model in the world coordinate system to obtain the final irradiance value of the triangular facets on the three-dimensional model; Step S7: output and save the final irradiance value of all triangular facets on the three-dimensional model, wherein the final irradiance value includes the components, vertices, normal information of the triangular facets of the irradiated three-dimensional model and the irradiance intensity distribution information on the triangular facets.
2. The method for real-time mapping of a three-dimensional model by a laser beam according to claim 1, characterized in that: The light source texture image is obtained by using frame buffer technology, and the specific steps include: Step S3.1: saving the illumination data to a texture image in the graphics card memory by means of a frame buffer object; Step S3.2: Use the open graphics library shading language to complete the acquisition of pixel values of the light source texture image to obtain the light source texture image.
3. The method for real-time mapping of a three-dimensional model by a laser beam according to claim 1, characterized in that: The irradiance intensity result on the triangular facet is obtained by using texture mapping technology, including the following steps: Step S4.1: sampling light source texture image data values by texture coordinate mapping, wherein the texture coordinates refer to the mapping of the light source texture image to the surface of the three-dimensional model; Step S4.2: taking the average of the irradiance values of T points around the texture coordinate as the irradiance intensity result on the triangle patch.
4. The method for real-time mapping of a three-dimensional model by a laser beam according to claim 3, characterized in that: The method of adopting texture coordinate mapping to sample light source texture image data values comprises the following steps: Step S4.1.1: Assuming that a point P on the three-dimensional model in the local coordinate system of the scene is known, the mapping point P′ of point P in the light source space coordinate system is obtained by the following formula: P'=M lightP *M lightV *M world *P Among them, M world Represents the transformation matrix that transforms point P to the world coordinate system, M lightV Represents the observation matrix of the light source virtual camera, M lightP Represents the projection matrix of the light source virtual camera, and the value of P′ result (x, y) ranges from [-1, 1]; Step S4.1.2: Determine P' x or P' y Is the value of less than -1 or greater than 1? If so, discard it directly. If not, go to step S4.1.3, where (x, y) corresponds to the normalized coordinate point (P' in the illumination data. x ,P' y ); Step S4.1.3: Set (P' x ,P' y ) is renormalized to the interval [0,1], and the normalized (P' x ,P' y ) as texture coordinates to map the sampled light source texture image data value.
5. The method for real-time mapping of a three-dimensional model by a laser beam according to claim 4, characterized in that: The clipping of the blocked triangles in the three-dimensional model is completed by using a depth cache algorithm. The value (x, y) of the mapping point P' obtained corresponds to the texture coordinate value of the illumination data, and the z value of the point P' represents the vertical distance between the point P in the world coordinate system and the light source plane. The specific steps are: Step S5.1: Compare the z value of point P' with the distance value stored in the illumination data to obtain the absolute value of the difference between the two; Step S5.2: If the absolute value of the difference between the two is less than or equal to the first threshold, it means that the point P on the three-dimensional model is the same point as the point of the illumination data; Step S5.3: If the absolute value of the difference between the two is greater than the first threshold, it means that the point P on the three-dimensional model is not the same point as the point of the illumination data, and point P is removed.
6. The method for real-time mapping of a three-dimensional model by a laser beam according to claim 1, characterized in that: The final irradiance value of the triangular facets on the three-dimensional model is obtained by simultaneously irradiating the three-dimensional model with an ambient light source and a normalized laser beam light source.
7. The method for real-time mapping of a three-dimensional model by a laser beam according to claim 1, characterized in that: The output and storage of the final irradiance values of all triangular facets on the three-dimensional model includes the following steps: Step S7.1: reading the light source texture image from the graphics processor memory into the system central processor memory; Step S7.2: traverse each triangle of the three-dimensional model and the vertex data on the triangle, set the irradiance value corresponding to the vertex blocked by other triangles to zero, and set the vertex not blocked by other triangles to the value corresponding to the vertex texture; Step S7.3: Save the final irradiance values of all triangular facets on the three-dimensional model into a file.
8. The method for real-time mapping of a three-dimensional model by a laser beam according to claim 7, characterized in that: The light source texture image is read from the graphics processor memory to the system central processor memory, and the specific steps include: Step S7.1.1: Project any vertex A of the triangle into the light source space coordinate system to obtain a two-dimensional coordinate A' and a depth value d; Step S7.1.2: Compare the value range of A' with the resolution of the light source texture. If the value range of A' is greater than the resolution of the light source texture, discard vertex A; otherwise, do not discard vertex A. Step S7.1.3: Obtain the distance value c between vertex A and the nearest point on the model according to the illumination data result; Step S7.1.4: Determine whether the face normal of the triangle where vertex A is located is on the same side as the light source direction. If so, discard vertex A; otherwise, do not discard vertex A. Step S7.1.5: Determine whether the absolute value of the difference between the distance value c and the depth value d is less than or equal to a second threshold value. If so, retain vertex A; if not, discard vertex A.
9. The method for real-time mapping of a three-dimensional model by a laser beam according to claim 1, characterized in that: The laser beam includes multiple laser beams or a single laser beam. When multiple laser beams are used, multiple light source texture images and corresponding multiple fragment shader variable values are established and calculated separately in the graphics processor; when a single laser beam is used, a single light source texture image is established.
10. A device for real-time mapping of a three-dimensional model by a laser beam, characterized in that: It includes a 3D model reading unit, a 3D model irradiation unit, a lighting data rendering unit, a light source texture image mapping unit, a triangle patch cutting unit, a triangle patch information restoration mapping unit, and a triangle patch information storage unit, and each unit is connected in sequence; The 3D model reading unit is used to read the 3D model using the 3D model reading and writing plug-in; The three-dimensional model irradiation unit is used to establish a beam source data structure, and in the light source space coordinate system, use a parallel surface light source to simulate a laser beam to irradiate the three-dimensional model to obtain illumination data; The illumination data rendering unit is used to render the illumination data into the graphics card memory to obtain a light source texture image; The light source texture image mapping unit is used to restore the light source texture image to the world coordinate system and map it to the surface of the three-dimensional model to obtain the irradiance intensity result on the triangular facet, and the triangular facet is located on the surface of the three-dimensional model; The triangle patch cutting unit is used to cut the blocked triangle patches in the three-dimensional model and obtain the irradiance intensity result on the cut triangle patches; The triangle patch information restoration and mapping unit is used to restore and map the irradiance intensity result on the clipped triangle patch to the three-dimensional model in the world coordinate system to obtain the final irradiance value of the triangle patch on the three-dimensional model; The triangle patch information storage unit is used to output and store the final irradiance value of all triangle patches on the three-dimensional model, wherein the final irradiance value includes the components, vertices, normal information of the triangle patches of the irradiated three-dimensional model and the irradiance intensity distribution information on the triangle patches.
Citation Information
Patent Citations
Stripe projection three-dimensional measurement system based on bundle adjustment principle and calibration method thereof
CN102654391A
Method for 3D information acquisition based on fusion of optical scanning and smart vision
WO2022078442A1