OpenGL (Open Graphics Library) three-dimensional simulation-based method for quickly selecting contour in laser pipe cutting
By defining the pre -selection in the OpenGL three -dimensional scene, combined with OpenGL's selection and rendering mode, the problem of slow selection and slow selection in the existing technology, and the rapid selection of the contour of the pipe.
Patent Information
- Application Number
- CN202411442319.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-16
- Publication Date
- 2025-01-28
AI Technical Summary
The existing OpenGL-based primitive picking and selection methods are slow when there are a large number of primitives in the scene, especially when each point and edge need to be independently selected, resulting in the program being stuck when the user clicks to select.
By defining a circle or square area, the mouse clicks is centered, determining whether each outline on the pipe is located in the area, first select the options, and then enter the options of OpenGL The pattern determines the actual outline.
Effectively improved the outline of the pipelines during the three -dimensional simulation process of the laser tube, avoiding the problem of the program card due to the slow selection speed.
Smart Images

Figure CN119379726A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of numerical control machining, and in particular relates to a method for quickly selecting contours for laser tube cutting based on OpenGL three-dimensional simulation. Background Art
[0002] OpenGL provides a Picking mechanism for picking and selecting primitives. When the user clicks the mouse, the view volume A in the area set at the click position can be obtained. After entering the selection mode, the name stack is used to draw the primitives, and then the API interface function glRenderMode is called to enter the GL_RENDER rendering drawing mode. The name and Zbuffer depth information of the primitives drawn in the view volume A can be obtained. The primitive selected by the user can be obtained according to the name, and the information such as whether the primitive is covered by other primitives can be obtained according to the Zbuffer. Developers can change the properties of the selected primitive based on this information to respond to the user's click event. The Picking mechanism is perfect, but it is not without shortcomings. One of the biggest flaws is the slow speed, especially when there are a large number of primitives in the scene, and each point and edge in the primitive must be able to be selected independently. In this case, if the user clicks the mouse to make a selection, the program will inevitably freeze.
[0003] Patent number "CN201910829623.2" discloses a method and system for drawing primitives based on OpenGL ES2.0. By setting a shader management class that stores multiple preset shader source code strings, the process of drawing primitives using OpenGL ES2.0 is simplified. At the same time, the required shaders can be customized without frequently modifying the shader source code strings, which can facilitate customized drawing. However, the above-mentioned problems still exist in the process of picking and selecting primitives. Summary of the invention
[0004] The purpose of the present invention is to provide a method for quickly selecting contours of laser tube cutting based on OpenGL three-dimensional simulation, which can greatly improve the speed of picking and selecting primitives on the tube and realize the rapid selection of the tube contour.
[0005] In order to achieve the above-mentioned invention object, the technical solution adopted by the present invention is as follows:
[0006] A method for quickly selecting contours for laser tube cutting based on OpenGL three-dimensional simulation, when there is a tube including several contours in the OpenGL three-dimensional scene, the method comprises the following steps:
[0007] S1. Click the mouse at any position in the three-dimensional scene;
[0008] S2. Define the radius of the circle or the side length of the square, use the mouse click position as the center of the circle or square, and select a circular or square area according to the defined radius or side length;
[0009] S3. Determine whether each contour on the pipe is completely or partially located in the area; if so, determine that the contour has passed the pre-selection and proceed to step S4; if not, determine that the contour has not passed the pre-selection and turn to end;
[0010] S4. Enter the selection mode of OpenGL, draw all the contours that have passed the pre-selection, and then enter the rendering mode of OpenGL, determine the successfully drawn contours as having passed the re-selection, and record the number and information of the contours that have passed the re-selection, and analyze and determine the contours actually selected by the mouse.
[0011] First, determine whether the tube contour passes the pre-selection, then draw all the pre-selected contours, then enter the rendering mode to determine the contours that pass the re-selection, and finally combine the number and information of the recorded contours to analyze and determine the contour actually selected by the mouse. This method can effectively improve the speed of tube contour selection in the laser tube cutting 3D simulation process.
[0012] Preferably, the method is applied to the contour selection process of a tube in laser tube cutting, the tube includes a plurality of contours located at different positions on the tube, each of the contours includes a plurality of line segments, and each of the line segments is connected by two endpoints.
[0013] Preferably, the step S3 comprises: in each contour, determining a number of line segments included therein one by one.
[0014] Preferably, assuming that the pipe includes n contours, recorded as contours O1 to On; assuming that contour O1 includes x line segments, recorded as line segments L1 to Lx; assuming that line segment L1 is formed by connecting two endpoints P1 and P2, then step S3 includes:
[0015] S3.1.1. Start to determine whether there is a point on the first line segment L1 in the contour O1 located in the region: transform the coordinates of the endpoint P1 of the first line segment L1 to obtain the screen coordinates of P1; determine whether the screen coordinates of P1 are located in the region; if so, determine that the contour O1 passes the pre-selection; if not, proceed to step S3.1.2;
[0016] S3.1.2. Perform coordinate transformation on the endpoint P2 of the first line segment L1 to obtain the screen coordinates of P2; determine whether the screen coordinates of P2 are within the region; if so, determine that the contour O1 passes the preselection; if not, proceed to step S3.1.3;
[0017] S3.1.3. Take the points between P1 and P2 on the first line segment L1 as P3~Pm, transform the coordinates of P3~Pm one by one and determine whether the screen coordinates are within the area; if so, determine that the contour O1 passes the pre-selection; if not, start to determine whether there is a point on the second line segment L2 in the contour O1 located in the area; if so, determine that the contour O1 passes the pre-selection; if not, start to determine whether there is a point on the third line segment L3 in the contour O1 located in the area, until the contour O1 passes the pre-selection; if the contour O1 still fails to pass the pre-selection after determining x line segments of the contour O1, determine that the contour O1 fails to pass the pre-selection and end.
[0018] Preferably, in step S3, after determining whether the first contour O1 on the pipe is completely or partially located in the area, it is determined whether the second contour O2 on the pipe is completely or partially located in the area, until the nth pipe On is determined, and the contours O1 to On enter step S4 through the pre-selected partial contours.
[0019] Preferably, the step S3.1.1 comprises:
[0020] S3.1.1.1.OpenGL pre-calculates the 4*4 projection matrix M after the tube is transformed by projection projection ; OpenGL pre-calculates the 4*4 view matrix M after the pipe is transformed by the view view ; OpenGL pre-calculates the 4*4 model matrix M after the pipe is transformed by the model model ;
[0021] S3.1.1.2. Set the three-dimensional model coordinates (x i ,y i ,z i ) is converted to four-dimensional coordinates V model =(x i ,y i ,z i ,1);
[0022] S3.1.1.3. V model Convert to another four-dimensional coordinate V 0 : Calculate V 0 =M projection *M view *M model *V model ; Get V 0 The x-axis coordinate x 0 , y-axis coordinate y 0 , z-axis coordinate z 0 And the distance component w, denoted as V 0 =(x 0 ,y0 ,z 0 ,w);
[0023] S3.1.1.4. V 0 The x-axis coordinate x 0 Divide by the distance component w to get x 1 , V 0 The y-axis coordinate y 0 Divide by the distance component w to get y 1 , then x 1 and 1 Composition V 0 The corresponding two-dimensional coordinate point V 1 , denoted as V 1 =(x 1 ,y 1 );
[0024] S3.1.1.5. For the two-dimensional coordinate V 1 Perform viewport transformation to obtain the screen coordinate V of the corresponding endpoint P1 2 =(x 2 ,y 2 ).
[0025] Preferably, the step S3.1.1.5 comprises:
[0026] S3.1.1.5.1. Call the function through the OpenGL viewport matrix Glint viewport[4]
[0027] glGetIntegerv(GL_VIEWPORT,viewport) gets the first value of the array viewport[0], the second value viewport[1], the third value viewport[2], and the fourth value viewport[3];
[0028] S3.1.1.5.2. Calculate the screen coordinate V of endpoint P1 2 as follows:
[0029]
[0030] Preferably, the step S4 further comprises:
[0031] S4.1. Enter the OpenGL selection mode, call the gluPickMatrix function, and obtain the selection matrix Mpick;
[0032] S4.2. Calculate the drawing matrix as follows:
[0033] Plotting the matrix M draw =M pick *M projection;
[0034] S4.3. By plotting the matrix M draw , draw in selection mode for all pre-selected contours.
[0035] Preferably, the step S4 further comprises:
[0036] S4.4. Enter the rendering mode of OpenGL, call the API interface function glRenderMode, determine the successfully drawn contours among all the contours drawn in step S4.3 as having passed the reselection, and record the number and information of the contours that have passed the reselection, and analyze and determine the contours that are actually selected by the mouse.
[0037] Preferably, the method for fast contour selection in laser tube cutting based on OpenGL three-dimensional simulation is applied to an industrial computer of a laser cutting system; the industrial computer includes a CPU and a GPU; step S3 is implemented by the CPU; and step S4 is implemented by the GPU.
[0038] Beneficial effects:
[0039] The invention discloses a method for quickly selecting contours for laser tube cutting based on OpenGL three-dimensional simulation. The method implements the coordinate transformation function of points on the tube and the position judgment of the transformed screen coordinates through the CPU of the industrial computer to determine whether the contour passes the pre-selection. Then, the GPU of the industrial computer draws all the contours that pass the pre-selection, enters the rendering mode to determine the contours that pass the re-selection, and finally analyzes and judges the contours actually selected by the mouse in combination with the number and information of the recorded contours. The invention utilizes the high-speed logic processing advantage of the CPU to enable the method used to effectively improve the selection speed of the tube contour. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 The figure shows a general flow chart of a method for quickly selecting contours for laser tube cutting based on OpenGL three-dimensional simulation in this embodiment;
[0041] Figure 2 Shown Figure 1 The first sub-flowchart of;
[0042] Figure 3 Shown Figure 1 The second sub-flowchart;
[0043] Figure 4 Shown Figure 1 The third sub-flowchart of . DETAILED DESCRIPTION
[0044] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the specific implementation methods of the present invention will be described below with reference to the accompanying drawings. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings and other implementation methods can be obtained based on these drawings without creative work.
[0045] The technical solution of the present invention is described in detail below with specific embodiments.
[0046] Example
[0047] like Figures 1 to 4 As shown, a method for quickly selecting contours for laser tube cutting based on OpenGL three-dimensional simulation in this embodiment, when there is a tube including several contours in the three-dimensional scene of OpenGL, the method comprises the following steps:
[0048] S1. Click the mouse at any position in the three-dimensional scene;
[0049] S2. Define the radius of the circle or the side length of the square, use the mouse click position as the center of the circle or square, and select a circular or square area according to the defined radius or side length;
[0050] S3. Determine whether each contour on the pipe is completely or partially located in the area; if so, determine that the contour has passed the pre-selection and proceed to step S4; if not, determine that the contour has not passed the pre-selection and turn to end;
[0051] S4. Enter the selection mode of OpenGL, draw all the contours that have passed the pre-selection, and then enter the rendering mode of OpenGL, determine the successfully drawn contours as having passed the re-selection, and record the number and information of the contours that have passed the re-selection, and analyze and determine the contours actually selected by the mouse.
[0052] The present embodiment provides a method for quickly selecting contours for laser tube cutting based on OpenGL 3D simulation. First, it is determined whether the tube contour passes the pre-selection, then all the contours that pass the pre-selection are drawn, and then the rendering mode is entered to determine the contours that pass the re-selection. Finally, the contour actually selected by the mouse is analyzed and determined based on the number and information of the recorded contours. This method can effectively improve the speed of selecting the tube contour in the 3D simulation process of laser tube cutting.
[0053] Preferably, the method is applied to the contour selection process of a tube in laser tube cutting, the tube includes a plurality of contours located at different positions on the tube, each of the contours includes a plurality of line segments, and each of the line segments is connected by two endpoints.
[0054] Preferably, the step S3 comprises: in each contour, determining a number of line segments included therein one by one.
[0055] Preferably, assuming that the pipe includes n contours, recorded as contours O1 to On; assuming that contour O1 includes x line segments, recorded as line segments L1 to Lx; assuming that line segment L1 is formed by connecting two endpoints P1 and P2, then step S3 includes:
[0056] S3.1.1. Start to determine whether there is a point on the first line segment L1 in the contour O1 located in the region: transform the coordinates of the endpoint P1 of the first line segment L1 to obtain the screen coordinates of P1; determine whether the screen coordinates of P1 are located in the region; if so, determine that the contour O1 passes the pre-selection; if not, proceed to step S3.1.2;
[0057] S3.1.2. Perform coordinate transformation on the endpoint P2 of the first line segment L1 to obtain the screen coordinates of P2; determine whether the screen coordinates of P2 are within the region; if so, determine that the contour O1 passes the preselection; if not, proceed to step S3.1.3;
[0058] S3.1.3. Take the points between P1 and P2 on the first line segment L1 as P3~Pm, transform the coordinates of P3~Pm one by one and determine whether the screen coordinates are within the area; if so, determine that the contour O1 passes the pre-selection; if not, start to determine whether there is a point on the second line segment L2 in the contour O1 located in the area; if so, determine that the contour O1 passes the pre-selection; if not, start to determine whether there is a point on the third line segment L3 in the contour O1 located in the area, until the contour O1 passes the pre-selection; if the contour O1 still fails to pass the pre-selection after determining x line segments of the contour O1, determine that the contour O1 fails to pass the pre-selection and end.
[0059] Preferably, in step S3, after determining whether the first contour O1 on the pipe is completely or partially located in the area, it is determined whether the second contour O2 on the pipe is completely or partially located in the area, until the nth pipe On is determined, and the contours O1 to On enter step S4 through the pre-selected partial contours.
[0060] Preferably, the step S3.1.1 comprises:
[0061] S3.1.1.1.OpenGL pre-calculates the 4*4 projection matrix M after the tube is transformed by projection projection ; OpenGL pre-calculates the 4*4 view matrix M after the pipe is transformed by the view view ; OpenGL pre-calculates the 4*4 model matrix M after the pipe is transformed by the model model ;
[0062] S3.1.1.2. Set the three-dimensional model coordinates (x i ,y i ,z i ) is converted to four-dimensional coordinates V model =(x i ,y i ,z i ,1);
[0063] S3.1.1.3. V model Convert to another four-dimensional coordinate V 0 : Calculate V 0 =M projection *M view *M model *V model ; Get V 0 The x-axis coordinate x 0 , y-axis coordinate y 0 , z-axis coordinate z 0 And the distance component w, denoted as V 0 =(x 0 ,y 0 ,z 0 ,w);
[0064] S3.1.1.4. V 0 The x-axis coordinate x 0 Divide by the distance component w to get x 1 , V 0 The y-axis coordinate y 0 Divide by the distance component w to get y 1 , then x 1 and 1 Composition V 0 The corresponding two-dimensional coordinate point V 1 , denoted as V 1 =(x 1 ,y 1 );
[0065] S3.1.1.5. For the two-dimensional coordinate V 1 Perform viewport transformation to obtain the screen coordinate V of the corresponding endpoint P1 2 =(x 2 ,y 2 ).
[0066] Preferably, the step S3.1.1.5 comprises:
[0067] S3.1.1.5.1. Call the function through the OpenGL viewport matrix Glint viewport[4]
[0068] glGetIntegerv(GL_VIEWPORT,viewport) gets the first value of the array viewport[0], the second value viewport[1], the third value viewport[2], and the fourth value viewport[3];
[0069] S3.1.1.5.2. Calculate the screen coordinate V of endpoint P1 2 as follows:
[0070]
[0071] Preferably, the step S4 further comprises:
[0072] S4.1. Enter OpenGL selection mode and call gluPickMatrix function to obtain the selection matrix M pick ;
[0073] S4.2. Calculate the drawing matrix as follows:
[0074] Plotting the matrix M draw =M pick *M projection ;
[0075] S4.3. By plotting the matrix M draw , draw in selection mode for all pre-selected contours.
[0076] Preferably, the step S4 further comprises:
[0077] S4.4. Enter the rendering mode of OpenGL, call the API interface function glRenderMode, determine the successfully drawn contours among all the contours drawn in step S4.3 as having passed the reselection, and record the number and information of the contours that have passed the reselection, and analyze and determine the contours that are actually selected by the mouse.
[0078] Preferably, the method for fast contour selection in laser tube cutting based on OpenGL three-dimensional simulation is applied to an industrial computer of a laser cutting system; the industrial computer includes a CPU and a GPU; step S3 is implemented by the CPU; and step S4 is implemented by the GPU.
[0079] Specifically, the CPU configuration of this embodiment is Intel i3-10100 3.60 GHz 3.60 GHz; the CPU of this embodiment runs on an industrial computer with 4 GB of running memory.
[0080] Specifically, the above Picking mechanism, function glGetIntegerv(GL_VIEWPORT, viewport), and function gluPickMatrix are all common functions of OpenGL.
[0081] The method of quickly selecting contours for laser tube cutting based on OpenGL three-dimensional simulation in this embodiment uses the CPU of the industrial computer to implement the coordinate transformation function of the points on the tube and the position judgment of the transformed screen coordinates to determine whether the contour has passed the pre-selection; then the GPU of the industrial computer draws all the contours that have passed the pre-selection, enters the rendering mode to determine the contours that have passed the re-selection, and finally combines the number and information of the recorded contours to analyze and judge the contour actually selected by the mouse. The present invention uses the high-speed logic processing advantage of the CPU to enable the method used to effectively improve the selection speed of the tube contour.
[0082] The above is a detailed description of an embodiment of a method for quickly selecting contours for laser tube cutting based on OpenGL three-dimensional simulation provided by the present invention. This article uses specific examples to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the core idea of the present invention. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present invention, the present invention can also be improved and modified, and these improvements and modifications also fall within the scope of protection of the claims of the present invention.
Claims
1. A method for quickly selecting contours for laser tube cutting based on OpenGL three-dimensional simulation, characterized in that: When there is a pipe including several outlines in the OpenGL three-dimensional scene, the method comprises the following steps: S1. Click the mouse at any position in the three-dimensional scene; S2. Define the radius of the circle or the side length of the square, use the mouse click position as the center of the circle or square, and select a circular or square area according to the defined radius or side length; S3. Determine whether each contour on the pipe is completely or partially located in the area; if so, determine that the contour has passed the pre-selection and proceed to step S4; if not, determine that the contour has not passed the pre-selection and turn to end; S4. Enter the selection mode of OpenGL, draw all the contours that have passed the pre-selection, and then enter the rendering mode of OpenGL, determine the successfully drawn contours as having passed the re-selection, and record the number and information of the contours that have passed the re-selection, and analyze and determine the contours actually selected by the mouse.
2. The method according to claim 1, characterized in that The method is applied to the contour selection process of a tube in laser tube cutting. The tube includes a plurality of contours located at different positions on the tube, each of the contours includes a plurality of line segments, and each of the line segments is connected by two endpoints.
3. The method according to claim 2, characterized in that The step S3 includes: in each contour, determining the number of line segments included therein one by one.
4. The method according to claim 3, characterized in that Assume that the pipe includes n contours, which are recorded as contours O1 to On; Assume that contour O1 includes x line segments, which are recorded as line segments L1 to Lx; Assume that line segment L1 is formed by connecting two endpoints P1 and P2, then step S3 includes: S3.1.
1. Start to determine whether there is a point on the first line segment L1 in the contour O1 located in the region: transform the coordinates of the endpoint P1 of the first line segment L1 to obtain the screen coordinates of P1; determine whether the screen coordinates of P1 are located in the region; if so, determine that the contour O1 passes the pre-selection; if not, proceed to step S3.1.2; S3.1.
2. Perform coordinate transformation on the endpoint P2 of the first line segment L1 to obtain the screen coordinates of P2; determine whether the screen coordinates of P2 are within the region; if so, determine that the contour O1 passes the preselection; if not, proceed to step S3.1.3; S3.1.
3. Take the points between P1 and P2 on the first line segment L1 as P3~Pm, transform the coordinates of P3~Pm one by one and determine whether the screen coordinates are within the area; if so, determine that the contour O1 passes the pre-selection; if not, start to determine whether there is a point on the second line segment L2 in the contour O1 located in the area; if so, determine that the contour O1 passes the pre-selection; if not, start to determine whether there is a point on the third line segment L3 in the contour O1 located in the area, until the contour O1 passes the pre-selection; if the contour O1 still fails to pass the pre-selection after determining x line segments of the contour O1, determine that the contour O1 fails to pass the pre-selection and end.
5. The method according to claim 4, characterized in that In the step S3, after determining whether the first contour O1 on the pipe is completely or partially located in the area, it is determined whether the second contour O2 on the pipe is completely or partially located in the area, until the nth pipe On is determined, and the contours O1 to On enter step S4 through the pre-selected partial contours.
6. The method according to claim 5, characterized in that The step S3.1.1 comprises: S3.1.1.1.OpenGL pre-calculates the 4*4 projection matrix M after the tube is transformed by projection projection ; OpenGL pre-calculates the 4*4 view matrix M after the pipe is transformed by the view view ; OpenGL pre-calculates the 4*4 model matrix M after the pipe is transformed by the model model ; S3.1.1.
2. Set the three-dimensional model coordinates (x i ,y i ,z i ) is converted to four-dimensional coordinates V model =(x i ,y i ,z i ,1); S3.1.1.
3. V model Convert to another four-dimensional coordinate V0: calculate V0 = M projection *M view *M model *V model ; Get the x-axis coordinate x0, y-axis coordinate y0, z-axis coordinate z0 and distance component w of V0, recorded as V0 = (x0, y0, z0, w); S3.1.1.
4. Divide the x-axis coordinate x0 of V0 by the distance component w to obtain x1, and divide the y-axis coordinate y0 of V0 by the distance component w to obtain y1. Then x1 and y1 form the two-dimensional coordinate point V1 corresponding to V0, denoted as V1 = (x1, y1); S3.1.1.
5. Perform viewport transformation on the two-dimensional coordinate V1 to obtain the screen coordinate V2 = (x2, y2) of the corresponding endpoint P1.
7. The method according to claim 6, characterized in that The step S3.1.1.5 comprises: S3.1.1.5.
1. Call the function through the OpenGL viewport matrix Glintviewport[4] glGetIntegerv(GL_VIEWPORT,viewport) gets the first value of the array viewport[0], the second value viewport[1], the third value viewport[2], and the fourth value viewport[3]; S3.1.1.5.
2. Calculate the screen coordinate V2 of endpoint P1 as follows:
8. The method according to claim 6, characterized in that The step S4 further comprises: S4.
1. Enter OpenGL selection mode and call gluPickMatrix function to obtain the selection matrix M pick ; S4.
2. Calculate the drawing matrix as follows: Plotting the matrix M draw =M pick* M projection ; S4.
3. By plotting the matrix M draw , draw in selection mode for all pre-selected contours.
9. The method according to claim 8, characterized in that The step S4 further comprises: S4.
4. Enter the rendering mode of OpenGL, call the API interface function glRenderMode, determine the successfully drawn contours among all the contours drawn in step S4.3 as having passed the reselection, and record the number and information of the contours that have passed the reselection, and analyze and determine the contours that are actually selected by the mouse.
10. The method according to any one of claims 1 to 9, characterized in that: The method for fast contour selection in laser tube cutting based on OpenGL three-dimensional simulation is applied to an industrial computer of a laser cutting system; the industrial computer includes a CPU and a GPU; step S3 is implemented by the CPU; and step S4 is implemented by the GPU.
Citation Information
Patent Citations
Method and system for drawing primitives based on OpenGL ES2.0
CN110543620A