Vertex filtering method and system based on OpenGL
Through the OpenGL-based vertex filtering method, linear fitting filtering is used to process vertices, which solves the problem of excessive data volume of CNC machine tools, effectively release of memory and image integrity, improves processing quality and saves costs.
Patent Information
- Application Number
- CN202411714388.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-27
- Publication Date
- 2025-03-21
AI Technical Summary
The amount of trajectory data generated by the CNC machine tool interpolator during the precision machining process is too large, resulting in too much memory usage of the system and lag. The traditional solution limits the number of data or increases hardware memory, resulting in incomplete images or increased hardware costs.
The vertex filtering method based on OpenGL is used to process the vertices in the same line through line fitting filtering, and the vertices in the middle of the line are deleted, reducing the number of vertices and freeing up memory space.
It effectively reduces the number of vertices, frees up memory space, ensures that the feature points of the image are not lost, ensures the integrity of the image, improves the processing quality, and does not need to clean the drawn trajectory or upgrade the hardware, saving production costs.
Smart Images

Figure CN119668843A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of numerical control machining, and in particular to a vertex filtering method and system based on OpenGL. Background Art
[0002] As the products processed by CNC machine tools become more and more complex, the data generated by CNC machine tool interpolators is increasing. Since CNC machine tool interpolators need to record a large amount of trajectory data to draw tool path trajectories during precision machining, when drawing more detailed images, excessive trajectory data will cause excessive system memory usage and jamming. The traditional solution is to limit the upper limit of the amount of data. When the data reaches the set upper limit, the previous trajectory is automatically cleared. This method will result in the inability to retain more feature points, and the drawn image will be incomplete. Alternatively, the method of increasing hardware memory and video memory will lead to increased hardware costs. Summary of the invention
[0003] In view of the above problems, the present disclosure proposes a vertex filtering method and system based on OpenGL.
[0004] In order to solve at least one of the above technical problems, the present disclosure proposes the following technical solutions:
[0005] In a first aspect, a vertex filtering method based on OpenGL is provided, comprising the following steps:
[0006] Step 1: Determine whether the current number of vertices meets the filtering conditions. If the current number of vertices meets the filtering conditions, execute step 2;
[0007] Step 2: Record the subscripts of all current vertices to form a subscript list;
[0008] Step 3: Read the vertex and determine whether the subscript of the currently read vertex is less than the maximum subscript in the subscript list. If so, execute step 4; if not, execute step 7.
[0009] Step 4: Add the vertices read in step 3 to the vertex list to be filtered, and return to step 3 until the number of vertices in the vertex list meets the preset maximum value, and then execute step 5;
[0010] Step 5: Perform straight line fitting filtering on the vertices in the vertex list;
[0011] Step 6: Return to step 3;
[0012] Step 7: Determine whether all vertices in the vertex list have been subjected to straight line fitting filtering. If so, execute step 8; if not, execute step 9;
[0013] Step 8: Filtering is completed;
[0014] Step 9: Wait for new vertices to be stored and return to step 1.
[0015] In a second aspect, a vertex filtering system based on OpenGL is provided, which is used to execute any of the above-mentioned vertex filtering methods based on OpenGL, and the system comprises:
[0016] Vertex cache, used to cache vertices;
[0017] Vertex subscript judgment module, used to judge whether the current vertex subscript is in the subscript list;
[0018] A filter condition judgment module is used to judge whether the number of vertices in the vertex cache meets the filter condition;
[0019] The straight line fitting filtering module is used to perform straight line fitting filtering on the vertices in the vertex list.
[0020] In a third aspect, a numerical control device is provided, which includes at least one processor and a memory communicatively connected to the at least one processor, wherein the memory stores at least one instruction, at least one program, code set or instruction set, and the at least one instruction, at least one program, code set or instruction set is loaded by the processor and executes any of the above-mentioned OpenGL-based vertex filtering methods disclosed herein.
[0021] In a fourth aspect, a computer-readable storage medium is provided, in which at least one instruction, at least one program, code set or instruction set is stored, and the at least one instruction, at least one program, code set or instruction set is loaded by a processor and executed by any of the above-mentioned OpenGL-based vertex filtering methods disclosed herein.
[0022] The beneficial effect of the present invention is that by filtering the vertices in the same straight line by means of straight line fitting and deleting the vertices in the middle of the straight line, memory space can be effectively released, and the feature points of the image are not lost, the integrity of the image is guaranteed, and the processing quality is guaranteed. At the same time, there is no need to upgrade the hardware, thus saving production costs.
[0023] In addition, in the technical solution disclosed in the present invention, unless otherwise specified, the technical solution can be implemented by adopting conventional means in the art. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the specific embodiments of the present disclosure or the technical solutions in the prior art, the drawings required for use in the specific embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0025] Figure 1 A flowchart of a vertex filtering method based on OpenGL is provided for one embodiment of the present disclosure. DETAILED DESCRIPTION
[0026] In order to make the purpose, technical solutions and advantages of the present disclosure more clearly understood, the present disclosure is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are part of the embodiments of the present disclosure, rather than all of the embodiments, and are only used to explain the present disclosure, and are not used to limit the present disclosure. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present disclosure.
[0027] It should be noted that the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or server that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units that are not explicitly listed or are inherent to these processes, methods, products or devices.
[0028] Embodiment 1:
[0029] Reference Manual Attached Figure 1 , shows an OpenGL-based vertex filtering method provided by an embodiment of the present application.
[0030] The vertex filtering method based on OpenGL may specifically include the following steps:
[0031] Step 1: Determine whether the current number of vertices meets the filtering conditions. If the current number of vertices meets the filtering conditions, execute step 2;
[0032] Step 2: Record the subscripts of all current vertices to form a subscript list;
[0033] Step 3: Read the vertex and determine whether the subscript of the currently read vertex is less than the maximum subscript in the subscript list. If so, execute step 4; if not, execute step 7.
[0034] Step 4: Add the vertices read in step 3 to the vertex list to be filtered, and return to step 3 until the number of vertices in the vertex list meets the preset maximum value, and then execute step 5;
[0035] Step 5: Perform straight line fitting filtering on the vertices in the vertex list;
[0036] Step 6: Return to step 3;
[0037] Step 7: Determine whether all vertices in the vertex list have been subjected to straight line fitting filtering. If so, execute step 8; if not, execute step 9;
[0038] Step 8: Filtering is completed;
[0039] Step 9: Wait for new vertices to be stored and return to step 1.
[0040] In the CNC system, the vertex data generated by the interpolator will be sent to the simulator, and the vertex data in the simulator will be written into the GPU's video memory. The GPU will draw a trajectory image based on the vertex data in the video memory and display it on the HMI.
[0041] In step 1, determining whether the current number of vertices meets the filtering condition may specifically refer to determining whether the number of vertices in the current simulator meets the filtering condition. The filtering condition may be that the number of vertices accumulated in the simulator exceeds a preset vertex upper limit. In this embodiment, the preset vertex upper limit is set to 1000.
[0042] The vertices in the simulator are marked with consecutive vertex subscripts according to the order in which they are written. The vertex subscripts can indicate the vertex order and distinguish the vertices. If this is the first filtering, the number of vertices in the simulator is obtained directly according to the vertex subscripts currently stored in the simulator. If this is not the first filtering, the subscript of the last vertex at the end of the last filtering and the vertex subscript currently stored in the simulator are obtained, and the difference between the two subscripts is calculated to see if it is greater than 999. If it is greater than 999, it means that the accumulated number of vertices in the simulator is greater than 1000. If it is not greater than 999, it means that the accumulated number of vertices in the simulator is not greater than 1000, and it is necessary to wait for the interpolator to store new vertices.
[0043] In step 2, the subscripts of all current vertices are recorded to form a subscript list. At this time, the number of vertices in the simulator is greater than 1000, and filtering needs to be started. It should be understood that the vertices stored in the simulator by the interpolator may not be stored one by one, but in batches. Therefore, the number of vertices in the simulator may not be exactly 1001. In this embodiment, it is assumed that the number of vertex subscripts recorded in step 2 is 1050.
[0044] Steps 3 and 4 are the process of obtaining a vertex list. Even during vertex filtering, the interpolator may continue to store vertices in the simulator. However, continuously filtering the subsequently stored vertices in one filtering will require higher performance from the computing module, which is contrary to the requirement of not upgrading the hardware device to be achieved in this application. Therefore, in step 3, the subscript of the read vertex is judged to determine whether the currently read vertex has been recorded in step 2. If so, it participates in this filtering. If not, it does not participate in this filtering, ensuring that the vertices participating in this filtering are all vertices recorded in step 2. On the one hand, it reduces the computing pressure, and on the other hand, it ensures the filtering effect, making the trajectory drawn by the filtered vertices more complete.
[0045] Assuming that the vertex subscripts recorded in step 2 are 1 to 1050, the last vertex subscript stored in the vertex list is 1050. In this embodiment, the maximum number of vertices in the pre-set vertex list is 250. Therefore, the vertices are read in sequence according to the vertex subscripts, and when the number of vertices in the vertex list is 250, step 5 can be executed.
[0046] In step 5, performing straight line fitting filtering on the vertices in the vertex list includes:
[0047] Step 5.1: Assign the initial value of the current index i to 2;
[0048] Step 5.2: Determine whether the number of vertices in the current vertex list is not less than 3. If it is not less than 3, execute step 5.3; if it is less than 3, execute step 5.8;
[0049] Step 5.3: Determine whether the last set of vertices in the current vertex list has been filtered. If so, execute step 5.8; if not, execute step 5.4;
[0050] Step 5.4: Determine whether the vertices corresponding to i, i-1 and i-2 belong to the same curve type. If so, execute step 5.5; if not, execute step 5.6;
[0051] Step 5.5: Determine whether the vertices corresponding to i, i-1 and i-2 are collinear. If so, execute step 5.7; if not, execute step 5.6.
[0052] Step 5.6: Let i=i+1, and return to step 5.2;
[0053] Step 5.7: Remove the vertex corresponding to i-1, update the vertex list, and return to execute 5.2;
[0054] Step 5.8: Filtering is completed and the vertex list is updated.
[0055] Assume that the vertex subscripts in the vertex list are 1-250 at this time. In step 5.1, the current index i is initialized to 2. At this time, the subscript corresponding to index i is 3.
[0056] Since it is assumed that the filtering has just started, the number of vertices in the vertex list is still 250, and the first group of vertices is about to be filtered. Therefore, step 5.4 is executed, that is, whether the three vertices with subscripts 1, 2 and 3 belong to the same curve type. If not, all three vertices are retained, and continue to determine whether the three vertices corresponding to subscripts 2, 3 and 4 belong to the same curve type.
[0057] If the three vertices 1, 2, and 3 belong to the same curve type, you need to continue to determine whether the three vertices are collinear. If they are collinear, remove the vertex corresponding to subscript 2. If they are not collinear, keep all three vertices.
[0058] When the three vertices with subscripts 1, 2, and 3 are collinear, after removing the vertex corresponding to subscript 2, the vertex list needs to be updated. At this time, the number of vertices in the list is 249, namely subscripts 1, 3, 4, ..., 250. When the index i is 2, the corresponding subscript becomes 4. At this time, it is necessary to determine whether subscripts 1, 3, and 4 belong to the same curve type and are collinear.
[0059] Therefore, with three vertices as a group, step 5.2 to step 5.7 are executed repeatedly until two situations occur, ending the filtering of the current vertex list. One is that the number of vertices in the current vertex list is less than 3, that is, the vertices from subscript 1 to subscript 250 are all collinear. At this time, the number of vertices in the vertex list is generally 2, namely the first vertex and the last vertex in the current vertex list; the other is that although the number of vertices in the vertex list is greater than 3, the last group of vertices has also been judged, indicating that all vertices that can be removed in the current vertex list have been removed.
[0060] After the current vertex list is filtered, the subscripts of the vertices in the list remain unchanged, but because vertices have been removed, the positions of the remaining vertices in the vertex list have changed. The vertex list needs to be updated and the value of the current index i needs to be recorded. In subsequent steps, even if new vertices are added to the vertex list, the value of index i can indicate which vertices have been filtered. After the new vertices are added, they only need to be processed according to the value of index i. This ensures that no repeated operations are performed, improves computing efficiency, and saves computing resources.
[0061] Assume that in the vertex list formed by the vertices with subscripts 1-250, there are 60 vertices left, and at this time, index i=59, and it is necessary to continue reading vertices and add them to the vertex list, that is, return to execute step 3 until the number of points in the vertex list reaches 250. In actual production, there is generally no situation where 250 consecutive vertices are not collinear, so this application does not consider this extreme case.
[0062] After step 5.8, you can also include,
[0063] Determine whether the number of vertices in the current vertex list is equal to the maximum value of the vertices in the vertex list. If so, execute step 8; if not, return to execute step 3.
[0064] As the filtering progresses, the number of vertices left in the vertex list will increase. It may happen that not all vertices recorded in the subscript list have been filtered, but the number of vertices left in the vertex list has reached the maximum value in the vertex list. At this time, the filtering can be ended, and the vertices in the current vertex list are written into the GPU's video memory and displayed in the HMI. The remaining vertices that have not been filtered return to execute step 1. If the number of vertices that have not been filtered exceeds the preset vertex upper limit, or the sum of the number of vertices that have not been filtered and the number of newly stored vertices exceeds the preset vertex upper limit, a new round of filtering can be restarted, that is, steps 2 to 9. If the number of vertices that have not been filtered does not exceed the preset vertex upper limit, or the sum of the number of vertices that have not been filtered and the number of newly stored vertices does not exceed the preset vertex upper limit, wait for new vertices to be stored until the filtering conditions are met and a new round of filtering begins.
[0065] If, during the process of reading vertices, the subscript of the vertex currently being read is not in the subscript list, that is, the vertex currently being read is a vertex newly stored after the filtering starts, it is necessary to determine whether all the vertices in the vertex list have been subjected to the linear fitting filtering process, that is, step 7. If so, the filtering can be ended at this time, and the vertices in the current vertex list are written to the GPU's video memory and displayed in the HMI. If not, since vertices are still being read at this time, it means that there are less than 250 vertices in the current vertex list, and there are still vertices in the vertex list that have not been filtered, then the vertices in the current vertex list can be added to the next round of filtering, that is, waiting for new vertices to be stored. After the new vertices are stored and the cumulative number of vertices triggers the filtering condition, continue to execute steps 2 to 9. At this time, the initial value of index i in step 5.1 is not set to 2, but is set to the index i value at the end of the last filtering in the previous round of filtering.
[0066] In an optional embodiment, the preset vertex upper limit value is four times the maximum number of vertices in the vertex list. For example, in the present application, the preset vertex upper limit value is 1000, and the maximum number of vertices in the vertex list is 250. Thus, according to the setting of the preset vertex upper limit value and the maximum number of vertices in the vertex list, the number of vertices can be effectively reduced, so that the number of vertices finally retained is about 25% of the original number of vertices.
[0067] The beneficial effect of the present invention is that the vertices in the same straight line are filtered by straight line fitting, the vertices in the middle of the straight line are deleted, and a complete image can be drawn using a small number of vertices, which effectively releases memory space and ensures that the feature points of the image are not lost, thereby ensuring the integrity of the image and thus ensuring the processing quality. There is no need to clean up the drawn tracks and no need to upgrade the hardware, thus saving production costs and improving user experience.
[0068] Embodiment 2:
[0069] The present application also provides an OpenGL-based vertex filtering system for executing any of the aforementioned OpenGL-based vertex filtering methods, including:
[0070] Vertex cache, used to cache vertices;
[0071] Vertex subscript judgment module, used to judge whether the current vertex subscript is in the subscript list;
[0072] A filter condition judgment module is used to judge whether the number of vertices in the vertex cache meets the filter condition;
[0073] The straight line fitting filtering module is used to perform straight line fitting filtering on the vertices in the vertex list. In an optional embodiment, in the merging condition judgment module 103, the preset merging condition is that the total length of the motion instruction segment in the cache is not less than twice the radius compensation amount.
[0074] In an optional embodiment, the filtering condition is that the cumulative number of vertices exceeds a preset vertex upper limit.
[0075] In an optional embodiment, the preset vertex upper limit value is four times the maximum number of vertices in the vertex list.
[0076] The beneficial effect of the present invention is that the vertices in the same straight line are filtered by straight line fitting, the vertices in the middle of the straight line are deleted, and a complete image can be drawn using a small number of vertices, which effectively releases memory space and ensures that the feature points of the image are not lost, thereby ensuring the integrity of the image and thus ensuring the processing quality. There is no need to clean up the drawn tracks and no need to upgrade the hardware, thus saving production costs and improving user experience.
[0077] The system provided in the above embodiment, when realizing its functions, is only illustrated by the division of the above functional modules. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the system and method embodiments provided in the above embodiment belong to the same concept, and the specific implementation process is detailed in the method embodiment, which will not be repeated here.
[0078] Embodiment 3:
[0079] The present application provides a numerical control device, which includes:
[0080] One or more processors and memory.
[0081] The numerical control device may also include: an input device and an output device.
[0082] As a non-volatile computer-readable storage medium, the memory can be used to store non-volatile software programs, non-volatile computer executable programs and modules, such as the program instructions / modules corresponding to the OpenGL-based vertex filtering method in the embodiment of the present application. The processor executes various functional applications and data processing of the server by running the non-volatile software programs, instructions and modules stored in the memory, that is, the OpenGL-based vertex filtering method in the above method embodiment is implemented.
[0083] The memory may include a program storage area and a data storage area, wherein the program storage area may store an operating system and applications required by at least one function; the data storage area may store data created according to the use of an OpenGL-based vertex filtering system, etc. In addition, the memory may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory may optionally include a memory remotely arranged relative to the processor, and these remote memories may be connected to the OpenGL-based vertex filtering system via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0084] The input device can receive input digital or character information and generate signal input related to user settings and function control. The output device can include display devices such as display screens.
[0085] One or more modules are located in the memory, and when executed by one or more processors, perform the OpenGL-based vertex filtering method in any of the above method embodiments.
[0086] The above device can execute the method provided in the embodiment of the present application, and has the functional modules and beneficial effects corresponding to the execution method. For technical details not described in detail in this embodiment, please refer to the method provided in the embodiment of the present application.
[0087] Embodiment 4:
[0088] On the other hand, embodiment 4 of the present disclosure provides a computer-readable storage medium, which stores one or more programs including execution instructions. The execution instructions can be read and executed by a device (including but not limited to a computer, a server or a network device, etc.) to execute the relevant steps in the above method embodiments.
[0089] The embodiments described above are merely illustrative, wherein the units or modules described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, and may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art may understand and implement it without creative effort.
[0090] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, or of course by hardware. Based on this understanding, the above technical solution, in essence or in other words, the part that contributes to the prior art, can be expressed in the form of a software product, which can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which may be a personal computer, a server or a network device, etc.) to execute the methods of each embodiment or some parts of the embodiment.
[0091] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present disclosure, rather than to limit them. Although the present disclosure has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not make the corresponding technical solutions essentially deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure.
Claims
1. The vertex filtering method based on OpenGL is characterized by: include: Step 1: Determine whether the current number of vertices meets the filtering conditions. If the current number of vertices meets the filtering conditions, execute step 2; Step 2: Record the subscripts of all current vertices to form a subscript list; Step 3: Read the vertex and determine whether the subscript of the currently read vertex is less than the maximum subscript in the subscript list. If so, execute step 4; if not, execute step 7. Step 4: Add the vertices read in step 3 to the vertex list to be filtered, and return to step 3 until the number of vertices in the vertex list meets the preset maximum value, and then execute step 5; Step 5: Perform straight line fitting filtering on the vertices in the vertex list; Step 6: Return to step 3; Step 7: Determine whether all vertices in the vertex list have been subjected to straight line fitting filtering. If so, execute step 8; if not, execute step 9; Step 8: Filtering is completed; Step 9: Wait for new vertices to be stored and return to step 1.
2. The OpenGL-based vertex filtering method according to claim 1, characterized in that: In step 1, the filtering condition is that the cumulative number of vertices exceeds a preset vertex upper limit.
3. The vertex filtering method based on OpenGL according to claim 1, characterized in that: In step 5, performing straight line fitting filtering on the vertices in the vertex list includes: Step 5.1: Assign the initial value of the current index i to 2; Step 5.2: Determine whether the number of vertices in the current vertex list is not less than 3. If it is not less than 3, execute step 5.3; if it is less than 3, execute step 5.8; Step 5.3: Determine whether the last set of vertices in the current vertex list has been filtered. If so, execute step 5.8; if not, execute step 5.4; Step 5.4: Determine whether the vertices corresponding to i, i-1 and i-2 belong to the same curve type. If so, execute step 5.5; if not, execute step 5.6; Step 5.5: Determine whether the vertices corresponding to i, i-1 and i-2 are collinear. If so, execute step 5.7; if not, execute step 5.6; Step 5.6: Let i=i+1, and return to step 5.2; Step 5.7: Remove the vertex corresponding to i-1, update the vertex list, and return to execute 5.2; Step 5.8: Filtering is completed and the vertex list is updated.
4. The OpenGL-based vertex filtering method according to claim 1, characterized in that: The preset vertex cap value is four times the maximum number of vertices in the vertex list.
5. An OpenGL-based vertex filtering system, used to execute the OpenGL-based vertex filtering method according to any one of claims 1 to 4, characterized in that: include, Vertex cache, used to cache vertices; Vertex subscript judgment module, used to judge whether the current vertex subscript is in the subscript list; A filter condition judgment module is used to judge whether the number of vertices in the vertex cache meets the filter condition; The straight line fitting filtering module is used to perform straight line fitting filtering on the vertices in the vertex list.
6. The OpenGL-based vertex filtering system according to claim 5, characterized in that: The filtering condition is that the cumulative number of vertices exceeds the preset vertex upper limit.
7. The OpenGL-based vertex filtering system according to claim 6, characterized in that: The preset vertex cap value is four times the maximum number of vertices in the vertex list.
8. A numerical control device, characterized in that: The numerical control device includes a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the OpenGL-based vertex filtering method as described in any one of claims 1-4.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the OpenGL-based vertex filtering method described in any one of claims 1-4.