STL (Standard Template Library) model lightweight method based on OpenGL rendering visual judgment
Through the rendering visual determination method based on OpenGL, the spatial visual calculation of the three-dimensional model is converted into graphic rendering calculation, which solves the problem of model distortion and high programming complexity in the lightweight processing of 3-dimensional model STL files, and achieves efficient and accurate lightweight processing effects.
Patent Information
- Application Number
- CN202411897782.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-23
- Publication Date
- 2025-04-25
AI Technical Summary
In the lightweight processing of three-dimensional model STL files, the prior art is prone to model distortion, high programming complexity, large calculation tasks, and cannot be effectively applied to model lightweight reduction of mechanical parts.
The rendering visual determination method based on OpenGL is adopted to convert the spatial visual calculation of the three-dimensional model into graphic rendering calculation, and parallel rasterization calculation is performed using GPU to simplify programming logic and improve computing efficiency.
It realizes lightweight processing of three-dimensional model STL files, maintains the accuracy of the patch, reduces programming complexity and calculation tasks, and improves computing efficiency and algorithm encapsulation.
Smart Images

Figure CN119888034A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the technical field of STL model lightweighting, and specifically relates to an STL model lightweighting method based on OpenGL rendering visualization judgment. Background Art
[0002] The lightweight method in relative technology is mainly based on the optimization of visualization angle, using technologies such as visual cone to identify and remove invisible faces inside the model, thereby reducing the number of faces. However, the face reduction method based on topology is prone to model distortion, and the reduction method based on visual cone requires ray tracing to calculate the ray intersection of the model faces, which increases the programming complexity and the amount of calculation tasks. The large-scale object reduction method based on GPU is too simplified for the overall model and cannot be applied to the lightweight reduction of mechanical parts.
[0003] To this end, while maintaining the fineness of the STL model facets, the present invention starts from the perspective of GPU image rendering calculation, converts traditional spatial visualization calculations into calculations based on graphics rendering, so as to simplify the complexity of programming calculations and transfer complex operations to GPU calculations, thereby greatly reducing the difficulty of programming while improving calculation efficiency. Summary of the invention
[0004] Purpose of the invention: To provide a lightweight algorithm for visibility-based facet reduction of three-dimensional model STL files, so as to solve the problems of complex algorithm logic of traditional three-dimensional model space visualization judgment algorithm and distortion caused by transition simplification of model faces, and to achieve overall algorithm simplification and good encapsulation through GPU-based image space rendering calculation.
[0005] The present application provides a method for lightweighting an STL model based on OpenGL rendering visualization judgment, the method comprising:
[0006] Step 1: For the three-dimensional model, first give the visual judgment perspective and obtain its spatial size;
[0007] Step 2: Configure the rendering of the 3D model in OpenGL;
[0008] Step 3: For the STL file of the three-dimensional model, specify a unique index i for each face in a specified order, and then convert i into RGB color based on a preset rule;
[0009] Step 4: For each facet, set the color to RGB based on i conversion and render the 3D model STL file;
[0010] Step 5: After the model is rendered, read its color cache;
[0011] Step 6: For all pixels in the color buffer, parse the stored color RGB to obtain an index number i=R×256×256+G×256+B, and mark the face with index number i in the three-dimensional model;
[0012] Step 7, calculating for multiple viewing angles according to steps 2 to 6;
[0013] Step 8: Delete all unmarked faces of the 3D model to obtain a lightweight STL file.
[0014] Preferably, the preset rule is as follows: R=INT(i / (256×256)), G=MOD(INT(i / 256) / 256), B=MOD(i / 256); wherein INT() is integer rounding, and MOD() is remainder finding.
[0015] Preferably, step 2 comprises:
[0016] The viewing volume completely contains the 3D model; the viewport is set to the visualization determination direction; the projection mode uses orthogonal projection; the depth test uses minimum pass, which is the default mode.
[0017] Preferably, step 2 comprises:
[0018] glOrtho() sets the viewing volume in orthographic view mode, gluLookAt(0,0,0,1,0,0,0,0,1) sets the viewport along the x direction and the z direction upward, glEnable(GL_DEPTH_TEST) turns on depth testing, glDepthFunc(GL_LESS) is set to the default mode of minimum pass; glViewport() sets the pixel size of the rendered viewport; glClear(1.0) clears the cache.
[0019] Preferably, step 4 comprises:
[0020] Set the color of each face using glColor(color);
[0021] Then in glEnbale(GL_TRIANGLES) mode, set the three vertices of the triangle patch through glVertex().
[0022] Preferably, step 5 comprises:
[0023] After all the facets are input, the rendering is triggered by the glFlush() function. After the rendering is completed, the color cache of the current rendering result is read by glReadPixels(), and the result is an image with the same number of pixels as the viewport.
[0024] Preferably, step 6 comprises:
[0025] For all pixels in the color buffer, traverse and analyze the color of each pixel, its index number index = R × 256 × 256 + G × 256 + B;
[0026] Then mark the index-th face in the 3D model STL file as visible.
[0027] Preferably, the step 7 comprises:
[0028] The visibility of all faces of the 3D model is determined and calculated from multiple perspectives. Finally, all unmarked faces in the STL file are deleted, and only marked visible faces are retained, thereby obtaining a lightweight STL file.
[0029] This application has the following technical effects:
[0030] The present invention no longer uses the traditional visualization calculation of three-dimensional space model patches, avoids the complex calculation logic design of ray tracing / intersection for patch models, and reduces the workload of algorithm development;
[0031] The visualization computing method of the present invention is based on image rendering calculation and is organized based on standard OpenGL function operations. It utilizes the inherent computing logic of the GPU image rendering pipeline to complete operations such as ray tracing intersection calculation and intersection point sorting. The function algorithm organization design based on OpenGL is simple and easy to encapsulate and promote for application.
[0032] The present invention does not reduce the topological structure of the model facets, maintains the accuracy of the facets, and only removes them from the perspective of visibility;
[0033] The computational essence of the present invention utilizes the parallel rasterization computation of the GPU, and compared with the traditional serial interference computation, the computational efficiency is higher and the algorithm execution robustness is good. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] Figure 1 It is a schematic diagram of the calculation principle of the present invention;
[0035] Figure 2 It is a schematic diagram of the calculation flow of the present invention. DETAILED DESCRIPTION
[0036] The present invention converts the traditional STL model reduction calculation based on three-dimensional space visibility into the visualization rendering calculation in the image space, while maintaining the undistorted reduction of the model STL facets, avoiding the complex programming of the three-dimensional space visualization calculation, etc., and realizes the graphics rendering through the GPU through the OpenGL standard function, which improves the calculation efficiency and facilitates the encapsulation of the algorithm. The specific technical effects and advantages are as follows:
[0037] (A) The present invention no longer uses the traditional visualization calculation of three-dimensional space model patches, avoids the complex calculation logic design of ray tracing / intersection for patch models, and reduces the workload of algorithm development;
[0038] (B) The visualization computing method of the present invention is based on image rendering calculation and is organized based on standard OpenGL function operations. It utilizes the inherent computing logic of the GPU image rendering pipeline to complete functions such as ray tracing intersection calculation and intersection sorting. The function algorithm organization design based on OpenGL is simple and easy to encapsulate and promote for application.
[0039] (C) The present invention does not reduce the topological structure of the model facets, maintains the accuracy of the facets, and only removes them from the perspective of visibility;
[0040] (D) The computational nature of the present invention utilizes the parallel rasterization computation of the GPU. Compared with the traditional serial interference computation, the computational efficiency is higher and the algorithm execution robustness is good.
[0041] See also Figure 1-Figure 2 , the present invention adopts the following technical solution:
[0042] The OpenGL general library function is used to prepare the rendering of the orthogonal view for the STL file of the three-dimensional model; then, the visualization judgment of each face along the viewport direction is converted into the default depth test in OpenGL rendering, and is calculated in parallel in the rasterization stage; in this implicit calculation process, each triangle face is uniquely numbered and converted into a color index and compressed into the implicit calculation process; after the rendering is completed, the color cache is read and the triangle face number is parsed for each relative color index, thereby determining the triangle faces visible in the current viewport; further, the lightweight of the three-dimensional model STL model is achieved by eliminating invisible faces.
[0043] The present application provides a method for lightweighting an STL model based on OpenGL rendering visualization judgment, comprising the following steps:
[0044] (1) For the 3D model, firstly, the visual judgment perspective is given and its spatial size is obtained;
[0045] (2) For the rendering of the 3D model, the following configurations are made in OpenGL: the viewing volume completely contains the 3D model; the viewport is set to the visualization determination direction; the projection mode uses orthogonal projection; the depth test uses the minimum pass, i.e. the default mode;
[0046] (3) For the STL file of the 3D model, specify the order of traversal of the unique index i for each face, and then convert i into RGB color according to the following rules: R = INT(i / (256×256)), G = MOD(INT(i / 256) / 256), B = MOD(i / 256), where INT() is rounding and MOD() is remainder;
[0047] (4) For each facet, the color is set to RGB based on i conversion, and the 3D model STL file is rendered;
[0048] (5) After the model is rendered, read its color cache;
[0049] (6) For all pixels in the color buffer, parse the stored color RGB to obtain an index number i=R×256×256+G×256+B, and mark the face with index number i in the 3D model;
[0050] (7) performing calculations for multiple viewing angles according to steps (2) to (6);
[0051] (8) All unmarked faces of the 3D model are deleted to obtain a lightweight STL file.
[0052] It should be noted that:
[0053] (A) Patch reduction algorithm based on OpenGL visualization
[0054] The present invention relates to a lightweight processing method for three-dimensional model STL files, the core of which is to use OpenGL rendering technology and color index to achieve visual judgment and lightweight processing of facets. Compared with traditional visual judgment algorithms, this algorithm has the following significant features:
[0055] The OpenGL general library function is used to render the view, avoiding the complex logical processing of traditional algorithms.
[0056] The patch visibility is implicitly calculated through color index, which simplifies the algorithm and makes it encapsulable.
[0057] (B) Rendering and color conversion of patch processing
[0058] This method includes the following key steps:
[0059] Use OpenGL to configure the viewing angle and rendering conditions, and traverse each face in the STL file.
[0060] The unique index of the patch is converted into RGB color, and the color index is used as the basis for patch compression and decompression, realizing visual judgment and lightweight processing of the patch.
[0061] (C) Multi-view computing and lightweight processing based on OpenGL
[0062] In addition to processing from a single perspective, the present invention also covers the visibility determination of all facets from multiple perspectives based on OpenGL, and finally realizes lightweight processing of STL files. Through the flexibility and efficiency of OpenGL, the facets that are not marked as visible are successfully deleted, and only the visible parts are retained, thereby obtaining a lightweight STL file.
[0063] The above description emphasizes that the present invention fully utilizes the OpenGL rendering technology in the entire processing flow, and uses this as the core to implement the methods of facet processing, visualization determination and lightweight processing.
[0064] In other embodiments of the present application, Figure 1 The STL file of the three-dimensional model shown is used as the object for implementation:
[0065] (1) For the three-dimensional model, it is set to perform visualization judgment along the x direction;
[0066] (2) For the 3D model, OpenGL rendering configuration is performed as follows: glOrtho() sets the view volume in orthographic view mode, gluLookAt(0,0,0,1,0,0,0,0,1) sets the viewport along the x direction and the z direction upward, glEnable(GL_DEPTH_TEST) turns on the depth test, and glDepthFunc(GL_LESS) is set to the default mode of minimum pass; glViewport() sets the pixel size of the rendered viewport; glClear(1.0) clears the cache;
[0067] (3) For the STL file of the 3D model, traverse each face in the order in which the file is read, and the traversal sequence number is the index number of each face. Convert index to RGB color color = (INT (i / (256×256)), MOD (INT (i / 256) / 256), B = MOD (i / 256)), where INT () is rounding and MOD () is remainder;
[0068] (4) For the STL file of the 3D model, all the faces are traversed and rendered. Specifically, the color of each face is set using glColor(color), and then the three vertices of the triangle face are set using glVertex() in the glEnable(GL_TRIANGLES) mode.
[0069] (5) After all the facets are input, the rendering is triggered by the glFlush() function. After the rendering is completed, the color cache of the current rendering result is read by glReadPixels(). The result is an image with the same number of pixels as the viewport.
[0070] (6) Traverse all pixels in the color buffer, parse the color of each pixel and find its index number index = R × 256 × 256 + G × 256 + B, and then mark the index-th face in the 3D model STL file as visible;
[0071] (7) The visibility of all faces of the three-dimensional model is determined and calculated from multiple perspectives. Finally, all unmarked faces in the STL file are deleted, and only the marked visible faces are retained, thereby obtaining a lightweight STL file.
Claims
1. A lightweight STL model method based on OpenGL rendering visualization judgment, characterized in that: The method comprises: Step 1: For the three-dimensional model, first give the visual judgment perspective and obtain its spatial size; Step 2: Configure the rendering of the 3D model in OpenGL; Step 3: For the STL file of the three-dimensional model, specify a unique index i for each face in a specified order, and then convert i into RGB color based on a preset rule; Step 4: For each facet, set the color to RGB based on i conversion and render the 3D model STL file; Step 5: After the model is rendered, read its color cache; Step 6: For all pixels in the color buffer, parse the stored color RGB to obtain an index number i=R×256×256+G×256+B, and mark the face with index number i in the three-dimensional model; Step 7, calculating for multiple viewing angles according to steps 2 to 6; Step 8: Delete all unmarked faces of the 3D model to obtain a lightweight STL file.
2. The method according to claim 1, characterized in that The preset rule is as follows: R=INT(i / (256×256)), G=MOD(INT(i / 256) / 256), B=MOD(i / 256); wherein INT() is for rounding, and MOD() is for finding the remainder.
3. The method according to claim 1, characterized in that The step 2 comprises: The viewing volume completely contains the 3D model; the viewport is set to the visualization determination direction; the projection mode uses orthogonal projection; the depth test uses minimum pass, which is the default mode.
4. The method according to claim 1, characterized in that: The step 2 comprises: glOrtho() sets the viewing volume in orthographic view mode, gluLookAt(0,0,0,1,0,0,0,0,1) sets the viewport along the x direction and the z direction upward, glEnable(GL_DEPTH_TEST) turns on depth testing, glDepthFunc(GL_LESS) is set to the default mode of minimum pass; glViewport() sets the pixel size of the rendered viewport; glClear(1.0) clears the cache.
5. The method according to claim 4, characterized in that The step 4 comprises: Set the color of each face using glColor(color); Then, in glEnbale(GL_TRIANGLES) mode, set the three vertices of the triangle patch through glVertex().
6. The method according to claim 5, characterized in that The step 5 comprises: After all the facets are input, the rendering is triggered by the glFlush() function. After the rendering is completed, the color cache of the current rendering result is read by glReadPixels(), and the result is an image with the same number of pixels as the viewport.
7. The method according to claim 6, characterized in that The step 6 comprises: For all pixels in the color buffer, traverse and analyze the color of each pixel, its index number index = R × 256 × 256 + G × 256 + B; Then mark the index-th face in the 3D model STL file as visible.
8. The method according to claim 7, characterized in that The step 7 comprises: The visibility of all faces of the 3D model is determined and calculated from multiple perspectives. Finally, all unmarked faces in the STL file are deleted, and only marked visible faces are retained, thereby obtaining a lightweight STL file.