Method for removing residual materials in numerical control machining

By reconstructing and indexing the CNC machining path, and combining blank pixelation and GPU parallel computing, an efficient secondary roughing path is generated, which solves the problem of low collision detection efficiency in the existing technology and achieves efficient and accurate removal of excess material.

CN121028680APending Publication Date: 2025-11-28SHANDONG GUOKE CNC TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511102195.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-07
Publication Date
2025-11-28

AI Technical Summary

Technical Problem

In existing CNC machining, the secondary roughing path planning is not optimized for the characteristics of the residual area, resulting in low collision detection efficiency and data redundancy, and making it impossible to quickly locate the corresponding layer path.

Method used

By inputting the roughing path and parameters into the CNC system, the path is reconstructed into polyline segments, a hierarchical index is established, and collision detection is performed by combining blank pixelation and GPU parallel computing to generate an efficient secondary roughing path.

Benefits of technology

It significantly improves the efficiency and precision of CNC machining, ensures accurate machining boundaries, reduces tool wear in finishing, and enhances the automation level and finished product quality of complex parts.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121028680A_ABST
    Figure CN121028680A_ABST
Patent Text Reader

Abstract

The invention discloses a method for removing residual materials in numerical control machining, and the method comprises the steps: firstly reconstructing a rough machining path, simplifying the rough machining path into a straight line segment broken line, and building a hierarchical index, so as to compress data and improve the subsequent processing efficiency; secondly, pixelating the blank to generate a multi-layer image, and identifying a machinable area and a processing residual area through a double-collision detection mechanism: firstly, judging a collision relationship between pixels and a model through a geometric algorithm, then projecting a coarse path as an envelope surface, and positioning the residual area through space operation; then corrosion, connected domain extraction and smoothing processing are carried out on the boundary of the machinable area, and two coarse contour lines are obtained; and finally, a cavity milling algorithm is adopted to fill a path in the residual area, and a conflict-free secondary rough machining path is generated through the steps of offset arc compensation, interference processing and the like. According to the scheme, through multi-dimensional optimization, the problems of excess material residues, low path planning efficiency and the like in secondary rough machining are systematically solved, and efficient and accurate machining of complex parts is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of CNC machining technology, and more specifically, to a method for removing residual material during CNC machining. Background Technology

[0002] Roughing is the first stage of CNC machining. It efficiently removes most of the excess material from the blank (typically 70%-90%), bringing the workpiece shape and dimensions closer to the finished product. Its core focus is rapid material removal, rather than precision or surface quality. Therefore, it utilizes high-power machine tools, large cutting volumes (high feed, large depth of cut), and specialized roughing tools (such as end mills and drills). Roughing tool design emphasizes chip removal and heat dissipation to maximize material removal rate (MRR) and shorten the overall machining cycle. The roughing tool undertakes the main cutting task; removing more material reduces wear on finishing tools, extends their lifespan, and lowers costs. After roughing, due to the large size of the roughing tool, uneven material may remain in narrow corners, deep cavities, or complex surfaces. In this case, a smaller roughing tool is used for a secondary roughing process (hereinafter referred to as second roughing) to further remove the remaining material, reducing tool wear during finishing and lowering tool wear costs. Existing coarse-path planning methods often directly adopt the simplified logic of coarse-path planning without optimizing for the characteristics of residual regions. For example, the reconstruction of coarse-path planning lacks a hierarchical indexing mechanism, which makes it impossible to quickly locate the corresponding layer path during collision detection, resulting in low computational efficiency and data redundancy. Summary of the Invention

[0003] This specification provides a method for removing residual material during CNC machining, thereby overcoming at least one technical problem existing in related technologies.

[0004] This specification provides a method for removing residual material during CNC machining, applied to the secondary roughing stage of a CNC machine tool. The method involves the following steps, interacting with the CNC system hardware, to remove the residual material:

[0005] S1. Input the primary roughing path and secondary roughing parameters from the CNC system. The parameters include tool type, cutting step distance, and residual amount threshold.

[0006] S2, First-stage roughing path reconstruction, specifically including:

[0007] S21. Path simplification and reconstruction, specifically including:

[0008] The roughing path is compressed into a set of straight line segments consisting of a start point and an end point, forming a polyline representation;

[0009] S22. Projection height annotation, specifically including:

[0010] Mark the vertical projection height value along the tool feed direction for each polyline segment, and the path height values ​​are the same for the same layer.

[0011] S23. Establish a hierarchical index, specifically including:

[0012] A layered index table is created based on the projection height value to enable layer path retrieval.

[0013] S3. Generate the secondary roughing contour path, specifically including:

[0014] S31. Blank pixelation, including: constructing a new coordinate system with the cutting direction as the z-axis, and discretizing the blank bounding box into an image of 256×256 pixels / layer;

[0015] S32. Performing dual collision detection based on GPU parallel computing, including:

[0016] a) Internal inspection of the blank:

[0017] i) For a cuboid blank, determine whether a pixel is inside the blank, including:

[0018] Calculate the pixel Q = (x, y, z) relative to the bottom left corner P of the blank. min =(x min ,y min ,z min Projected distances along each coordinate axis:

[0019]

[0020] Wherein, symbol P min The coordinates of the bottom left corner of the cuboid blank are represented by the symbol Q, and the coordinates of the pixel to be detected are represented by the symbol x. axis ,y axis ,z axis Represents the unit vector of the coordinate axes, symbol Indicates from coordinate P min A vector pointing to coordinate Q;

[0021] The judgment criteria include:

[0022] 0≤x proj ≤l

[0023] 0≤y proj ≤w

[0024] 0≤z proj ≤h

[0025] Wherein, the symbols l, w, and h represent the length, width, and height of the blank, respectively;

[0026] ii) For cylindrical blanks, determine whether a pixel is inside the blank, including:

[0027] Calculate the axial projection distance of pixel Q relative to the center point C = (x, y, z) at the bottom of the cylindrical blank: Where, symbol C represents the coordinates of the center point of the bottom of the cylindrical blank, symbol axis represents the unit vector along the cylinder axis, and symbol This represents the vector pointing from coordinate C to pixel Q;

[0028] If proj_dis < 0 or proj_dis > h, then

[0029] Calculate radial distance:

[0030]

[0031] Judgment conditions:

[0032] 0≤proj_dis≤h

[0033] r dis ≤r

[0034] Where h represents the height of the cylinder and r represents the radius of the cylinder;

[0035] b) Tool-model collision detection: The tool is abstracted as a cylinder or a combination of a cylinder and a sphere, and the collision is detected through the following steps:

[0036] i) Point detection:

[0037] First, determine the relationship between the height of the point and the height of the cylinder:

[0038]

[0039] Next, determine the distance from the point to the axis, D = |CP*sin(θ)|, where θ represents the angle between CP and the tool axis dir. Then, determine whether the point is inside the cylinder based on the following formula.

[0040]

[0041] ii) Line detection: Determine whether line segment PQ intersects with the cylindrical geometry of the tool, specifically including:

[0042] If the direction of the line segment is parallel to the axis of the tool, then when points P and Q are not inside the cylinder, they are determined not to intersect.

[0043] If the direction of the line segment is not parallel to the axis of the tool:

[0044] Calculate the vertical direction vector Then calculate the projected distance d from point CP to ver_dir. If d > R, then they do not intersect;

[0045] If d < R, calculate the normal vector N = dir × ver_dir, then calculate the nearest point from line segment PQ to the direction of the normal vector N, and determine whether the point is inside the cylinder;

[0046] iii) Surface inspection: Determine whether the cylindrical axis of the tool intersects with the triangular facet, specifically including:

[0047] Calculate the normal vector of the triangular facet:

[0048]

[0049] Wherein, symbols V1, V2, and V3 represent the coordinates of the three vertices of the triangular facet; symbols and Represents the edge vector of the triangular facet;

[0050] Calculate the intersection point foot of the tool axis and the plane containing the triangular facet:

[0051]

[0052] Calculate the centroid coordinates:

[0053]

[0054] If U>0, V>0, and U+V<1 are all satisfied, then it can be determined that point foot is inside the triangular facet, meaning the tool collides with the triangular facet; otherwise, there is no collision.

[0055] S33. For the erosion processing of the image after collision detection, a hybrid object labeling algorithm is used to extract the boundaries of connected components, and the extracted boundary point sequence is smoothed using an SG filter; wherein, the SG filter design matrix is ​​as follows:

[0056]

[0057] Wherein, the symbol p represents half the window width. The symbol N represents the window size and is an odd number; the symbol M represents the polynomial degree.

[0058] The smoothing value is calculated as a0 = W·b; where the symbol W represents the matrix (A T A) -1 A T The first row vector, and the symbol b represents the column vector formed by the coordinate sequence within the window;

[0059] S4. Generation of the path for the residual area in the secondary roughing process, specifically including:

[0060] S41, Path-Pixel Collision Detection:

[0061] S41. Path-pixel collision detection, specifically including:

[0062] S411. Reconstruct a coarse path layer by layer into a polyline segment containing only the start, end, and inflection points, obtain the number of layers of the coarse path and generate the corresponding number of second coarse pixel layers.

[0063] S412. For each layer of 256×256 pixel point P(x,y) and path segment L=AB, construct the two-dimensional projection of the envelope of L: with the tool radius R as the reference, generate a semicircle with points A and B as the center and a rectangle with the line connecting AB as the side.

[0064] S413. Calculate the distances from point P to A and B, d1 = |PA| and d2 = |PB|. If d1 ≤ R or d2 ≤ R, then it is determined that there is a collision with the semicircle.

[0065] S414. Calculate the dot product d3 of vectors AP and AB = dot(AP,AB). If 0 ≤ d3 ≤ |AB|, then calculate the distance d4 from point P to line segment AB. If d4 ≤ R, then determine that it is in collision with the rectangle.

[0066] S415. If P collides with any geometric shape, it is marked as "processed".

[0067] S42. Extract the boundary of the residual region, including:

[0068] S421. Integrate coarse path collision information with model collision information, and non-collision pixels constitute the remaining processable area.

[0069] S422. Use the 8-connected-part algorithm to extract the boundaries of connected parts;

[0070] S423. Perform erosion operation on the boundary image;

[0071] S424. Use an SG filter to smooth the boundary;

[0072] S43. Generate the cavity milling path, including:

[0073] S431. Divide the boundary of the residual region into an outer boundary counterclockwise polygon and an inner boundary clockwise polygon according to the inclusion relationship, and convert it into a polyline segment structure.

[0074] S432. Offset each line segment of the polygon in the counterclockwise normal direction along the tangent vector of the line segment;

[0075] S433, Filling the offset gap: Convex corner offsets supplement the positive arc, concave corner offsets supplement the reverse arc, forming the original offset chain;

[0076] S434. For each line segment in the original bias chain, calculate the strict intersection point based on the minimum bounding box and split the line segment.

[0077] S435. Set the initial interference index to 0, traverse the bias chain, and update the interference index according to the following rules:

[0078] When the tangent direction of the current line segment is the same as the offset normal of the intersecting line segment, the interference index is decreased by 1.

[0079] When the directions are opposite, the interference index increases by 1;

[0080] S436. Retain the split segment with the smallest interference index and merge them into a minimum bias ring that satisfies the following conditions:

[0081] A counterclockwise loop is not completely contained within any clockwise loop;

[0082] The clockwise loop is completely contained by at least one counterclockwise loop;

[0083] The minimum offset loop does not contain reverse circular arc segments and is not completely contained within the original inner boundary;

[0084] S437. Repeat S432-S436 until no new paths are generated, and output the cavity milling path for the remaining area.

[0085] S5. The CNC system processor merges the contour path generated in step S3 with the residual area cavity milling path generated in step S43 to generate a G-code file that conforms to the ISO standard. The file is then transmitted to the machine tool controller via the RS-232 interface to drive the tool to perform secondary roughing.

[0086] In some alternative implementations, the collision detection employs GPU parallel computing, which is implemented using OpenGL and stores pixel data and tool geometry parameters in memory blocks.

[0087] One embodiment of this specification can achieve at least the following beneficial effects:

[0088] The technical solution of this application significantly improves the efficiency and accuracy of CNC machining through multi-step collaborative optimization. A coarse path reconstruction simplifies complex trajectories into polylines and establishes a hierarchical index, reducing data volume while enabling rapid retrieval, laying an efficient foundation for subsequent processing. The combination of blank pixelation and a dual collision detection mechanism with GPU parallel computing can accurately identify the internal regions of the blank and the interference between the tool and the model, while also significantly shortening the collision detection time through parallel computation, solving the problem of low computational efficiency in traditional methods.

[0089] In the path generation stage, contour lines are smoothed through erosion, connected component extraction, and SG filtering to ensure precise machining boundaries. The cavity milling algorithm generates a second-coarse path with no overcutting and reasonable topology through polygon offset, arc filling, and interference index filtering, effectively removing residual material from the first-coarse path. This solution systematically integrates data processing, collision detection, and path planning, reducing tool wear in finishing and improving the automation level and finished product quality of complex parts machining, achieving efficient and precise material removal. Attached Figure Description

[0090] To more clearly illustrate the technical solutions in the embodiments or related technologies of this specification, the drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0091] Figure 1 A simplified flowchart illustrating the method for removing residual material during CNC machining, as provided in the embodiments of the present invention.

[0092] Figure 2 This is a simplified flowchart of the process for extracting and processing the contour of the residual material area during the secondary roughing of CNC machining. Detailed Implementation

[0093] The technical solutions in the embodiments of this specification will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0094] This invention provides a method for removing residual material during CNC machining. The following is a brief introduction to the relevant background of the technical solution of this invention. Roughing is the first stage of CNC machining, efficiently removing most of the excess material from the blank (typically 70%-90%), making the workpiece shape and size initially approach the finished product. Its core lies in rapid material removal, rather than precision or surface quality; therefore, high-power machine tools, large cutting volumes (high feed, large depth of cut), and dedicated roughing tools (such as end mills and drills) are used. The design of roughing tools emphasizes chip removal and heat dissipation to maximize the material removal rate (MRR) and shorten the overall machining cycle. The roughing tools undertake the main cutting task; roughing can remove more excess material, thus reducing the wear of finishing tools, extending their lifespan, and lowering costs. After roughing, due to the large size of the roughing tool, uneven material may remain in narrow corners, deep cavities, or complex curved surfaces. In this case, a second roughing process (hereinafter referred to as second roughing) is performed using a smaller roughing tool to further remove the remaining material, which can reduce tool wear during finishing and lower tool wear costs.

[0095] The technical solution of this application will be described below with reference to the accompanying drawings, in which... Figure 1 This is a simplified flowchart illustrating a method for removing residual material during CNC machining, provided by an embodiment of the present invention. The following section will first discuss this method in conjunction with... Figure 1 This paper provides a brief overview of the technical solution, followed by a detailed explanation of each step. First, the term "first roughing path" is explained. The first roughing path refers to the tool trajectory (including cutting start point, tool path, and cutting depth) generated during the first roughing operation; it serves as the "pre-processing record" for the second roughing operation. The second roughing parameters refer to the process settings for the second roughing operation, such as tool type (flat end mill / ball end mill), cutting step distance, residual material threshold, and safety height, guiding the algorithmic logic of the second roughing process. The first roughing path and the second roughing parameters, as the initial inputs to the entire process, are passed to the "first roughing path reconstruction," providing the raw data basis for subsequent processing.

[0096] The purpose of coarse path reconstruction is to optimize the original coarse path, which includes three steps: (1) Path simplification, that is, compressing the continuous and complex coarse path into straight line segments and reducing the amount of data. (2) Projection height labeling, that is, labeling the vertical projection height of each segment along the tool feed direction (such as the z-axis), and unifying the path height values ​​in the same layer for easy layered management. Establishing a layered index, that is, layering according to projection height and constructing an index table (such as the mapping of height values ​​to layer paths) to achieve "fast path retrieval by layer" and improve the efficiency of subsequent processing. The "coarse path reconstruction" step receives the coarse path and coarse parameters from the upstream "input" link, outputs the simplified + layered indexed path data, and passes it to the subsequent "skeleton pixelation" and "path and pixel collision detection" steps as the basis for subsequent judgment of the processed area.

[0097] The implementation of the blank pixelation step can be as follows: After obtaining the cuboid bounding box in the new coordinate system, it is directly divided into 256×256×layer pixel units, and the spacing of each pixel in the XYZ directions is calculated to generate voxel vertices; for cuboid and cylindrical blanks, they are first transformed to the cuboid bounding box in the new coordinate system and then discretized, and the pixelation method is the same for both. This step receives the layer height information (the layer logic guiding pixelation) from the "coarse path reconstruction" step, outputs the pixelated blank space data, and passes it to the subsequent "collision detection calculation" step (as the "spatial carrier" for collision judgment) and "path and pixel collision detection" step (as the basis for path interference judgment).

[0098] The collision detection process is divided into two categories to identify the interference risk between the tool and the workpiece. The first is internal workpiece detection. For cuboid workpieces, the projected distance of pixels is calculated, and the length and width boundaries are compared to determine if the workpiece is inside. For cylindrical workpieces, the radial distance of pixels (distance to the central axis) is calculated, and the radius is compared to determine if the workpiece is inside. The second is tool model collision detection, including point detection, line detection, and face detection. Point detection checks whether the vertices of triangular facets collide with geometric objects (spheres, cylinders). Line detection checks the edges of triangular facets, and face detection checks the entire triangular facet. This process can be accelerated by parallel computing using a GPU. GPU parallel computing is implemented using OpenGL, storing pixel data and tool geometry parameters in memory blocks. It simultaneously processes collisions between a large number of pixels and the tool, outputting "collision / no collision" flags. This step receives layered pixel data from the upstream step "workpiece pixelation" (as the spatial object for collision detection), outputs the collision detection results, and passes them to the subsequent "detecting machinable areas" step to filter "safely machinable pixel areas."

[0099] The step "Detect Machinable Area" is based on the results of the step "Calculate Collision Detection". It filters pixel areas that are collision-free and meet the machining conditions, i.e., it excludes pixels outside the blank and areas at risk of tool collision. At the same time, it combines roughing parameters (such as residual material threshold) to retain pixel areas that "have excess material and need to be removed" and marks them as "machinable areas". This step receives the collision mark data from the step "Calculate Collision Detection", outputs the pixel range of the machinable area, and passes it to the step "Machining Area Boundary as Contour Line" for extracting the machining contour.

[0100] The first step processes the pixel data of the "machinable region" using the boundary of the processing area as a contour line. This involves extracting the boundary, performing erosion, boundary extraction, and SG filtering for smoothing. Erosion is used to reduce the machinable region and eliminate edge burrs (similar to morphological operations in image processing). Boundary extraction identifies the contour edges of the pixel region, obtaining discrete boundary points. SG filtering smoothing uses an SG filter (with an odd window size N and a polynomial degree M ≥ 2) to process the boundary points, optimizing the contour curve and generating a continuous, smooth processing contour line. This step receives the pixel range data from the "Detecting the Machinable Region" step, outputs the smoothed processing contour line, and passes it to the "Second Roughing Processing Path" step as the boundary basis for path planning.

[0101] The step path and pixel collision detection are used to determine the interference between the envelope of a coarse path and the pixelated area of ​​the blank. Specifically, an envelope of the coarse path in the XY plane is constructed (since the cutting direction is the Z-axis, intersection along the Z-axis can be disregarded; only intersection detection in the XY direction with the envelope is required). This envelope is formed by the tool traversing the machining path and is represented in the XY plane as a geometric shape composed of hemispheres at both ends and a rectangle in the middle. Then, it detects whether pixels are within the envelope, marking "processed pixels" and "residual pixels" (areas not covered by the coarse path). This step receives the simplified path from the "coarse path reconstruction" step (used to construct the envelope) and the pixel data from the "blank pixelation" step (as the detection object), outputs residual pixel markers, and passes them to the "obtaining the machining residual area" step for accurate identification of the target residual material area in the second coarse path.

[0102] The first step obtains residual pixel markers from the machining residual region for integrating path and pixel collision detection, delineates continuous machining residual regions by performing connected component analysis on discrete residual pixels and merging adjacent residual pixels; then, using coarse parameters (such as the minimum residual area threshold), it filters out small invalid regions and outputs clear residual region boundaries. This step receives the residual pixel markers from the "path and pixel collision detection" step. It outputs continuous machining residual regions, which are then passed to the "fill region with cavity milling algorithm" step as the target range for path filling.

[0103] The first step uses a cavity milling algorithm to fill the region and plan the toolpath for the "machining residual area," including boundary offset, path filling, and interference detection and filtering. Boundary offset is used to offset the boundary of the residual area inward (distance = tool radius safety clearance), generating the toolpath at the tool center. In the path filling process, a positive arc transition is generated at convex corners to avoid overcutting; a reverse arc transition is generated at concave corners (ensuring complete cutting). In the interference detection and filtering step, the "interference index" is used to assess the risk of path conflicts, eliminating overcutting paths and retaining safe and feasible toolpaths. This step receives continuous residual area data from the "Obtaining Machining Residual Area" step. The filled toolpath segment is output and passed to the "Second Roughing Path" step for integration into the final trajectory.

[0104] Step 2, the roughing path, integrates the contour information from step "machining area boundary as contour line" and the tool path from step "filling area with cavity milling algorithm" to generate a complete second roughing trajectory. This trajectory includes complete process information such as cutting start point, tool path sequence, tool lift safety height, and cutting depth. The output conforms to the CNC system format, such as G-code or tool position file (CLSF), and can be directly used for machine tool processing.

[0105] In summary, the technical solution of this application is based on a coarse path and blank features. Through layered processing of pixel discretization → collision detection screening → contour extraction and path filling, it accurately identifies the residual material after the first roughing process and plans an efficient and overcut-free secondary roughing path.

[0106] The following provides a detailed explanation of the relevant content mentioned above. In this scheme, the CNC system first inputs the primary roughing path and secondary roughing parameters. These parameters may include tool type, cutting step distance, and residual material threshold. In this step, the CNC system acts as the starting point for data interaction, receiving two types of core information: first, the tool motion path data generated from the primary roughing, recording the spatial trajectory of the tool during roughing (including coordinates of each axis, feed direction, etc.); second, the secondary roughing process parameters, including the tool type determining the compatibility of the tool geometry model with collision detection, the cutting step distance relating machining efficiency and residual material density, and the residual material threshold defining whether secondary machining is required. This input information constitutes the initial data foundation for secondary roughing, providing a basis for subsequent collision detection, residual area identification, and path planning.

[0107] Based on the above, the following section introduces coarse path reorganization, which mainly includes three steps:

[0108] (1) Path simplification and reconstruction:

[0109] A coarse path is simplified into a polyline representation formed by straight line segments consisting of a start point and an end point, thus achieving a compressed representation of path data.

[0110] (2) Projection height annotation:

[0111] After the previous step, each path segment is now a straight line. Since a coarse path is also generated layer by layer according to the cutting direction, we can obtain the vertical projection height value of each path along the tool feed direction. Paths belonging to the same layer have the same projection height. Record the corresponding height and index.

[0112] (3) Hierarchical index creation:

[0113] Based on the recorded projection height and index, all segments of the first-layer path can be quickly obtained, which facilitates the subsequent generation of the second-coarse path by directly finding the first-coarse layer that performs collision detection with each pixel of the second-coarse layer.

[0114] Next, we will introduce the content of generating the coarse contour path. The contour path generation mainly includes: blank pixelation, collision detection, finding connected components, and then using the boundary of the connected components as the coarse path. The following will elaborate on each step.

[0115] First, let's explain the pixelation of the raw material:

[0116] First, the bounding box of the blank (cubic prism) is obtained. Then, the cutting direction is used as the z-axis to construct a new coordinate system. The eight vertices of the bounding box are transformed to the new coordinate system. Based on these eight points, the two corner points of the new bounding box are obtained, and a bounding box in the new coordinate system is constructed. Then, the number of layers is determined according to the downcut step distance. In each layer, a fixed image of size 256*256 pixels is generated.

[0117] Collision detection: Before performing collision detection on the pixels and model triangles obtained in the previous step, since the technical solution of this application is pixelated based on the generated bounding box, a step is first performed to determine whether the pixels are inside the blank. Since the blank is generally a cuboid or cylinder, this step is faster than the collision detection step, and the time required for collision detection can be shortened by this step.

[0118] The algorithm further performs collision detection between pixels and model triangular faces. The principle is to treat pixels as the contact points of cutting tools and generate different tool assemblies according to the tool type: flat-end tools are cylinders, ball-end tools are the union of cylinder and sphere, and round-end tools are two cylinders with different radii. Then, collision detection is performed between triangular faces and corresponding geometric primitives.

[0119] The algorithms above all perform GPU parallel computing to shorten computation time.

[0120] Pixel detection inside the blank:

[0121] (1) Rectangular blank:

[0122] Raw material data: bottom left corner point P min =(x min ,y min ,z min Axis data: z axis x axis Length, width, and height: l, w, h.

[0123] Pixel: Q = (x, y, z).

[0124] Obtain the y-axis based on the axis data: y axis calculate Projected distances to the three axes: x proj y proj z proj A point is considered to be within the blank only if the projected distance on each axis is in [0,l], [0,w], or [0,h].

[0125] (2) Cylindrical blank:

[0126] Blank data: Bottom center point C = (x, y, z), radius r, height h, axis.

[0127] Pixel: Q = (x, y, z). First calculate... If proj_dis < 0 or proj_dis > h, is_in_cylinder = true; otherwise, continue the calculation. The perpendicular distance r_dis to the axis is used to determine whether is_in_cylinder is false if proj_dis > r, and true otherwise.

[0128] Collision detection between geometric solids and triangular facets:

[0129] This application's technical solution abstracts different tool types into different geometric combinations. The main body of each tool is composed of a cylinder. For the tool tip, flat-end tools are not considered, ball-end tools use a sphere, and ring tools use a cylinder with a smaller radius at the bottom. Collision detection between the tool and pixels involves detecting the corresponding geometry between the cylinder of the tool body and the tool tip.

[0130] The detection process consists of three stages: point detection, line detection, and surface detection. Collisions are checked sequentially, and a value is returned immediately upon a collision.

[0131] Cylinder: bottom center C, axis direction dir, radius R, height H.

[0132] Point detection:

[0133] Directly determine whether point P is inside the cylinder.

[0134] First, determine the relationship between the height of the point and the height of the cylinder:

[0135]

[0136] Next, the technical solution of this application determines the distance from the point to the axis, D = |CP * sin(θ)|, where θ is the angle between CP and dir:

[0137]

[0138] Line detection:

[0139] Mainly by finding the closest point from the line PQ to the cylinder.

[0140] If PQ || dir, then according to the fact that the vertex is not inside the cylinder in the previous step, then PQ is not inside the cylinder either.

[0141] Otherwise, calculate ver_dir = cross(dir, PQ), then calculate the projection distance d from CP to ver_dir. If d > R, then they do not intersect.

[0142] If d < R, then calculate N = cross(dir, ver_dir), then calculate the closest point from the PQ segment to N, and similarly determine whether the point is inside the cylinder.

[0143] Plane detection:

[0144] For the three vertices V1, V2, V3 of the triangular patch, the tool center C, the axial dir, and the height H, first calculate the normal of the triangular patch, E1 = V1V2, E2 = V1V3, the normal N = Cross(E1, E2), then calculate the intersection point foot of the tool center axis and the plane where the triangular patch is located.

[0145] Then calculate the vector Vec = foot - V1;

[0146] Calculate the coordinates of Vec under E1 and E2:

[0147] det = dot(E1, E1) * dot(E2, E2) - dot(E1, E2) * dot(E1, E2);

[0148]

[0149] Then if U > 0, V > 0, and U + V < 1 are all satisfied, then it can be determined that the point foot is inside the triangular patch, that is, the tool and the triangular patch collide; otherwise, they do not collide.

[0150] Connected domain algorithm:

[0151] After completing the collision detection in the previous stage, the technical solution of this application has determined the collision area and the processable area for each layer. Now, the technical solution of this application will find the connected domains of the processing area in each layer and extract the inner and outer boundaries of the connected domains of the processing area.

[0152] Connectivity definition: If there exists a path (a1 = p, a = q) between two target pixels p and q, and adjacent pixels in the path are each other's 8-neighbors (or 4-neighbors), then they are said to be 8-connected (or 4-connected). The technical solution of this application adopts 8-connectivity.

[0153] A connected component is a maximal set of pixels in an image that satisfies the condition that any two pixels are connected.

[0154] The algorithm first takes a 256x256 image as input. To prevent overcutting, the proposed solution performs an erosion operation on the input image, which reduces the processing area by one level. Then, the Hybrid Object Labeling (HOL) algorithm is used to group the input image by row and process it in parallel. A global atomic counter is used to manage the label numbers and record the connectivity between adjacent pixels in the rows. Equivalent labels are first labeled independently and then merged. After calling the HOL algorithm, the boundary points of the connected components of the image layer are obtained. Finally, the boundary points are traversed and connected to form boundary lines. Then, the boundary lines are spliced ​​and truncated to extract the closed boundaries.

[0155] Due to pixelation, the boundaries extracted by the technical solution of this application will appear jagged and not smooth enough. Therefore, the technical solution of this application uses the SG filter method to smooth the boundaries.

[0156] Among them, SG filtering (Savitzky-Golay filtering) is a data smoothing method based on local polynomial least squares fitting. This method performs polynomial fitting within a sliding window on the input, calculating the smoothing value at the window's center point, thereby effectively suppressing noise while preserving the high-frequency characteristics of the signal. The window size N is required to be an odd number, ensuring that each point is selected to the left and right. For each point, assuming the polynomial degree is M, then for each point, fit an M-degree polynomial y = a0 + a1x + ... + a... M x M To improve computational efficiency, the technical solution of this application performs SG filtering on each coordinate of the boundary point. This only requires calculating the convolution matrix once, because the technical solution of this application treats each coordinate of the boundary point as a set of signals, and their horizontal coordinates are all considered to be from -p to p.

[0157] Design matrix:

[0158] The fitted equation is: AX = b, where X are the polynomial coefficients and b is the signal value. Then, using least squares, X = (A T A) -1 A T b, for a window only the center point is changed, so only a0, i.e. X[0], is needed. Therefore, the technical solution of this application only needs to calculate (A T A) -1 A T The first row of data is denoted as W. Subsequent smoothing operations can directly use W. The smoothed signal is then a0 = Wb.

[0159] The following describes the generation of paths for the residual areas in the second roughing process. In the previous section, the generated outline was mainly used to clean up the residual material near the model. In this step, the technical solution of this application detects the residual areas that were not processed in the first roughing process and generates paths for the second roughing process for these areas.

[0160] First, in the previous step, the technical solution of this application has obtained the area information that the tool used for the second roughing can process without considering the first roughing path. Next, the technical solution of this application adds the path information of the first roughing to the processing area information of the second roughing. That is, if a pixel collides with the path of the first roughing, it is considered that the pixel has been processed.

[0161] Similarly, the technical solution of this application considers the collision between a layer of pixels and the path of the first coarse processing. Since the path of the first coarse processing is also generated layer by layer, the technical solution of this application only needs to consider the path of each layer of pixels and the first layer below it for analysis, and thus only needs to analyze the collision between points and paths in two dimensions.

[0162] The technical solution of this application pre-reconstructs a path layer, where each path is a polyline segment containing only the start, end, and inflection points. Collision detection is performed by checking if a point is within the path's envelope. For a straight line segment, the path generates an envelope of two semicircles and a rectangle; therefore, it is only necessary to check if the corresponding pixel is within these three geometric shapes. First, the number of layers in the coarse path is obtained, and then the corresponding number of collision detection results for the second-coarse pixel layers are generated. Then, for each second-coarse pixel layer, the collision information of the underlying coarse path layer is searched, and path collision information is assigned to the second-coarse pixel layer.

[0163] Path and pixel collision detection:

[0164] Considering the collision detection of a single-layer path, there is a pixel layer of 256*256. Since the pixel layer and the path layer have the same normal direction, in the technical solution of this application, the collision information can be calculated on the projection plane, thus transforming it into a two-dimensional level. For pixel information P(x,y), for a path segment L = AB, in the technical solution of this application, only the envelope formed by the tool passing through L needs to be calculated, the two-dimensional projection of the envelope is obtained, and then it is calculated whether P is inside the projection of the envelope. For example, for a flat-bottom cutter, when the tool passes through L, the projection of the envelope is the circle passing through points A and B and the rectangle between AB. Assume the tool radius is R;

[0165] In the technical solution of this application, calculate d1 = |PA| and d2 = |PB|. If d1 > R, then the point does not collide with the sphere at point A. Similarly, check the sphere at point B,

[0166] Then check the middle rectangle. Calculate d3 = dot(AP, AB). If d3 < 0 or d3 > |AB|, then the point is not inside the rectangle. Otherwise, continue to calculate d4 as the distance from P to AB. If d4 < R, then the point is inside the cuboid.

[0167] In the technical solution of this application, as long as it is determined that the point P is inside any geometric figure, it can be determined that the point collides with the path.

[0168] After obtaining the collision information between the pixel points and the first rough machining, combine it with the initial model collision information; the remaining pixel points that have not collided are the remaining machinable ones. Then, the technical solution of this application continues to call the connected component algorithm to obtain the boundary of the remaining area, and then uses the cavity milling algorithm to generate a path for the remaining area.

[0169] The content of the cavity milling algorithm is elaborated in detail below:

[0170] For the obtained contour line point sequence, divide the inner and outer boundaries according to the inclusion relationship. The inner boundary must be completely contained within the outer boundary.

[0171] Furthermore, the inner and outer boundary data points are converted into polyline segment data, making the inner and outer boundaries a polygonal structure. The outer boundary is set as a counterclockwise polygon, and the inner boundary as a clockwise polygon. In this step, converting the inner and outer boundary data points into polyline segment data means connecting the discrete point series of the inner and outer boundaries within the residual region extracted by the connected component algorithm in sequence with straight line segments to form a polygonal structure. This approximates the potentially continuous curve boundary as a polygon composed of multiple straight line segments, facilitating subsequent geometric operations such as offsetting and arc filling. The division of the inner and outer boundaries is based on inclusion relationships; the inner boundary must be completely contained within the outer boundary. Setting the outer boundary as a counterclockwise polygon and the inner boundary as a clockwise polygon is to unify the topological direction of the boundaries, ensuring that subsequent counterclockwise normal offset operations along the tangent vector of the line segment can consistently extend outward or inward, avoiding intersections or interference in the offset paths due to directional confusion. This directional setting also conforms to the conventional planning logic of tool paths in CNC machining, making it easier to distinguish the inner and outer ranges of the machining area, ensuring that the tool moves in a unified direction during machining, and reducing path conflicts.

[0172] Furthermore, each line segment of the polygon is offset once along the counterclockwise normal direction of its tangent vector. In this step, offsetting each line segment of the polygon along the counterclockwise normal direction of its tangent vector means, for the inner and outer boundary polygons (outer boundary is a counterclockwise polygon, inner boundary is a clockwise polygon) that have been converted into polyline data, determining the tangent vector direction for each line segment, and then taking a counterclockwise normal direction perpendicular to this tangent vector and pointing outwards from the polygon (outwards for a counterclockwise outer boundary, inwards for a clockwise inner boundary), moving the line segment a certain distance along this direction to form a new line segment; the purpose of this operation is to generate a new line segment that maintains the characteristics of the original boundary through a unified offset direction. The offset lines at fixed distances prepare for subsequent gap filling and construction of the original offset chain. The uniformity of the offset direction (based on the counterclockwise normal of the line segment tangent vector) can avoid the intersection or overlap of the line segments after offset due to confusion in direction. At the same time, the topology setting of counterclockwise outer boundary and clockwise inner boundary ensures that the offset path can accurately surround the remaining machinable area. This provides the basis for subsequent steps such as constructing arc segments to fill the gaps at convex and concave corners (convex corners are filled with positive arcs, and concave corners are filled with reverse arcs) and calculating strict intersection points, and finally realizes the generation of conflict-free secondary roughing path.

[0173] Furthermore, for the aforementioned first-order offset line, the gaps created by the offset between the broken line segments can be filled by constructing arc segments to obtain the original offset chain; specifically, for convex angle offsets, positive arcs are added; for concave angle offsets, reverse arcs are added. A positive arc is one where the tangent vectors at the start and end points of the arc are in the same direction as the tangent vectors of the two adjacent line segments, while a reverse arc is in the opposite direction. In this step, the offset line obtained by offsetting once along the counterclockwise normal direction of the tangent vector of the line segment is formed because the original polygon is composed of broken line segments. At the corners of adjacent broken line segments, the offset line segments will produce discontinuous gaps due to changes in direction. In order to eliminate these gaps and form a continuous path basis, it is necessary to fill the gaps by constructing arc segments, and finally form the original offset chain. Among them, when the corner is a convex angle (i.e. the angle between two adjacent broken line segments is less than 180 degrees), the gaps generated after offset are filled by supplementing positive arcs. When the corner is a concave angle (i.e. the angle between two adjacent broken line segments is greater than 180 degrees), the gaps generated after offset are filled by supplementing reverse arcs. The characteristic of a positive arc is that the tangent vectors of its starting and ending points are consistent with the tangent vectors of the two adjacent broken line segments. The characteristic of a reverse arc is that the tangent vectors of its starting and ending points are opposite to the tangent vectors of the two adjacent broken line segments.

[0174] Furthermore, for each straight line segment or arc segment in the original bias chain, based on the minimum bounding box, potentially intersecting line segments are obtained, and strict intersection points (i.e., intersection points that strictly pass through the line segments, excluding the endpoints) are calculated. This is explained in detail below. First, for each straight line segment or arc segment in the original bias chain, its minimum bounding box (the smallest rectangular area that completely contains the line segment or arc segment) is calculated. By comparing whether the minimum bounding boxes of different line segments or arc segments overlap, potentially intersecting line segments or arc segments are quickly filtered out, thereby reducing unnecessary intersection detection calculations. For the filtered potentially intersecting line segments or arc segments, their intersection points are further precisely calculated. Strict intersection points refer to intersection points that truly pass through the solid part of the line segment or arc segment, excluding contact or coincidence points at the endpoints. The purpose of this step is to provide accurate geometric basis for subsequent operations such as splitting line segments based on intersection points and calculating interference indices, ensuring the accuracy of subsequent path processing.

[0175] Furthermore, based on the intersection points of the line segments, the line segments are divided into multiple segments. In this step, dividing the line segments into multiple segments based on the intersection points refers to segmenting the intersecting line segments or arc segments involved in the intersection process, which are determined after strict intersection point calculation in the original bias chain, excluding the endpoints of the line segments. That is, the originally continuous line segments are broken at each strict intersection point to form multiple independent sub-segments that do not intersect. The purpose of this operation is to decompose the line segments that may have path conflicts due to intersections into units that can be analyzed separately, so that the subsequent interference index calculation can accurately correspond to each sub-segment, avoiding index calculation errors caused by the overall intersection of line segments. At the same time, it provides a basis for selecting the split segments with the smallest interference index and merging them to form conflict-free minimum bias loops, ensuring that the split sub-segments do not overlap spatially and have clear boundaries, which facilitates subsequent path optimization and integration according to rules.

[0176] Furthermore, the interference index of the initial segment of the original bias chain is set to 0. The bias chain is traversed sequentially. Each time a strict intersection point is crossed, the interference flag of the intersection segment at that point is counted, added to the current interference index, the interference index is updated, and marked on the segment. The calculation rule for the interference flag is as follows: if the tangent direction of the current line segment and the bias normal vector at the intersection point of the intersecting line segment are the same, the value is decreased by 1; if they are opposite, the value is increased by 1. If there are multiple intersecting segments at the same intersection point, they are accumulated separately according to the rule. The following is a detailed explanation of this content. In this content, the interference index of the initial segment in the original bias chain after splitting is set to 0. Then, the bias chain is traversed sequentially. Whenever a strict intersection point (i.e., an intersection point that strictly passes through the line segments except for the endpoints) is reached, the interference flags of all intersecting segments at that intersection point are counted. These interference flags are added to the interference index of the currently occupied line segment to obtain the updated interference index, which is then marked on the current line segment. The calculation of the interference flags follows these rules: For the current line segment and an intersecting line segment at their intersection point, if the tangent direction of the current line segment is the same as the bias normal vector direction at the intersection point, the interference flag of that intersecting segment is -1; if the directions are opposite, the interference flag is +1. If multiple intersecting segments exist at the same intersection point, the interference flag of each intersecting segment must be calculated separately according to the above rules and accumulated.

[0177] Furthermore, for the original bias chain marked above, only the segments with the smallest interference index are retained, and these segments are merged into one or more minimum bias loops based on distance and angle relationships. This will be explained in detail below. In this process, for the original bias chain with marked interference indices, only those segments with the smallest interference index values ​​are retained from all the segments obtained after splitting. This is because segments with smaller interference indices are less likely to interfere with other segments, making them more suitable as the basis for subsequent paths. Then, based on the spatial distance (i.e., whether the straight-line distance between the endpoints of the segments is close enough to meet the continuity requirements of the path connection) and angle relationships (i.e., whether the angle between the tangent directions of adjacent segments meets the conditions for a smooth path transition), the segments with continuous connections are sequentially connected to form one or more closed loop structures, i.e., minimum bias loops. These loops are the basic units constituting the secondary roughing path, laying the foundation for the subsequent generation of conflict-free processing paths.

[0178] Furthermore, each minimum offset ring should satisfy the following conditions: a counterclockwise minimum ring cannot be completely contained by any clockwise minimum ring; a clockwise minimum ring should be completely contained by at least one counterclockwise minimum ring; a minimum offset ring cannot contain a reverse circular arc segment; and a minimum offset ring cannot be completely contained by any original inner boundary. The following is a detailed explanation of this content. Each minimum offset loop must satisfy four topological and geometric constraints: First, the counter-clockwise minimum loop, acting as the outer boundary loop, cannot be completely covered by any clockwise minimum loop (inner boundary loop) to ensure the outer boundary completely surrounds the processing area. Second, the clockwise minimum loop, acting as the inner boundary loop, must be completely surrounded by at least one counter-clockwise minimum loop to ensure the inner boundary is always within the processing area defined by the outer boundary. Third, the minimum offset loop cannot contain reverse circular arc segments, as the starting and ending tangent vectors of the reverse circular arc are opposite in direction to the tangent vectors of adjacent line segments, which may lead to path turning conflicts and affect processing continuity. Fourth, the minimum offset loop cannot be completely contained by any original inner boundary to avoid the generated processing path being limited to the original inner boundary range, ensuring sufficient coverage of the residual material area.

[0179] Furthermore, the smallest loop that satisfies all the above conditions is the new bias path. This will be explained in detail below. The smallest bias path that satisfies all the above conditions (i.e., the counter-clockwise smallest loop is not completely contained by any clockwise smallest loop, the clockwise smallest loop is completely contained by at least one counter-clockwise smallest loop, it does not contain reverse arc segments, and it is not completely contained by any original inner boundary) can be used as a new bias path because it guarantees the correct nesting relationship between inner and outer boundaries in its topological structure, avoids path conflicts caused by reverse arcs in its geometric shape, and can fully cover the residual material area without being limited to the original inner boundary range. This path can guide the movement trajectory of the secondary roughing tool, ensuring that when the tool processes along this path, it can effectively remove residual material while avoiding interference with the already processed area or the model itself, thus guaranteeing the safety and effectiveness of the processing.

[0180] Furthermore, repeat the above steps until no new offset paths are generated, at which point the offsetting process ends. The following is a detailed explanation of this process: repeating the above steps refers to repeatedly performing the following series of operations: offsetting each line segment of the polygon counterclockwise along the tangent vector; filling the offset gaps with constructed arc segments to form the original offset chain; calculating strict intersection points and splitting the line segments; statistically updating the interference index by calculating the interference markers; retaining the smallest split segment with the smallest interference index and merging them into the smallest offset cycle that satisfies the topological constraints; and using the minimum cycle that meets the conditions as the new offset path. Through repeated execution, new offset paths are continuously generated until no new offset paths can be generated during a certain repetition, at which point the offsetting process ends. This ensures that the secondary roughing path can fully cover the residual material area, completing the removal of residual material.

[0181] Finally, the CNC system processor can merge the generated contour path used to define the boundary of the machining area with the cavity milling path planned for the residual material area. The trajectory data of the two are integrated by the algorithm to generate a G-code file that conforms to the ISO international standard (the file contains machining instructions such as tool movement trajectory, feed rate, and cutting parameters). The G-code is transmitted to the machine tool controller via the RS-232 serial communication interface. After the machine tool controller parses the code, it coordinates the movement of each axis, the spindle speed, etc., and drives the tool to perform a second roughing operation according to the merged path. This efficiently removes the uneven material remaining after the first roughing operation, laying the foundation for subsequent finishing.

[0182] like Figure 2 As shown, Figure 2This is a simplified flowchart of the contour extraction and processing of residual material areas in the secondary roughing of CNC machining, showing the following core steps from collision information analysis to machining contour line generation: (1) Collision information: Identify the spatial distribution of residual material through pixelation detection (top left color image, yellow represents the residual material area). (2) Machining area boundary: Extract the initial boundary of the residual material (top right red box + circle, distinguishing the inner and outer ranges of the residual material); (3) Smooth boundary: Smooth the initial boundary (bottom left regular boundary, eliminating jagged edges and optimizing topology); (4) Contour line result: Finally generate a machining contour that can be used for CNC programming (bottom right curved trajectory, reflecting the process application).

[0183] The technical solution presented in this application significantly improves the efficiency and accuracy of CNC machining through multi-step collaborative optimization. Specifically, a coarse path reconstruction simplifies complex trajectories into polylines and establishes a hierarchical index, reducing data volume while enabling rapid retrieval and laying a high-efficiency foundation for subsequent processing. The combination of blank pixelation and a dual collision detection mechanism with GPU parallel computing accurately identifies the internal regions of the blank and the interference between the tool and the model, while also significantly shortening collision detection time through parallel computation, thus solving the problem of low computational efficiency in traditional methods.

[0184] In the path generation stage, contour lines are smoothed through erosion, connected component extraction, and SG filtering to ensure precise machining boundaries. The cavity milling algorithm generates a second-coarse path with no overcutting and reasonable topology through polygon offset, arc filling, and interference index filtering, effectively removing residual material from the first-coarse path. This solution systematically integrates data processing, collision detection, and path planning, reducing tool wear in finishing and improving the automation level and finished product quality of complex parts machining, achieving efficient and precise material removal.

[0185] It should be noted that the terms "comprising" and "having," and any variations thereof, in the embodiments and drawings of this specification are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the steps or units listed, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or devices.

[0186] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for removing residual material during CNC machining, applied to the secondary roughing stage of a CNC machine tool, characterized in that, The following steps are used to interact with the CNC system hardware to remove excess material: S1. Input the primary roughing path and secondary roughing parameters from the CNC system. The parameters include tool type, cutting step distance, and residual amount threshold. S2, First-stage roughing path reconstruction, specifically including: S21. Path simplification and reconstruction, specifically including: The roughing path is compressed into a set of straight line segments consisting of a start point and an end point, forming a polyline representation; S22. Projection height annotation, specifically including: Mark the vertical projection height value along the tool feed direction for each polyline segment, and the path height values ​​are the same for the same layer. S23. Establish a hierarchical index, specifically including: A layered index table is created based on the projection height value to enable layer path retrieval. S3. Generate the secondary roughing contour path, specifically including: S31. Blank pixelation, including: constructing a new coordinate system with the cutting direction as the z-axis, and discretizing the blank bounding box into an image of 256×256 pixels / layer; S32. Performing dual collision detection based on GPU parallel computing, including: a) Internal inspection of the blank: i) For a cuboid blank, determine whether a pixel is inside the blank, including: Calculate the pixel Q = (x, y, z) relative to the bottom left corner P of the blank. min =(x min ,y min ,z min Projected distances along each coordinate axis: Wherein, symbol P min The coordinates of the bottom left corner of the cuboid blank are represented by the symbol Q, and the coordinates of the pixel to be detected are represented by the symbol x. axis ,y axis ,z axis Represents the unit vector of the coordinate axes, symbol Indicates from coordinate P min A vector pointing to coordinate Q; The judgment criteria include: 0≤x proj ≤l 0≤y proj ≤w 0≤z proj ≤h Wherein, the symbols l, w, and h represent the length, width, and height of the blank, respectively; ii) For cylindrical blanks, determine whether a pixel is inside the blank, including: Calculate the axial projection distance of pixel Q relative to the center point C = (x, y, z) at the bottom of the cylindrical blank: Where, symbol C represents the coordinates of the center point of the bottom of the cylindrical blank, symbol axis represents the unit vector along the cylinder axis, and symbol This represents the vector pointing from coordinate C to pixel Q; If proj_dis < 0 or proj_dis > h, then Calculate radial distance: Judgment conditions: 0≤proj_dis≤h r dis ≤r Where h represents the height of the cylinder and r represents the radius of the cylinder; b) Tool-model collision detection: The tool is abstracted as a cylinder or a combination of a cylinder and a sphere, and the collision is detected through the following steps: i) Point detection: First, determine the relationship between the height of the point and the height of the cylinder: Next, determine the distance from the point to the axis, D = |CP*sin(θ)|, where θ represents the angle between CP and the tool axis dir. Then, determine whether the point is inside the cylinder based on the following formula. ii) Line detection: Determine whether line segment PQ intersects with the cylindrical geometry of the tool, specifically including: If the direction of the line segment is parallel to the axis of the tool, then when points P and Q are not inside the cylinder, they are determined not to intersect. If the direction of the line segment is not parallel to the axis of the tool: Calculate the vertical direction vector Then calculate the projected distance d from point CP to ver_dir. If d > R, then they do not intersect; If d < R, calculate the normal vector N = dir × ver_dir, then calculate the nearest point from line segment PQ to the direction of the normal vector N, and determine whether the point is inside the cylinder; iii) Surface inspection: Determine whether the cylindrical axis of the tool intersects with the triangular facet, specifically including: Calculate the normal vector of the triangular facet: Wherein, symbols V1, V2, and V3 represent the coordinates of the three vertices of the triangular facet; symbols and Represents the edge vector of the triangular facet; Calculate the intersection point foot of the tool axis and the plane containing the triangular facet: Calculate the centroid coordinates: If U>0, V>0, and U+V<1 are all satisfied, then it can be determined that point foot is inside the triangular facet, meaning the tool collides with the triangular facet; otherwise, there is no collision. S33. For the erosion processing of the image after collision detection, a hybrid object labeling algorithm is used to extract the boundaries of connected components, and the extracted boundary point sequence is smoothed using an SG filter; wherein, the SG filter design matrix is ​​as follows: Wherein, the symbol p represents half the window width. The symbol N represents the window size and is an odd number; the symbol M represents the polynomial degree. The smoothing value is calculated as a0 = W·b; where the symbol W represents the matrix (A T A) -1 A T The first row vector, and the symbol b represents the column vector formed by the coordinate sequence within the window; S4. Generation of the path for the residual area in the secondary roughing process, specifically including: S41, Path-Pixel Collision Detection: S41. Path-pixel collision detection, specifically including: S411. Reconstruct a coarse path layer by layer into a polyline segment containing only the start, end, and inflection points, obtain the number of layers of the coarse path and generate the corresponding number of second coarse pixel layers. S412. For each layer of 256×256 pixel point P(x,y) and path segment L=AB, construct the two-dimensional projection of the envelope of L: with the tool radius R as the reference, generate a semicircle with points A and B as the center and a rectangle with the line connecting AB as the side. S413. Calculate the distances from point P to A and B, d1 = |PA| and d2 = |PB|. If d1 ≤ R or d2 ≤ R, then it is determined that there is a collision with the semicircle. S414. Calculate the dot product d3 of vectors AP and AB = dot(AP,AB). If 0≤d3≤|AB|, then calculate the distance d4 from point P to line segment AB. If d4≤R, then determine that it is in collision with the rectangle. S415. If P collides with any geometric shape, it is marked as "processed". S42. Extract the boundary of the residual region, including: S421. Integrate coarse path collision information with model collision information, and non-collision pixels constitute the remaining processable area. S422. Use the 8-connected-part algorithm to extract the boundaries of connected parts; S423. Perform erosion operation on the boundary image; S424. Use an SG filter to smooth the boundary; S43. Generate the cavity milling path, including: S431. Divide the boundary of the residual region into an outer boundary counterclockwise polygon and an inner boundary clockwise polygon according to the inclusion relationship, and convert it into a polyline segment structure. S432. Offset each line segment of the polygon in the counterclockwise normal direction along the tangent vector of the line segment; S433, Filling the offset gap: Convex corner offsets supplement the positive arc, concave corner offsets supplement the reverse arc, forming the original offset chain; S434. For each line segment in the original bias chain, calculate the strict intersection point based on the minimum bounding box and split the line segment. S435. Set the initial interference index to 0, traverse the bias chain, and update the interference index according to the following rules: When the tangent direction of the current line segment is the same as the offset normal of the intersecting line segment, the interference index is decreased by 1. When the directions are opposite, the interference index increases by 1; S436. Retain the split segment with the smallest interference index and merge them into a minimum bias ring that satisfies the following conditions: A counterclockwise loop is not completely contained within any clockwise loop; The clockwise loop is completely contained by at least one counterclockwise loop; The minimum offset loop does not contain reverse circular arc segments and is not completely contained within the original inner boundary; S437, Repeat S432-S436 until no new paths are generated, and output the cavity milling path for the remaining area. S5. The CNC system processor merges the contour path generated in step S3 with the residual area cavity milling path generated in step S43 to generate a G-code file that conforms to the ISO standard. The file is then transmitted to the machine tool controller via the RS-232 interface to drive the tool to perform secondary roughing.

2. The method for removing residual material in CNC machining according to claim 1, characterized in that, The collision detection employs GPU parallel computing, which is implemented using OpenGL. Pixel data and tool geometry parameters are stored in memory blocks.